示例#1
0
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, &regs);

  maxId = regs.eax;

  ::memcpy(cpuInfo->_vendorString, &regs.ebx, 4);
  ::memcpy(cpuInfo->_vendorString + 4, &regs.edx, 4);
  ::memcpy(cpuInfo->_vendorString + 8, &regs.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, &regs);

  // 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;
  }
示例#2
0
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, &regs);

  memcpy(out->_vendorString, &regs.ebx, 4);
  memcpy(out->_vendorString + 4, &regs.edx, 4);
  memcpy(out->_vendorString + 8, &regs.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, &regs);

  // 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;
  }