소스 검색

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

git-svn-id: trunk@45781 -
pierre 5 년 전
부모
커밋
8cf26b7a0f
2개의 변경된 파일15개의 추가작업 그리고 5개의 파일을 삭제
  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';
 procedure set_fsr(fsr : dword);external name 'FPC_SETFSR';
 
+
 function GetRoundMode: TFPURoundingMode;
+  const
+    bits2rm: array[0..3] of TFPURoundingMode = (rmNearest,rmTruncate,rmUp,rmDown);
   begin
-    result:=TFPURoundingMode(get_fsr shr 30);
+    result:=TFPURoundingMode(bits2rm[(get_fsr shr 30) and 3])
   end;
 
+
 function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
+  const
+    rm2bits: array[TFPURoundingMode] of byte = (0,3,2,1);
   var
     cw: dword;
   begin
     cw:=get_fsr;
     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;
 
-
 function GetPrecisionMode: TFPUPrecisionMode;
   begin
     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';
 
 function GetRoundMode: TFPURoundingMode;
+  const
+    bits2rm: array[0..3] of TFPURoundingMode = (rmNearest,rmTruncate,rmUp,rmDown);
   begin
-    result:=TFPURoundingMode(get_fsr shr 30);
+    result:=TFPURoundingMode(bits2rm[(get_fsr shr 30) and 3])
   end;
 
+
 function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
+  const
+    rm2bits: array[TFPURoundingMode] of byte = (0,3,2,1);
   var
     cw: dword;
   begin
     cw:=get_fsr;
     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;