Esempio n. 1
0
float16_t f128M_to_f16( const float128_t *aPtr )
{
    const uint32_t *aWPtr;
    uint32_t uiA96;
    bool sign;
    int32_t exp;
    uint32_t frac32;
    struct commonNaN commonNaN;
    uint16_t uiZ, frac16;
    union ui16_f16 uZ;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    aWPtr = (const uint32_t *) aPtr;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    uiA96 = aWPtr[indexWordHi( 4 )];
    sign = signF128UI96( uiA96 );
    exp  = expF128UI96( uiA96 );
    frac32 =
        fracF128UI96( uiA96 )
            | ((aWPtr[indexWord( 4, 2 )] | aWPtr[indexWord( 4, 1 )]
                    | aWPtr[indexWord( 4, 0 )])
                   != 0);
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( exp == 0x7FFF ) {
        if ( frac32 ) {
            softfloat_f128MToCommonNaN( aWPtr, &commonNaN );
            uiZ = softfloat_commonNaNToF16UI( &commonNaN );
        } else {
            uiZ = packToF16UI( sign, 0x1F, 0 );
        }
        goto uiZ;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    frac16 = frac32>>2 | (frac32 & 3);
    if ( ! (exp | frac16) ) {
        uiZ = packToF16UI( sign, 0, 0 );
        goto uiZ;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    exp -= 0x3FF1;
    if ( sizeof (int_fast16_t) < sizeof (int32_t) ) {
        if ( exp < -0x40 ) exp = -0x40;
    }
    return softfloat_roundPackToF16( sign, exp, frac16 | 0x4000 );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 uiZ:
    uZ.ui = uiZ;
    return uZ.f;

}
Esempio n. 2
0
float32_t f128M_to_f32( const float128_t *aPtr )
{
    const uint32_t *aWPtr;
    uint32_t uiA96;
    bool sign;
    int32_t exp;
    uint64_t frac64;
    struct commonNaN commonNaN;
    uint32_t uiZ, frac32;
    union ui32_f32 uZ;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    aWPtr = (const uint32_t *) aPtr;
    uiA96 = aWPtr[indexWordHi( 4 )];
    sign = signF128UI96( uiA96 );
    exp  = expF128UI96( uiA96 );
    frac64 =
        (uint64_t) fracF128UI96( uiA96 )<<32 | aWPtr[indexWord( 4, 2 )]
            | ((aWPtr[indexWord( 4, 1 )] | aWPtr[indexWord( 4, 0 )]) != 0);
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( exp == 0x7FFF ) {
        if ( frac64 ) {
            softfloat_f128MToCommonNaN( aWPtr, &commonNaN );
            uiZ = softfloat_commonNaNToF32UI( &commonNaN );
        } else {
            uiZ = packToF32UI( sign, 0xFF, 0 );
        }
        goto uiZ;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    frac32 = softfloat_shortShiftRightJam64( frac64, 18 );
    if ( ! (exp | frac32) ) {
        uiZ = packToF32UI( sign, 0, 0 );
        goto uiZ;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    exp -= 0x3F81;
    if ( sizeof (int_fast16_t) < sizeof (int32_t) ) {
        if ( exp < -0x1000 ) exp = -0x1000;
    }
    return softfloat_roundPackToF32( sign, exp, frac32 | 0x40000000 );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 uiZ:
    uZ.ui = uiZ;
    return uZ.f;

}
Esempio n. 3
0
void f128M_to_extF80M( const float128_t *aPtr, extFloat80_t *zPtr )
{
    const uint32_t *aWPtr;
    struct extFloat80M *zSPtr;
    uint32_t uiA96;
    bool sign;
    int32_t exp;
    struct commonNaN commonNaN;
    uint32_t sig[4];

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    aWPtr = (const uint32_t *) aPtr;
    zSPtr = (struct extFloat80M *) zPtr;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    uiA96 = aWPtr[indexWordHi( 4 )];
    sign = signF128UI96( uiA96 );
    exp  = expF128UI96( uiA96 );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( exp == 0x7FFF ) {
        if ( softfloat_isNaNF128M( aWPtr ) ) {
            softfloat_f128MToCommonNaN( aWPtr, &commonNaN );
            softfloat_commonNaNToExtF80M( &commonNaN, zSPtr );
            return;
        }
        zSPtr->signExp = packToExtF80UI64( sign, 0x7FFF );
        zSPtr->signif = UINT64_C( 0x8000000000000000 );
        return;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    exp = softfloat_shiftNormSigF128M( aWPtr, 15, sig );
    if ( exp == -128 ) {
        zSPtr->signExp = packToExtF80UI64( sign, 0 );
        zSPtr->signif = 0;
        return;
    }
    if ( sig[indexWord( 4, 0 )] ) sig[indexWord( 4, 1 )] |= 1;
    softfloat_roundPackMToExtF80M(
        sign, exp, &sig[indexMultiwordHi( 4, 3 )], 80, zSPtr );

}
Esempio n. 4
0
uint_fast64_t
 f128M_to_ui64( const float128_t *aPtr, uint_fast8_t roundingMode, bool exact )
{
    const uint32_t *aWPtr;
    uint32_t uiA96;
    bool sign;
    int32_t exp;
    uint32_t sig96;
    int32_t shiftDist;
    uint32_t sig[4];

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    aWPtr = (const uint32_t *) aPtr;
    uiA96 = aWPtr[indexWordHi( 4 )];
    sign  = signF128UI96( uiA96 );
    exp   = expF128UI96( uiA96 );
    sig96 = fracF128UI96( uiA96 );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    shiftDist = 0x404F - exp;
    if ( shiftDist < 17 ) {
        softfloat_raiseFlags( softfloat_flag_invalid );
        return
            (exp == 0x7FFF)
                && (sig96
                        || (aWPtr[indexWord( 4, 2 )] | aWPtr[indexWord( 4, 1 )]
                                | aWPtr[indexWord( 4, 0 )]))
                ? ui64_fromNaN
                : sign ? ui64_fromNegOverflow : ui64_fromPosOverflow;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( exp ) sig96 |= 0x00010000;
    sig[indexWord( 4, 3 )] = sig96;
    sig[indexWord( 4, 2 )] = aWPtr[indexWord( 4, 2 )];
    sig[indexWord( 4, 1 )] = aWPtr[indexWord( 4, 1 )];
    sig[indexWord( 4, 0 )] = aWPtr[indexWord( 4, 0 )];
    softfloat_shiftRightJam128M( sig, shiftDist, sig );
    return
        softfloat_roundMToUI64(
            sign, sig + indexMultiwordLo( 4, 3 ), roundingMode, exact );

}
Esempio n. 5
0
int_fast64_t
 f128M_to_i64( const float128_t *aPtr, uint_fast8_t roundingMode, bool exact )
{
    const uint32_t *aWPtr;
    uint32_t uiA96;
    int32_t exp;
    bool sign;
    uint32_t sig96;
    int32_t shiftCount;
    uint32_t sig[4];

    aWPtr = (const uint32_t *) aPtr;
    uiA96 = aWPtr[indexWordHi( 4 )];
    exp = expF128UI96( uiA96 );
    sign  = signF128UI96( uiA96 );
    sig96 = fracF128UI96( uiA96 );
    shiftCount = 0x404F - exp;
    if ( shiftCount < 17 ) {
        softfloat_raiseFlags( softfloat_flag_invalid );
        return
            ! sign
                || ((exp == 0x7FFF)
                        && (sig96
                                || (  aWPtr[indexWord( 4, 2 )]
                                    | aWPtr[indexWord( 4, 1 )]
                                    | aWPtr[indexWord( 4, 0 )]
                                   )))
                ? INT64_C( 0x7FFFFFFFFFFFFFFF )
                : -INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1;
    }
    if ( exp ) sig96 |= 0x00010000;
    sig[indexWord( 4, 3 )] = sig96;
    sig[indexWord( 4, 2 )] = aWPtr[indexWord( 4, 2 )];
    sig[indexWord( 4, 1 )] = aWPtr[indexWord( 4, 1 )];
    sig[indexWord( 4, 0 )] = aWPtr[indexWord( 4, 0 )];
    softfloat_shiftRightJam128M( sig, shiftCount, sig );
    return
        softfloat_roundPackMToI64(
            sign, sig + indexMultiwordLo( 4, 3 ), roundingMode, exact );

}
Esempio n. 6
0
uint_fast32_t
 f128M_to_ui32( const float128_t *aPtr, uint_fast8_t roundingMode, bool exact )
{
    const uint32_t *aWPtr;
    uint32_t uiA96;
    bool sign;
    int32_t exp;
    uint64_t sig64;
    int32_t shiftDist;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    aWPtr = (const uint32_t *) aPtr;
    uiA96 = aWPtr[indexWordHi( 4 )];
    sign = signF128UI96( uiA96 );
    exp  = expF128UI96( uiA96 );
    sig64 = (uint64_t) fracF128UI96( uiA96 )<<32 | aWPtr[indexWord( 4, 2 )];
    if ( aWPtr[indexWord( 4, 1 )] | aWPtr[indexWord( 4, 0 )] ) sig64 |= 1;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
#if (ui32_fromNaN != ui32_fromPosOverflow) || (ui32_fromNaN != ui32_fromNegOverflow)
    if ( (exp == 0x7FFF) && sig64 ) {
#if (ui32_fromNaN == ui32_fromPosOverflow)
        sign = 0;
#elif (ui32_fromNaN == ui32_fromNegOverflow)
        sign = 1;
#else
        softfloat_raiseFlags( softfloat_flag_invalid );
        return ui32_fromNaN;
#endif
    }
#endif
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( exp ) sig64 |= UINT64_C( 0x0001000000000000 );
    shiftDist = 0x4028 - exp;
    if ( 0 < shiftDist ) sig64 = softfloat_shiftRightJam64( sig64, shiftDist );
    return softfloat_roundPackToUI32( sign, sig64, roundingMode, exact );

}
Esempio n. 7
0
uint_fast32_t
 f128M_to_ui32( const float128_t *aPtr, uint_fast8_t roundingMode, bool exact )
{
    const uint32_t *aWPtr;
    uint32_t uiA96;
    int32_t exp;
    uint64_t sig64;
    int32_t shiftCount;

    aWPtr = (const uint32_t *) aPtr;
    uiA96 = aWPtr[indexWordHi( 4 )];
    exp = expF128UI96( uiA96 );
    sig64 = (uint64_t) fracF128UI96( uiA96 )<<32 | aWPtr[indexWord( 4, 2 )];
    if ( exp ) sig64 |= UINT64_C( 0x0001000000000000 );
    if ( aWPtr[indexWord( 4, 1 )] | aWPtr[indexWord( 4, 0 )] ) sig64 |= 1;
    shiftCount = 0x4028 - exp;
    if ( 0 < shiftCount ) {
        sig64 = softfloat_shiftRightJam64( sig64, shiftCount );
    }
    return
        softfloat_roundPackToUI32(
            signF128UI96( uiA96 ), sig64, roundingMode, exact );

}
void
 f128M_roundToInt(
     const float128_t *aPtr,
     uint_fast8_t roundingMode,
     bool exact,
     float128_t *zPtr
 )
{
    const uint32_t *aWPtr;
    uint32_t *zWPtr;
    uint32_t ui96;
    int32_t exp;
    uint32_t sigExtra;
    bool sign;
    uint_fast8_t bitPos;
    bool roundNear;
    unsigned int index, lastIndex;
    bool extra;
    uint32_t wordA, bit, wordZ;
    uint_fast8_t carry;
    uint32_t extrasMask;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    aWPtr = (const uint32_t *) aPtr;
    zWPtr = (uint32_t *) zPtr;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    ui96 = aWPtr[indexWordHi( 4 )];
    exp = expF128UI96( ui96 );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( exp < 0x3FFF ) {
        zWPtr[indexWord( 4, 2 )] = 0;
        zWPtr[indexWord( 4, 1 )] = 0;
        zWPtr[indexWord( 4, 0 )] = 0;
        sigExtra = aWPtr[indexWord( 4, 2 )];
        if ( ! sigExtra ) {
            sigExtra = aWPtr[indexWord( 4, 1 )] | aWPtr[indexWord( 4, 0 )];
        }
        if ( ! sigExtra && ! (ui96 & 0x7FFFFFFF) ) goto ui96;
        if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact;
        sign = signF128UI96( ui96 );
        switch ( roundingMode ) {
         case softfloat_round_near_even:
            if ( ! fracF128UI96( ui96 ) && ! sigExtra ) break;
         case softfloat_round_near_maxMag:
            if ( exp == 0x3FFE ) goto mag1;
            break;
         case softfloat_round_min:
            if ( sign ) goto mag1;
            break;
         case softfloat_round_max:
            if ( ! sign ) goto mag1;
            break;
        }
        ui96 = packToF128UI96( sign, 0, 0 );
        goto ui96;
     mag1:
        ui96 = packToF128UI96( sign, 0x3FFF, 0 );
        goto ui96;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( 0x406F <= exp ) {
        if (
            (exp == 0x7FFF)
                && (fracF128UI96( ui96 )
                        || (aWPtr[indexWord( 4, 2 )] | aWPtr[indexWord( 4, 1 )]
                                | aWPtr[indexWord( 4, 0 )]))
        ) {
            softfloat_propagateNaNF128M( aWPtr, 0, zWPtr );
            return;
        }
        zWPtr[indexWord( 4, 2 )] = aWPtr[indexWord( 4, 2 )];
        zWPtr[indexWord( 4, 1 )] = aWPtr[indexWord( 4, 1 )];
        zWPtr[indexWord( 4, 0 )] = aWPtr[indexWord( 4, 0 )];
        goto ui96;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    bitPos = 0x406F - exp;
    roundNear =
           (roundingMode == softfloat_round_near_maxMag)
        || (roundingMode == softfloat_round_near_even);
    bitPos -= roundNear;
    index = indexWordLo( 4 );
    lastIndex = indexWordHi( 4 );
    extra = 0;
    for (;;) {
        wordA = aWPtr[index];
        if ( bitPos < 32 ) break;
        if ( wordA ) extra = 1;
        zWPtr[index] = 0;
        index += wordIncr;
        bitPos -= 32;
    }
    bit = (uint32_t) 1<<bitPos;
    if ( roundNear ) {
        wordZ = wordA + bit;
        carry = (wordZ < wordA);
        bit <<= 1;
        extrasMask = bit - 1;
        if (
            (roundingMode == softfloat_round_near_even)
                && ! extra && ! (wordZ & extrasMask)
        ) {
            if ( ! bit ) {
                zWPtr[index] = wordZ;
                index += wordIncr;
                wordZ = aWPtr[index] + carry;
                carry &= ! wordZ;
                zWPtr[index] = wordZ & ~1;
                goto propagateCarry;
            }
            wordZ &= ~bit;
        }
    } else {
        extrasMask = bit - 1;
        wordZ = wordA;
        carry = 0;
        if (
               (roundingMode != softfloat_round_minMag)
            && (signF128UI96( ui96 ) ^ (roundingMode == softfloat_round_max))
        ) {
            if ( extra || (wordA & extrasMask) ) {
                wordZ += bit;
                carry = (wordZ < wordA);
            }
        }
    }
    wordZ &= ~extrasMask;
    zWPtr[index] = wordZ;
 propagateCarry:
    while ( index != lastIndex ) {
        index += wordIncr;
        wordZ = aWPtr[index] + carry;
        zWPtr[index] = wordZ;
        carry &= ! wordZ;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( exact && (softfloat_compare128M( aWPtr, zWPtr ) != 0) ) {
        softfloat_exceptionFlags |= softfloat_flag_inexact;
    }
    return;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 ui96:
    zWPtr[indexWordHi( 4 )] = ui96;

}
Esempio n. 9
0
void
 f128M_mul( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr )
{
    const uint32_t *aWPtr, *bWPtr;
    uint32_t *zWPtr;
    uint32_t uiA96;
    int32_t expA;
    uint32_t uiB96;
    int32_t expB;
    bool signZ;
    const uint32_t *ptr;
    uint32_t uiZ96, sigA[4];
    uint_fast8_t shiftDist;
    uint32_t sigB[4];
    int32_t expZ;
    uint32_t sigProd[8], *extSigZPtr;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    aWPtr = (const uint32_t *) aPtr;
    bWPtr = (const uint32_t *) bPtr;
    zWPtr = (uint32_t *) zPtr;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    uiA96 = aWPtr[indexWordHi( 4 )];
    expA = expF128UI96( uiA96 );
    uiB96 = bWPtr[indexWordHi( 4 )];
    expB = expF128UI96( uiB96 );
    signZ = signF128UI96( uiA96 ) ^ signF128UI96( uiB96 );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
        if ( softfloat_tryPropagateNaNF128M( aWPtr, bWPtr, zWPtr ) ) return;
        ptr = aWPtr;
        if ( ! expA ) goto possiblyInvalid;
        if ( ! expB ) {
            ptr = bWPtr;
     possiblyInvalid:
            if (
                ! fracF128UI96( ptr[indexWordHi( 4 )] )
                    && ! (ptr[indexWord( 4, 2 )] | ptr[indexWord( 4, 1 )]
                              | ptr[indexWord( 4, 0 )])
            ) {
                softfloat_invalidF128M( zWPtr );
                return;
            }
        }
        uiZ96 = packToF128UI96( signZ, 0x7FFF, 0 );
        goto uiZ96;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( expA ) {
        sigA[indexWordHi( 4 )] = fracF128UI96( uiA96 ) | 0x00010000;
        sigA[indexWord( 4, 2 )] = aWPtr[indexWord( 4, 2 )];
        sigA[indexWord( 4, 1 )] = aWPtr[indexWord( 4, 1 )];
        sigA[indexWord( 4, 0 )] = aWPtr[indexWord( 4, 0 )];
    } else {
        expA = softfloat_shiftNormSigF128M( aWPtr, 0, sigA );
        if ( expA == -128 ) goto zero;
    }
    if ( expB ) {
        sigB[indexWordHi( 4 )] = fracF128UI96( uiB96 ) | 0x00010000;
        sigB[indexWord( 4, 2 )] = bWPtr[indexWord( 4, 2 )];
        sigB[indexWord( 4, 1 )] = bWPtr[indexWord( 4, 1 )];
        sigB[indexWord( 4, 0 )] = bWPtr[indexWord( 4, 0 )];
    } else {
        expB = softfloat_shiftNormSigF128M( bWPtr, 0, sigB );
        if ( expB == -128 ) goto zero;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    expZ = expA + expB - 0x4000;
    softfloat_mul128MTo256M( sigA, sigB, sigProd );
    if (
        sigProd[indexWord( 8, 2 )]
            || (sigProd[indexWord( 8, 1 )] | sigProd[indexWord( 8, 0 )])
    ) {
        sigProd[indexWord( 8, 3 )] |= 1;
    }
    extSigZPtr = &sigProd[indexMultiwordHi( 8, 5 )];
    shiftDist = 16;
    if ( extSigZPtr[indexWordHi( 5 )] & 2 ) {
        ++expZ;
        shiftDist = 15;
    }
    softfloat_shortShiftLeft160M( extSigZPtr, shiftDist, extSigZPtr );
    softfloat_roundPackMToF128M( signZ, expZ, extSigZPtr, zWPtr );
    return;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 zero:
    uiZ96 = packToF128UI96( signZ, 0, 0 );
 uiZ96:
    zWPtr[indexWordHi( 4 )] = uiZ96;
    zWPtr[indexWord( 4, 2 )] = 0;
    zWPtr[indexWord( 4, 1 )] = 0;
    zWPtr[indexWord( 4, 0 )] = 0;

}
Esempio n. 10
0
void
 softfloat_mulAddF128M(
     const uint32_t *aWPtr,
     const uint32_t *bWPtr,
     const uint32_t *cWPtr,
     uint32_t *zWPtr,
     uint_fast8_t op
 )
{
    uint32_t uiA96;
    int32_t expA;
    uint32_t uiB96;
    int32_t expB;
    uint32_t uiC96;
    bool signC;
    int32_t expC;
    bool signProd, prodIsInfinite;
    uint32_t *ptr, uiZ96, sigA[4];
    uint_fast8_t shiftCount;
    uint32_t sigX[5];
    int32_t expProd;
    uint32_t sigProd[8], wordSig;
    bool doSub;
    uint_fast8_t
     (*addCarryMRoutinePtr)(
         uint_fast8_t,
         const uint32_t *,
         const uint32_t *,
         uint_fast8_t,
         uint32_t *
     );
    int32_t expDiff;
    bool signZ;
    int32_t expZ;
    uint32_t *extSigPtr;
    uint_fast8_t carry;
    void (*roundPackRoutinePtr)( bool, int32_t, uint32_t *, uint32_t * );

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    uiA96 = aWPtr[indexWordHi( 4 )];
    expA = expF128UI96( uiA96 );
    uiB96 = bWPtr[indexWordHi( 4 )];
    expB = expF128UI96( uiB96 );
    uiC96 = cWPtr[indexWordHi( 4 )];
    signC = signF128UI96( uiC96 ) ^ (op == softfloat_mulAdd_subC);
    expC = expF128UI96( uiC96 );
    signProd =
        signF128UI96( uiA96 ) ^ signF128UI96( uiB96 )
            ^ (op == softfloat_mulAdd_subProd);
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    prodIsInfinite = false;
    if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
        if ( softfloat_tryPropagateNaNF128M( aWPtr, bWPtr, zWPtr ) ) {
            goto propagateNaN_ZC;
        }
        ptr = (uint32_t *) aWPtr;
        if ( ! (uint32_t) (uiA96<<1) ) goto possibleInvalidProd;
        if ( ! (uint32_t) (uiB96<<1) ) {
            ptr = (uint32_t *) bWPtr;
     possibleInvalidProd:
            if (
                ! (ptr[indexWord( 4, 2 )] | ptr[indexWord( 4, 1 )]
                       | ptr[indexWord( 4, 0 )])
            ) {
                goto invalid;
            }
        }
        prodIsInfinite = true;
    }
    if ( expC == 0x7FFF ) {
        if (
            fracF128UI96( uiC96 )
                || (cWPtr[indexWord( 4, 2 )] | cWPtr[indexWord( 4, 1 )]
                        | cWPtr[indexWord( 4, 0 )])
        ) {
            zWPtr[indexWordHi( 4 )] = 0;
            goto propagateNaN_ZC;
        }
        if ( prodIsInfinite && (signProd != signC) ) goto invalid;
        goto copyC;
    }
    if ( prodIsInfinite ) {
        uiZ96 = packToF128UI96( signProd, 0x7FFF, 0 );
        goto uiZ;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( expA ) {
        sigA[indexWordHi( 4 )] = fracF128UI96( uiA96 ) | 0x00010000;
        sigA[indexWord( 4, 2 )] = aWPtr[indexWord( 4, 2 )];
        sigA[indexWord( 4, 1 )] = aWPtr[indexWord( 4, 1 )];
        sigA[indexWord( 4, 0 )] = aWPtr[indexWord( 4, 0 )];
    } else {
        expA = softfloat_shiftNormSigF128M( aWPtr, 0, sigA );
        if ( expA == -128 ) goto zeroProd;
    }
    if ( expB ) {
        sigX[indexWordHi( 4 )] = fracF128UI96( uiB96 ) | 0x00010000;
        sigX[indexWord( 4, 2 )] = bWPtr[indexWord( 4, 2 )];
        sigX[indexWord( 4, 1 )] = bWPtr[indexWord( 4, 1 )];
        sigX[indexWord( 4, 0 )] = bWPtr[indexWord( 4, 0 )];
    } else {
        expB = softfloat_shiftNormSigF128M( bWPtr, 0, sigX );
        if ( expB == -128 ) goto zeroProd;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    expProd = expA + expB - 0x3FF0;
    softfloat_mul128MTo256M( sigA, sigX, sigProd );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    wordSig = fracF128UI96( uiC96 );
    if ( expC ) {
        --expC;
        wordSig |= 0x00010000;
    }
    sigX[indexWordHi( 5 )] = wordSig;
    sigX[indexWord( 5, 3 )] = cWPtr[indexWord( 4, 2 )];
    sigX[indexWord( 5, 2 )] = cWPtr[indexWord( 4, 1 )];
    sigX[indexWord( 5, 1 )] = cWPtr[indexWord( 4, 0 )];
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    doSub = (signProd != signC);
    addCarryMRoutinePtr =
        doSub ? softfloat_addComplCarryM : softfloat_addCarryM;
    expDiff = expProd - expC;
    if ( expDiff <= 0 ) {
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
        signZ = signC;
        expZ = expC;
        if (
            sigProd[indexWord( 8, 2 )]
                || (sigProd[indexWord( 8, 1 )] | sigProd[indexWord( 8, 0 )])
        ) {
            sigProd[indexWord( 8, 3 )] |= 1;
        }
        extSigPtr = &sigProd[indexMultiwordHi( 8, 5 )];
        if ( expDiff ) {
            softfloat_shiftRightJam160M( extSigPtr, -expDiff, extSigPtr );
        }
        carry = 0;
        if ( doSub ) {
            wordSig = extSigPtr[indexWordLo( 5 )];
            extSigPtr[indexWordLo( 5 )] = -wordSig;
            carry = ! wordSig;
        }
        (*addCarryMRoutinePtr)(
            4,
            &sigX[indexMultiwordHi( 5, 4 )],
            extSigPtr + indexMultiwordHi( 5, 4 ),
            carry,
            extSigPtr + indexMultiwordHi( 5, 4 )
        );
        wordSig = extSigPtr[indexWordHi( 5 )];
        if ( ! expZ ) {
            if ( wordSig & 0x80000000 ) {
                signZ = ! signZ;
                softfloat_negX160M( extSigPtr );
                wordSig = extSigPtr[indexWordHi( 5 )];
            }
            goto checkCancellation;
        }
        if ( wordSig < 0x00010000 ) {
            --expZ;
            softfloat_add160M( extSigPtr, extSigPtr, extSigPtr );
            goto roundPack;
        }
        goto extSigReady_noCancellation;
    } else {
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
        signZ = signProd;
        expZ = expProd;
        sigX[indexWordLo( 5 )] = 0;
        expDiff -= 128;
        if ( 0 <= expDiff ) {
            /*----------------------------------------------------------------
            *----------------------------------------------------------------*/
            if ( expDiff ) softfloat_shiftRightJam160M( sigX, expDiff, sigX );
            wordSig = sigX[indexWordLo( 5 )];
            carry = 0;
            if ( doSub ) {
                carry = ! wordSig;
                wordSig = -wordSig;
            }
            carry =
                (*addCarryMRoutinePtr)(
                    4,
                    &sigProd[indexMultiwordLo( 8, 4 )],
                    &sigX[indexMultiwordHi( 5, 4 )],
                    carry,
                    &sigProd[indexMultiwordLo( 8, 4 )]
                );
            sigProd[indexWord( 8, 2 )] |= wordSig;
            ptr = &sigProd[indexWord( 8, 4 )];
        } else {
            /*----------------------------------------------------------------
            *----------------------------------------------------------------*/
            shiftCount = expDiff & 31;
            if ( shiftCount ) {
                softfloat_shortShiftRight160M( sigX, shiftCount, sigX );
            }
            expDiff >>= 5;
            extSigPtr =
                &sigProd[indexMultiwordLo( 8, 5 )] - wordIncr
                    + expDiff * -wordIncr;
            carry =
                (*addCarryMRoutinePtr)( 5, extSigPtr, sigX, doSub, extSigPtr );
            if ( expDiff == -4 ) {
                /*------------------------------------------------------------
                *------------------------------------------------------------*/
                wordSig = sigProd[indexWordHi( 8 )];
                if ( wordSig & 0x80000000 ) {
                    signZ = ! signZ;
                    softfloat_negX256M( sigProd );
                    wordSig = sigProd[indexWordHi( 8 )];
                }
                /*------------------------------------------------------------
                *------------------------------------------------------------*/
                if ( wordSig ) goto expProdBigger_noWordShift;
                wordSig = sigProd[indexWord( 8, 6 )];
                if ( 0x00040000 <= wordSig ) goto expProdBigger_noWordShift;
                expZ -= 32;
                extSigPtr = &sigProd[indexMultiwordHi( 8, 5 )] - wordIncr;
                for (;;) {
                    if ( wordSig ) break;
                    wordSig = extSigPtr[indexWord( 5, 3 )];
                    if ( 0x00040000 <= wordSig ) break;
                    expZ -= 32;
                    extSigPtr -= wordIncr;
                    if ( extSigPtr == &sigProd[indexMultiwordLo( 8, 5 )] ) {
                        goto checkCancellation;
                    }
                }
                /*------------------------------------------------------------
                *------------------------------------------------------------*/
                ptr = extSigPtr + indexWordLo( 5 );
                do {
                    ptr -= wordIncr;
                    if ( *ptr ) {
                        extSigPtr[indexWordLo( 5 )] |= 1;
                        break;
                    }
                } while ( ptr != &sigProd[indexWordLo( 8 )] );
                wordSig = extSigPtr[indexWordHi( 5 )];
                goto extSigReady;
            }
            ptr = extSigPtr + indexWordHi( 5 ) + wordIncr;
        }
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
        if ( carry != doSub ) {
            if ( doSub ) {
                do {
                    wordSig = *ptr;
                    *ptr = wordSig - 1;
                    ptr += wordIncr;
                } while ( ! wordSig );
            } else {
                do {
                    wordSig = *ptr + 1;
                    *ptr = wordSig;
                    ptr += wordIncr;
                } while ( ! wordSig );
            }
        }
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
     expProdBigger_noWordShift:
        if (
            sigProd[indexWord( 8, 2 )]
                || (sigProd[indexWord( 8, 1 )] | sigProd[indexWord( 8, 0 )])
        ) {
            sigProd[indexWord( 8, 3 )] |= 1;
        }
        extSigPtr = &sigProd[indexMultiwordHi( 8, 5 )];
        wordSig = extSigPtr[indexWordHi( 5 )];
    }
 extSigReady:
    roundPackRoutinePtr = softfloat_normRoundPackMToF128M;
    if ( wordSig < 0x00010000 ) goto doRoundPack;
 extSigReady_noCancellation:
    if ( 0x00020000 <= wordSig ) {
        ++expZ;
        softfloat_shortShiftRightJam160M( extSigPtr, 1, extSigPtr );
    }
 roundPack:
    roundPackRoutinePtr = softfloat_roundPackMToF128M;
 doRoundPack:
    (*roundPackRoutinePtr)( signZ, expZ, extSigPtr, zWPtr );
    return;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 invalid:
    softfloat_invalidF128M( zWPtr );
 propagateNaN_ZC:
    softfloat_propagateNaNF128M( zWPtr, cWPtr, zWPtr );
    return;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 zeroProd:
    if (
        ! (uint32_t) (uiC96<<1) && (signProd != signC)
            && ! cWPtr[indexWord( 4, 2 )]
            && ! (cWPtr[indexWord( 4, 1 )] | cWPtr[indexWord( 4, 0 )])
    ) {
        goto completeCancellation;
    }
 copyC:
    zWPtr[indexWordHi( 4 )] = uiC96;
    zWPtr[indexWord( 4, 2 )] = cWPtr[indexWord( 4, 2 )];
    zWPtr[indexWord( 4, 1 )] = cWPtr[indexWord( 4, 1 )];
    zWPtr[indexWord( 4, 0 )] = cWPtr[indexWord( 4, 0 )];
    return;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 checkCancellation:
    if (
        wordSig
            || (extSigPtr[indexWord( 5, 3 )] | extSigPtr[indexWord( 5, 2 )])
            || (extSigPtr[indexWord( 5, 1 )] | extSigPtr[indexWord( 5, 0 )])
    ) {
        goto extSigReady;
    }
 completeCancellation:
    uiZ96 =
        packToF128UI96(
            (softfloat_roundingMode == softfloat_round_min), 0, 0 );
 uiZ:
    zWPtr[indexWordHi( 4 )] = uiZ96;
    zWPtr[indexWord( 4, 2 )] = 0;
    zWPtr[indexWord( 4, 1 )] = 0;
    zWPtr[indexWord( 4, 0 )] = 0;

}
Esempio n. 11
0
void
 softfloat_addF128M(
     const uint32_t *aWPtr,
     const uint32_t *bWPtr,
     uint32_t *zWPtr,
     bool negateB
 )
{
    uint32_t uiA96;
    int32_t expA;
    uint32_t uiB96;
    int32_t expB;
    uint32_t uiZ96;
    bool signZ, signB;
    const uint32_t *tempPtr;
    uint32_t sig96A, sig96B;
    int32_t expDiff;
    uint_fast8_t
     (*addCarryMRoutinePtr)(
         uint_fast8_t,
         const uint32_t *,
         const uint32_t *,
         uint_fast8_t,
         uint32_t *
     );
    uint32_t extSigZ[5], wordSigZ;
    uint_fast8_t carry;
    void (*roundPackRoutinePtr)( bool, int32_t, uint32_t *, uint32_t * );

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    uiA96 = aWPtr[indexWordHi( 4 )];
    expA = expF128UI96( uiA96 );
    uiB96 = bWPtr[indexWordHi( 4 )];
    expB = expF128UI96( uiB96 );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
        if ( softfloat_tryPropagateNaNF128M( aWPtr, bWPtr, zWPtr ) ) return;
        uiZ96 = uiA96;
        if ( expB == 0x7FFF ) {
            uiZ96 = uiB96 ^ packToF128UI96( negateB, 0, 0 );
            if ( (expA == 0x7FFF) && (uiZ96 != uiA96) ) {
                softfloat_invalidF128M( zWPtr );
                return;
            }
        }
        zWPtr[indexWordHi( 4 )] = uiZ96;
        zWPtr[indexWord( 4, 2 )] = 0;
        zWPtr[indexWord( 4, 1 )] = 0;
        zWPtr[indexWord( 4, 0 )] = 0;
        return;
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    signZ = signF128UI96( uiA96 );
    signB = signF128UI96( uiB96 ) ^ negateB;
    negateB = (signZ != signB);
    if ( (uint32_t) (uiA96<<1) < (uint32_t) (uiB96<<1) ) {
        signZ = signB;
        expA = expB;
        expB = expF128UI96( uiA96 );
        tempPtr = aWPtr;
        aWPtr = bWPtr;
        bWPtr = tempPtr;
        uiA96 = uiB96;
        uiB96 = bWPtr[indexWordHi( 4 )];
    }
    sig96A = fracF128UI96( uiA96 );
    sig96B = fracF128UI96( uiB96 );
    if ( expA ) {
        --expA;
        sig96A |= 0x00010000;
        if ( expB ) {
            --expB;
            sig96B |= 0x00010000;
        }
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    addCarryMRoutinePtr =
        negateB ? softfloat_addComplCarryM : softfloat_addCarryM;
    expDiff = expA - expB;
    if ( expDiff ) {
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
        extSigZ[indexWordHi( 5 )] = sig96B;
        extSigZ[indexWord( 5, 3 )] = bWPtr[indexWord( 4, 2 )];
        extSigZ[indexWord( 5, 2 )] = bWPtr[indexWord( 4, 1 )];
        extSigZ[indexWord( 5, 1 )] = bWPtr[indexWord( 4, 0 )];
        extSigZ[indexWord( 5, 0 )] = 0;
        softfloat_shiftRightJam160M( extSigZ, expDiff, extSigZ );
        sig96B = extSigZ[indexWordHi( 5 )];
        carry = 0;
        if ( negateB ) {
            sig96B = ~sig96B;
            wordSigZ = extSigZ[indexWordLo( 5 )];
            extSigZ[indexWordLo( 5 )] = -wordSigZ;
            carry = ! wordSigZ;
        }
        carry =
            (*addCarryMRoutinePtr)(
                3,
                &aWPtr[indexMultiwordLo( 4, 3 )],
                &extSigZ[indexMultiword( 5, 3, 1 )],
                carry,
                &extSigZ[indexMultiword( 5, 3, 1 )]
            );
        wordSigZ = sig96A + sig96B + carry;
    } else {
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
        extSigZ[indexWordLo( 5 )] = 0;
        carry =
            (*addCarryMRoutinePtr)(
                3,
                &aWPtr[indexMultiwordLo( 4, 3 )],
                &bWPtr[indexMultiwordLo( 4, 3 )],
                negateB,
                &extSigZ[indexMultiword( 5, 3, 1 )]
            );
        if ( negateB ) {
            wordSigZ = sig96A + ~sig96B + carry;
            if ( wordSigZ & 0x80000000 ) {
                signZ = ! signZ;
                carry =
                    softfloat_addComplCarry96M(
                        &bWPtr[indexMultiwordLo( 4, 3 )],
                        &aWPtr[indexMultiwordLo( 4, 3 )],
                        1,
                        &extSigZ[indexMultiword( 5, 3, 1 )]
                    );
                wordSigZ = sig96B + ~sig96A + carry;
            } else {
                if (
                    ! wordSigZ && ! extSigZ[indexWord( 5, 3 )]
                        && ! (  extSigZ[indexWord( 5, 2 )]
                              | extSigZ[indexWord( 5, 1 )]
                              | extSigZ[indexWord( 5, 0 )]
                             )
                ) {
                    signZ = (softfloat_roundingMode == softfloat_round_min);
                    zWPtr[indexWordHi( 4 )] = packToF128UI96( signZ, 0, 0 );
                    zWPtr[indexWord( 4, 2 )] = 0;
                    zWPtr[indexWord( 4, 1 )] = 0;
                    zWPtr[indexWord( 4, 0 )] = 0;
                    return;
                }
            }
        } else {
            wordSigZ = sig96A + sig96B + carry;
        }
    }
    extSigZ[indexWordHi( 5 )] = wordSigZ;
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    roundPackRoutinePtr = softfloat_normRoundPackMToF128M;
    if ( 0x00010000 <= wordSigZ ) {
        if ( 0x00020000 <= wordSigZ ) {
            ++expA;
            softfloat_shortShiftRightJam160M( extSigZ, 1, extSigZ );
        }
        roundPackRoutinePtr = softfloat_roundPackMToF128M;
    }
    (*roundPackRoutinePtr)( signZ, expA, extSigZ, zWPtr );

}