How to detect if a CPU supports MMX (Views: 100)


How to detect if a CPU supports MMX


You have to use the CPUID instruction. Bit 23 of the feature flags (for EAX = 1) indicate if a processor supports the MMX instructions. Here is an example of how it could be used for MMX detection only (on Delphi versions prior to D6, you'll need to replace CPUID by DB $0f,$a2):

function SupportsMMX: Boolean;
  Supported: LongBool;
  mov Supported, 0
  pop eax
  mov edx, eax
  xor eax, 1 shl 21
  push eax
  pop eax
  xor eax, edx
  and eax, 1 shl 21  {only if bit 21 can toggle, CPUID is supported}
  jz @ending  {if not, then exit}
  xor eax, eax
  cmp eax, 0  {check highest input value for CPUID}
  je @ending  {if highest value is zero, then exit}
  mov eax, 1
  cpuid  {We only need feature flags}
  test edx, 1 shl 23
  jz @ending
  inc Supported
  mov eax, DWORD PTR Supported

CPUID causes a lot of overhead, so make sure you call it only once during initialization and store the result somewhere to consult at any later stage. All remarks made apply to Intel processors unless specifiedotherwise

<< Back to main page