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