Snippet CPUID availability test (64-bit)
3 months ago
            {**
 * Test availability of CPUID instruction
 *
 * @return boolean true if CPUID supported
 *}
function TCpuIdentifier.cpuidSupported() : boolean;
var supported:boolean;
begin
    asm
       push rax
       push rcx

       //copy RFLAGS -> RAX
       pushfq
       pop rax

       //store original RFLAGS
       //so we can restore it later
       mov rcx, rax

       //change bit 21
       xor rax, CPUID_BIT

       //copy RAX -> RFLAGS
       push rax
       popfq

       //copy RFLAGS back to EAX
       pushfq
       pop rax

       //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 rax, CPUID_BIT
       shr rax, 21
       mov supported, al

       //restore original RFLAGS
       push rcx
       popfq

       pop rcx
       pop rax
    end;
    result := supported;
end;
        
add