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

Function roundAndPackFloat32

src/softfloat/softfloat.cpp:750–826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

748*----------------------------------------------------------------------------*/
749
750static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig,
751 float_status *status)
752{
753 int8_t roundingMode;
754 flag roundNearestEven;
755 int8_t roundIncrement, roundBits;
756 flag isTiny;
757
758 roundingMode = status->float_rounding_mode;
759 roundNearestEven = ( roundingMode == float_round_nearest_even );
760 switch (roundingMode) {
761 case float_round_nearest_even:
762 case float_round_ties_away:
763 roundIncrement = 0x40;
764 break;
765 case float_round_to_zero:
766 roundIncrement = 0;
767 break;
768 case float_round_up:
769 roundIncrement = zSign ? 0 : 0x7f;
770 break;
771 case float_round_down:
772 roundIncrement = zSign ? 0x7f : 0;
773 break;
774 default:
775 abort();
776 break;
777 }
778 roundBits = zSig & 0x7F;
779 if ( 0xFD <= (uint16_t) zExp ) {
780 if ( ( 0xFD < zExp )
781 || ( ( zExp == 0xFD )
782 && ( (int32_t) ( zSig + roundIncrement ) < 0 ) )
783 ) {
784#ifdef SOFTFLOAT_68K
785 float_raise( float_flag_overflow, status );
786 saveFloat32Internal( zSign, zExp, zSig, status );
787 if ( roundBits ) float_raise( float_flag_inexact, status );
788#else
789 float_raise(float_flag_overflow | float_flag_inexact, status);
790#endif
791 return packFloat32( zSign, 0xFF, - ( roundIncrement == 0 ));
792 }
793 if ( zExp < 0 ) {
794 if (status->flush_to_zero) {
795 //float_raise(float_flag_output_denormal, status);
796 return packFloat32(zSign, 0, 0);
797 }
798 isTiny =
799 (status->float_detect_tininess
800 == float_tininess_before_rounding)
801 || ( zExp < -1 )
802 || ( zSig + roundIncrement < 0x80000000 );
803#ifdef SOFTFLOAT_68K
804 if ( isTiny ) {
805 float_raise( float_flag_underflow, status );
806 saveFloat32Internal( zSign, zExp, zSig, status );
807 }

Callers 1

floatx80_to_float32Function · 0.85

Calls 4

float_raiseFunction · 0.85
saveFloat32InternalFunction · 0.85
packFloat32Function · 0.85
shift32RightJammingFunction · 0.85

Tested by

no test coverage detected