浏览代码

* Get rid of last softfloat dependencies in genmath.inc. Replaced remaining calls to float_raise with expressions which generate appropriate floating-point exceptions at runtime. This is probably somewhat slower on actual softfloat targets, but the change only affects exceptional control flow, so not a significant issue.

git-svn-id: trunk@27198 -
sergei 11 年之前
父节点
当前提交
dcb46051c4
共有 1 个文件被更改,包括 18 次插入8 次删除
  1. 18 8
      rtl/inc/genmath.inc

+ 18 - 8
rtl/inc/genmath.inc

@@ -70,6 +70,7 @@ const
       DP1 =   7.85398125648498535156E-1;
       DP1 =   7.85398125648498535156E-1;
       DP2 =   3.77489470793079817668E-8;
       DP2 =   3.77489470793079817668E-8;
       DP3 =   2.69515142907905952645E-15;
       DP3 =   2.69515142907905952645E-15;
+      zero: double = 0;
 
 
 {$if not defined(FPC_SYSTEM_HAS_SIN) or not defined(FPC_SYSTEM_HAS_COS)}
 {$if not defined(FPC_SYSTEM_HAS_SIN) or not defined(FPC_SYSTEM_HAS_COS)}
 const sincof : array[0..5] of Real = (
 const sincof : array[0..5] of Real = (
@@ -121,6 +122,16 @@ Begin
      HandleError(207);
      HandleError(207);
 end;
 end;
 
 
+
+{ This function does nothing, but its argument is expected to be an expression
+  which causes FPE when calculated. If exception is masked, it just returns true,
+  allowing to use it in expressions. }
+function fpe_helper(x: valreal): boolean;
+begin
+  result:=true;
+end;
+
+
 {$ifdef SUPPORT_DOUBLE}
 {$ifdef SUPPORT_DOUBLE}
 
 
 {$ifndef FPC_HAS_FLOAT64HIGH}
 {$ifndef FPC_HAS_FLOAT64HIGH}
@@ -181,9 +192,9 @@ type
          begin
          begin
            if aExp>=$43e then
            if aExp>=$43e then
              begin
              begin
-               if (a.high<>$C3E00000) or (a.low<>0) then
+               if (a.high<>longint($C3E00000)) or (a.low<>0) then
                  begin
                  begin
-                   float_raise(float_flag_invalid);
+                   fpe_helper(zero/zero);
                    if (longint(a.high)>=0) or ((aExp=$7FF) and
                    if (longint(a.high)>=0) or ((aExp=$7FF) and
                       (aSig<>$0010000000000000 )) then
                       (aSig<>$0010000000000000 )) then
                      begin
                      begin
@@ -231,7 +242,7 @@ type
          Begin
          Begin
            if ( a <> Float32($DF000000) ) then
            if ( a <> Float32($DF000000) ) then
              Begin
              Begin
-               float_raise( float_flag_invalid );
+               fpe_helper( zero/zero );
                if ( (longint(a)>=0) or ( ( aExp = $FF ) and (aSig<>0) ) ) then
                if ( (longint(a)>=0) or ( ( aExp = $FF ) and (aSig<>0) ) ) then
                  Begin
                  Begin
                    result:=$7fffffffffffffff;
                    result:=$7fffffffffffffff;
@@ -969,11 +980,10 @@ type
     begin
     begin
        if( d <= 0.0 ) then
        if( d <= 0.0 ) then
        begin
        begin
-           if d < 0.0 then begin
-             float_raise(float_flag_invalid);
-             d := 0/0;
-           end;
-           result := 0.0;
+           if d < 0.0 then
+             result:=(d-d)/zero
+           else
+             result := 0.0;
        end
        end
      else
      else
        begin
        begin