Skip to content

fpu/fpnew: complete a lane group only when every lane is done; fix div/sqrt boxing and 0/0 flags - #486

Open
tinebp wants to merge 1 commit into
masterfrom
fix/fpnew-lane-handshake
Open

tinebp wants to merge 1 commit into
masterfrom
fix/fpnew-lane-handshake

Conversation

@tinebp

@tinebp tinebp commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

FPnew drops lanes. VX_fpu_fpnew ran one fpnew_top per lane but took valid, ready, tag and fflags from lane 0. Div/sqrt latency depends on the operands, so lanes finished out of step: other lanes returned stale or zero results, and their flags were lost. Fixes #437.

  • Each lane now has a fixed-latency lockstep instance (ADDMUL, NONCOMP, CONV) and a separate div/sqrt instance.
  • A VX_stream_fork and VX_stream_join complete a div/sqrt group only when every lane has a result. VX_stream_arb merges the two paths.
  • fflags are ORed over the instruction's active lanes.
  • At XLEN 64, an improperly NaN-boxed single operand to the PULP divider reads as the canonical NaN. Before, it was used as a number.
  • 0/0 raises NV only, not NV|DZ.

Two related defects outside FPnew, found in review:

  • Flags moved between warps. With fewer FPU lanes than threads, VX_fpu_block ORed every packet's flags into one shared register until the last packet. Packets of different instructions complete interleaved, so one warp's flags reached another and were lost from their own. fcsr accrues flags by OR, so each packet now writes its own flags as it returns.
  • Unboxed operands on STD and DSP. These backends fed F32 FMA and div/sqrt inputs as raw low words at FLEN 64. fp_unbox_s and fp_unbox_fmt in VX_fpu_pkg now substitute the canonical NaN there. FLEN 32 builds are unchanged.

New dogfood tests:

  • fdiv-special: mixes special and normal divides across lanes.
  • fp-nanbox: unboxed sqrt, div and FMA operands.
  • fflags-lanes: flags raised by single lanes, with lanes masked and warps mixing divides and adds.

Impact and evidence

Impact class: R2 (ci/change_impact.py classify)

Contracts touched: none

evidence status detail
functional tests (simx / rtlsim / xrt) run On master with FPnew they fail: fdiv-special 264, fp-nanbox 342, fflags-lanes 388 errors. With the fix they pass on SimX and rtlsim with DPI, STD, DSP and FPnew at XLEN 32 and 64, along with the dogfood suite, rv64uf/ud and rv32uf on FPnew. fflags-lanes with 2 FPU lanes for 4 threads fails 7 cases on FPnew with the old accumulator and passes with the fix.
model_parity n/a No parity case builds FPnew; the cycle change is limited to that backend.
perf_gate not run Default backends' cycles are unchanged.
Beacon logic_gate run core (XLEN 32): PASS, depth, LUT and FF unchanged. No DUT builds FPnew or XLEN 64.
synthesis not run
XLEN 64 build run rtlsim -Wall lint at XLEN 32 and 64 across the standard config matrix, STD, DSP and FPNEW, partial-bandwidth STD and FPNEW, and the DSP split FMA64 pool

New CI cases:

  • dogfood-fpnew

  • dogfood-fflags-pbw-std and dogfood-fflags-pbw-fpnew

  • dogfood-nanbox-dsp

  • No test silenced.

  • No golden data changed.

  • Cycle movement is FPnew-only, with no parity case for it.

  • No toolchain pin change.

🤖 Generated with Claude Code

…v/sqrt boxing and 0/0 flags

VX_fpu_fpnew ran one fpnew_top per lane but took valid, ready, tag and
fflags from lane 0 only. Div/sqrt has operand-dependent latency (special
operands finish early), so lanes finished out of step: the group was
released on lane 0's handshake and the other lanes returned zeros or stale
results, and fflags raised by any lane but lane 0 were lost. Aggregating
the lane valids alone is not enough, because inside one fpnew_top the op
groups have different latencies and can return results in a different
order on different lanes.

Split each lane into two fpnew instances:
- a lockstep instance with ADDMUL/NONCOMP/CONV only. Their latency does not
  depend on the data and every lane sees the same handshake, so lane 0's
  handshake is exact (a runtime assertion checks it);
- a div/sqrt-only instance. A VX_stream_fork hands each instruction to every
  lane exactly once, and a VX_stream_join completes the group when all lanes
  have a result. Each lane's divider is in order, so the k-th result of
  every lane belongs to the same instruction.
VX_stream_arb merges the two response streams (replacing the response
buffer), and fflags are ORed across the instruction's active lanes, with
the mask carried in the tag.

Two divider bugs found on the way, fixed in the wrapper (the PULP submodule
is untouched):
- at XLEN 64, fpnew's divider ignores NaN-boxing, so an improperly boxed
  single operand was used as a number. It now reads as the canonical NaN.
- 0/0 raised NV and DZ together; the spec raises NV only. DZ is cleared
  when NV is set.

Two flag and boxing defects outside the FPnew wrapper, found in review:
- with fewer FPU lanes than threads, an instruction runs as lane packets
  and VX_fpu_block ORed their flags into one shared register until the
  last packet. Packets of different warps' instructions complete
  interleaved (the cores have different latencies, and FPnew's div/sqrt
  path is merged by priority), so one warp's flags went to another and
  were lost from their own. fcsr accrues flags by OR, so each packet now
  writes its own flags as it returns; the scoreboard still releases fflags
  readers on the last packet, which writes no later than before.
- the STD and DSP backends fed F32 FMA and div/sqrt operands to the units
  as raw low words, so an improperly NaN-boxed operand was used as a
  number at FLEN 64. fp_unbox_s/fp_unbox_fmt in VX_fpu_pkg substitute the
  canonical NaN at those inputs; FLEN 32 builds are unchanged.

New dogfood tests fdiv-special (special and normal divides mixed across
lanes), fp-nanbox (64-bit only: an unboxed operand of sqrt, div and each
FMA operand) and fflags-lanes (flags raised by a single non-zero lane,
masked lanes must not contribute, warps mixing divides and adds). On master
with FPnew (XLEN 64, 8 lanes) the first and last fail with 264 and 388
errors and the div/sqrt rows of fp-nanbox with 342; with the fix they
pass, as do the full dogfood suite, rv64uf/rv64ud and rv32uf on FPnew,
and the new tests on SimX and the DPI, STD and DSP backends at XLEN 32 and
64. fflags-lanes with two FPU lanes for four threads fails 7 lanes on
FPnew with the shared accumulator and passes with per-packet writes (the
STD backend's fixed latencies did not interleave packets in this test).
CI: dogfood-fpnew runs the suite on rtlsim with FPnew at XLEN 32 and 64;
dogfood-fflags-pbw-{std,fpnew} run fflags-lanes with two FPU lanes;
dogfood-nanbox-dsp runs fp-nanbox on DSP at XLEN 64 (STD and FPnew are
covered by the default and FPnew suites). No model_parity case builds
FPnew, and the cycle change is limited to that backend. The dogfood
Makefile now declares its headers, so editing testcases.h rebuilds the
host binary. Beacon (core, XLEN 32, which does not build FPnew): depth,
LUT and FF unchanged.

Fixes #437.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

VX_fpu_fpnew completes the group on lane 0's handshake, so other lanes can return zero

1 participant