Browse Source

* check also for XGETBV support, resolves problem reported by Pierre

florian 1 year ago
parent
commit
b164817e18
1 changed files with 19 additions and 15 deletions
  1. 19 15
      rtl/x86_64/x86_64.inc

+ 19 - 15
rtl/x86_64/x86_64.inc

@@ -1250,7 +1250,7 @@ const
 {$define FPC_SYSTEM_HAS_FPC_CPUINIT}
 {$define FPC_SYSTEM_HAS_FPC_CPUINIT}
 procedure fpc_cpuinit;
 procedure fpc_cpuinit;
   var
   var
-    _eax,_ebx,_ecx : dword;
+    _eax,_ebx,cpuid1_ecx : dword;
   begin
   begin
     { don't let libraries influence the FPU cw set by the host program }
     { don't let libraries influence the FPU cw set by the host program }
     if IsLibrary then
     if IsLibrary then
@@ -1267,26 +1267,30 @@ procedure fpc_cpuinit;
     if _eax>=7 then
     if _eax>=7 then
       begin
       begin
         asm
         asm
+          movl $1,%eax
           xorl %ecx,%ecx
           xorl %ecx,%ecx
-          .byte   0x0f,0x01,0xd0 { xgetbv }
-          movl %eax,_eax
+          cpuid
+          movl %ecx,cpuid1_ecx
         end;
         end;
-        if (_eax and 6)=6 then
+        { XGETBV support? }
+        if (cpuid1_ecx and $8000000)<>0 then 
           begin
           begin
             asm
             asm
-              movl $1,%eax
               xorl %ecx,%ecx
               xorl %ecx,%ecx
-              cpuid
-              movl %ecx,_ecx
+              .byte   0x0f,0x01,0xd0 { xgetbv }
+              movl %eax,_eax
             end;
             end;
-            has_avx_support:=(_ecx and $10000000)<>0;
-            asm
-              movl $7,%eax
-              xorl %ecx,%ecx
-              cpuid
-              movl %ebx,_ebx
-            end;
-            has_avx2_support:=(_ebx and $20)<>0;
+            if (_eax and 6)=6 then
+              begin
+                has_avx_support:=(cpuid1_ecx and $10000000)<>0;
+                asm
+                  movl $7,%eax
+                  xorl %ecx,%ecx
+                  cpuid
+                  movl %ebx,_ebx
+                end;
+                has_avx2_support:=(_ebx and $20)<>0;
+              end;
           end;
           end;
       end;
       end;
   end;
   end;