mirror of
https://github.com/antonblanchard/microwatt.git
synced 2026-01-13 15:18:09 +00:00
This implements floating-point division A/B by a process that starts with normalizing both inputs if necessary. Then an estimate of 1/B from a lookup table is refined by 3 Newton-Raphson iterations and then multiplied by A to get a quotient. The remainder is calculated as A - R * B (where R is the result, i.e. the quotient) and the remainder is compared to 0 and to B to see whether the quotient needs to be incremented by 1. The calculations of 1 / B are done with 56 fraction bits and intermediate results are truncated rather than rounded, meaning that the final estimate of 1 / B is always correct or a little bit low, never too high, and thus the calculated quotient is correct or 1 unit too low. Doing the estimate of 1 / B with sufficient precision that the quotient is always correct to the last bit without needing any adjustment would require many more bits of precision. This implements fdivs by computing a double-precision quotient and then rounding it to single precision. It would be possible to optimize this by e.g. doing only 2 iterations of Newton-Raphson and then doing the remainder calculation and adjustment at single precision rather than double precision. Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
18 lines
238 B
Plaintext
18 lines
238 B
Plaintext
test 01:PASS
|
|
test 02:PASS
|
|
test 03:PASS
|
|
test 04:PASS
|
|
test 05:PASS
|
|
test 06:PASS
|
|
test 07:PASS
|
|
test 08:PASS
|
|
test 09:PASS
|
|
test 10:PASS
|
|
test 11:PASS
|
|
test 12:PASS
|
|
test 13:PASS
|
|
test 14:PASS
|
|
test 15:PASS
|
|
test 16:PASS
|
|
test 17:PASS
|