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

Function roundAndPackFloatx80

src/softfloat/softfloat.cpp:1349–1498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1347#else // SOFTFLOAT_68K
1348
1349floatx80 roundAndPackFloatx80( int8_t roundingPrecision, flag zSign, int32_t zExp, uint64_t zSig0, uint64_t zSig1, float_status *status )
1350{
1351 int8_t roundingMode;
1352 flag roundNearestEven, increment;
1353 uint64_t roundMask, roundBits;
1354 uint64_t roundIncrement;
1355 int32_t expOffset;
1356
1357 roundingMode = status->float_rounding_mode;
1358 roundNearestEven = ( roundingMode == float_round_nearest_even );
1359 if ( roundingPrecision == 80 ) goto precision80;
1360 if ( roundingPrecision == 64 ) {
1361 roundIncrement = LIT64( 0x0000000000000400 );
1362 roundMask = LIT64( 0x00000000000007FF );
1363 expOffset = 0x3C00;
1364 } else if ( roundingPrecision == 32 ) {
1365 roundIncrement = LIT64( 0x0000008000000000 );
1366 roundMask = LIT64( 0x000000FFFFFFFFFF );
1367 expOffset = 0x3F80;
1368 } else {
1369 goto precision80;
1370 }
1371 zSig0 |= ( zSig1 != 0 );
1372 if ( ! roundNearestEven ) {
1373 if ( roundingMode == float_round_to_zero ) {
1374 roundIncrement = 0;
1375 } else {
1376 roundIncrement = roundMask;
1377 if ( zSign ) {
1378 if ( roundingMode == float_round_up ) roundIncrement = 0;
1379 } else {
1380 if ( roundingMode == float_round_down ) roundIncrement = 0;
1381 }
1382 }
1383 }
1384 roundBits = zSig0 & roundMask;
1385 if ( ( ( 0x7FFE - expOffset ) < zExp ) ||
1386 ( ( zExp == ( 0x7FFE - expOffset ) ) && ( zSig0 + roundIncrement < zSig0 ) ) ) {
1387 float_raise( float_flag_overflow, status );
1388 saveFloatx80Internal( roundingPrecision, zSign, zExp, zSig0, zSig1, status );
1389 if ( zSig0 & roundMask ) float_raise( float_flag_inexact, status );
1390 if ( ( roundingMode == float_round_to_zero )
1391 || ( zSign && ( roundingMode == float_round_up ) )
1392 || ( ! zSign && ( roundingMode == float_round_down ) )
1393 ) {
1394 return packFloatx80( zSign, 0x7FFE - expOffset, ~ roundMask );
1395 }
1396 return packFloatx80( zSign, 0x7FFF, floatx80_default_infinity_low );
1397 }
1398 if ( zExp < ( expOffset + 1 ) ) {
1399 float_raise( float_flag_underflow, status );
1400 saveFloatx80Internal( roundingPrecision, zSign, zExp, zSig0, zSig1, status );
1401 shift64RightJamming( zSig0, -( zExp - ( expOffset + 1 ) ), &zSig0 );
1402 zExp = expOffset + 1;
1403 roundBits = zSig0 & roundMask;
1404 if ( roundBits ) float_raise( float_flag_inexact, status );
1405 zSig0 += roundIncrement;
1406 roundIncrement = roundMask + 1;

Callers 15

roundSigAndPackFloatx80Function · 0.85
addFloatx80SigsFunction · 0.85
floatx80_mulFunction · 0.85
floatx80_divFunction · 0.85
floatx80_modFunction · 0.85
floatx80_sqrtFunction · 0.85
floatx80_scaleFunction · 0.85
floatx80_absFunction · 0.85
floatx80_negFunction · 0.85

Calls 5

float_raiseFunction · 0.85
saveFloatx80InternalFunction · 0.85
packFloatx80Function · 0.85
shift64RightJammingFunction · 0.85
shift64ExtraRightJammingFunction · 0.85

Tested by

no test coverage detected