LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Looking for linux equivalent of __cpuid() intrinsic (porting from Visual Studio) (https://www.linuxquestions.org/questions/programming-9/looking-for-linux-equivalent-of-__cpuid-intrinsic-porting-from-visual-studio-706742/)

Mr_Nuke 02-23-2009 12:43 AM

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!

wje_lq 02-23-2009 04:03 AM

Here, let me google that for you.

Mr_Nuke 02-23-2009 10:06 AM

Quote:

Originally Posted by wje_lq (Post 3454138)
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.

wje_lq 02-23-2009 12:10 PM

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.

johnsfine 02-23-2009 12:54 PM

Quote:

Originally Posted by Mr_Nuke (Post 3454464)
I don't need sarcasm.

Quote:

Originally Posted by wje_lq (Post 3454596)
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 (Post 3454018)
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.

Mr_Nuke 02-23-2009 03:22 PM

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.

johnsfine 02-23-2009 03:32 PM

Quote:

Originally Posted by Mr_Nuke (Post 3454838)
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.

Mr_Nuke 02-23-2009 03:55 PM

Quote:

Originally Posted by johnsfine (Post 3454849)
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.

johnsfine 02-23-2009 04:56 PM

Quote:

Originally Posted by Mr_Nuke (Post 3454838)
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.

Mr_Nuke 02-23-2009 08:45 PM

Quote:

Originally Posted by johnsfine (Post 3454946)
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.

Mr_Nuke 02-24-2009 05:40 PM

2 Attachment(s)
Alright, here's my little cross-platform CPUID library, in case anyone stumbles upon this thread.


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