From dde8f54ee70849c6a179f126f085c6dcc5eff9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kl=C3=A4mpfl?= Date: Tue, 28 Dec 2021 17:05:26 +0100 Subject: [PATCH] + LZCNTSupport + test extended --- rtl/i386/cpu.pp | 21 ++++++++++++++++++++- rtl/x86_64/cpu.pp | 18 ++++++++++++++++++ tests/test/units/cpu/tcpu1.pp | 21 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/rtl/i386/cpu.pp b/rtl/i386/cpu.pp index 92a0b6bf0b..c16a837cfb 100644 --- a/rtl/i386/cpu.pp +++ b/rtl/i386/cpu.pp @@ -46,6 +46,7 @@ unit cpu; function SHASupport: boolean;inline; function FMASupport: boolean;inline; function POPCNTSupport: boolean;inline; + function LZCNTSupport: boolean;inline; function SSE41Support: boolean;inline; function SSE42Support: boolean;inline; function MOVBESupport: boolean;inline; @@ -78,6 +79,7 @@ unit cpu; _SHASupport, _FMASupport, _POPCNTSupport, + _LZCNTSupport, _SSE41Support, _SSE42Support, _MOVBESupport, @@ -185,7 +187,7 @@ unit cpu; procedure SetupSupport; var - _ecx,_ebx,maxcpuidvalue : longint; + _edx,_ecx,_ebx,maxcpuidvalue : longint; begin is_sse3_cpu:=false; if cpuid_support then @@ -224,6 +226,17 @@ unit cpu; _FMASupport:=_AVXSupport and ((_ecx and $1000)<>0); + asm + pushl %ebx + movl $0x80000001,%eax + cpuid + movl %ecx,_ecx + movl %edx,_edx + popl %ebx + end; + _LZCNTSupport:=(_ecx and $20)<>0; + + if maxcpuidvalue>=7 then begin asm @@ -344,6 +357,12 @@ unit cpu; end; + function LZCNTSupport: boolean;inline; + begin + result:=_LZCNTSupport; + end; + + function SSE41Support: boolean;inline; begin result:=_SSE41Support; diff --git a/rtl/x86_64/cpu.pp b/rtl/x86_64/cpu.pp index 98e44a3343..bbcb2295ba 100644 --- a/rtl/x86_64/cpu.pp +++ b/rtl/x86_64/cpu.pp @@ -43,6 +43,7 @@ unit cpu; function SHASupport: boolean;inline; function FMASupport: boolean;inline; function POPCNTSupport: boolean;inline; + function LZCNTSupport: boolean;inline; function SSE41Support: boolean;inline; function SSE42Support: boolean;inline; function MOVBESupport: boolean;inline; @@ -77,6 +78,7 @@ unit cpu; _SHASupport, _FMASupport, _POPCNTSupport, + _LZCNTSupport, _SSE41Support, _SSE42Support, _MOVBESupport, @@ -167,6 +169,7 @@ unit cpu; procedure SetupSupport; var + _edx, _ecx, _ebx,maxcpuidvalue : longint; begin @@ -201,6 +204,14 @@ unit cpu; _FMASupport:=_AVXSupport and ((_ecx and $1000)<>0); + asm + movl $0x80000001,%eax + cpuid + movl %ecx,_ecx + movl %edx,_edx + end; + _LZCNTSupport:=(_ecx and $20)<>0; + { very early x86-64 CPUs might not support eax=7 } if maxcpuidvalue>=7 then begin @@ -316,6 +327,13 @@ unit cpu; result:=_POPCNTSupport; end; + + function LZCNTSupport: boolean;inline; + begin + result:=_LZCNTSupport; + end; + + function SSE41Support: boolean;inline; begin result:=_SSE41Support; diff --git a/tests/test/units/cpu/tcpu1.pp b/tests/test/units/cpu/tcpu1.pp index 984133e794..30d81680db 100644 --- a/tests/test/units/cpu/tcpu1.pp +++ b/tests/test/units/cpu/tcpu1.pp @@ -24,6 +24,17 @@ begin end else writeln('no'); + write('AVXF512 support: '); + if AVX512FSupport then + begin + writeln('yes'); + asm + vpxor %ymm0,%ymm0,%ymm0 + vaddpd %zmm0,%zmm0,%zmm0 + end; + end + else + writeln('no'); write('FMA support: '); if FMASupport then begin @@ -45,5 +56,15 @@ begin end else writeln('no'); + write('LZCNT support: '); + if LZCNTSupport then + begin + writeln('yes'); + asm + lzcnt %eax,%eax + end; + end + else + writeln('no'); end.