[libre-riscv-dev] [Bug 43] create an IEEE754 FP "sqrt"

bugzilla-daemon at libre-riscv.org bugzilla-daemon at libre-riscv.org
Thu Apr 25 20:25:19 BST 2019

```http://bugs.libre-riscv.org/show_bug.cgi?id=43

--- Comment #6 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
> > paper) into python, which we will *need anyway as part of the unit
> > tests*.
> >

> Yes i will convert that code to python.

great.  look fwd to seeing it.  always wanted to impl.

idea.

sqrt of num on 2-bit boundary always whole num.

sqrt 1 -> 1
sqrt 4 -> 2
sqrt 16 -> 4
sqrt 64 -> 8

sqrt of num on *odd* 2-bit boundry *never* whole.

why?

represent as exponent / mantissa, basically exponent LSB has to be zero.

to sqrt exponent, just divide exponent by two.

except, if exp LSB == 1, CANNOT DO THAT.

however... there is a trick:

* shift mantissa DOWN by 1 bit to compensate

*NOW* exp LSB is guaranteed to be zero.

*NOW* can divide exp by 2 without destroying (losing) info.

mantissa shifted by 1 means, interestingly, 2-bit loop now has input
shifted by 1 compared to before.

fascinating.

example

exp = 0b1101, m = 01101011
exp = 0b1110, m = 00110101 (lose 1 bit, must make room internally!
this is what extra bits are for)

before, m would be divided 01 | 10 | 10 | 11
now it is divided 00 | 11 | 01 | 01

sqrt: exp /= 2 --> 0b0111, mant = pipealgorithm(00 | 11 | 01 | 01)

example

exp = 0b0100, m = 01010101
exp LSB = 0, -->
*NO SHIFT*

sqrt: exp /= 2 --> 0b0010, mant = pipealgorithm(01 | 01 | 01 | 01)

--
You are receiving this mail because:
You are on the CC list for the bug.
```