Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to probe the availability of Intel® Advanced Vector Extensions?

How can I check using Delphi 2007 that a box is AVX capable.

My question is only restricted to querying the support in the CPU (Assumption is made that the OS is OK / Windows 7 with SP1).

The PDF document entitled Introduction to Intel® Advanced Vector Extensions by Chris Lomont explains how to do it and provides an example code implementation but in c++.

It's also available at this page.

like image 462
menjaraz Avatar asked Mar 30 '12 11:03

menjaraz


Video Answer


1 Answers

Here's a translation of the assembler code given on an Intel blog:

function isAvxSupported: Boolean;
asm
{$IFDEF CPUX86}
    push ebx
{$ENDIF}
{$IFDEF CPUX64}
    mov r10, rbx
{$ENDIF}
    xor eax, eax
    cpuid
    cmp eax, 1
    jb @not_supported
    mov eax, 1
    cpuid
    and ecx, 018000000h
    cmp ecx, 018000000h
    jne @not_supported
    xor ecx, ecx
    db 0Fh, 01h, 0D0h //XGETBV
    and eax, 110b
    cmp eax, 110b
    jne @not_supported
    mov eax, 1
    jmp @done
@not_supported:
    xor eax, eax
@done:
{$IFDEF CPUX86}
    pop ebx
{$ENDIF}
{$IFDEF CPUX64}
    mov rbx, r10
{$ENDIF}
end;

This code will work in both 32 and 64 bit versions of Delphi.

Update: Register saving code added thanks to @PhiS.

like image 143
David Heffernan Avatar answered Nov 09 '22 19:11

David Heffernan