VirtualBox

Changeset 94677 in vbox


Ignore:
Timestamp:
Apr 21, 2022 11:51:12 PM (3 years ago)
Author:
vboxsync
Message:

lib/softfloat: Fixed one case of setting the C1 flag during rounding and amended the bias-adjust code to correctly handle the large exponents FSCALE can produce. bugref:9898

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/softfloat-3e/source/s_roundPackToExtF80.c

    r94641 r94677  
    217217            }
    218218            if ( doIncrement ) {
    219                 softfloat_exceptionFlags |= softfloat_flag_c1;                                          /* VBox: C1 */
    220                 //RTAssertMsg2("softfloat_roundPackToExtF80: C1 #5\n");                                 /* VBox: C1 */
     219                uint64_t const uOldSig = sig;                                                           /* VBox: C1 */
    221220                ++sig;
    222221                sig &=
     
    224223                         (! (sigExtra & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
    225224                              & roundNearEven);
     225                if (sig > uOldSig) {                                                                    /* VBox: C1 */
     226                    softfloat_exceptionFlags |= softfloat_flag_c1;                                      /* VBox: C1 */
     227                    //RTAssertMsg2("softfloat_roundPackToExtF80: C1 #5\n");                             /* VBox: C1 */
     228                }                                                                                       /* VBox: C1 */
    226229                exp = ((sig & UINT64_C( 0x8000000000000000 )) != 0);
    227230            }
     
    296299}
    297300
     301/**
     302 * VBox: Wrapper for implementing underflow and overflow bias adjustment.
     303 */
    298304extFloat80_t
    299305 softfloat_roundPackToExtF80(
     
    306312 )
    307313{
     314    static union extF80M_extF80 const s_aExtF80Zero[2]     =
     315    {
     316        EXTF80M_EXTF80_INIT3_C( 0, 0, 0 ), EXTF80M_EXTF80_INIT3_C( 1, 0, 0 ),
     317    };
     318    static union extF80M_extF80 const s_aExtF80Infinity[2] =
     319    {
     320        EXTF80M_EXTF80_INIT3( 0, RT_BIT_64( 63 ), RTFLOAT80U_EXP_MAX ),
     321        EXTF80M_EXTF80_INIT3( 1, RT_BIT_64( 63 ), RTFLOAT80U_EXP_MAX ),
     322    };
     323
    308324    uint8_t const exceptionFlagsSaved = softfloat_exceptionFlags;
    309325    softfloat_exceptionFlags = 0;
    310     extFloat80_t r80Result = softfloat_roundPackToExtF80Inner(sign, exp, sig, sigExtra, roundingPrecision, pState);
     326    extFloat80_t r80Result = softfloat_roundPackToExtF80Inner( sign, exp, sig, sigExtra, roundingPrecision, pState );
    311327
    312328    if ( !(softfloat_exceptionFlags & ~pState->exceptionMask & (softfloat_flag_underflow | softfloat_flag_overflow)) ) {
    313329        /* likely */
     330    }
     331    /* On Intel 10980XE the FSCALE instruction can cause really large exponents
     332       and the rounding changes when we exceed the bias adjust. */
     333    else if (exp >= RTFLOAT80U_EXP_BIAS_ADJUST + RTFLOAT80U_EXP_MAX) {
     334        Assert( softfloat_exceptionFlags & softfloat_flag_overflow );
     335        softfloat_exceptionFlags |= softfloat_flag_inexact | softfloat_flag_c1;
     336        r80Result = s_aExtF80Infinity[sign].f;
     337    } else if (exp <= -RTFLOAT80U_EXP_BIAS_ADJUST) {
     338        Assert( softfloat_exceptionFlags & softfloat_flag_underflow );
     339        softfloat_exceptionFlags &= ~softfloat_flag_c1;
     340        softfloat_exceptionFlags |= softfloat_flag_inexact;
     341        r80Result = s_aExtF80Zero[sign].f;
    314342    } else {
     343        /* Redo the conversion with the bias applied.  */
    315344        softfloat_exceptionFlags &= softfloat_flag_underflow | softfloat_flag_overflow;
    316345        if ( softfloat_exceptionFlags & softfloat_flag_underflow ) {
    317             exp = (exp + RTFLOAT80U_EXP_BIAS_ADJUST) & RTFLOAT80U_EXP_MAX;
     346            exp += RTFLOAT80U_EXP_BIAS_ADJUST;
     347            Assert( exp > 0 );
    318348        } else {
    319             exp = (exp - RTFLOAT80U_EXP_BIAS_ADJUST) & RTFLOAT80U_EXP_MAX;
    320         }
    321         r80Result = softfloat_roundPackToExtF80Inner(sign, exp, sig, sigExtra, roundingPrecision, pState);
     349            exp -= RTFLOAT80U_EXP_BIAS_ADJUST;
     350            Assert( exp < RTFLOAT80U_EXP_MAX );
     351        }
     352        r80Result = softfloat_roundPackToExtF80Inner( sign, exp, sig, sigExtra, roundingPrecision, pState );
    322353    }
    323354
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette