Browse Source

Fix conversion between TFPURoundMode and bits of get_fsr according to SPARC-V8 specifications

git-svn-id: trunk@45781 -
pierre 5 years ago
parent
commit
8cf26b7a0f
2 changed files with 15 additions and 5 deletions
  1. 8 3
      rtl/sparc/mathu.inc
  2. 7 2
      rtl/sparc64/mathu.inc

+ 8 - 3
rtl/sparc/mathu.inc

@@ -16,21 +16,26 @@
 function get_fsr : dword;external name 'FPC_GETFSR';
 function get_fsr : dword;external name 'FPC_GETFSR';
 procedure set_fsr(fsr : dword);external name 'FPC_SETFSR';
 procedure set_fsr(fsr : dword);external name 'FPC_SETFSR';
 
 
+
 function GetRoundMode: TFPURoundingMode;
 function GetRoundMode: TFPURoundingMode;
+  const
+    bits2rm: array[0..3] of TFPURoundingMode = (rmNearest,rmTruncate,rmUp,rmDown);
   begin
   begin
-    result:=TFPURoundingMode(get_fsr shr 30);
+    result:=TFPURoundingMode(bits2rm[(get_fsr shr 30) and 3])
   end;
   end;
 
 
+
 function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
 function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
+  const
+    rm2bits: array[TFPURoundingMode] of byte = (0,3,2,1);
   var
   var
     cw: dword;
     cw: dword;
   begin
   begin
     cw:=get_fsr;
     cw:=get_fsr;
     result:=TFPURoundingMode(cw shr 30);
     result:=TFPURoundingMode(cw shr 30);
-    set_fsr((cw and $3fffffff) or (dword(RoundMode) shl 30));
+    set_fsr((cw and $3fffffff) or (rm2bits[RoundMode] shl 30));
   end;
   end;
 
 
-
 function GetPrecisionMode: TFPUPrecisionMode;
 function GetPrecisionMode: TFPUPrecisionMode;
   begin
   begin
     result:=pmDouble;
     result:=pmDouble;

+ 7 - 2
rtl/sparc64/mathu.inc

@@ -17,17 +17,22 @@ function get_fsr : dword;external name 'FPC_GETFSR';
 procedure set_fsr(fsr : dword);external name 'FPC_SETFSR';
 procedure set_fsr(fsr : dword);external name 'FPC_SETFSR';
 
 
 function GetRoundMode: TFPURoundingMode;
 function GetRoundMode: TFPURoundingMode;
+  const
+    bits2rm: array[0..3] of TFPURoundingMode = (rmNearest,rmTruncate,rmUp,rmDown);
   begin
   begin
-    result:=TFPURoundingMode(get_fsr shr 30);
+    result:=TFPURoundingMode(bits2rm[(get_fsr shr 30) and 3])
   end;
   end;
 
 
+
 function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
 function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
+  const
+    rm2bits: array[TFPURoundingMode] of byte = (0,3,2,1);
   var
   var
     cw: dword;
     cw: dword;
   begin
   begin
     cw:=get_fsr;
     cw:=get_fsr;
     result:=TFPURoundingMode(cw shr 30);
     result:=TFPURoundingMode(cw shr 30);
-    set_fsr((cw and $3fffffff) or (dword(RoundMode) shl 30));
+    set_fsr((cw and $3fffffff) or (rm2bits[RoundMode] shl 30));
   end;
   end;