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

Jacob Lifshay programmerjake at gmail.com
Mon Jul 1 12:15:28 BST 2019


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.

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

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).

Jacob



More information about the libre-riscv-dev mailing list