Changeset 3af72dc in mainline for softfloat/generic/arithmetic.c


Ignore:
Timestamp:
2006-01-08T16:26:00Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
feef1cd
Parents:
75a23abf
Message:

Function for multiplying added to softfloat lib.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • softfloat/generic/arithmetic.c

    r75a23abf r3af72dc  
    4444                        if (isFloat32SigNaN(b)) {
    4545                        };
     46
    4647                        return b;
    4748                };
     
    219220                if(mant1 == 0) {
    220221                        /* Realy is it an underflow? ... */
    221                         //TODO: fix underflow
     222                        /* TODO: fix underflow */
    222223                };
    223224        };
     
    237238};
    238239
     240/** Multiply two 32 bit float numbers
     241 *
     242 */
     243float32 mulFloat32(float32 a, float32 b)
     244{
     245        float32 result;
     246        __u64 mant1, mant2;
     247        __s32 exp;
     248
     249        result.parts.sign = a.parts.sign ^ b.parts.sign;
     250       
     251        if ((isFloat32NaN(a))||(isFloat32NaN(b))) {
     252                /* TODO: fix SigNaNs */
     253                if (isFloat32SigNaN(a)) {
     254                        result.parts.mantisa = a.parts.mantisa;
     255                        result.parts.exp = a.parts.exp;
     256                        return result;
     257                };
     258                if (isFloat32SigNaN(b)) { /* TODO: fix SigNaN */
     259                        result.parts.mantisa = b.parts.mantisa;
     260                        result.parts.exp = b.parts.exp;
     261                        return result;
     262                };
     263                /* set NaN as result */
     264                result.parts.mantisa = 0x1;
     265                result.parts.exp = 0xFF;
     266                return result;
     267        };
     268               
     269        if (isFloat32Infinity(a)) {
     270                if (isFloat32Zero(b)) {
     271                        /* FIXME: zero * infinity */
     272                        result.parts.mantisa = 0x1;
     273                        result.parts.exp = 0xFF;
     274                        return result;
     275                }
     276                result.parts.mantisa = a.parts.mantisa;
     277                result.parts.exp = a.parts.exp;
     278                return result;
     279        }
     280
     281        if (isFloat32Infinity(b)) {
     282                if (isFloat32Zero(a)) {
     283                        /* FIXME: zero * infinity */
     284                        result.parts.mantisa = 0x1;
     285                        result.parts.exp = 0xFF;
     286                        return result;
     287                }
     288                result.parts.mantisa = b.parts.mantisa;
     289                result.parts.exp = b.parts.exp;
     290                return result;
     291        }
     292
     293        /* exp is signed so we can easy detect underflow */
     294        exp = a.parts.exp + b.parts.exp;
     295        exp -= FLOAT32_BIAS;
     296       
     297        if (exp >= 0xFF ) {
     298                /* FIXME: overflow */
     299                /* set infinity as result */
     300                result.parts.mantisa = 0x0;
     301                result.parts.exp = 0xFF;
     302                return result;
     303        };
     304       
     305        if (exp < 0) {
     306                /* FIXME: underflow */
     307                /* return signed zero */
     308                result.parts.mantisa = 0x0;
     309                result.parts.exp = 0x0;
     310                return result;
     311        };
     312       
     313        mant1 = a.parts.mantisa;
     314        if (a.parts.exp>0) {
     315                mant1 |= 0x800000;
     316        } else {
     317                ++exp;
     318        };
     319       
     320        mant2 = b.parts.mantisa;
     321        if (b.parts.exp>0) {
     322                mant2 |= 0x800000;
     323        } else {
     324                ++exp;
     325        };
     326
     327        mant1 <<= 1; /* one bit space for rounding */
     328
     329        mant1 = mant1 * mant2;
     330/* round and return */
     331       
     332        while ((exp < 0xFF )&&(mant1 > 0x1FFFFFF )) { /* 0xFFFFFF is 23 bits of mantisa + one more for hidden bit (all shifted 1 bit left)*/
     333                ++exp;
     334                mant1 >>= 1;
     335        };
     336
     337        /* rounding */
     338        //++mant1; /* FIXME: not works - without it is ok */
     339        mant1 >>= 1; /* shift off rounding space */
     340       
     341        if ((exp < 0xFF )&&(mant1 > 0xFFFFFF )) {
     342                ++exp;
     343                mant1 >>= 1;
     344        };
     345
     346        if (exp >= 0xFF ) {     
     347                /* TODO: fix overflow */
     348                /* return infinity*/
     349                result.parts.exp = 0xFF;
     350                result.parts.mantisa = 0x0;
     351                return result;
     352        }
     353       
     354        exp -= FLOAT32_MANTISA_SIZE;
     355
     356        if (exp <= FLOAT32_MANTISA_SIZE) {
     357                /* denormalized number */
     358                mant1 >>= 1; /* denormalize */
     359                while ((mant1 > 0) && (exp < 0)) {
     360                        mant1 >>= 1;
     361                        ++exp;
     362                };
     363                if (mant1 == 0) {
     364                        /* FIXME : underflow */
     365                result.parts.exp = 0;
     366                result.parts.mantisa = 0;
     367                return result;
     368                };
     369        };
     370        result.parts.exp = exp;
     371        result.parts.mantisa = mant1 & 0x7FFFFF;
     372       
     373        return result; 
     374       
     375};
     376
     377
Note: See TracChangeset for help on using the changeset viewer.