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

git-svn-id: trunk@45781 -
This commit is contained in:
pierre 2020-07-13 14:40:09 +00:00
parent 7020490f81
commit 8cf26b7a0f
2 changed files with 15 additions and 5 deletions

View File

@ -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;

View File

@ -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;