[libre-riscv-dev] div/mod algorithm written in python

Luke Kenneth Casson Leighton lkcl at lkcl.net
Mon Jul 1 13:10:34 BST 2019


On Mon, Jul 1, 2019 at 12:15 PM Jacob Lifshay <programmerjake at gmail.com> wrote:
>
> Implemented the code+tests to compute fixed-point sqrt with remainder
> and reciprocal sqrt with remainder. Planning on implementing
> HW-friendly algorithms in FixedSqrt and FixedRSqrt classes tomorrow,
> then will convert to nmigen.

 superb.  ok, hmm, i need to get some FP single-argument pipeline
infrastructure in place: alternatively you could use the 2-arg version
for now [and set one of the args to zero].


> It successfully computes the sqrt of 2 and recip sqrt of 1/2 to 32-bits.

 excellent!

> both algorithms compute the largest fixed-point number x that makes
> the remainder >= 0, where the remainder for sqrt is defined as:
> radicand - x * x
> and the remainder for recip sqrt is defined as:
> 1 - x * x * radicand
> where radicand is the input to the sqrt or recip sqrt.
>
> This provides the equivalent of the floor of the sqrt or recip sqrt.
>
> To compute the guard, round, and sticky bits:
> compute the mantissa with 2 (not 3) additional LSB bits. the guard and
> round bits are then the 2 additional LSB bits and the sticky bit is 1
> when remainder != 0 (since remainder == 0 means the result is exact).

 neat trick.

l.



More information about the libre-riscv-dev mailing list