Changeset 12c6f2d in mainline
- Timestamp:
- 2006-01-22T14:13:02Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4a5abddd
- Parents:
- 350514c
- Location:
- softfloat
- Files:
-
- 6 added
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
softfloat/generic/mul.c
r350514c r12c6f2d 28 28 29 29 #include<sftypes.h> 30 #include< arithmetic.h>30 #include<mul.h> 31 31 #include<comparison.h> 32 33 /** Add two Float32 numbers with same signs34 */35 float32 addFloat32(float32 a, float32 b)36 {37 int expdiff;38 __u32 exp1,exp2,mant1,mant2;39 40 expdiff=a.parts.exp - b.parts.exp;41 if (expdiff<0) {42 if (isFloat32NaN(b)) {43 //TODO: fix SigNaN44 if (isFloat32SigNaN(b)) {45 };46 47 return b;48 };49 50 if (b.parts.exp==0xFF) {51 return b;52 }53 54 mant1=b.parts.mantisa;55 exp1=b.parts.exp;56 mant2=a.parts.mantisa;57 exp2=a.parts.exp;58 expdiff*=-1;59 } else {60 if (isFloat32NaN(a)) {61 //TODO: fix SigNaN62 if ((isFloat32SigNaN(a))||(isFloat32SigNaN(b))) {63 };64 return a;65 };66 67 if (a.parts.exp==0xFF) {68 return a;69 }70 71 mant1=a.parts.mantisa;72 exp1=a.parts.exp;73 mant2=b.parts.mantisa;74 exp2=b.parts.exp;75 };76 77 if (exp1==0) {78 //both are denormalized79 mant1+=mant2;80 if (mant1&0xF00000) {81 a.parts.exp=1;82 };83 a.parts.mantisa=mant1;84 return a;85 };86 87 // create some space for rounding88 mant1<<=6;89 mant2<<=6;90 91 mant1|=0x20000000; //add hidden bit92 93 94 if (exp2==0) {95 --expdiff;96 } else {97 mant2|=0x20000000; //hidden bit98 };99 100 if (expdiff>24) {101 goto done;102 };103 104 mant2>>=expdiff;105 mant1+=mant2;106 done:107 if (mant1&0x40000000) {108 ++exp1;109 mant1>>=1;110 };111 112 //rounding - if first bit after mantisa is set then round up113 mant1+=0x20;114 115 if (mant1&0x40000000) {116 ++exp1;117 mant1>>=1;118 };119 120 a.parts.exp=exp1;121 a.parts.mantisa = ((mant1&(~0x20000000))>>6); /*Clear hidden bit and shift */122 return a;123 };124 125 /** Subtract two float32 numbers with same signs126 */127 float32 subFloat32(float32 a, float32 b)128 {129 int expdiff;130 __u32 exp1,exp2,mant1,mant2;131 float32 result;132 133 result.f = 0;134 135 expdiff=a.parts.exp - b.parts.exp;136 if ((expdiff<0)||((expdiff==0)&&(a.parts.mantisa<b.parts.mantisa))) {137 if (isFloat32NaN(b)) {138 //TODO: fix SigNaN139 if (isFloat32SigNaN(b)) {140 };141 return b;142 };143 144 if (b.parts.exp==0xFF) {145 b.parts.sign=!b.parts.sign; /* num -(+-inf) = -+inf */146 return b;147 }148 149 result.parts.sign = !a.parts.sign;150 151 mant1=b.parts.mantisa;152 exp1=b.parts.exp;153 mant2=a.parts.mantisa;154 exp2=a.parts.exp;155 expdiff*=-1;156 } else {157 if (isFloat32NaN(a)) {158 //TODO: fix SigNaN159 if ((isFloat32SigNaN(a))||(isFloat32SigNaN(b))) {160 };161 return a;162 };163 164 if (a.parts.exp==0xFF) {165 if (b.parts.exp==0xFF) {166 /* inf - inf => nan */167 //TODO: fix exception168 result.binary = FLOAT32_NAN;169 return result;170 };171 return a;172 }173 174 result.parts.sign = a.parts.sign;175 176 mant1=a.parts.mantisa;177 exp1=a.parts.exp;178 mant2=b.parts.mantisa;179 exp2=b.parts.exp;180 181 182 183 };184 185 if (exp1==0) {186 //both are denormalized187 result.parts.mantisa=mant1-mant2;188 if (result.parts.mantisa>mant1) {189 //TODO: underflow exception190 return result;191 };192 result.parts.exp=0;193 return result;194 };195 196 // create some space for rounding197 mant1<<=6;198 mant2<<=6;199 200 mant1|=0x20000000; //add hidden bit201 202 203 if (exp2==0) {204 --expdiff;205 } else {206 mant2|=0x20000000; //hidden bit207 };208 209 if (expdiff>24) {210 goto done;211 };212 213 mant1 = mant1-(mant2>>expdiff);214 done:215 216 //TODO: find first nonzero digit and shift result and detect possibly underflow217 while ((exp1>0)&&(!(mant1&0x20000000))) {218 exp1--;219 mant1 <<= 1;220 if(mant1 == 0) {221 /* Realy is it an underflow? ... */222 /* TODO: fix underflow */223 };224 };225 226 //rounding - if first bit after mantisa is set then round up227 mant1 += 0x20;228 229 if (mant1&0x40000000) {230 ++exp1;231 mant1>>=1;232 };233 234 result.parts.mantisa = ((mant1&(~0x20000000))>>6); /*Clear hidden bit and shift */235 result.parts.exp = exp1;236 237 return result;238 };239 32 240 33 /** Multiply two 32 bit float numbers … … 330 123 /* round and return */ 331 124 332 while ((exp < 0xFF )&&(mant1 > 0x1FFFFFF )) { /* 0xFFFFFF is 23 bits of mantisa + one more for hidden bit (all shifted 1 bit left)*/ 125 while ((exp < 0xFF )&&(mant1 > 0x1FFFFFF )) { 126 /* 0xFFFFFF is 23 bits of mantisa + one more for hidden bit (all shifted 1 bit left)*/ 333 127 ++exp; 334 128 mant1 >>= 1; … … 373 167 return result; 374 168 375 } ;169 } 376 170 377 171 172 -
softfloat/generic/softfloat.c
r350514c r12c6f2d 29 29 #include<softfloat.h> 30 30 #include<sftypes.h> 31 #include<arithmetic.h> 31 32 #include<add.h> 33 #include<sub.h> 34 #include<mul.h> 35 #include<div.h> 36 32 37 #include<conversion.h> 33 38 #include<comparison.h> … … 77 82 fa.f=a; 78 83 fb.f=b; 79 //return divFloat32(fa, fb).f;84 //return divFloat32(fa, fb).f; 80 85 } 81 86 -
softfloat/include/add.h
r350514c r12c6f2d 27 27 */ 28 28 29 #ifndef __A RITHMETIC_H__30 #define __A RITHMETIC_H__29 #ifndef __ADD_H__ 30 #define __ADD_H__ 31 31 32 32 float32 addFloat32(float32 a, float32 b); 33 float32 subFloat32(float32 a, float32 b); 34 float 32 mulFloat32(float32 a, float32b);33 34 float64 addFloat64(float64 a, float64 b); 35 35 36 36 #endif -
softfloat/include/sftypes.h
r350514c r12c6f2d 81 81 #define FLOAT64_MANTISA_SIZE 52 82 82 83 #define FLOAT32_HIDDEN_BIT_MASK 0x800000 84 #define FLOAT64_HIDDEN_BIT_MASK 0x10000000000000l 85 83 86 #define FLOAT32_BIAS 0x7F 84 87 #define FLOAT64_BIAS 0x3FF
Note:
See TracChangeset
for help on using the changeset viewer.