berkeley-hardfloat icon indicating copy to clipboard operation
berkeley-hardfloat copied to clipboard

Division/sqrt algorithm

Open sally-aha opened this issue 8 years ago • 8 comments

Which algorithm does hardfloat use for division and square root?

sally-aha avatar Dec 26 '17 08:12 sally-aha

There are two. DivSqrtRecF64 uses a quadratically convergent iterative algorithm, using a pre-multiplication to get a 10-ish-bit initial approximation. DivSqrtRecFN_small uses a straightforward one-bit-at-a-time algorithm.

aswaterman avatar Dec 27 '17 09:12 aswaterman

Then how can I choose which one to use? Which performs better? And does DivSqrtRecFN_small use SRT? If so, which radix? Thank you very much for your reply.

sally-aha avatar Dec 27 '17 09:12 sally-aha

It's too dependent on your application for me to provide an answer. The first option has latency of 25-ish cycles and throughput of 1/3 operations per cycle, but the area cost is high and the clock rate might be limited. The second option has latency of S-ish cycles (where S is the width of the significand) and has throughput of 1/S operations per cycle, but the area cost is low and it can run at higher clock rate.

aswaterman avatar Dec 27 '17 09:12 aswaterman

DivSqrtRecFN_small doesn't use SRT; it's just one bit at a time.

aswaterman avatar Dec 27 '17 09:12 aswaterman

Does DivSqrtRecF64 use algorithm of Goldschmidt or Newton-Raphson? @aswaterman And did you consider using the mainstream SRT algorithm?

JonnySmith0011 avatar Mar 04 '18 08:03 JonnySmith0011

Hi, I want to generate the Verilog of the division. Could you please tell me how to generate Verilog from hardfloat files? Thank you so much.

liwt07 avatar Mar 22 '18 01:03 liwt07

The original Verilog code is still available here: http://www.jhauser.us/arithmetic/HardFloat.html

aamartin0000 avatar Mar 09 '23 20:03 aamartin0000

FYI. I had a bare configurable SRT in sequencer/arithmetic. I'll find some time to PR hardfloat this year.

sequencer avatar Mar 10 '23 01:03 sequencer