runtime: fix softfloat64 add/sub for normal operands cancelling to subnormal#79965
runtime: fix softfloat64 add/sub for normal operands cancelling to subnormal#79965omarsy wants to merge 1 commit into
Conversation
|
This PR (HEAD: f92b8c0) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/789861. Important tips:
|
…bnormal fpack64 returns a wrongly-scaled subnormal when fadd64/fsub64 produce a heavily-cancelled mantissa: subtracting two near-equal, opposite-sign normal operands yields a mant0 far below 1<<mantbits64 while exp0 is still a normal-range exponent. The denormal branch resets to (mant0, exp0) and only right-shifts to align to the subnormal exponent, but with exp0 above the subnormal range that shift goes the wrong direction, so the result is the un-normalized cancellation mantissa at the wrong scale rather than the correctly rounded subnormal. Re-normalize the mantissa (left-shift) before the alignment loop. This is a no-op for already-normalized callers (fmul64/fdiv64/conversions), so they are unaffected; only the cancellation case is corrected. fpack32 has the same structure and is fixed for parity. This only manifests on softfloat targets (e.g. GOMIPS=softfloat), which is why it has gone unnoticed on hardware-float platforms. A randomized differential check against hardware found the previous code wrong on >50% of normal pairs that cancel into a subnormal; with this change those cases match hardware. Fixes golang#79964
f92b8c0 to
319d857
Compare
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/789861. |
|
This PR (HEAD: 319d857) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/789861. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/789861. |
fpack64 returns a wrongly-scaled subnormal when fadd64/fsub64 produce a
heavily-cancelled mantissa: subtracting two near-equal, opposite-sign normal
operands yields a mant0 far below 1<<mantbits64 while exp0 is still a
normal-range exponent. The denormal branch resets to (mant0, exp0) and only
right-shifts to align to the subnormal exponent, but with exp0 above the
subnormal range that shift goes the wrong direction, so the result is the
un-normalized cancellation mantissa at the wrong scale rather than the correctly
rounded subnormal.
Re-normalize the mantissa (left-shift) before the alignment loop. This is a
no-op for already-normalized callers (fmul64/fdiv64/conversions), so they are
unaffected; only the cancellation case is corrected. fpack32 has the same
structure and is fixed for parity.
This only manifests on softfloat targets (e.g. GOMIPS=softfloat), which is why
it has gone unnoticed on hardware-float platforms. A randomized differential
check against hardware found the previous code wrong on >50% of normal pairs
that cancel into a subnormal; with this change those cases match hardware.
Fixes #79964