Skip to content

fpnew_fma_multi: fix after-rounding underflow for narrow formats - #190

Open
theOfficeCat wants to merge 1 commit into
openhwfoundation:developfrom
bsc-loca:fix/fma-uf-after-round
Open

theOfficeCat wants to merge 1 commit into
openhwfoundation:developfrom
bsc-loca:fix/fma-uf-after-round

Conversation

@theOfficeCat

Copy link
Copy Markdown

Fixes #182

What

Use the format-relative remainder bit in the after-rounding underflow detection of fpnew_fma_multi instead of the single-format expression sum_sticky_bits[MAN_BITS*2 + 4].

Why

The after-rounding UF term handles the case where a subnormal pre-round value rounds up to the smallest normal, and looks at the bit just below the round bit (for RNE/RMM). In the single-format fpnew_fma unit PRECISION_BITS == MAN_BITS + 1, so sum_sticky_bits[MAN_BITS*2 + 4] is exactly that bit. In the multi-format unit the datapath is sized for the widest enabled format (SUPER_MAN_BITS), so for narrower destination formats the bit lives in final_mantissa[SUPER_MAN_BITS-MAN_BITS-1] and the sum_sticky_bits one is typically zero: the check then always takes the underflow branch and raises spurious underflow (RNE/RMM) when the result rounds up to the smallest normal, e.g. FP32 FMADD/MUL with FpFmtConfig={FP32,FP64} (ADDMUL merged).

The remainder bit is now selected per format: final_mantissa[SUPER_MAN_BITS-MAN_BITS-1] when MAN_BITS < SUPER_MAN_BITS, and sum_sticky_bits[2*PRECISION_BITS+2] for the widest format (same bit as before, so FP64 is unchanged).

cc @Axionix77 (who reported #182) — could you confirm this matches the case on your side?

The after-rounding underflow detection reused the single-format
expression `sum_sticky_bits[MAN_BITS*2 + 4]`, which only points to the
bit just below the round bit when the datapath is sized for the
destination format. In the multi-format unit the datapath is sized for
the widest enabled format, so for narrower formats that bit lives in
`final_mantissa[SUPER_MAN_BITS-MAN_BITS-1]` and `sum_sticky_bits` is
typically zero, causing spurious underflow to be flagged when a
subnormal result rounds up to the smallest normal.
@Axionix77

Copy link
Copy Markdown

Hi @theOfficeCat,

Can confirm it is working with the new changes of this commit.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The selected indices match the rounding-bit layout for narrow and widest formats, with no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes spurious after-rounding underflow flags for narrow destination formats in the multi-format FMA unit, addressing #182.

Changes:

  • Selects the bit below the round bit relative to each format’s mantissa width.
  • Preserves the existing behavior for the widest enabled format.
File Description
src/​fpnew_fma_multi.sv Uses a format-relative bit for after-rounding underflow detection.

Review effort: Balanced

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.

[BUG] Underflow flag incorrect on some edge cases when ADDMUL unit is set to MERGED

3 participants