Changeset 3af72dc in mainline
- Timestamp:
- 2006-01-08T16:26:00Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- feef1cd
- Parents:
- 75a23abf
- Location:
- softfloat
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
softfloat/generic/arithmetic.c
r75a23abf r3af72dc 44 44 if (isFloat32SigNaN(b)) { 45 45 }; 46 46 47 return b; 47 48 }; … … 219 220 if(mant1 == 0) { 220 221 /* Realy is it an underflow? ... */ 221 / /TODO: fix underflow222 /* TODO: fix underflow */ 222 223 }; 223 224 }; … … 237 238 }; 238 239 240 /** Multiply two 32 bit float numbers 241 * 242 */ 243 float32 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 -
softfloat/generic/comparison.c
r75a23abf r3af72dc 44 44 return ((f.parts.exp==0xFF)&&(f.parts.mantisa==0x0)); 45 45 }; 46 47 inline int isFloat32Zero(float32 f) 48 { 49 return (((f.binary) & 0x7FFFFFFF) == 0); 50 } 46 51 47 52 /** -
softfloat/generic/softfloat.c
r75a23abf r3af72dc 64 64 }; 65 65 66 float __mulsf3(float a, float b) 67 { 68 float32 fa, fb; 69 fa.f=a; 70 fb.f=b; 71 return mulFloat32(fa, fb).f; 72 } 73 66 74 float __negsf2(float a) 67 75 { -
softfloat/include/arithmetic.h
r75a23abf r3af72dc 32 32 float32 addFloat32(float32 a, float32 b); 33 33 float32 subFloat32(float32 a, float32 b); 34 float32 mulFloat32(float32 a, float32 b); 34 35 35 36 #endif -
softfloat/include/comparison.h
r75a23abf r3af72dc 34 34 35 35 inline int isFloat32Infinity(float32 f); 36 inline int isFloat32Zero(float32 f); 36 37 37 38 inline int isFloat32eq(float32 a, float32 b); -
softfloat/include/sftypes.h
r75a23abf r3af72dc 79 79 #define FLOAT32_INF 0x7F800000 80 80 81 #define FLOAT32_BIAS 0xF7 81 #define FLOAT32_MANTISA_SIZE 23 82 83 #define FLOAT32_BIAS 0x7F 82 84 #define FLOAT64_BIAS 0x3FF 83 85 #define FLOAT80_BIAS 0x3FFF
Note:
See TracChangeset
for help on using the changeset viewer.