Changes in uspace/lib/softfloat/generic/div.c [9d58539:88d5c1e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/generic/div.c
r9d58539 r88d5c1e 41 41 #include <common.h> 42 42 43 /** 44 * Divide two single-precision floats. 45 * 43 /** Divide two single-precision floats. 44 * 46 45 * @param a Nominator. 47 46 * @param b Denominator. 47 * 48 48 * @return Result of division. 49 */ 50 float32 divFloat32(float32 a, float32 b) 49 * 50 */ 51 float32 div_float32(float32 a, float32 b) 51 52 { 52 53 float32 result; … … 56 57 result.parts.sign = a.parts.sign ^ b.parts.sign; 57 58 58 if (is Float32NaN(a)) {59 if (is Float32SigNaN(a)) {60 / *FIXME: SigNaN*/61 } 62 /* NaN*/59 if (is_float32_nan(a)) { 60 if (is_float32_signan(a)) { 61 // FIXME: SigNaN 62 } 63 /* NaN */ 63 64 return a; 64 65 } 65 66 66 if (is Float32NaN(b)) {67 if (is Float32SigNaN(b)) {68 / *FIXME: SigNaN*/69 } 70 /* NaN*/67 if (is_float32_nan(b)) { 68 if (is_float32_signan(b)) { 69 // FIXME: SigNaN 70 } 71 /* NaN */ 71 72 return b; 72 73 } 73 74 74 if (is Float32Infinity(a)) {75 if (is Float32Infinity(b)) {75 if (is_float32_infinity(a)) { 76 if (is_float32_infinity(b)) { 76 77 /*FIXME: inf / inf */ 77 result.bin ary= FLOAT32_NAN;78 result.bin = FLOAT32_NAN; 78 79 return result; 79 80 } … … 83 84 return result; 84 85 } 85 86 if (is Float32Infinity(b)) {87 if (is Float32Zero(a)) {86 87 if (is_float32_infinity(b)) { 88 if (is_float32_zero(a)) { 88 89 /* FIXME 0 / inf */ 89 90 result.parts.exp = 0; … … 97 98 } 98 99 99 if (is Float32Zero(b)) {100 if (is Float32Zero(a)) {100 if (is_float32_zero(b)) { 101 if (is_float32_zero(a)) { 101 102 /*FIXME: 0 / 0*/ 102 result.bin ary= FLOAT32_NAN;103 result.bin = FLOAT32_NAN; 103 104 return result; 104 105 } … … 121 122 return result; 122 123 } 123 124 124 125 /* normalize it*/ 125 126 afrac <<= 1; 126 /* afrac is nonzero => it must stop */ 127 /* afrac is nonzero => it must stop */ 127 128 while (!(afrac & FLOAT32_HIDDEN_BIT_MASK)) { 128 129 afrac <<= 1; … … 130 131 } 131 132 } 132 133 133 134 if (bexp == 0) { 134 135 bfrac <<= 1; 135 /* bfrac is nonzero => it must stop */ 136 /* bfrac is nonzero => it must stop */ 136 137 while (!(bfrac & FLOAT32_HIDDEN_BIT_MASK)) { 137 138 bfrac <<= 1; … … 139 140 } 140 141 } 141 142 afrac = 143 bfrac = 144 142 143 afrac = (afrac | FLOAT32_HIDDEN_BIT_MASK) << (32 - FLOAT32_FRACTION_SIZE - 1); 144 bfrac = (bfrac | FLOAT32_HIDDEN_BIT_MASK) << (32 - FLOAT32_FRACTION_SIZE); 145 145 146 if (bfrac <= (afrac << 1)) { 146 147 afrac >>= 1; … … 169 170 ++cexp; 170 171 cfrac >>= 1; 171 } 172 172 } 173 173 174 /* check overflow */ 174 175 if (cexp >= FLOAT32_MAX_EXPONENT) { … … 178 179 return result; 179 180 } 180 181 181 182 if (cexp < 0) { 182 183 /* FIXME: underflow */ … … 190 191 cexp++; 191 192 cfrac >>= 1; 192 } 193 } 193 194 } else { 194 195 result.parts.exp = (uint32_t) cexp; … … 197 198 result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 198 199 199 return result; 200 return result; 200 201 } 201 202 202 /** 203 * Divide two double-precision floats. 203 /** Divide two double-precision floats. 204 204 * 205 205 * @param a Nominator. 206 206 * @param b Denominator. 207 * 207 208 * @return Result of division. 208 */ 209 float64 divFloat64(float64 a, float64 b) 209 * 210 */ 211 float64 div_float64(float64 a, float64 b) 210 212 { 211 213 float64 result; … … 217 219 result.parts.sign = a.parts.sign ^ b.parts.sign; 218 220 219 if (is Float64NaN(a)) {220 if (is Float64SigNaN(b)) {221 / *FIXME: SigNaN*/221 if (is_float64_nan(a)) { 222 if (is_float64_signan(b)) { 223 // FIXME: SigNaN 222 224 return b; 223 225 } 224 226 225 if (is Float64SigNaN(a)) {226 / *FIXME: SigNaN*/227 } 228 /* NaN*/227 if (is_float64_signan(a)) { 228 // FIXME: SigNaN 229 } 230 /* NaN */ 229 231 return a; 230 232 } 231 233 232 if (is Float64NaN(b)) {233 if (is Float64SigNaN(b)) {234 / *FIXME: SigNaN*/235 } 236 /* NaN*/234 if (is_float64_nan(b)) { 235 if (is_float64_signan(b)) { 236 // FIXME: SigNaN 237 } 238 /* NaN */ 237 239 return b; 238 240 } 239 241 240 if (is Float64Infinity(a)) {241 if (is Float64Infinity(b) || isFloat64Zero(b)) {242 / *FIXME: inf / inf */243 result.bin ary= FLOAT64_NAN;242 if (is_float64_infinity(a)) { 243 if (is_float64_infinity(b) || is_float64_zero(b)) { 244 // FIXME: inf / inf 245 result.bin = FLOAT64_NAN; 244 246 return result; 245 247 } … … 249 251 return result; 250 252 } 251 252 if (is Float64Infinity(b)) {253 if (is Float64Zero(a)) {253 254 if (is_float64_infinity(b)) { 255 if (is_float64_zero(a)) { 254 256 /* FIXME 0 / inf */ 255 257 result.parts.exp = 0; … … 263 265 } 264 266 265 if (is Float64Zero(b)) {266 if (is Float64Zero(a)) {267 if (is_float64_zero(b)) { 268 if (is_float64_zero(a)) { 267 269 /*FIXME: 0 / 0*/ 268 result.bin ary= FLOAT64_NAN;270 result.bin = FLOAT64_NAN; 269 271 return result; 270 272 } … … 274 276 return result; 275 277 } 276 278 277 279 afrac = a.parts.fraction; 278 280 aexp = a.parts.exp; … … 287 289 return result; 288 290 } 289 291 290 292 /* normalize it*/ 291 293 aexp++; … … 296 298 } 297 299 } 298 300 299 301 if (bexp == 0) { 300 302 bexp++; … … 305 307 } 306 308 } 307 308 afrac = 309 bfrac = 310 309 310 afrac = (afrac | FLOAT64_HIDDEN_BIT_MASK) << (64 - FLOAT64_FRACTION_SIZE - 2); 311 bfrac = (bfrac | FLOAT64_HIDDEN_BIT_MASK) << (64 - FLOAT64_FRACTION_SIZE - 1); 312 311 313 if (bfrac <= (afrac << 1)) { 312 314 afrac >>= 1; … … 330 332 331 333 /* round and shift */ 332 result = finish Float64(cexp, cfrac, result.parts.sign);334 result = finish_float64(cexp, cfrac, result.parts.sign); 333 335 return result; 334 336 } 335 337 336 /** 337 * Divide two quadruple-precision floats. 338 /** Divide two quadruple-precision floats. 338 339 * 339 340 * @param a Nominator. 340 341 * @param b Denominator. 342 * 341 343 * @return Result of division. 342 */ 343 float128 divFloat128(float128 a, float128 b) 344 * 345 */ 346 float128 div_float128(float128 a, float128 b) 344 347 { 345 348 float128 result; … … 349 352 uint64_t rem_hihi, rem_hilo, rem_lohi, rem_lolo; 350 353 uint64_t tmp_hihi, tmp_hilo, tmp_lohi, tmp_lolo; 351 354 352 355 result.parts.sign = a.parts.sign ^ b.parts.sign; 353 354 if (is Float128NaN(a)) {355 if (is Float128SigNaN(b)) {356 / *FIXME: SigNaN*/356 357 if (is_float128_nan(a)) { 358 if (is_float128_signan(b)) { 359 // FIXME: SigNaN 357 360 return b; 358 361 } 359 360 if (is Float128SigNaN(a)) {361 / *FIXME: SigNaN*/362 } 363 /* NaN*/362 363 if (is_float128_signan(a)) { 364 // FIXME: SigNaN 365 } 366 /* NaN */ 364 367 return a; 365 368 } 366 367 if (is Float128NaN(b)) {368 if (is Float128SigNaN(b)) {369 / *FIXME: SigNaN*/370 } 371 /* NaN*/369 370 if (is_float128_nan(b)) { 371 if (is_float128_signan(b)) { 372 // FIXME: SigNaN 373 } 374 /* NaN */ 372 375 return b; 373 376 } 374 375 if (is Float128Infinity(a)) {376 if (is Float128Infinity(b) || isFloat128Zero(b)) {377 / *FIXME: inf / inf */378 result.bin ary.hi = FLOAT128_NAN_HI;379 result.bin ary.lo = FLOAT128_NAN_LO;377 378 if (is_float128_infinity(a)) { 379 if (is_float128_infinity(b) || is_float128_zero(b)) { 380 // FIXME: inf / inf 381 result.bin.hi = FLOAT128_NAN_HI; 382 result.bin.lo = FLOAT128_NAN_LO; 380 383 return result; 381 384 } … … 386 389 return result; 387 390 } 388 389 if (is Float128Infinity(b)) {390 if (is Float128Zero(a)) {391 / * FIXME 0 / inf */391 392 if (is_float128_infinity(b)) { 393 if (is_float128_zero(a)) { 394 // FIXME 0 / inf 392 395 result.parts.exp = 0; 393 396 result.parts.frac_hi = 0; … … 395 398 return result; 396 399 } 397 / * FIXME: num / inf*/400 // FIXME: num / inf 398 401 result.parts.exp = 0; 399 402 result.parts.frac_hi = 0; … … 401 404 return result; 402 405 } 403 404 if (is Float128Zero(b)) {405 if (is Float128Zero(a)) {406 / *FIXME: 0 / 0*/407 result.bin ary.hi = FLOAT128_NAN_HI;408 result.bin ary.lo = FLOAT128_NAN_LO;409 return result; 410 } 411 / * FIXME: division by zero */406 407 if (is_float128_zero(b)) { 408 if (is_float128_zero(a)) { 409 // FIXME: 0 / 0 410 result.bin.hi = FLOAT128_NAN_HI; 411 result.bin.lo = FLOAT128_NAN_LO; 412 return result; 413 } 414 // FIXME: division by zero 412 415 result.parts.exp = 0; 413 416 result.parts.frac_hi = 0; … … 415 418 return result; 416 419 } 417 420 418 421 afrac_hi = a.parts.frac_hi; 419 422 afrac_lo = a.parts.frac_lo; … … 422 425 bfrac_lo = b.parts.frac_lo; 423 426 bexp = b.parts.exp; 424 427 425 428 /* denormalized numbers */ 426 429 if (aexp == 0) { … … 431 434 return result; 432 435 } 433 436 434 437 /* normalize it*/ 435 438 aexp++; … … 443 446 } 444 447 } 445 448 446 449 if (bexp == 0) { 447 450 bexp++; … … 455 458 } 456 459 } 457 460 458 461 or128(afrac_hi, afrac_lo, 459 462 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, … … 466 469 lshift128(bfrac_hi, bfrac_lo, 467 470 (128 - FLOAT128_FRACTION_SIZE - 1), &bfrac_hi, &bfrac_lo); 468 471 469 472 if (le128(bfrac_hi, bfrac_lo, afrac_hi, afrac_lo)) { 470 473 rshift128(afrac_hi, afrac_lo, 1, &afrac_hi, &afrac_lo); 471 474 aexp++; 472 475 } 473 476 474 477 cexp = aexp - bexp + FLOAT128_BIAS - 2; 475 478 476 479 cfrac_hi = div128est(afrac_hi, afrac_lo, bfrac_hi); 477 480 478 481 mul128(bfrac_hi, bfrac_lo, 0x0ll, cfrac_hi, 479 482 &tmp_lolo /* dummy */, &tmp_hihi, &tmp_hilo, &tmp_lohi); 480 481 /* sub192(afrac_hi, afrac_lo, 0, 483 484 /* sub192(afrac_hi, afrac_lo, 0, 482 485 * tmp_hihi, tmp_hilo, tmp_lohi 483 486 * &rem_hihi, &rem_hilo, &rem_lohi); */ … … 487 490 } 488 491 rem_lohi = -tmp_lohi; 489 492 490 493 while ((int64_t) rem_hihi < 0) { 491 494 --cfrac_hi; 492 /* add192(rem_hihi, rem_hilo, rem_lohi, 495 /* add192(rem_hihi, rem_hilo, rem_lohi, 493 496 * 0, bfrac_hi, bfrac_lo, 494 497 * &rem_hihi, &rem_hilo, &rem_lohi); */ … … 498 501 } 499 502 } 500 503 501 504 cfrac_lo = div128est(rem_hilo, rem_lohi, bfrac_lo); 502 505 503 506 if ((cfrac_lo & 0x3FFF) <= 4) { 504 507 mul128(bfrac_hi, bfrac_lo, 0x0ll, cfrac_lo, 505 506 508 &tmp_hihi /* dummy */, &tmp_hilo, &tmp_lohi, &tmp_lolo); 509 507 510 /* sub192(rem_hilo, rem_lohi, 0, 508 511 * tmp_hilo, tmp_lohi, tmp_lolo, … … 513 516 } 514 517 rem_lolo = -tmp_lolo; 515 518 516 519 while ((int64_t) rem_hilo < 0) { 517 520 --cfrac_lo; … … 524 527 } 525 528 } 526 529 527 530 cfrac_lo |= ((rem_hilo | rem_lohi | rem_lolo) != 0 ); 528 531 } 529 532 530 533 shift_out = cfrac_lo << (64 - (128 - FLOAT128_FRACTION_SIZE - 1)); 531 534 rshift128(cfrac_hi, cfrac_lo, (128 - FLOAT128_FRACTION_SIZE - 1), 532 535 &cfrac_hi, &cfrac_lo); 533 534 result = finish Float128(cexp, cfrac_hi, cfrac_lo, result.parts.sign, shift_out);536 537 result = finish_float128(cexp, cfrac_hi, cfrac_lo, result.parts.sign, shift_out); 535 538 return result; 536 539 }
Note:
See TracChangeset
for help on using the changeset viewer.