#include #include typedef uint32_t u32; struct cpuid { u32 ebx; u32 edx; u32 ecx; u32 eax; }; static inline __attribute__((const)) struct cpuid cpuid(u32 leaf, u32 subleaf) { struct cpuid rv; asm("cpuid" : "=a" (rv.eax), "=c" (rv.ecx), "=d" (rv.edx), "=b" (rv.ebx) : "a" (leaf), "c" (subleaf)); return rv; } static inline __attribute__((const)) u32 cpuid_eax(u32 leaf, u32 subleaf) { struct cpuid rv = cpuid(leaf, subleaf); return rv.eax; } static inline __attribute__((const)) u32 cpuid_ecx(u32 leaf, u32 subleaf) { struct cpuid rv = cpuid(leaf, subleaf); return rv.ecx; } static inline __attribute__((const)) u32 cpuid_edx(u32 leaf, u32 subleaf) { struct cpuid rv = cpuid(leaf, subleaf); return rv.edx; } static inline __attribute__((const)) u32 cpuid_ebx(u32 leaf, u32 subleaf) { struct cpuid rv = cpuid(leaf, subleaf); return rv.ebx; } u32 eax(u32 leaf, u32 subleaf) { return cpuid_eax(leaf, subleaf); } struct cpuid _cpuid(u32 leaf, u32 subleaf) { return cpuid(leaf, subleaf); } int test_cpuid(void) { int found = 0; found += !!(cpuid_edx(1, 0) & (1 << 26)); /* SSE2 */ found += !!(cpuid_ecx(1, 0) & (1 << 0)); /* SSE3 */ found += !!(cpuid(1, 0).ecx & (1 << 9)); /* SSSE3 */ return found; }