Browse Source

+ SHA512Support

florian 8 months ago
parent
commit
e471c08cf8
3 changed files with 80 additions and 50 deletions
  1. 35 25
      rtl/i386/cpu.pp
  2. 33 23
      rtl/x86_64/cpu.pp
  3. 12 2
      tests/test/units/cpu/tcpu1.pp

+ 35 - 25
rtl/i386/cpu.pp

@@ -62,6 +62,7 @@ type
     function RDSEEDSupport: boolean;inline;
     function ADXSupport: boolean;inline;
     function SHASupport: boolean;inline;
+    function SHA512Support: boolean;inline;
     function FMASupport: boolean;inline;
     function POPCNTSupport: boolean;inline;
     function LZCNTSupport: boolean;inline;
@@ -86,7 +87,7 @@ type
 {$ASMMODE INTEL}
     var
       data: record
-        cpuid1, cpuid7: TCpuidResult;
+        cpuid1, cpuid7_0, cpuid7_1: TCpuidResult;
         AVXSupport,
         LZCNTSupport: boolean;
       end;
@@ -231,7 +232,10 @@ type
             maxcpuidvalue:=CPUID(0).eax;
             CPUID(1, 0, data.cpuid1);
             if maxcpuidvalue>=7 then
-              CPUID(7, 0, data.cpuid7);
+              begin
+                CPUID(7, 0, data.cpuid7_0);
+                CPUID(7, 1, data.cpuid7_1);
+              end;
 
             is_sse3_cpu:=(data.cpuid1.ecx and (1 shl 0))<>0;
 
@@ -286,113 +290,119 @@ type
 
     function AVX2Support: boolean;inline;
       begin
-        result:=data.AVXSupport and ((data.cpuid7.ebx and (1 shl 5))<>0);
+        result:=data.AVXSupport and ((data.cpuid7_0.ebx and (1 shl 5))<>0);
       end;
 
 
     function AVX512FSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 16))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 16))<>0;
       end;
 
 
     function AVX512DQSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 17))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 17))<>0;
       end;
 
 
     function AVX512IFMASupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 21))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 21))<>0;
       end;
 
 
     function AVX512PFSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 26))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 26))<>0;
       end;
 
 
     function AVX512ERSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 27))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 27))<>0;
       end;
 
 
     function AVX512CDSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 28))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 28))<>0;
       end;
 
 
     function AVX512BWSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 30))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 30))<>0;
       end;
 
 
     function AVX512VLSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 31))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 31))<>0;
       end;
 
 
     function AVX512VBMISupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 1))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 1))<>0;
       end;
 
 
     function AVX512VBMI2Support: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 6))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 6))<>0;
       end;
 
 
     function VAESSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 9))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 9))<>0;
       end;
 
 
     function VCLMULSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 10))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 10))<>0;
       end;
 
 
     function AVX512VNNISupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 11))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 11))<>0;
       end;
 
 
     function AVX512BITALGSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 12))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 12))<>0;
       end;
 
 
     function RDSEEDSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 18))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 18))<>0;
       end;
 
 
     function ADXSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 19))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 19))<>0;
       end;
 
 
-     function SHASupport: boolean;inline;
+    function SHASupport: boolean;inline;
+      begin
+        result:=(data.cpuid7_0.ebx and (1 shl 29))<>0;
+      end;
+
+
+    function SHA512Support: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 29))<>0;
+        result:=(data.cpuid7_1.eax and 1)<>0;
       end;
 
 
-   function FMASupport: boolean;inline;
+    function FMASupport: boolean;inline;
       begin
         result:=data.AVXSupport and ((data.cpuid1.ecx and (1 shl 12))<>0);
       end;
@@ -454,19 +464,19 @@ type
 
     function RTMSupport: boolean;inline;
       begin
-        result:=((data.cpuid7.ebx and (1 shl 11))<>0) and (data.cpuid7.edx and (1 shl 11)=0 {RTM_ALWAYS_ABORT});
+        result:=((data.cpuid7_0.ebx and (1 shl 11))<>0) and (data.cpuid7_0.edx and (1 shl 11)=0 {RTM_ALWAYS_ABORT});
       end;
 
 
     function BMI1Support: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 3))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 3))<>0;
       end;
 
 
     function BMI2Support: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 8))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 8))<>0;
       end;
 
 begin

+ 33 - 23
rtl/x86_64/cpu.pp

@@ -57,6 +57,7 @@ type
     function RDSEEDSupport: boolean;inline;
     function ADXSupport: boolean;inline;
     function SHASupport: boolean;inline;
+    function SHA512Support: boolean;inline;
     function FMASupport: boolean;inline;
     function CMPXCHG16BSupport: boolean;inline;
     function POPCNTSupport: boolean;inline;
@@ -83,7 +84,7 @@ type
 
     var
       data: record
-        cpuid1, cpuid7: TCpuidResult;
+        cpuid1, cpuid7_0, cpuid7_1: TCpuidResult;
         AVXSupport,
         LZCNTSupport: boolean;
       end;
@@ -215,7 +216,10 @@ type
         CPUID(1, 0, data.cpuid1);
         { very early x86-64 CPUs might not support eax=7 }
         if maxcpuidvalue>=7 then
-          CPUID(7, 0, data.cpuid7);
+          begin
+            CPUID(7, 0, data.cpuid7_0);
+            CPUID(7, 1, data.cpuid7_1);
+          end;
 
         is_sse3_cpu:=(data.cpuid1.ecx and (1 shl 0))<>0;
 
@@ -255,109 +259,115 @@ type
 
     function AVX2Support: boolean;inline;
       begin
-        result:=data.AVXSupport and ((data.cpuid7.ebx and (1 shl 5))<>0);
+        result:=data.AVXSupport and ((data.cpuid7_0.ebx and (1 shl 5))<>0);
       end;
 
 
     function AVX512FSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 16))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 16))<>0;
       end;
 
 
     function AVX512DQSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 17))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 17))<>0;
       end;
 
 
     function AVX512IFMASupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 21))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 21))<>0;
       end;
 
 
     function AVX512PFSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 26))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 26))<>0;
       end;
 
 
     function AVX512ERSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 27))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 27))<>0;
       end;
 
 
     function AVX512CDSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 28))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 28))<>0;
       end;
 
 
     function AVX512BWSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 30))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 30))<>0;
       end;
 
 
     function AVX512VLSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 31))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 31))<>0;
       end;
 
 
     function AVX512VBMISupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 1))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 1))<>0;
       end;
 
 
     function AVX512VBMI2Support: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 6))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 6))<>0;
       end;
 
 
     function VAESSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 9))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 9))<>0;
       end;
 
 
     function VCLMULSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 10))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 10))<>0;
       end;
 
 
     function AVX512VNNISupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 11))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 11))<>0;
       end;
 
 
     function AVX512BITALGSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ecx and (1 shl 12))<>0;
+        result:=(data.cpuid7_0.ecx and (1 shl 12))<>0;
       end;
 
 
     function RDSEEDSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 18))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 18))<>0;
       end;
 
 
     function ADXSupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 19))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 19))<>0;
       end;
 
 
     function SHASupport: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 29))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 29))<>0;
+      end;
+
+
+    function SHA512Support: boolean;inline;
+      begin
+        result:=(data.cpuid7_1.eax and 1)<>0;
       end;
 
 
@@ -429,19 +439,19 @@ type
 
     function RTMSupport: boolean;inline;
       begin
-        result:=((data.cpuid7.ebx and (1 shl 11))<>0) and (data.cpuid7.edx and (1 shl 11)=0 {RTM_ALWAYS_ABORT});
+        result:=((data.cpuid7_0.ebx and (1 shl 11))<>0) and (data.cpuid7_0.edx and (1 shl 11)=0 {RTM_ALWAYS_ABORT});
       end;
 
 
     function BMI1Support: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 3))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 3))<>0;
       end;
 
 
     function BMI2Support: boolean;inline;
       begin
-        result:=(data.cpuid7.ebx and (1 shl 8))<>0;
+        result:=(data.cpuid7_0.ebx and (1 shl 8))<>0;
       end;
 
 

+ 12 - 2
tests/test/units/cpu/tcpu1.pp

@@ -5,7 +5,7 @@ uses
 
 var
   dummy16b : array[0..15] of byte;
-  
+
 begin
   write('CMOV support: ');
   if CMOVSupport then
@@ -166,6 +166,16 @@ begin
     end
   else
     writeln('no');
+  write('SHA512 support: ');
+  if SHA512Support then
+    begin
+      writeln('yes');
+      asm
+//        vsha512msg2 %ymm0,%ymm0
+      end;
+    end
+  else
+    writeln('no');
   write('LZCNT support: ');
   if LZCNTSupport then
     begin
@@ -213,6 +223,6 @@ begin
     end
   else
     writeln('no');
-{$endif cpui386}    
+{$endif cpui386}
 end.