Commit 8689395a authored by Robert Sprowson's avatar Robert Sprowson Committed by ROOL
Browse files

Demark SoftFloat library changes

Wrap changes in __riscos so it's easier to see where they are. Binary identical result.
parent 9dadbd27
......@@ -40,8 +40,10 @@ these four paragraphs for those parts of this code that are retained.
| Floating-point rounding mode, extended double-precision rounding precision,
| and exception flags.
*----------------------------------------------------------------------------*/
//int8 float_rounding_mode = float_round_nearest_even;
//int8 float_exception_flags = 0;
#ifndef __riscos
int8 float_rounding_mode = float_round_nearest_even;
int8 float_exception_flags = 0;
#endif
#ifdef FLOATX80
int8 floatx80_rounding_precision = 80;
#endif
......@@ -98,10 +100,17 @@ static int32 roundAndPackInt32( flag zSign, bits64 absZ )
}
}
}
#ifdef __riscos
roundBits = (int8) (absZ & 0x7F);
absZ = ( absZ + roundIncrement )>>7;
absZ &= ~ (bits64) (flag) ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven );
z = (int32) absZ;
#else
roundBits = absZ & 0x7F;
absZ = ( absZ + roundIncrement )>>7;
absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven );
z = absZ;
#endif
if ( zSign ) z = - z;
if ( ( absZ>>32 ) || ( z && ( ( z < 0 ) ^ zSign ) ) ) {
float_raise( float_flag_invalid );
......@@ -149,7 +158,11 @@ static int64 roundAndPackInt64( flag zSign, bits64 absZ0, bits64 absZ1 )
if ( increment ) {
++absZ0;
if ( absZ0 == 0 ) goto overflow;
#ifdef __riscos
absZ0 &= ~ (bits64) (flag) ( ( (bits64) ( absZ1<<1 ) == 0 ) & roundNearestEven );
#else
absZ0 &= ~ ( ( (bits64) ( absZ1<<1 ) == 0 ) & roundNearestEven );
#endif
}
z = absZ0;
if ( zSign ) z = - z;
......@@ -345,7 +358,11 @@ INLINE bits64 extractFloat64Frac( float64 a )
INLINE int16 extractFloat64Exp( float64 a )
{
#ifdef __riscos
return (int16) (( a>>52 ) & 0x7FF);
#else
return ( a>>52 ) & 0x7FF;
#endif
}
......@@ -356,7 +373,11 @@ INLINE int16 extractFloat64Exp( float64 a )
INLINE flag extractFloat64Sign( float64 a )
{
#ifdef __riscos
return (flag) (a>>63);
#else
return a>>63;
#endif
}
......@@ -442,7 +463,11 @@ static float64 roundAndPackFloat64( flag zSign, int16 zExp, bits64 zSig )
}
}
}
#ifdef __riscos
roundBits = ((int16) zSig) & 0x3FF;
#else
roundBits = zSig & 0x3FF;
#endif
if ( 0x7FD <= (bits16) zExp ) {
if ( ( 0x7FD < zExp )
|| ( ( zExp == 0x7FD )
......@@ -458,13 +483,21 @@ static float64 roundAndPackFloat64( flag zSign, int16 zExp, bits64 zSig )
|| ( zSig + roundIncrement < LIT64( 0x8000000000000000 ) );
shift64RightJamming( zSig, - zExp, &zSig );
zExp = 0;
#ifdef __riscos
roundBits = ((int16) zSig) & 0x3FF;
#else
roundBits = zSig & 0x3FF;
#endif
if ( isTiny && roundBits ) float_raise( float_flag_underflow );
}
}
if ( roundBits ) float_exception_flags |= float_flag_inexact;
zSig = ( zSig + roundIncrement )>>10;
#ifdef __riscos
zSig &= ~ (bits64) (flag) ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven );
#else
zSig &= ~ ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven );
#endif
if ( zSig == 0 ) zExp = 0;
return packFloat64( zSign, zExp, zSig );
......@@ -1140,13 +1173,20 @@ float32 int64_to_float32( int64 a )
flag zSign;
uint64 absA;
int8 shiftCount;
#ifndef __riscos
bits32 zSig;
#endif
if ( a == 0 ) return 0;
zSign = ( a < 0 );
absA = zSign ? - a : a;
shiftCount = countLeadingZeros64( absA ) - 40;
if ( 0 <= shiftCount ) {
#ifdef __riscos
return packFloat32( zSign, 0x95 - shiftCount, ((bits32) absA)<<shiftCount );
#else
return packFloat32( zSign, 0x95 - shiftCount, absA<<shiftCount );
#endif
}
else {
shiftCount += 7;
......@@ -1156,7 +1196,11 @@ float32 int64_to_float32( int64 a )
else {
absA <<= shiftCount;
}
#ifdef __riscos
return roundAndPackFloat32( zSign, 0x9C - shiftCount, (bits32) absA );
#else
return roundAndPackFloat32( zSign, 0x9C - shiftCount, absA );
#endif
}
}
......@@ -1385,7 +1429,11 @@ int64 float32_to_int64_round_to_zero( float32 a )
if ( aExp | aSig ) float_exception_flags |= float_flag_inexact;
return 0;
}
#ifdef __riscos
aSig64 = (bits64) (bits32) (aSig | 0x00800000);
#else
aSig64 = aSig | 0x00800000;
#endif
aSig64 <<= 40;
z = aSig64>>( - shiftCount );
if ( (bits64) ( aSig64<<( shiftCount & 63 ) ) ) {
......@@ -1789,7 +1837,11 @@ float32 float32_mul( float32 a, float32 b )
aSig = ( aSig | 0x00800000 )<<7;
bSig = ( bSig | 0x00800000 )<<8;
shift64RightJamming( ( (bits64) aSig ) * bSig, 32, &zSig64 );
#ifdef __riscos
zSig = (bits32) zSig64;
#else
zSig = zSig64;
#endif
if ( 0 <= (sbits32) ( zSig<<1 ) ) {
zSig <<= 1;
--zExp;
......@@ -1852,7 +1904,11 @@ float32 float32_div( float32 a, float32 b )
aSig >>= 1;
++zExp;
}
#ifdef __riscos
zSig = (bits32) (( ( (bits64) aSig )<<32 ) / bSig);
#else
zSig = ( ( (bits64) aSig )<<32 ) / bSig;
#endif
if ( ( zSig & 0x3F ) == 0 ) {
zSig |= ( (bits64) bSig * zSig != ( (bits64) aSig )<<32 );
}
......@@ -1917,7 +1973,11 @@ float32 float32_rem( float32 a, float32 b )
q = ( bSig <= aSig );
if ( q ) aSig -= bSig;
if ( 0 < expDiff ) {
#ifdef __riscos
q = (bits32) (( ( (bits64) aSig )<<32 ) / bSig);
#else
q = ( ( (bits64) aSig )<<32 ) / bSig;
#endif
q >>= 32 - expDiff;
bSig >>= 2;
aSig = ( ( aSig>>1 )<<( expDiff - 1 ) ) - bSig * q;
......@@ -1941,9 +2001,15 @@ float32 float32_rem( float32 a, float32 b )
expDiff += 64;
q64 = estimateDiv128To64( aSig64, 0, bSig64 );
q64 = ( 2 < q64 ) ? q64 - 2 : 0;
#ifdef __riscos
q = (bits32) (q64>>( 64 - expDiff ));
bSig <<= 6;
aSig = ((bits32) ( ( aSig64>>33 )<<( expDiff - 1 ) )) - bSig * q;
#else
q = q64>>( 64 - expDiff );
bSig <<= 6;
aSig = ( ( aSig64>>33 )<<( expDiff - 1 ) ) - bSig * q;
#endif
}
do {
alternateASig = aSig;
......@@ -2122,6 +2188,9 @@ flag float32_eq_signaling( float32 a, float32 b )
flag float32_le_quiet( float32 a, float32 b )
{
flag aSign, bSign;
#ifndef __riscos
int16 aExp, bExp;
#endif
if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|| ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
......@@ -2223,7 +2292,11 @@ int32 float64_to_int32_round_to_zero( float64 a )
shiftCount = 0x433 - aExp;
savedASig = aSig;
aSig >>= shiftCount;
#ifdef __riscos
z = (int32) aSig;
#else
z = aSig;
#endif
if ( aSign ) z = - z;
if ( ( z < 0 ) ^ aSign ) {
invalid:
......@@ -2353,7 +2426,11 @@ float32 float64_to_float32( float64 a )
return packFloat32( aSign, 0xFF, 0 );
}
shift64RightJamming( aSig, 22, &aSig );
#ifdef __riscos
zSig = (bits32) aSig;
#else
zSig = aSig;
#endif
if ( aExp || zSig ) {
zSig |= 0x40000000;
aExp -= 0x381;
......@@ -2903,6 +2980,9 @@ float64 float64_sqrt( float64 a )
int16 aExp, zExp;
bits64 aSig, zSig, doubleZSig;
bits64 rem0, rem1, term0, term1;
#ifndef __riscos
float64 z;
#endif
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
......@@ -2924,7 +3004,11 @@ float64 float64_sqrt( float64 a )
}
zExp = ( ( aExp - 0x3FF )>>1 ) + 0x3FE;
aSig |= LIT64( 0x0010000000000000 );
#ifdef __riscos
zSig = estimateSqrt32( aExp, (bits32) (aSig>>21) );
#else
zSig = estimateSqrt32( aExp, aSig>>21 );
#endif
aSig <<= 9 - ( aExp & 1 );
zSig = estimateDiv128To64( aSig, 0, zSig<<32 ) + ( zSig<<30 );
if ( ( zSig & 0x1FF ) <= 5 ) {
......@@ -3040,6 +3124,9 @@ flag float64_eq_signaling( float64 a, float64 b )
flag float64_le_quiet( float64 a, float64 b )
{
flag aSign, bSign;
#ifndef __riscos
int16 aExp, bExp;
#endif
if ( ( ( extractFloat64Exp( a ) == 0x7FF ) && extractFloat64Frac( a ) )
|| ( ( extractFloat64Exp( b ) == 0x7FF ) && extractFloat64Frac( b ) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment