看了很多的 C/C++ 代码,都感觉太复杂。而且有的只支持 X86,不支持 X64。所以自己找了一番。
费了九牛二虎之力,才发现 Delphi原生就支持。
哎,浪费了很多时间,还得多研究研究 Delphi源码!
{ 检测 CPU 支持的指令集 <Check CPU support instruction set> }
procedure CheckCPU(var bMMX, bSSE1, bSSE2, bSSE3, bSSEE3, bSSE41, bSSE42, bAES, bFMA, bAVX1, bAVX2, bAVX512: Boolean);
begin
bMMX := GetCPUID(1).EDX and (1 shl 23) = (1 shl 23);
bSSE1 := GetCPUID(1).EDX and (1 shl 25) = (1 shl 25);
bSSE2 := GetCPUID(1).EDX and (1 shl 26) = (1 shl 26);
bSSE3 := GetCPUID(1).ECX and (1 shl 00) = (1 shl 00);
bSSEE3 := GetCPUID(1).ECX and (1 shl 09) = (1 shl 09);
bSSE41 := GetCPUID(1).ECX and (1 shl 19) = (1 shl 19);
bSSE42 := GetCPUID(1).ECX and (1 shl 20) = (1 shl 20);
bAES := GetCPUID(1).ECX and (1 shl 25) = (1 shl 25);
bAVX1 := GetCPUID(1).ECX and (1 shl 28) = (1 shl 28);
bFMA := GetCPUID(1).ECX and (1 shl 12) = (1 shl 12);
bAVX2 := GetCPUID(7).EBX and (1 shl 05) = (1 shl 05);
bAVX512 := GetCPUID(7).EBX and (1 shl 16) = (1 shl 16);
end;
GetCPUID 在System.pas 单元中,无需引用,直接使用。
基于 Delphi 10.4.2 。其它低版本有没有,我就不知道了。
源码地址:GitHub - dbyoung720/CheckCPU: Check CPU support instruction set