Intrinsics for CPUID like informations?

后端 未结 5 1706
夕颜
夕颜 2020-11-29 10:12

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

5条回答
  •  野性不改
    2020-11-29 10:40

    Gcc includes a cpuid interface:

    http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/i386/cpuid.h

    These don't seem to be well documented, but example usage can be found here:

    http://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=gcc/config/i386/driver-i386.c

    Note that you must use __cpuid_count() and not __cpuid() when the initial value of ecx matters, such as with avx/avx2 detection.

    As user2485710 pointed out, gcc can do all the cpu feature detection work for you. As of gcc 4.8.1, the full list of features supported by __builtin_cpu_supports() is: cmov, mmx, popcnt, sse, sse2, sse3, ssse3, sse4.1, sse4.2, avx and avx2.

提交回复
热议问题