Changeset 3b5c119 in mainline for uspace/lib/softfloat/generic/mul.c


Ignore:
Timestamp:
2012-04-08T08:07:21Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1196df6
Parents:
ce6de59 (diff), f3378ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/softfloat/generic/mul.c

    rce6de59 r3b5c119  
    3939#include <common.h>
    4040
    41 /**
    42  * Multiply two single-precision floats.
     41/** Multiply two single-precision floats.
    4342 *
    4443 * @param a First input operand.
    4544 * @param b Second input operand.
     45 *
    4646 * @return Result of multiplication.
    47  */
    48 float32 mulFloat32(float32 a, float32 b)
     47 *
     48 */
     49float32 mul_float32(float32 a, float32 b)
    4950{
    5051        float32 result;
    5152        uint64_t frac1, frac2;
    5253        int32_t exp;
    53 
     54       
    5455        result.parts.sign = a.parts.sign ^ b.parts.sign;
    5556       
    56         if (isFloat32NaN(a) || isFloat32NaN(b)) {
     57        if (is_float32_nan(a) || is_float32_nan(b)) {
    5758                /* TODO: fix SigNaNs */
    58                 if (isFloat32SigNaN(a)) {
     59                if (is_float32_signan(a)) {
    5960                        result.parts.fraction = a.parts.fraction;
    6061                        result.parts.exp = a.parts.exp;
    6162                        return result;
    6263                }
    63                 if (isFloat32SigNaN(b)) { /* TODO: fix SigNaN */
     64                if (is_float32_signan(b)) { /* TODO: fix SigNaN */
    6465                        result.parts.fraction = b.parts.fraction;
    6566                        result.parts.exp = b.parts.exp;
     
    6768                }
    6869                /* set NaN as result */
    69                 result.binary = FLOAT32_NAN;
    70                 return result;
    71         }
    72                
    73         if (isFloat32Infinity(a)) {
    74                 if (isFloat32Zero(b)) {
    75                         /* FIXME: zero * infinity */
    76                         result.binary = FLOAT32_NAN;
     70                result.bin = FLOAT32_NAN;
     71                return result;
     72        }
     73       
     74        if (is_float32_infinity(a)) {
     75                if (is_float32_zero(b)) {
     76                        /* FIXME: zero * infinity */
     77                        result.bin = FLOAT32_NAN;
    7778                        return result;
    7879                }
     
    8182                return result;
    8283        }
    83 
    84         if (isFloat32Infinity(b)) {
    85                 if (isFloat32Zero(a)) {
    86                         /* FIXME: zero * infinity */
    87                         result.binary = FLOAT32_NAN;
     84       
     85        if (is_float32_infinity(b)) {
     86                if (is_float32_zero(a)) {
     87                        /* FIXME: zero * infinity */
     88                        result.bin = FLOAT32_NAN;
    8889                        return result;
    8990                }
     
    9293                return result;
    9394        }
    94 
     95       
    9596        /* exp is signed so we can easy detect underflow */
    9697        exp = a.parts.exp + b.parts.exp;
     
    100101                /* FIXME: overflow */
    101102                /* set infinity as result */
    102                 result.binary = FLOAT32_INF;
     103                result.bin = FLOAT32_INF;
    103104                result.parts.sign = a.parts.sign ^ b.parts.sign;
    104105                return result;
     
    121122       
    122123        frac2 = b.parts.fraction;
    123 
     124       
    124125        if (b.parts.exp > 0) {
    125126                frac2 |= FLOAT32_HIDDEN_BIT_MASK;
     
    127128                ++exp;
    128129        }
    129 
     130       
    130131        frac1 <<= 1; /* one bit space for rounding */
    131 
     132       
    132133        frac1 = frac1 * frac2;
    133 
     134       
    134135        /* round and return */
    135         while ((exp < FLOAT32_MAX_EXPONENT) && (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 2)))) {
     136        while ((exp < FLOAT32_MAX_EXPONENT) &&
     137            (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 2)))) {
    136138                /* 23 bits of fraction + one more for hidden bit (all shifted 1 bit left) */
    137139                ++exp;
    138140                frac1 >>= 1;
    139141        }
    140 
     142       
    141143        /* rounding */
    142144        /* ++frac1; FIXME: not works - without it is ok */
    143145        frac1 >>= 1; /* shift off rounding space */
    144146       
    145         if ((exp < FLOAT32_MAX_EXPONENT) && (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 1)))) {
     147        if ((exp < FLOAT32_MAX_EXPONENT) &&
     148            (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 1)))) {
    146149                ++exp;
    147150                frac1 >>= 1;
    148151        }
    149 
    150         if (exp >= FLOAT32_MAX_EXPONENT) {     
     152       
     153        if (exp >= FLOAT32_MAX_EXPONENT) {
    151154                /* TODO: fix overflow */
    152155                /* return infinity*/
     
    157160       
    158161        exp -= FLOAT32_FRACTION_SIZE;
    159 
    160         if (exp <= FLOAT32_FRACTION_SIZE) { 
     162       
     163        if (exp <= FLOAT32_FRACTION_SIZE) {
    161164                /* denormalized number */
    162165                frac1 >>= 1; /* denormalize */
     
    175178        result.parts.fraction = frac1 & ((1 << FLOAT32_FRACTION_SIZE) - 1);
    176179       
    177         return result; 
     180        return result;
    178181}
    179182
    180 /**
    181  * Multiply two double-precision floats.
     183/** Multiply two double-precision floats.
    182184 *
    183185 * @param a First input operand.
    184186 * @param b Second input operand.
     187 *
    185188 * @return Result of multiplication.
    186  */
    187 float64 mulFloat64(float64 a, float64 b)
     189 *
     190 */
     191float64 mul_float64(float64 a, float64 b)
    188192{
    189193        float64 result;
    190194        uint64_t frac1, frac2;
    191195        int32_t exp;
    192 
     196       
    193197        result.parts.sign = a.parts.sign ^ b.parts.sign;
    194198       
    195         if (isFloat64NaN(a) || isFloat64NaN(b)) {
     199        if (is_float64_nan(a) || is_float64_nan(b)) {
    196200                /* TODO: fix SigNaNs */
    197                 if (isFloat64SigNaN(a)) {
     201                if (is_float64_signan(a)) {
    198202                        result.parts.fraction = a.parts.fraction;
    199203                        result.parts.exp = a.parts.exp;
    200204                        return result;
    201205                }
    202                 if (isFloat64SigNaN(b)) { /* TODO: fix SigNaN */
     206                if (is_float64_signan(b)) { /* TODO: fix SigNaN */
    203207                        result.parts.fraction = b.parts.fraction;
    204208                        result.parts.exp = b.parts.exp;
     
    206210                }
    207211                /* set NaN as result */
    208                 result.binary = FLOAT64_NAN;
    209                 return result;
    210         }
    211                
    212         if (isFloat64Infinity(a)) {
    213                 if (isFloat64Zero(b)) {
    214                         /* FIXME: zero * infinity */
    215                         result.binary = FLOAT64_NAN;
     212                result.bin = FLOAT64_NAN;
     213                return result;
     214        }
     215       
     216        if (is_float64_infinity(a)) {
     217                if (is_float64_zero(b)) {
     218                        /* FIXME: zero * infinity */
     219                        result.bin = FLOAT64_NAN;
    216220                        return result;
    217221                }
     
    220224                return result;
    221225        }
    222 
    223         if (isFloat64Infinity(b)) {
    224                 if (isFloat64Zero(a)) {
    225                         /* FIXME: zero * infinity */
    226                         result.binary = FLOAT64_NAN;
     226       
     227        if (is_float64_infinity(b)) {
     228                if (is_float64_zero(a)) {
     229                        /* FIXME: zero * infinity */
     230                        result.bin = FLOAT64_NAN;
    227231                        return result;
    228232                }
     
    231235                return result;
    232236        }
    233 
     237       
    234238        /* exp is signed so we can easy detect underflow */
    235239        exp = a.parts.exp + b.parts.exp - FLOAT64_BIAS;
    236240       
    237241        frac1 = a.parts.fraction;
    238 
     242       
    239243        if (a.parts.exp > 0) {
    240244                frac1 |= FLOAT64_HIDDEN_BIT_MASK;
     
    244248       
    245249        frac2 = b.parts.fraction;
    246 
     250       
    247251        if (b.parts.exp > 0) {
    248252                frac2 |= FLOAT64_HIDDEN_BIT_MASK;
     
    250254                ++exp;
    251255        }
    252 
     256       
    253257        frac1 <<= (64 - FLOAT64_FRACTION_SIZE - 1);
    254258        frac2 <<= (64 - FLOAT64_FRACTION_SIZE - 2);
    255 
     259       
    256260        mul64(frac1, frac2, &frac1, &frac2);
    257 
     261       
    258262        frac1 |= (frac2 != 0);
    259263        if (frac1 & (0x1ll << 62)) {
     
    261265                exp--;
    262266        }
    263 
    264         result = finishFloat64(exp, frac1, result.parts.sign);
     267       
     268        result = finish_float64(exp, frac1, result.parts.sign);
    265269        return result;
    266270}
    267271
    268 /**
    269  * Multiply two quadruple-precision floats.
     272/** Multiply two quadruple-precision floats.
    270273 *
    271274 * @param a First input operand.
    272275 * @param b Second input operand.
     276 *
    273277 * @return Result of multiplication.
    274  */
    275 float128 mulFloat128(float128 a, float128 b)
     278 *
     279 */
     280float128 mul_float128(float128 a, float128 b)
    276281{
    277282        float128 result;
    278283        uint64_t frac1_hi, frac1_lo, frac2_hi, frac2_lo, tmp_hi, tmp_lo;
    279284        int32_t exp;
    280 
     285       
    281286        result.parts.sign = a.parts.sign ^ b.parts.sign;
    282 
    283         if (isFloat128NaN(a) || isFloat128NaN(b)) {
     287       
     288        if (is_float128_nan(a) || is_float128_nan(b)) {
    284289                /* TODO: fix SigNaNs */
    285                 if (isFloat128SigNaN(a)) {
     290                if (is_float128_signan(a)) {
    286291                        result.parts.frac_hi = a.parts.frac_hi;
    287292                        result.parts.frac_lo = a.parts.frac_lo;
     
    289294                        return result;
    290295                }
    291                 if (isFloat128SigNaN(b)) { /* TODO: fix SigNaN */
     296                if (is_float128_signan(b)) { /* TODO: fix SigNaN */
    292297                        result.parts.frac_hi = b.parts.frac_hi;
    293298                        result.parts.frac_lo = b.parts.frac_lo;
     
    296301                }
    297302                /* set NaN as result */
    298                 result.binary.hi = FLOAT128_NAN_HI;
    299                 result.binary.lo = FLOAT128_NAN_LO;
    300                 return result;
    301         }
    302 
    303         if (isFloat128Infinity(a)) {
    304                 if (isFloat128Zero(b)) {
    305                         /* FIXME: zero * infinity */
    306                         result.binary.hi = FLOAT128_NAN_HI;
    307                         result.binary.lo = FLOAT128_NAN_LO;
     303                result.bin.hi = FLOAT128_NAN_HI;
     304                result.bin.lo = FLOAT128_NAN_LO;
     305                return result;
     306        }
     307       
     308        if (is_float128_infinity(a)) {
     309                if (is_float128_zero(b)) {
     310                        /* FIXME: zero * infinity */
     311                        result.bin.hi = FLOAT128_NAN_HI;
     312                        result.bin.lo = FLOAT128_NAN_LO;
    308313                        return result;
    309314                }
     
    313318                return result;
    314319        }
    315 
    316         if (isFloat128Infinity(b)) {
    317                 if (isFloat128Zero(a)) {
    318                         /* FIXME: zero * infinity */
    319                         result.binary.hi = FLOAT128_NAN_HI;
    320                         result.binary.lo = FLOAT128_NAN_LO;
     320       
     321        if (is_float128_infinity(b)) {
     322                if (is_float128_zero(a)) {
     323                        /* FIXME: zero * infinity */
     324                        result.bin.hi = FLOAT128_NAN_HI;
     325                        result.bin.lo = FLOAT128_NAN_LO;
    321326                        return result;
    322327                }
     
    326331                return result;
    327332        }
    328 
     333       
    329334        /* exp is signed so we can easy detect underflow */
    330335        exp = a.parts.exp + b.parts.exp - FLOAT128_BIAS - 1;
    331 
     336       
    332337        frac1_hi = a.parts.frac_hi;
    333338        frac1_lo = a.parts.frac_lo;
    334 
     339       
    335340        if (a.parts.exp > 0) {
    336341                or128(frac1_hi, frac1_lo,
    337                 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
    338                 &frac1_hi, &frac1_lo);
    339         } else {
    340                 ++exp;
    341         }
    342 
     342                    FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
     343                    &frac1_hi, &frac1_lo);
     344        } else {
     345                ++exp;
     346        }
     347       
    343348        frac2_hi = b.parts.frac_hi;
    344349        frac2_lo = b.parts.frac_lo;
    345 
     350       
    346351        if (b.parts.exp > 0) {
    347352                or128(frac2_hi, frac2_lo,
     
    351356                ++exp;
    352357        }
    353 
     358       
    354359        lshift128(frac2_hi, frac2_lo,
    355360            128 - FLOAT128_FRACTION_SIZE, &frac2_hi, &frac2_lo);
    356 
     361       
    357362        tmp_hi = frac1_hi;
    358363        tmp_lo = frac1_lo;
     
    361366        add128(frac1_hi, frac1_lo, tmp_hi, tmp_lo, &frac1_hi, &frac1_lo);
    362367        frac2_hi |= (frac2_lo != 0x0ll);
    363 
     368       
    364369        if ((FLOAT128_HIDDEN_BIT_MASK_HI << 1) <= frac1_hi) {
    365370                frac2_hi >>= 1;
     
    370375                ++exp;
    371376        }
    372 
    373         result = finishFloat128(exp, frac1_hi, frac1_lo, result.parts.sign, frac2_hi);
     377       
     378        result = finish_float128(exp, frac1_hi, frac1_lo, result.parts.sign, frac2_hi);
    374379        return result;
    375380}
Note: See TracChangeset for help on using the changeset viewer.