* softfloat: Fixed int64->double and qword->double conversions to take rounding mode into account (actually, brought them up to date with Softfloat-2b C source). Now test/units/math/troundm.pp is consistent for all targets.

git-svn-id: trunk@28312 -
This commit is contained in:
sergei 2014-08-04 21:56:40 +00:00
parent ff5410b152
commit 0dea20d8e7

View File

@ -2860,6 +2860,15 @@ Procedure
roundAndPackFloat64( zSign, zExp, zSig0, zSig1, zSig2, c ); roundAndPackFloat64( zSign, zExp, zSig0, zSig1, zSig2, c );
End; End;
function normalizeRoundAndPackFloat64(zSign: flag; zExp: int16; zSig: bits64): float64;
var
shiftCount: int8;
begin
shiftCount := countLeadingZeros64( zSig ) - 1;
result := roundAndPackFloat64( zSign, zExp - shiftCount, zSig shl shiftCount);
end;
{* {*
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Returns the result of converting the 32-bit two's complement integer `a' to Returns the result of converting the 32-bit two's complement integer `a' to
@ -5808,20 +5817,11 @@ End;
*----------------------------------------------------------------------------*} *----------------------------------------------------------------------------*}
function qword_to_float64( a: qword ): float64; function qword_to_float64( a: qword ): float64;
{$ifdef fpc}[public,Alias:'QWORD_TO_FLOAT64'];compilerproc;{$endif} {$ifdef fpc}[public,Alias:'QWORD_TO_FLOAT64'];compilerproc;{$endif}
var
shiftcount : int8;
Begin Begin
if ( a = 0 ) then if ( a = 0 ) then
Begin result := packFloat64( 0, 0, 0 )
result:=packFloat64( 0, 0, 0); else
exit; result := normalizeRoundAndPackFloat64( 0, $43c, a );
end;
shiftCount := countLeadingZeros64( a ) - 11;
if ( 0 <= shiftCount ) then
a := a shl shiftcount
else
a := a shr (-shiftCount);
result := packFloat64( 0, $432 - shiftCount, a );
End; End;
@ -5833,27 +5833,15 @@ End;
*----------------------------------------------------------------------------*} *----------------------------------------------------------------------------*}
function int64_to_float64( a: int64 ): float64; function int64_to_float64( a: int64 ): float64;
{$ifdef fpc}[public,Alias:'INT64_TO_FLOAT64'];compilerproc;{$endif} {$ifdef fpc}[public,Alias:'INT64_TO_FLOAT64'];compilerproc;{$endif}
var
zSign : flag;
AbsA : bits64;
shiftcount : int8;
Begin Begin
if ( a = 0 ) then if ( a = 0 ) then
Begin result := packFloat64( 0, 0, 0 )
result:=packFloat64( 0, 0, 0); else if (a = int64($8000000000000000)) then
exit; result := packFloat64( 1, $43e, 0 )
end; else if (a < 0) then
zSign := flag( a < 0 ); result := normalizeRoundAndPackFloat64( 1, $43c, -a )
if ZSign<>0 then else
AbsA := -a result := normalizeRoundAndPackFloat64( 0, $43c, a );
else
AbsA := a;
shiftCount := countLeadingZeros64( absA ) - 11;
if ( 0 <= shiftCount ) then
absA := absA shl shiftcount
else
absA := absA shr (-shiftcount);
result := packFloat64( zSign, $432 - shiftCount, absA );
End; End;