riscv-software-src / riscv-isa-sim

Spike, a RISC-V ISA Simulator
Other
2.38k stars 839 forks source link

Add several BF16 ops to SoftFloat #1695

Closed aswaterman closed 3 months ago

aswaterman commented 3 months ago

I recently got a request to add basic BF16 arithmetic to SoftFloat. Although I don't object, I want to keep the implementations as simple as possible, so I've implemented them in terms of FP32 ops.

This is straightforward enough for add/sub/mul/div/sqrt, where double rounding is correct. It's tricker for FMA, where we need to perform the addition using round-to-odd to account for double rounding. (We then need to correct for -0.0 outputs when rounding down.)

I've added these to Spike first because it was easier for me to test them this way. If the PR is accepted, I'll backport them to https://github.com/ucb-bar/berkeley-softfloat-3.