Changeset a35b458 in mainline for uspace/lib/softfloat/div.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/div.c
r3061bc1 ra35b458 53 53 int32_t aexp, bexp, cexp; 54 54 uint64_t afrac, bfrac, cfrac; 55 55 56 56 result.parts.sign = a.parts.sign ^ b.parts.sign; 57 57 58 58 if (is_float32_nan(a)) { 59 59 if (is_float32_signan(a)) { … … 63 63 return a; 64 64 } 65 65 66 66 if (is_float32_nan(b)) { 67 67 if (is_float32_signan(b)) { … … 71 71 return b; 72 72 } 73 73 74 74 if (is_float32_infinity(a)) { 75 75 if (is_float32_infinity(b)) { … … 83 83 return result; 84 84 } 85 85 86 86 if (is_float32_infinity(b)) { 87 87 if (is_float32_zero(a)) { … … 96 96 return result; 97 97 } 98 98 99 99 if (is_float32_zero(b)) { 100 100 if (is_float32_zero(a)) { … … 108 108 return result; 109 109 } 110 110 111 111 afrac = a.parts.fraction; 112 112 aexp = a.parts.exp; 113 113 bfrac = b.parts.fraction; 114 114 bexp = b.parts.exp; 115 115 116 116 /* denormalized numbers */ 117 117 if (aexp == 0) { … … 121 121 return result; 122 122 } 123 123 124 124 /* normalize it*/ 125 125 afrac <<= 1; … … 130 130 } 131 131 } 132 132 133 133 if (bexp == 0) { 134 134 bfrac <<= 1; … … 139 139 } 140 140 } 141 141 142 142 afrac = (afrac | FLOAT32_HIDDEN_BIT_MASK) << (32 - FLOAT32_FRACTION_SIZE - 1); 143 143 bfrac = (bfrac | FLOAT32_HIDDEN_BIT_MASK) << (32 - FLOAT32_FRACTION_SIZE); 144 144 145 145 if (bfrac <= (afrac << 1)) { 146 146 afrac >>= 1; 147 147 aexp++; 148 148 } 149 149 150 150 cexp = aexp - bexp + FLOAT32_BIAS - 2; 151 151 152 152 cfrac = (afrac << 32) / bfrac; 153 153 if ((cfrac & 0x3F) == 0) { 154 154 cfrac |= (bfrac * cfrac != afrac << 32); 155 155 } 156 156 157 157 /* pack and round */ 158 158 159 159 /* find first nonzero digit and shift result and detect possibly underflow */ 160 160 while ((cexp > 0) && (cfrac) && (!(cfrac & (FLOAT32_HIDDEN_BIT_MASK << 7)))) { … … 163 163 /* TODO: fix underflow */ 164 164 } 165 165 166 166 cfrac += (0x1 << 6); /* FIXME: 7 is not sure*/ 167 167 168 168 if (cfrac & (FLOAT32_HIDDEN_BIT_MASK << 7)) { 169 169 ++cexp; 170 170 cfrac >>= 1; 171 171 } 172 172 173 173 /* check overflow */ 174 174 if (cexp >= FLOAT32_MAX_EXPONENT) { … … 178 178 return result; 179 179 } 180 180 181 181 if (cexp < 0) { 182 182 /* FIXME: underflow */ … … 194 194 result.parts.exp = (uint32_t) cexp; 195 195 } 196 196 197 197 result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 198 198 199 199 return result; 200 200 } … … 215 215 uint64_t remlo, remhi; 216 216 uint64_t tmplo, tmphi; 217 217 218 218 result.parts.sign = a.parts.sign ^ b.parts.sign; 219 219 220 220 if (is_float64_nan(a)) { 221 221 if (is_float64_signan(b)) { … … 223 223 return b; 224 224 } 225 225 226 226 if (is_float64_signan(a)) { 227 227 // FIXME: SigNaN … … 230 230 return a; 231 231 } 232 232 233 233 if (is_float64_nan(b)) { 234 234 if (is_float64_signan(b)) { … … 238 238 return b; 239 239 } 240 240 241 241 if (is_float64_infinity(a)) { 242 242 if (is_float64_infinity(b) || is_float64_zero(b)) { … … 250 250 return result; 251 251 } 252 252 253 253 if (is_float64_infinity(b)) { 254 254 if (is_float64_zero(a)) { … … 263 263 return result; 264 264 } 265 265 266 266 if (is_float64_zero(b)) { 267 267 if (is_float64_zero(a)) { … … 275 275 return result; 276 276 } 277 277 278 278 afrac = a.parts.fraction; 279 279 aexp = a.parts.exp; 280 280 bfrac = b.parts.fraction; 281 281 bexp = b.parts.exp; 282 282 283 283 /* denormalized numbers */ 284 284 if (aexp == 0) { … … 288 288 return result; 289 289 } 290 290 291 291 /* normalize it*/ 292 292 aexp++; … … 297 297 } 298 298 } 299 299 300 300 if (bexp == 0) { 301 301 bexp++; … … 306 306 } 307 307 } 308 308 309 309 afrac = (afrac | FLOAT64_HIDDEN_BIT_MASK) << (64 - FLOAT64_FRACTION_SIZE - 2); 310 310 bfrac = (bfrac | FLOAT64_HIDDEN_BIT_MASK) << (64 - FLOAT64_FRACTION_SIZE - 1); 311 311 312 312 if (bfrac <= (afrac << 1)) { 313 313 afrac >>= 1; 314 314 aexp++; 315 315 } 316 316 317 317 cexp = aexp - bexp + FLOAT64_BIAS - 2; 318 318 319 319 cfrac = div128est(afrac, 0x0ll, bfrac); 320 320 321 321 if ((cfrac & 0x1FF) <= 2) { 322 322 mul64(bfrac, cfrac, &tmphi, &tmplo); 323 323 sub128(afrac, 0x0ll, tmphi, tmplo, &remhi, &remlo); 324 324 325 325 while ((int64_t) remhi < 0) { 326 326 cfrac--; … … 329 329 cfrac |= (remlo != 0); 330 330 } 331 331 332 332 /* round and shift */ 333 333 result = finish_float64(cexp, cfrac, result.parts.sign); … … 351 351 uint64_t rem_hihi, rem_hilo, rem_lohi, rem_lolo; 352 352 uint64_t tmp_hihi, tmp_hilo, tmp_lohi, tmp_lolo; 353 353 354 354 result.parts.sign = a.parts.sign ^ b.parts.sign; 355 355 356 356 if (is_float128_nan(a)) { 357 357 if (is_float128_signan(b)) { … … 359 359 return b; 360 360 } 361 361 362 362 if (is_float128_signan(a)) { 363 363 // FIXME: SigNaN … … 366 366 return a; 367 367 } 368 368 369 369 if (is_float128_nan(b)) { 370 370 if (is_float128_signan(b)) { … … 374 374 return b; 375 375 } 376 376 377 377 if (is_float128_infinity(a)) { 378 378 if (is_float128_infinity(b) || is_float128_zero(b)) { … … 388 388 return result; 389 389 } 390 390 391 391 if (is_float128_infinity(b)) { 392 392 if (is_float128_zero(a)) { … … 403 403 return result; 404 404 } 405 405 406 406 if (is_float128_zero(b)) { 407 407 if (is_float128_zero(a)) { … … 417 417 return result; 418 418 } 419 419 420 420 afrac_hi = a.parts.frac_hi; 421 421 afrac_lo = a.parts.frac_lo; … … 424 424 bfrac_lo = b.parts.frac_lo; 425 425 bexp = b.parts.exp; 426 426 427 427 /* denormalized numbers */ 428 428 if (aexp == 0) { … … 433 433 return result; 434 434 } 435 435 436 436 /* normalize it*/ 437 437 aexp++; … … 445 445 } 446 446 } 447 447 448 448 if (bexp == 0) { 449 449 bexp++; … … 457 457 } 458 458 } 459 459 460 460 or128(afrac_hi, afrac_lo, 461 461 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, … … 468 468 lshift128(bfrac_hi, bfrac_lo, 469 469 (128 - FLOAT128_FRACTION_SIZE - 1), &bfrac_hi, &bfrac_lo); 470 470 471 471 if (le128(bfrac_hi, bfrac_lo, afrac_hi, afrac_lo)) { 472 472 rshift128(afrac_hi, afrac_lo, 1, &afrac_hi, &afrac_lo); 473 473 aexp++; 474 474 } 475 475 476 476 cexp = aexp - bexp + FLOAT128_BIAS - 2; 477 477 478 478 cfrac_hi = div128est(afrac_hi, afrac_lo, bfrac_hi); 479 479 480 480 mul128(bfrac_hi, bfrac_lo, 0x0ll, cfrac_hi, 481 481 &tmp_lolo /* dummy */, &tmp_hihi, &tmp_hilo, &tmp_lohi); 482 482 483 483 /* sub192(afrac_hi, afrac_lo, 0, 484 484 * tmp_hihi, tmp_hilo, tmp_lohi … … 489 489 } 490 490 rem_lohi = -tmp_lohi; 491 491 492 492 while ((int64_t) rem_hihi < 0) { 493 493 --cfrac_hi; … … 500 500 } 501 501 } 502 502 503 503 cfrac_lo = div128est(rem_hilo, rem_lohi, bfrac_lo); 504 504 505 505 if ((cfrac_lo & 0x3FFF) <= 4) { 506 506 mul128(bfrac_hi, bfrac_lo, 0x0ll, cfrac_lo, 507 507 &tmp_hihi /* dummy */, &tmp_hilo, &tmp_lohi, &tmp_lolo); 508 508 509 509 /* sub192(rem_hilo, rem_lohi, 0, 510 510 * tmp_hilo, tmp_lohi, tmp_lolo, … … 515 515 } 516 516 rem_lolo = -tmp_lolo; 517 517 518 518 while ((int64_t) rem_hilo < 0) { 519 519 --cfrac_lo; … … 526 526 } 527 527 } 528 528 529 529 cfrac_lo |= ((rem_hilo | rem_lohi | rem_lolo) != 0 ); 530 530 } 531 531 532 532 shift_out = cfrac_lo << (64 - (128 - FLOAT128_FRACTION_SIZE - 1)); 533 533 rshift128(cfrac_hi, cfrac_lo, (128 - FLOAT128_FRACTION_SIZE - 1), 534 534 &cfrac_hi, &cfrac_lo); 535 535 536 536 result = finish_float128(cexp, cfrac_hi, cfrac_lo, result.parts.sign, shift_out); 537 537 return result; … … 544 544 float32_u ua; 545 545 ua.val = a; 546 546 547 547 float32_u ub; 548 548 ub.val = b; 549 549 550 550 float32_u res; 551 551 res.data = div_float32(ua.data, ub.data); 552 552 553 553 return res.val; 554 554 } … … 558 558 float32_u ua; 559 559 ua.val = a; 560 560 561 561 float32_u ub; 562 562 ub.val = b; 563 563 564 564 float32_u res; 565 565 res.data = div_float32(ua.data, ub.data); 566 566 567 567 return res.val; 568 568 } … … 576 576 float64_u ua; 577 577 ua.val = a; 578 578 579 579 float64_u ub; 580 580 ub.val = b; 581 581 582 582 float64_u res; 583 583 res.data = div_float64(ua.data, ub.data); 584 584 585 585 return res.val; 586 586 } … … 590 590 float64_u ua; 591 591 ua.val = a; 592 592 593 593 float64_u ub; 594 594 ub.val = b; 595 595 596 596 float64_u res; 597 597 res.data = div_float64(ua.data, ub.data); 598 598 599 599 return res.val; 600 600 } … … 608 608 float128_u ua; 609 609 ua.val = a; 610 610 611 611 float128_u ub; 612 612 ub.val = b; 613 613 614 614 float128_u res; 615 615 res.data = div_float128(ua.data, ub.data); 616 616 617 617 return res.val; 618 618 }
Note:
See TracChangeset
for help on using the changeset viewer.