11 #ifndef __DSL_OS_VERSION__
12 #define __DSL_OS_VERSION__
20 #define __real_cpuid __cpuid
23 DSL_API
void DSL_CC linux_cpuid(
int cpuInfo[4],
int function_id);
24 #define __real_cpuid linux_cpuid
36 DSL_API
const char * DSL_CC GetOSVersion();
37 DSL_API
bool DSL_CC Is64Bit();
39 #if defined(DSL_HAVE_CPUID) || defined(DOXYGEN_SKIP)
41 class DSL_API_CLASS InstructionSet
44 class InstructionSet_Internal;
48 static std::string Vendor(
void) {
return CPU_Rep.vendor_; }
49 static std::string Brand(
void) {
return CPU_Rep.brand_; }
51 static bool SSE3(
void) {
return CPU_Rep.f_1_ECX_[0]; }
52 static bool PCLMULQDQ(
void) {
return CPU_Rep.f_1_ECX_[1]; }
53 static bool MONITOR(
void) {
return CPU_Rep.f_1_ECX_[3]; }
54 static bool SSSE3(
void) {
return CPU_Rep.f_1_ECX_[9]; }
55 static bool FMA(
void) {
return CPU_Rep.f_1_ECX_[12]; }
56 static bool CMPXCHG16B(
void) {
return CPU_Rep.f_1_ECX_[13]; }
57 static bool SSE41(
void) {
return CPU_Rep.f_1_ECX_[19]; }
58 static bool SSE42(
void) {
return CPU_Rep.f_1_ECX_[20]; }
59 static bool MOVBE(
void) {
return CPU_Rep.f_1_ECX_[22]; }
60 static bool POPCNT(
void) {
return CPU_Rep.f_1_ECX_[23]; }
61 static bool AES(
void) {
return CPU_Rep.f_1_ECX_[25]; }
62 static bool XSAVE(
void) {
return CPU_Rep.f_1_ECX_[26]; }
63 static bool OSXSAVE(
void) {
return CPU_Rep.f_1_ECX_[27]; }
64 static bool AVX(
void) {
return CPU_Rep.f_1_ECX_[28]; }
65 static bool F16C(
void) {
return CPU_Rep.f_1_ECX_[29]; }
66 static bool RDRAND(
void) {
return CPU_Rep.f_1_ECX_[30]; }
68 static bool MSR(
void) {
return CPU_Rep.f_1_EDX_[5]; }
69 static bool CX8(
void) {
return CPU_Rep.f_1_EDX_[8]; }
70 static bool SEP(
void) {
return CPU_Rep.f_1_EDX_[11]; }
71 static bool CMOV(
void) {
return CPU_Rep.f_1_EDX_[15]; }
72 static bool CLFSH(
void) {
return CPU_Rep.f_1_EDX_[19]; }
73 static bool MMX(
void) {
return CPU_Rep.f_1_EDX_[23]; }
74 static bool FXSR(
void) {
return CPU_Rep.f_1_EDX_[24]; }
75 static bool SSE(
void) {
return CPU_Rep.f_1_EDX_[25]; }
76 static bool SSE2(
void) {
return CPU_Rep.f_1_EDX_[26]; }
78 static bool FSGSBASE(
void) {
return CPU_Rep.f_7_EBX_[0]; }
79 static bool BMI1(
void) {
return CPU_Rep.f_7_EBX_[3]; }
80 static bool HLE(
void) {
return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[4]; }
81 static bool AVX2(
void) {
return CPU_Rep.f_7_EBX_[5]; }
82 static bool BMI2(
void) {
return CPU_Rep.f_7_EBX_[8]; }
83 static bool ERMS(
void) {
return CPU_Rep.f_7_EBX_[9]; }
84 static bool INVPCID(
void) {
return CPU_Rep.f_7_EBX_[10]; }
85 static bool RTM(
void) {
return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[11]; }
86 static bool AVX512F(
void) {
return CPU_Rep.f_7_EBX_[16]; }
87 static bool RDSEED(
void) {
return CPU_Rep.f_7_EBX_[18]; }
88 static bool ADX(
void) {
return CPU_Rep.f_7_EBX_[19]; }
89 static bool AVX512PF(
void) {
return CPU_Rep.f_7_EBX_[26]; }
90 static bool AVX512ER(
void) {
return CPU_Rep.f_7_EBX_[27]; }
91 static bool AVX512CD(
void) {
return CPU_Rep.f_7_EBX_[28]; }
92 static bool SHA(
void) {
return CPU_Rep.f_7_EBX_[29]; }
94 static bool PREFETCHWT1(
void) {
return CPU_Rep.f_7_ECX_[0]; }
96 static bool LAHF(
void) {
return CPU_Rep.f_81_ECX_[0]; }
97 static bool LZCNT(
void) {
return CPU_Rep.isIntel_ && CPU_Rep.f_81_ECX_[5]; }
98 static bool ABM(
void) {
return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[5]; }
99 static bool SSE4a(
void) {
return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[6]; }
100 static bool XOP(
void) {
return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[11]; }
101 static bool TBM(
void) {
return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[21]; }
103 static bool SYSCALL(
void) {
return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[11]; }
104 static bool MMXEXT(
void) {
return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[22]; }
105 static bool RDTSCP(
void) {
return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[27]; }
106 static bool _3DNOWEXT(
void) {
return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[30]; }
107 static bool _3DNOW(
void) {
return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[31]; }
110 static const InstructionSet_Internal CPU_Rep;
112 class InstructionSet_Internal
115 InstructionSet_Internal()
130 std::array<int, 4> cpui;
134 __real_cpuid(cpui.data(), 0);
137 for (
int i = 0; i <= nIds_; ++i)
139 __real_cpuid(cpui.data(), i);
140 data_.push_back(cpui);
145 memset(vendor, 0,
sizeof(vendor));
146 *
reinterpret_cast<int*
>(vendor) = data_[0][1];
147 *
reinterpret_cast<int*
>(vendor + 4) = data_[0][3];
148 *
reinterpret_cast<int*
>(vendor + 8) = data_[0][2];
150 if (vendor_ ==
"GenuineIntel")
153 }
else if (vendor_ ==
"AuthenticAMD")
161 f_1_ECX_ = data_[1][2];
162 f_1_EDX_ = data_[1][3];
168 f_7_EBX_ = data_[7][1];
169 f_7_ECX_ = data_[7][2];
174 __real_cpuid(cpui.data(), 0x80000000);
178 memset(brand, 0,
sizeof(brand));
180 for (
int i = 0x80000000; i <= nExIds_; ++i)
182 __real_cpuid(cpui.data(), i);
183 extdata_.push_back(cpui);
187 if (nExIds_ >= 0x80000001)
189 f_81_ECX_ = extdata_[1][2];
190 f_81_EDX_ = extdata_[1][3];
194 if (nExIds_ >= 0x80000004)
196 memcpy(brand, extdata_[2].data(),
sizeof(cpui));
197 memcpy(brand + 16, extdata_[3].data(),
sizeof(cpui));
198 memcpy(brand + 32, extdata_[4].data(),
sizeof(cpui));
209 std::bitset<32> f_1_ECX_;
210 std::bitset<32> f_1_EDX_;
211 std::bitset<32> f_7_EBX_;
212 std::bitset<32> f_7_ECX_;
213 std::bitset<32> f_81_ECX_;
214 std::bitset<32> f_81_EDX_;
215 std::vector<std::array<int, 4>> data_;
216 std::vector<std::array<int, 4>> extdata_;