Browse Source

+ function needs_check_for_fpu_exceptions to unify fpu exception handling

florian 1 year ago
parent
commit
a71cc71585

+ 1 - 1
compiler/aarch64/ncpuadd.pas

@@ -493,7 +493,7 @@ interface
         if Result=nil then
         if Result=nil then
           begin
           begin
             if left.resultdef.typ=floatdef then
             if left.resultdef.typ=floatdef then
-              if cs_check_fpu_exceptions in current_settings.localswitches then
+              if needs_check_for_fpu_exceptions then
                 Include(current_procinfo.flags,pi_do_call);
                 Include(current_procinfo.flags,pi_do_call);
           end;
           end;
       end;
       end;

+ 8 - 8
compiler/aarch64/ncpuinl.pas

@@ -85,7 +85,7 @@ implementation
       begin
       begin
         expectloc:=LOC_MMREGISTER;
         expectloc:=LOC_MMREGISTER;
         result:=nil;
         result:=nil;
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           Include(current_procinfo.flags,pi_do_call);
           Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 
@@ -94,7 +94,7 @@ implementation
       begin
       begin
         expectloc:=LOC_MMREGISTER;
         expectloc:=LOC_MMREGISTER;
         result:=nil;
         result:=nil;
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           Include(current_procinfo.flags,pi_do_call);
           Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 
@@ -103,7 +103,7 @@ implementation
       begin
       begin
         expectloc:=LOC_MMREGISTER;
         expectloc:=LOC_MMREGISTER;
         result:=nil;
         result:=nil;
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           Include(current_procinfo.flags,pi_do_call);
           Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 
@@ -112,7 +112,7 @@ implementation
       begin
       begin
         expectloc:=LOC_MMREGISTER;
         expectloc:=LOC_MMREGISTER;
         result:=nil;
         result:=nil;
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           Include(current_procinfo.flags,pi_do_call);
           Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 
@@ -121,7 +121,7 @@ implementation
       begin
       begin
         expectloc:=LOC_MMREGISTER;
         expectloc:=LOC_MMREGISTER;
         result:=nil;
         result:=nil;
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           Include(current_procinfo.flags,pi_do_call);
           Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 
@@ -130,7 +130,7 @@ implementation
       begin
       begin
         expectloc:=LOC_MMREGISTER;
         expectloc:=LOC_MMREGISTER;
         result:=nil;
         result:=nil;
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           Include(current_procinfo.flags,pi_do_call);
           Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 
@@ -139,7 +139,7 @@ implementation
       begin
       begin
         expectloc:=LOC_MMREGISTER;
         expectloc:=LOC_MMREGISTER;
         result:=nil;
         result:=nil;
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           Include(current_procinfo.flags,pi_do_call);
           Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 
@@ -371,7 +371,7 @@ implementation
           begin
           begin
             expectloc:=LOC_MMREGISTER;
             expectloc:=LOC_MMREGISTER;
             Result:=nil;
             Result:=nil;
-            if cs_check_fpu_exceptions in current_settings.localswitches then
+            if needs_check_for_fpu_exceptions then
               Include(current_procinfo.flags,pi_do_call);
               Include(current_procinfo.flags,pi_do_call);
           end
           end
         else if is_32bitint(resultdef) then
         else if is_32bitint(resultdef) then

+ 1 - 1
compiler/aarch64/ncpumat.pas

@@ -487,7 +487,7 @@ implementation
       begin
       begin
         Result:=inherited pass_1;
         Result:=inherited pass_1;
         if Result=nil then
         if Result=nil then
-          if cs_check_fpu_exceptions in current_settings.localswitches then
+          if needs_check_for_fpu_exceptions then
             Include(current_procinfo.flags,pi_do_call);
             Include(current_procinfo.flags,pi_do_call);
       end;
       end;
 
 

+ 2 - 3
compiler/arm/cgcpu.pas

@@ -1780,9 +1780,8 @@ unit cgcpu;
         ai: taicpu;
         ai: taicpu;
         l: TAsmLabel;
         l: TAsmLabel;
       begin
       begin
-        if ((cs_check_fpu_exceptions in current_settings.localswitches) and
-            not(FPUARM_HAS_EXCEPTION_TRAPPING in fpu_capabilities[current_settings.fputype]) and
-            (force or current_procinfo.FPUExceptionCheckNeeded)) then
+        if needs_check_for_fpu_exceptions and
+          (force or current_procinfo.FPUExceptionCheckNeeded) then
           begin
           begin
             r:=getintregister(list,OS_INT);
             r:=getintregister(list,OS_INT);
             list.concat(taicpu.op_reg_reg(A_FMRX,r,NR_FPSCR));
             list.concat(taicpu.op_reg_reg(A_FMRX,r,NR_FPSCR));

+ 24 - 0
compiler/cgutils.pas

@@ -224,11 +224,17 @@ unit cgutils;
       WARNING: d must not be a power of 2 (including 2^0 = 1) }
       WARNING: d must not be a power of 2 (including 2^0 = 1) }
     procedure calc_mul_inverse(N: byte; d: aWord; out reciprocal: aWord; out shift: Byte);
     procedure calc_mul_inverse(N: byte; d: aWord; out reciprocal: aWord; out shift: Byte);
 
 
+    { returns true if the CPU architecture we are currently compiling for needs
+      software checks for fpu exceptions }
+    function needs_check_for_fpu_exceptions : boolean;
+
 implementation
 implementation
 
 
 uses
 uses
   systems,
   systems,
   verbose,
   verbose,
+  globals,
+  cpuinfo,
   cgobj;
   cgobj;
 
 
 {****************************************************************************
 {****************************************************************************
@@ -570,6 +576,24 @@ uses
           reciprocal:=swap_r;
           reciprocal:=swap_r;
         until d<=1;
         until d<=1;
       end;
       end;
+
+
+    function needs_check_for_fpu_exceptions: boolean;
+      begin
+{$if defined(AARCH64)}
+        result:=cs_check_fpu_exceptions in current_settings.localswitches;
+{$elseif defined(ARM)}
+        result:=(cs_check_fpu_exceptions in current_settings.localswitches) and
+          not(FPUARM_HAS_EXCEPTION_TRAPPING in fpu_capabilities[current_settings.fputype]);
+{$elseif defined(RISCV)}
+        result:=cs_check_fpu_exceptions in current_settings.localswitches;
+{$elseif defined(XTENSA)}
+        result:=cs_check_fpu_exceptions in current_settings.localswitches;
+{$else}
+        result:=false;
+{$endif}
+      end;
+
 {$pop}
 {$pop}
 
 
 end.
 end.

+ 1 - 1
compiler/riscv/cgrv.pas

@@ -1040,7 +1040,7 @@ unit cgrv;
         ai: taicpu;
         ai: taicpu;
         l: TAsmLabel;
         l: TAsmLabel;
       begin
       begin
-        if cs_check_fpu_exceptions in current_settings.localswitches then
+        if needs_check_for_fpu_exceptions then
           begin
           begin
             r:=getintregister(list,OS_INT);
             r:=getintregister(list,OS_INT);
             list.concat(taicpu.op_reg(A_FRFLAGS,r));
             list.concat(taicpu.op_reg(A_FRFLAGS,r));