void X86CpuUtil::detect(X86CpuInfo* cpuInfo) { X86CpuId regs; uint32_t i; uint32_t maxId; // Clear everything except the '_size' member. ::memset(reinterpret_cast<uint8_t*>(cpuInfo) + sizeof(uint32_t), 0, sizeof(CpuInfo) - sizeof(uint32_t)); // Fill safe defaults. cpuInfo->_hwThreadsCount = CpuInfo::detectHwThreadsCount(); // -------------------------------------------------------------------------- // [CPUID EAX=0x00000000] // -------------------------------------------------------------------------- // Get vendor string/id. callCpuId(0, 0, ®s); maxId = regs.eax; ::memcpy(cpuInfo->_vendorString, ®s.ebx, 4); ::memcpy(cpuInfo->_vendorString + 4, ®s.edx, 4); ::memcpy(cpuInfo->_vendorString + 8, ®s.ecx, 4); for (i = 0; i < ASMJIT_ARRAY_SIZE(x86CpuVendorList); i++) { if (x86CpuVendorEq(x86CpuVendorList[i], cpuInfo->_vendorString)) { cpuInfo->_vendorId = x86CpuVendorList[i].id; break; } } // -------------------------------------------------------------------------- // [CPUID EAX=0x00000001] // -------------------------------------------------------------------------- // Get feature flags in ecx/edx and family/model in eax. callCpuId(1, 0, ®s); // Fill family and model fields. cpuInfo->_family = (regs.eax >> 8) & 0x0F; cpuInfo->_model = (regs.eax >> 4) & 0x0F; cpuInfo->_stepping = (regs.eax ) & 0x0F; // Use extended family and model fields. if (cpuInfo->_family == 0x0F) { cpuInfo->_family += ((regs.eax >> 20) & 0xFF); cpuInfo->_model += ((regs.eax >> 16) & 0x0F) << 4; }
void x86CpuDetect(X86CpuInfo* out) { uint32_t i; X86CpuId regs; // Clear everything except the '_size' member. memset(reinterpret_cast<uint8_t*>(out) + sizeof(uint32_t), 0, sizeof(CpuInfo) - sizeof(uint32_t)); // Fill safe defaults. memcpy(out->_vendorString, "Unknown", 8); out->_numberOfProcessors = CpuInfo::detectNumberOfProcessors(); // Get vendor string/id. x86CpuId(0, ®s); memcpy(out->_vendorString, ®s.ebx, 4); memcpy(out->_vendorString + 4, ®s.edx, 4); memcpy(out->_vendorString + 8, ®s.ecx, 4); for (i = 0; i < 3; i++) { if (x86CpuVendorEq(x86CpuVendor[i], out->_vendorString)) { out->_vendorId = x86CpuVendor[i].id; break; } } // Get feature flags in ecx/edx, and family/model in eax. x86CpuId(1, ®s); // Fill family and model fields. out->_family = (regs.eax >> 8) & 0x0F; out->_model = (regs.eax >> 4) & 0x0F; out->_stepping = (regs.eax ) & 0x0F; // Use extended family and model fields. if (out->_family == 0x0F) { out->_family += ((regs.eax >> 20) & 0xFF); out->_model += ((regs.eax >> 16) & 0x0F) << 4; }