Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intrinsics for CPUID like informations?

Considering that I'm coding in C++, if possible, I would like to use an Intrinsics-like solution to read useful informations about the hardware, my concerns/considerations are:

  • I don't know assembly that well, it will be a considerable investment just to get this kind of informations ( altough it looks like CPU it's just about flipping values and reading registers. )
  • there at least 2 popular syntax for asm ( Intel and AT&T ), so it's fragmented
  • strangely enough Intrinsics are more popular and supported than asm code this days
  • not all the the compilers that are in my radar right now support inline asm, MSVC 64 bit is one; I'm afraid that I will find other similar flaws while digging more into the feature sets of the different compilers that I have to use.
  • considering the trand I think that is more productive for me to bet on Intrinsics, it should be also way more easy than any asm code.

And the last question that I have to answer to is: how to do a similar thing with intrinsics ? Because I haven't found nothing other than CPUID opcodes to get this kind of informations at all.

like image 255
user2485710 Avatar asked Jul 20 '13 03:07

user2485710


1 Answers

After some digging I have found a useful built-in functions that is gcc specific.

The only problem is that this kind of functions are really limited ( basically you have only 2 functions, 1 for the CPU "name" and 1 for the set of registers )

an example is

#include <stdio.h>

int main()
{
    if (__builtin_cpu_supports("mmx")) {
        printf("\nI got MMX !\n");
    } else
        printf("\nWhat ? MMX ? What is that ?\n");
    return (0);
}

and apparently this built-in functions work under mingw-w64 too.

like image 158
user2485710 Avatar answered Sep 21 '22 15:09

user2485710