LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2009, 12:43 AM   #1
Mr_Nuke
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Rep: Reputation: 3
Looking for linux equivalent of __cpuid() intrinsic (porting from Visual Studio)


Hi,

I'm trying to make a program I wrote under Windows / Visual Studio / Intel C++ cross-platform compatible with Linux / NetBeans / Intel C++. I got most of the headaches and sleepless nights out of the way, but I'm still looking on a way to get CPU information with the __cpuid() intrinsic, or whatever method is simple to use and uses CPUID.

My main concern is making it work for 64-bit compilation, but 32-bit compatibility would be a nice perk as well.

Is there anything that jumps into your mind right away?

Thanks in advance!
 
Old 02-23-2009, 04:03 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
Here, let me google that for you.
 
Old 02-23-2009, 10:06 AM   #3
Mr_Nuke
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by wje_lq View Post
Here, let me google that for you.

I don't need sarcasm. I already googled that a dozen times before posting. Google is not my friend here.
 
Old 02-23-2009, 12:10 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
Quote:
I don't need sarcasm.
Good, because I wasn't giving you any.
Quote:
Google is not my friend here.
That's up to you. But google wants to be your friend. When I followed the very link I gave you, the eighth entry on the results screen points to a place where you can download source code which uses the CPUID instruction and displays what it gets back.

You could have done that yourself. We're here to answer questions that google results can't.
 
Old 02-23-2009, 12:54 PM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by Mr_Nuke View Post
I don't need sarcasm.
Quote:
Originally Posted by wje_lq View Post
Good, because I wasn't giving you any.
As an unbiased (I think) observer, I'd like to take the OP's side here (but see comment at end of post). "let me google that for you" is a cute tool and in many forum threads it is a perfect answer, but:

Quote:
the eighth entry on the results screen points to a place where you can
I expect the OP is a lot happier with that answer. He might be even happier with

http://www.ka9q.net/code/cpuid/

Sometimes the google results take some expertise to use. The eighth entry !!? I clicked on a few of those entries, including the eighth and it wasn't obvious whether any one of them was a right or wrong place to start digging for this answer.

With the eighth one it wasn't all that obvious how to get the source code. (The link I just posted is the source code).

Quote:
Originally Posted by Mr_Nuke View Post
My main concern is making it work for 64-bit compilation,
I can't tell quickly whether that source code meets that concern. I didn't notice anything about that on the pages leading to the source code.

Mr_Nuke, I hope wje_lq's second answer and/or my clarifications help you.

wje_lq, once you went to the trouble of doing the google for him and apparently verifying that one of the results (the eighth) seems to be useful, it would have been nice to copy that link into your post.

I think a bare "let me google that for you" is appropriate only when any twit can spot the good results from the first page of google results. I almost know the material of this question myself and I couldn't spot the good results.

Mr_Nuke, I'd also like to refer you to my opposite take on a similar situation at
http://www.linuxquestions.org/questi...55#post3448655
When you are the one asking for help, you would be well advised to be more polite than the people offering help.

Last edited by johnsfine; 02-23-2009 at 02:18 PM.
 
Old 02-23-2009, 03:22 PM   #6
Mr_Nuke
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 3
johnsfine,

Thanks for your answer. I did happen to come across the code on the "8th listing, but wasn't able to compile that.

Intel is my friend:
http://software.intel.com/en-us/arti...udio-net-2005/

I was able to get that to compile under Windows, and I'll try it in Linux once I get home.
 
Old 02-23-2009, 03:32 PM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by Mr_Nuke View Post
Thanks for your answer. I did happen to come across the code on the "8th listing, but wasn't able to compile that.
I wasn't sure whether it would compile for 64 bit.

Maybe I can find some time later to try it myself. I think once I see the compile error messages I would know what to fix.

Not this time.

That code is very Windows specific. You are moving away from anything you might port to Linux, not toward it.
 
Old 02-23-2009, 03:55 PM   #8
Mr_Nuke
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by johnsfine View Post
That code is very Windows specific. You are moving away from anything you might port to Linux, not toward it.
I got rid of the Windows-specific stuff by defining DWORD and ULONGULONG, and no longer need "windows.h". I'll let you know if I can find a linux assembler and get it to work under Fedora.
 
Old 02-23-2009, 04:56 PM   #9
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by Mr_Nuke View Post
Thanks for your answer. I did happen to come across the code on the "8th listing, but wasn't able to compile that.
What did you try for compiling that and what went wrong?

I tried
Code:
gcc cpuid.c
on a 64-bit Linux system, and it just works. No problem.
 
Old 02-23-2009, 08:45 PM   #10
Mr_Nuke
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by johnsfine View Post
What did you try for compiling that and what went wrong?

I tried
Code:
gcc cpuid.c
on a 64-bit Linux system, and it just works. No problem.
I haven't tried that. I just copied the source into a new source file, and the Intel C++ compiler complained... I can't remember what about.

I was able to define my own intrinsic using the asm in cpuid.c as an example, so I got it working. Thanks for pointing me in the right direction.
 
Old 02-24-2009, 05:40 PM   #11
Mr_Nuke
LQ Newbie
 
Registered: Feb 2009
Posts: 13

Original Poster
Rep: Reputation: 3
Alright, here's my little cross-platform CPUID library, in case anyone stumbles upon this thread.
Attached Files
File Type: txt CPUID.cpp.txt (577 Bytes, 496 views)
File Type: txt CpuID.h.txt (2.9 KB, 317 views)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Studio.NET in Linux RySk8er30 Linux - Software 3 05-27-2009 04:11 PM
Stupid Question: Microsoft Visual Studio 6.0 (A.K.A. Visual Basic 6) Will it run? S0RD3N Linux - Software 8 05-07-2008 08:42 PM
MS Visual Studio .NET in Linux? cootetom Linux - Software 1 03-03-2007 03:04 PM
Problems when porting code from C++ under visual studio 6 to linux. Stor_G Programming 3 08-26-2004 07:19 AM
Is Visual Studio in Linux??? rob99 Linux - Software 6 01-22-2003 04:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration