Skip to content

Fix FMA sign handling in float_bvt for infinity and zero results#8985

Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:fix-fma-sign
Open

Fix FMA sign handling in float_bvt for infinity and zero results#8985
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:fix-fma-sign

Conversation

@tautschnig
Copy link
Copy Markdown
Collaborator

float_bvt::fma always set the sign to the add/sub sign, ignoring special cases. Added proper sign selection:

  • Infinity: use product sign if product is inf, else addend sign
  • Zero: respect ROUND_TO_MINUS_INF sign convention for signed zeros
  • Normal: use the add/sub sign (unchanged)
  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

float_bvt::fma always set the sign to the add/sub sign, ignoring
special cases. Added proper sign selection:
- Infinity: use product sign if product is inf, else addend sign
- Zero: respect ROUND_TO_MINUS_INF sign convention for signed zeros
- Normal: use the add/sub sign (unchanged)

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig self-assigned this Apr 28, 2026
Copilot AI review requested due to automatic review settings April 28, 2026 11:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes incorrect sign selection in float_bvt::fma results by choosing the sign based on whether the final result is infinity, zero, or a normal value, and adds a regression test focused on infinity-sign behavior.

Changes:

  • Update float_bvt::fma to select the result sign differently for infinity and zero outcomes.
  • Introduce a regression test (Float-fma-sign) for infinity-result sign handling in both bitvector and SMT modes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/solvers/floatbv/float_bv.cpp Adjusts FMA result sign selection for infinity and zero outcomes.
regression/cbmc/Float-fma-sign/main.c Adds regression assertions for infinity sign behavior using __CPROVER_fmaf.
regression/cbmc/Float-fma-sign/test.desc Runs the new regression under --floatbv.
regression/cbmc/Float-fma-sign/test_smt.desc Runs the new regression under SMT (--smt2 --z3).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +952 to +955
// Zero: result is zero when fraction is zero and not inf/NaN
result.zero = and_exprt(
not_exprt(or_exprt(result.infinity, result.NaN)),
equal_exprt(result.fraction, from_integer(0, result.fraction.type())));
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result.zero is being (re)derived solely from result.fraction == 0. If result.fraction is not a complete “value is zero” indicator at this stage (e.g., if the representation allows non-zero values with a zero fraction field, or if rounder/packing logic expects result.zero to be computed differently), this can misclassify non-zero values as zero and affect both sign selection and downstream handling in rounder. Consider: (1) using the existing zero classification already maintained by the unpacking/addition pipeline (if available), or (2) computing a local is_zero_result predicate for sign selection without assigning to result.zero, leaving result.zero to be set by the established canonical logic.

Copilot uses AI. Check for mistakes.
Comment on lines +960 to +965
// Sign for zero: under round-to-minus-inf, +0 + (-0) = -0
const rounding_mode_bitst rounding_mode_bits(rm);
exprt zero_sign = if_exprt(
rounding_mode_bits.round_to_minus_inf,
or_exprt(prod_sign, unpacked_add.sign),
and_exprt(prod_sign, unpacked_add.sign));
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentions zero-sign handling (round-to-minus-inf signed-zero convention), but the added regression test only covers infinity-result sign selection. Please add a regression case that forces an exact-zero FMA result and checks the sign across rounding modes—at minimum ROUND_TO_MINUS_INF vs a non-minus-inf mode—to ensure this new branch is exercised in both --floatbv and SMT runs.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.51%. Comparing base (a6531d4) to head (0621b61).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8985      +/-   ##
===========================================
+ Coverage    80.50%   80.51%   +0.01%     
===========================================
  Files         1704     1704              
  Lines       188796   188805       +9     
  Branches        73       73              
===========================================
+ Hits        151993   152024      +31     
+ Misses       36803    36781      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants