Repository navigation
Conversation
bf16_mulAdd adds the exact binary64 product to the addend in round-to-odd mode. When a nonzero product cancels the addend exactly, that sum is +0 whatever the caller's rounding mode, but IEEE 754-2019 section 6.3 requires -0 under roundTowardNegative. Give the zero the sign of the caller's mode. Signed-off-by: xpick-ed <109844902+xpick-ed@users.noreply.github.com>
aswaterman
approved these changes
Nov 25, 2026
aswaterman
left a comment
Member
There was a problem hiding this comment.
Agreed. However, I think we can also get rid of the if-statement that conditions whether we round to odd. I'll handle that part.
aswaterman
added a commit
that referenced
this pull request
Nov 25, 2026
We were getting it right for e.g. 1x0-0, but not e.g. 1x3-3. Supersedes #52 Signed-off-by: Andrew Waterman <andrew@sifive.com>
aswaterman
added a commit
that referenced
this pull request
Nov 25, 2026
We were getting it right for e.g. 1x0-0, but not e.g. 1x3-3. Supersedes #52 Signed-off-by: Andrew Waterman <andrew@sifive.com>
aswaterman
added a commit
that referenced
this pull request
Nov 25, 2026
We were getting it right for e.g. 1x0-0, but not e.g. 1x3-3. Supersedes #52 Signed-off-by: Andrew Waterman <andrew@sifive.com>
Member
|
Closing in favor of #53. Thanks for raising the issue. |
aswaterman
added a commit
that referenced
this pull request
Nov 25, 2026
We were getting it right for e.g. 1x0-0, but not e.g. 1x3-3. Supersedes #52 Signed-off-by: Andrew Waterman <andrew@sifive.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bf16_mulAddforms the product exactly in binary64 and adds the addend in round-to-odd mode to avoid double rounding. When a nonzero product cancels the addend exactly, the round-to-odd sum is +0, so the result is +0 in every rounding mode. IEEE 754-2019 section 6.3 requires -0 under roundTowardNegative:The zero-product case already uses the caller's rounding mode. This change applies the same rule when a nonzero product cancels the addend.
Example:
bf16_mulAdd(3.0, 3.0, -9.0)(0x4040, 0x4040, 0xc110) withsoftfloat_round_minreturns 0x0000; it should return 0x8000.Testing: I compared the old and new routine on 20 million random operand triples, half of them constructed so that c = -(a*b), in all five rounding modes. The only results that change are 209,990 exact cancellations under
softfloat_round_min, from +0 to -0, with the same exception flags. Every other result is identical, and all 209,990 agree with the host'sfmaf()underFE_DOWNWARD.Developed with AI assistance; I reviewed the change, and the results above are from local runs.