MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / roundSigAndPackFloatx80

Function roundSigAndPackFloatx80

src/softfloat/softfloat.cpp:1503–1592  ·  view source on GitHub ↗

21-01-2017: Added for Previous

Source from the content-addressed store, hash-verified

1501
1502#ifdef SOFTFLOAT_68K // 21-01-2017: Added for Previous
1503floatx80 roundSigAndPackFloatx80( int8_t roundingPrecision, flag zSign, int32_t zExp, uint64_t zSig0, uint64_t zSig1, float_status *status )
1504{
1505 int8_t roundingMode;
1506 flag roundNearestEven, isTiny;
1507 uint64_t roundMask, roundBits;
1508 uint64_t roundIncrement;
1509
1510 roundingMode = status->float_rounding_mode;
1511 roundNearestEven = ( roundingMode == float_round_nearest_even );
1512 if ( roundingPrecision == 32 ) {
1513 roundIncrement = LIT64( 0x0000008000000000 );
1514 roundMask = LIT64( 0x000000FFFFFFFFFF );
1515 } else if ( roundingPrecision == 64 ) {
1516 roundIncrement = LIT64( 0x0000000000000400 );
1517 roundMask = LIT64( 0x00000000000007FF );
1518 } else {
1519 return roundAndPackFloatx80( 80, zSign, zExp, zSig0, zSig1, status );
1520 }
1521 zSig0 |= ( zSig1 != 0 );
1522 if ( ! roundNearestEven ) {
1523 if ( roundingMode == float_round_to_zero ) {
1524 roundIncrement = 0;
1525 }
1526 else {
1527 roundIncrement = roundMask;
1528 if ( zSign ) {
1529 if ( roundingMode == float_round_up ) roundIncrement = 0;
1530 }
1531 else {
1532 if ( roundingMode == float_round_down ) roundIncrement = 0;
1533 }
1534 }
1535 }
1536 roundBits = zSig0 & roundMask;
1537
1538 if ( 0x7FFE <= (uint32_t) zExp ) {
1539 if ( ( 0x7FFE < zExp )
1540 || ( ( zExp == 0x7FFE ) && ( zSig0 + roundIncrement < zSig0 ) )
1541 ) {
1542 float_raise( float_flag_overflow, status );
1543 saveFloatx80Internal( roundingPrecision, zSign, zExp, zSig0, zSig1, status);
1544 if ( zSig0 & roundMask ) float_raise( float_flag_inexact, status );
1545 if ( ( roundingMode == float_round_to_zero )
1546 || ( zSign && ( roundingMode == float_round_up ) )
1547 || ( ! zSign && ( roundingMode == float_round_down ) )
1548 ) {
1549 return packFloatx80( zSign, 0x7FFE, LIT64( 0xFFFFFFFFFFFFFFFF ) );
1550 }
1551 return packFloatx80( zSign, 0x7FFF, floatx80_default_infinity_low );
1552 }
1553
1554 if ( zExp < 0 ) {
1555 isTiny =
1556 ( status->float_detect_tininess == float_tininess_before_rounding )
1557 || ( zExp < -1 )
1558 || ( zSig0 <= zSig0 + roundIncrement );
1559 if ( isTiny ) {
1560 float_raise( float_flag_underflow, status );

Callers 4

floatx80_round32Function · 0.85
floatx80_round64Function · 0.85
floatx80_sglmulFunction · 0.85
floatx80_sgldivFunction · 0.85

Calls 5

roundAndPackFloatx80Function · 0.85
float_raiseFunction · 0.85
saveFloatx80InternalFunction · 0.85
packFloatx80Function · 0.85
shift64RightJammingFunction · 0.85

Tested by

no test coverage detected