Changeset e979fea in mainline
- Timestamp:
- 2006-02-10T13:43:41Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d3ca210
- Parents:
- e6a40ac
- Location:
- softfloat
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
softfloat/generic/div.c
re6a40ac re979fea 32 32 #include<comparison.h> 33 33 #include<mul.h> 34 #include<common.h> 35 34 36 35 37 float32 divFloat32(float32 a, float32 b) … … 307 309 } 308 310 309 /* pack and round */ 310 311 /* find first nonzero digit and shift result and detect possibly underflow */ 312 while ((cexp > 0) && (cfrac) && (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1 ) )))) { 313 cexp--; 314 cfrac <<= 1; 315 /* TODO: fix underflow */ 316 }; 317 318 319 cfrac >>= 1; 320 ++cexp; 321 cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); 322 323 if (cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1 ))) { 324 ++cexp; 325 cfrac >>= 1; 326 } 327 328 /* check overflow */ 329 if (cexp >= FLOAT64_MAX_EXPONENT ) { 330 /* FIXME: overflow, return infinity */ 331 result.parts.exp = FLOAT64_MAX_EXPONENT; 332 result.parts.fraction = 0; 333 return result; 334 } 335 336 if (cexp < 0) { 337 /* FIXME: underflow */ 338 result.parts.exp = 0; 339 if ((cexp + FLOAT64_FRACTION_SIZE) < 0) { 340 result.parts.fraction = 0; 341 return result; 342 } 343 cfrac >>= 1; 344 while (cexp < 0) { 345 cexp ++; 346 cfrac >>= 1; 347 } 348 return result; 349 350 } else { 351 cexp ++; /*normalized*/ 352 result.parts.exp = (__u32)cexp; 353 } 354 355 result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2 ) ) & (~FLOAT64_HIDDEN_BIT_MASK)); 356 357 return result; 311 /* round and shift */ 312 result = finishFloat64(cexp, cfrac, result.parts.sign); 313 return result; 314 358 315 } 359 316 -
softfloat/generic/mul.c
re6a40ac re979fea 30 30 #include<mul.h> 31 31 #include<comparison.h> 32 #include<common.h> 32 33 33 34 /** Multiply two 32 bit float numbers … … 218 219 219 220 /* exp is signed so we can easy detect underflow */ 220 exp = a.parts.exp + b.parts.exp; 221 exp -= FLOAT64_BIAS; 222 223 if (exp >= FLOAT64_MAX_EXPONENT) { 224 /* FIXME: overflow */ 225 /* set infinity as result */ 226 result.binary = FLOAT64_INF; 227 result.parts.sign = a.parts.sign ^ b.parts.sign; 228 return result; 229 }; 230 231 if (exp < 0) { 232 /* FIXME: underflow */ 233 /* return signed zero */ 234 result.parts.fraction = 0x0; 235 result.parts.exp = 0x0; 236 return result; 237 }; 221 exp = a.parts.exp + b.parts.exp - FLOAT64_BIAS; 238 222 239 223 frac1 = a.parts.fraction; 224 240 225 if (a.parts.exp > 0) { 241 226 frac1 |= FLOAT64_HIDDEN_BIT_MASK; … … 252 237 }; 253 238 254 frac1 <<= 1; /* one bit space for rounding */ 239 frac1 <<= (64 - FLOAT64_FRACTION_SIZE - 1); 240 frac2 <<= (64 - FLOAT64_FRACTION_SIZE - 2); 255 241 256 242 mul64integers(frac1, frac2, &frac1, &frac2); 257 243 258 /* round and return */ 259 /* FIXME: ugly soulution is to shift whole frac2 >> as in 32bit version 260 * Here is is more slower because we have to shift two numbers with carry 261 * Better is find first nonzero bit and make only one shift 262 * Third version is to shift both numbers a bit to right and result will be then 263 * placed in higher part of result. Then lower part will be good only for rounding. 264 */ 265 266 while ((exp < FLOAT64_MAX_EXPONENT) && (frac2 > 0 )) { 267 frac1 >>= 1; 268 frac1 &= ((frac2 & 0x1) << 63); 269 frac2 >>= 1; 270 ++exp; 271 } 272 273 while ((exp < FLOAT64_MAX_EXPONENT) && (frac1 >= ( (__u64)1 << (FLOAT64_FRACTION_SIZE + 2)))) { 274 ++exp; 275 frac1 >>= 1; 276 }; 277 278 /* rounding */ 279 /* ++frac1; FIXME: not works - without it is ok */ 280 frac1 >>= 1; /* shift off rounding space */ 281 282 if ((exp < FLOAT64_MAX_EXPONENT) && (frac1 >= ((__u64)1 << (FLOAT64_FRACTION_SIZE + 1)))) { 283 ++exp; 284 frac1 >>= 1; 285 }; 286 287 if (exp >= FLOAT64_MAX_EXPONENT ) { 288 /* TODO: fix overflow */ 289 /* return infinity*/ 290 result.parts.exp = FLOAT64_MAX_EXPONENT; 291 result.parts.fraction = 0x0; 292 return result; 293 } 294 295 exp -= FLOAT64_FRACTION_SIZE; 296 297 if (exp <= FLOAT64_FRACTION_SIZE) { 298 /* denormalized number */ 299 frac1 >>= 1; /* denormalize */ 300 while ((frac1 > 0) && (exp < 0)) { 301 frac1 >>= 1; 302 ++exp; 303 }; 304 if (frac1 == 0) { 305 /* FIXME : underflow */ 306 result.parts.exp = 0; 307 result.parts.fraction = 0; 308 return result; 309 }; 310 }; 311 result.parts.exp = exp; 312 result.parts.fraction = frac1 & ( ((__u64)1 << FLOAT64_FRACTION_SIZE) - 1); 313 314 return result; 315 244 frac2 |= (frac1 != 0); 245 if (frac2 & (0x1ll << 62)) { 246 frac2 <<= 1; 247 exp--; 248 } 249 250 result = finishFloat64(exp, frac2, result.parts.sign); 251 return result; 316 252 } 317 253 … … 326 262 __u64 low, high, middle1, middle2; 327 263 __u32 alow, blow; 328 264 329 265 alow = a & 0xFFFFFFFF; 330 266 blow = b & 0xFFFFFFFF; -
softfloat/include/div.h
re6a40ac re979fea 34 34 35 35 __u64 divFloat64estim(__u64 a, __u64 b); 36 36 37 #endif 37 38
Note:
See TracChangeset
for help on using the changeset viewer.