Snippet Testing CPUID instruction availability on 32-bit m
2 months ago
            {**
 * Test availability of CPUID instruction
 *
 * @return boolean true if CPUID supported
 *}
function TCpu.cpuidSupported() : boolean;
var supported:boolean;
begin
    asm
       push eax
       push ecx

       //copy EFLAGS -> EAX
       pushfd
       pop eax

       //store original RFLAGS
       //so we can restore it later
       mov ecx, eax

       //change bit 21
       xor rax, CPUID_BIT

       //copy EAX -> EFLAGS
       push eax
       popfd

       //copy EFLAGS back to EAX
       pushfd
       pop eax

       //CPUID_BIT is reserved bit and cannot be changed
       //for 386 processor or lower
       //if we can change, it means we run on newer processor

       and eax, CPUID_BIT
       shr eax, 21
       mov supported, al

       //restore original EFLAGS
       push ecx
       popfd

       pop ecx
       pop eax
    end;
    result := supported;
end;
        
add