Beispiel #1
0
float16_t i32_to_f16( int32_t a )
{
    bool sign;
    uint_fast32_t absA;
    int_fast8_t shiftDist;
    union ui16_f16 u;
    uint_fast16_t sig;

    sign = (a < 0);
    absA = sign ? -(uint_fast32_t) a : (uint_fast32_t) a;
    shiftDist = softfloat_countLeadingZeros32( absA ) - 21;
    if ( 0 <= shiftDist ) {
        u.ui =
            a ? packToF16UI(
                    sign, 0x18 - shiftDist, (uint_fast16_t) absA<<shiftDist )
                : 0;
        return u.f;
    } else {
        shiftDist += 4;
        sig =
            (shiftDist < 0)
                ? absA>>(-shiftDist)
                      | ((uint32_t) (absA<<(shiftDist & 31)) != 0)
                : (uint_fast16_t) absA<<shiftDist;
        return softfloat_roundPackToF16( sign, 0x1C - shiftDist, sig );
    }

}
Beispiel #2
0
void i32_to_f128M( int32_t a, float128_t *zPtr )
{
    uint32_t *zWPtr;
    uint32_t uiZ96, uiZ64;
    bool sign;
    uint32_t absA;
    int_fast8_t shiftDist;
    uint64_t normAbsA;

    zWPtr = (uint32_t *) zPtr;
    uiZ96 = 0;
    uiZ64 = 0;
    if ( a ) {
        sign = (a < 0);
        absA = sign ? -(uint32_t) a : (uint32_t) a;
        shiftDist = softfloat_countLeadingZeros32( absA ) + 17;
        normAbsA = (uint64_t) absA<<shiftDist;
        uiZ96 = packToF128UI96( sign, 0x402E - shiftDist, normAbsA>>32 );
        uiZ64 = normAbsA;
    }
    zWPtr[indexWord( 4, 3 )] = uiZ96;
    zWPtr[indexWord( 4, 2 )] = uiZ64;
    zWPtr[indexWord( 4, 1 )] = 0;
    zWPtr[indexWord( 4, 0 )] = 0;

}
struct exp16_sig32 softfloat_normSubnormalF32Sig( uint_fast32_t sig )
{
    int_fast8_t shiftCount;
    struct exp16_sig32 z;

    shiftCount = softfloat_countLeadingZeros32( sig ) - 8;
    z.exp = 1 - shiftCount;
    z.sig = sig<<shiftCount;
    return z;

}
float32_t
 softfloat_normRoundPackToF32( bool sign, int_fast16_t exp, uint_fast32_t sig )
{
    int_fast8_t shiftDist;
    union ui32_f32 uZ;

    shiftDist = softfloat_countLeadingZeros32( sig ) - 1;
    exp -= shiftDist;
    if ( (7 <= shiftDist) && ((unsigned int) exp < 0xFD) ) {
        uZ.ui = packToF32UI( sign, sig ? exp : 0, sig<<(shiftDist - 7) );
        return uZ.f;
    } else {
        return softfloat_roundPackToF32( sign, exp, sig<<shiftDist );
    }

}
Beispiel #5
0
extFloat80_t ui32_to_extF80( uint32_t a )
{
    uint_fast16_t uiZ64;
    int_fast8_t shiftCount;
    union { struct extFloat80M s; extFloat80_t f; } uZ;

    uiZ64 = 0;
    if ( a ) {
        shiftCount = softfloat_countLeadingZeros32( a );
        uiZ64 = 0x401E - shiftCount;
        a <<= shiftCount;
    }
    uZ.s.signExp = uiZ64;
    uZ.s.signif = (uint_fast64_t) a<<32;
    return uZ.f;

}
Beispiel #6
0
float64_t ui32_to_f64( uint32_t a )
{
    uint_fast64_t uiZ;
    int_fast8_t shiftDist;
    union ui64_f64 uZ;

    if ( ! a ) {
        uiZ = 0;
    } else {
        shiftDist = softfloat_countLeadingZeros32( a ) + 21;
        uiZ =
            packToF64UI( 0, 0x432 - shiftDist, (uint_fast64_t) a<<shiftDist );
    }
    uZ.ui = uiZ;
    return uZ.f;

}
Beispiel #7
0
float128_t ui32_to_f128( uint32_t a )
{
    uint_fast64_t uiZ64;
    int_fast8_t shiftCount;
    union ui128_f128 uZ;

    uiZ64 = 0;
    if ( a ) {
        shiftCount = softfloat_countLeadingZeros32( a ) + 17;
        uiZ64 =
            packToF128UI64(
                0, 0x402E - shiftCount, (uint_fast64_t) a<<shiftCount );
    }
    uZ.ui.v64 = uiZ64;
    uZ.ui.v0  = 0;
    return uZ.f;

}
Beispiel #8
0
void ui32_to_extF80M( uint32_t a, extFloat80_t *zPtr )
{
    struct extFloat80M *zSPtr;
    uint_fast16_t uiZ64;
    uint64_t sigZ;
    int_fast8_t shiftDist;

    zSPtr = (struct extFloat80M *) zPtr;
    uiZ64 = 0;
    sigZ = 0;
    if ( a ) {
        shiftDist = softfloat_countLeadingZeros32( a );
        uiZ64 = packToExtF80UI64( 0, 0x401E - shiftDist );
        sigZ = (uint64_t) (a<<shiftDist)<<32;
    }
    zSPtr->signExp = uiZ64;
    zSPtr->signif = sigZ;

}
int softfloat_normSubnormalF128SigM( uint32_t *sigPtr )
{
    const uint32_t *ptr;
    int_fast16_t shiftCount;
    uint32_t wordSig;

    ptr = sigPtr + indexWordHi( 4 );
    shiftCount = 0;
    for (;;) {
        wordSig = *ptr;
        if ( wordSig ) break;
        shiftCount += 32;
        if ( 128 <= shiftCount ) return 1;
        ptr -= wordIncr;
    }
    shiftCount += softfloat_countLeadingZeros32( wordSig ) - 15;
    if ( shiftCount ) softfloat_shiftLeft128M( sigPtr, shiftCount, sigPtr );
    return 1 - shiftCount;

}
void ui32_to_f128M( uint32_t a, float128_t *zPtr )
{
    uint32_t *zWPtr, uiZ96, uiZ64;
    int_fast8_t shiftCount;
    uint64_t normA;

    zWPtr = (uint32_t *) zPtr;
    uiZ96 = 0;
    uiZ64 = 0;
    if ( a ) {
        shiftCount = softfloat_countLeadingZeros32( a ) + 17;
        normA = (uint64_t) a<<shiftCount;
        uiZ96 = packToF128UI96( 0, 0x402E - shiftCount, normA>>32 );
        uiZ64 = normA;
    }
    zWPtr[indexWord( 4, 3 )] = uiZ96;
    zWPtr[indexWord( 4, 2 )] = uiZ64;
    zWPtr[indexWord( 4, 1 )] = 0;
    zWPtr[indexWord( 4, 0 )] = 0;

}
Beispiel #11
0
float64_t i32_to_f64( int32_t a )
{
    uint_fast64_t uiZ;
    bool sign;
    uint_fast32_t absA;
    int_fast8_t shiftDist;
    union ui64_f64 uZ;

    if ( ! a ) {
        uiZ = 0;
    } else {
        sign = (a < 0);
        absA = sign ? -(uint_fast32_t) a : (uint_fast32_t) a;
        shiftDist = softfloat_countLeadingZeros32( absA ) + 21;
        uiZ =
            packToF64UI(
                sign, 0x432 - shiftDist, (uint_fast64_t) absA<<shiftDist );
    }
    uZ.ui = uiZ;
    return uZ.f;

}
Beispiel #12
0
float128_t i32_to_f128( int32_t a )
{
    uint_fast64_t uiZ64;
    bool sign;
    uint_fast32_t absA;
    int_fast8_t shiftDist;
    union ui128_f128 uZ;

    uiZ64 = 0;
    if ( a ) {
        sign = (a < 0);
        absA = sign ? -(uint_fast32_t) a : (uint_fast32_t) a;
        shiftDist = softfloat_countLeadingZeros32( absA ) + 17;
        uiZ64 =
            packToF128UI64(
                sign, 0x402E - shiftDist, (uint_fast64_t) absA<<shiftDist );
    }
    uZ.ui.v64 = uiZ64;
    uZ.ui.v0  = 0;
    return uZ.f;

}
Beispiel #13
0
void i32_to_extF80M( int32_t a, extFloat80_t *zPtr )
{
    struct extFloat80M *zSPtr;
    uint_fast16_t uiZ64;
    uint64_t sigZ;
    bool sign;
    uint32_t absA;
    int_fast8_t shiftDist;

    zSPtr = (struct extFloat80M *) zPtr;
    uiZ64 = 0;
    sigZ = 0;
    if ( a ) {
        sign = (a < 0);
        absA = sign ? -(uint32_t) a : (uint32_t) a;
        shiftDist = softfloat_countLeadingZeros32( absA );
        uiZ64 = packToExtF80UI64( sign, 0x401E - shiftDist );
        sigZ = (uint64_t) (absA<<shiftDist)<<32;
    }
    zSPtr->signExp = uiZ64;
    zSPtr->signif = sigZ;

}
void
 softfloat_normRoundPackMToExtF80M(
     bool sign,
     int32_t exp,
     uint32_t *extSigPtr,
     uint_fast8_t roundingPrecision,
     struct extFloat80M *zSPtr
 )
{
    int_fast16_t shiftCount;
    uint32_t wordSig;

    shiftCount = 0;
    wordSig = extSigPtr[indexWord( 3, 2 )];
    if ( ! wordSig ) {
        shiftCount = 32;
        wordSig = extSigPtr[indexWord( 3, 1 )];
        if ( ! wordSig ) {
            shiftCount = 64;
            wordSig = extSigPtr[indexWord( 3, 0 )];
            if ( ! wordSig ) {
                zSPtr->signExp = packToExtF80UI64( sign, 0 );
                zSPtr->signif = 0;
                return;
            }
        }
    }
    shiftCount += softfloat_countLeadingZeros32( wordSig );
    if ( shiftCount ) {
        exp -= shiftCount;
        softfloat_shiftLeft96M( extSigPtr, shiftCount, extSigPtr );
    }
    softfloat_roundPackMToExtF80M(
        sign, exp, extSigPtr, roundingPrecision, zSPtr );

}
Beispiel #15
0
float32_t softfloat_subMagsF32( uint_fast32_t uiA, uint_fast32_t uiB )
{
    int_fast16_t expA;
    uint_fast32_t sigA;
    int_fast16_t expB;
    uint_fast32_t sigB;
    int_fast16_t expDiff;
    uint_fast32_t uiZ;
    int_fast32_t sigDiff;
    bool signZ;
    int_fast8_t shiftDist;
    int_fast16_t expZ;
    uint_fast32_t sigX, sigY;
    union ui32_f32 uZ;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    expA = expF32UI( uiA );
    sigA = fracF32UI( uiA );
    expB = expF32UI( uiB );
    sigB = fracF32UI( uiB );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    expDiff = expA - expB;
    if ( ! expDiff ) {
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
        if ( expA == 0xFF ) {
            if ( sigA | sigB ) goto propagateNaN;
            softfloat_raiseFlags( softfloat_flag_invalid );
            uiZ = defaultNaNF32UI;
            goto uiZ;
        }
        sigDiff = sigA - sigB;
        if ( ! sigDiff ) {
            uiZ =
                packToF32UI(
                    (softfloat_roundingMode == softfloat_round_min), 0, 0 );
            goto uiZ;
        }
        if ( expA ) --expA;
        signZ = signF32UI( uiA );
        if ( sigDiff < 0 ) {
            signZ = ! signZ;
            sigDiff = -sigDiff;
        }
        shiftDist = softfloat_countLeadingZeros32( sigDiff ) - 8;
        expZ = expA - shiftDist;
        if ( expZ < 0 ) {
            shiftDist = expA;
            expZ = 0;
        }
        uiZ = packToF32UI( signZ, expZ, sigDiff<<shiftDist );
        goto uiZ;
    } else {
        /*--------------------------------------------------------------------
        *--------------------------------------------------------------------*/
        signZ = signF32UI( uiA );
        sigA <<= 7;
        sigB <<= 7;
        if ( expDiff < 0 ) {
            /*----------------------------------------------------------------
            *----------------------------------------------------------------*/
            signZ = ! signZ;
            if ( expB == 0xFF ) {
                if ( sigB ) goto propagateNaN;
                uiZ = packToF32UI( signZ, 0xFF, 0 );
                goto uiZ;
            }
            expZ = expB - 1;
            sigX = sigB | 0x40000000;
            sigY = sigA + (expA ? 0x40000000 : sigA);
            expDiff = -expDiff;
        } else {
            /*----------------------------------------------------------------
            *----------------------------------------------------------------*/
            if ( expA == 0xFF ) {
                if ( sigA ) goto propagateNaN;
                uiZ = uiA;
                goto uiZ;
            }
            expZ = expA - 1;
            sigX = sigA | 0x40000000;
            sigY = sigB + (expB ? 0x40000000 : sigB);
        }
        return
            softfloat_normRoundPackToF32(
                signZ, expZ, sigX - softfloat_shiftRightJam32( sigY, expDiff )
            );
    }
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 propagateNaN:
    uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
 uiZ:
    uZ.ui = uiZ;
    return uZ.f;

}