Skip to content

TFU timing fix - #584

Open
jel221 wants to merge 2 commits into
masterfrom
fix/tfu-timing
Open

jel221 wants to merge 2 commits into
masterfrom
fix/tfu-timing

Conversation

@jel221

@jel221 jel221 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Human comment: fixing TFU timing


Summary

The TFU PE's two deepest paths were not in the table or polynomial math:

  • Stage 1 (24 Beacon levels): ex2 and sin/cos range reduction. A subtract, range compares and two barrel shifts, then a full-width negate (ex2) or a 32-bit add (the cos phase).
  • Stage 5 (19–20 levels): the lg2 output. The 3-operand polynomial sum, then a 41-bit add and a 40-bit negate in series.

The rest of the core is 15 levels deep (the LSU).

This PR shortens both paths. Results stay bit-identical and the pipeline stays 7 stages. Everything is in VX_tfu_pe.sv:

  • One shared shift. ex2 and sin/cos both take x_sig * 2^(x_e - 96) over x_e in [96, 159]. On that range the shift amount is just {x_e[7], x_e[4:0]}, so there is no subtract and no compare. Outside that range the result is 0, as before.
  • ex2 negation split across stages 1 and 2. Stage 1 registers ~mag and two carries. Stage 2 adds them to the 18-bit fraction, the 6-bit table index and the exponent, in front of the ROM.
  • sin/cos ±1 test moved to stage 2. Its u[29:6] == 0 part reads the registered ~idx/~xl, and stage 1 tests only u[5:0]. The cos phase offset becomes two XORs.
  • lg2 without a final negate. k·2^30 + p and its negation are each one sum of the polynomial terms, computed in parallel and selected by sign.

Everything that reaches the result is the same function of the input, so SimX, cycle counts and perf baselines do not move.

Why now: Vivado already closes the tfu DUT at 317.9 MHz against its 300 MHz target. The gain is ASIC Fmax, where the TFU is the slowest unit in the ASIC baselines, plus FPGA margin for every configuration that enables the TFU.

Results

master this PR
Beacon tfu DUT (16 threads), max levels 24 13
Beacon NT8 / 16-warp core with TFU, max levels 23 (TFU) 15 (LSU; TFU 13–14)
Beacon tfu LUT / FF 5,751 / 1,813 5,652 / 1,816
gate_asic (Beacon ASAP7) tfu Fmax 913 MHz 1,239 MHz
gate_asic cells / FFs 15,150 / 1,813 14,074 (−7%) / 1,816
asic_gate (Yosys + OpenSTA) tfu Fmax 1,055 MHz 1,252 MHz
asic_gate area / power 2,014 µm² / 19.3 mW 2,056 µm² (+2%) / 21.7 mW (+12%)
fpga_gate (Vivado 2024.2, U55C, 300 MHz) tfu Fmax / LUT / FF 317.9 MHz / 2,030 / 1,105 346.4 MHz / 1,901 / 1,217

After the change, the TFU's worst Vivado path is a one-level enable net in the lane serializer, not the PE. Vivado's flip-flop count rises by 112 even though the RTL adds only 3 registers (Beacon: 1,813 → 1,816). Over the same build, Vivado's LUT-RAM count, which includes shift-register LUTs, falls from 64 to 41. So most likely about 23 shift-register LUTs in the serializer's delay line are now built from flip-flops instead. The ASIC area is under the 2,073 µm² budget. The +12% power comes from the second parallel sum in stage 5 and the stage-2 carry logic, measured at the gate's fixed clock.

Baseline re-record

gate_asic judges tfu IMPROVED, because cells moved −7%, past its ±5% band. That fails until the baseline records the gain. The second commit re-records ci/baselines/synthesis/beacon_asic/tfu.json with ci/logic_gate.py --tool beacon_asic -b tfu --update-baseline, on the CI toolchain pin (TOOLCHAIN_REV). It was run by the agent and authorized by jel221. No other baseline moves.

Impact and evidence

Impact class: R2 (path:rtl, evidence:simx-rtl-lockstep; from ci/change_impact.py). The lockstep warning is covered by the parity row below: cycles are identical, so no SimX change is needed.

Contracts touched: none

evidence status detail
functional tests (simx / rtlsim / xrt) run hw/unittest/tfu_unit (RTL vs sw/common/tfu.cpp, bit-exact): default sweep (659k checks) and a stride-17 sweep of all 2^32 inputs per function plus 4M random (1,772,516,204 checks), 0 errors. tfu app (checks every result against the golden model), all PASSED: simx default; rtlsim default, -DVX_CFG_NUM_THREADS=16 -DVX_CFG_NUM_WARPS=16, -DVX_CFG_NUM_TFU_LANES=4. xrt not run (no card used).
model_parity run parity-tfu, parity-tfu-nt8, parity-tfu-nt16 shapes on rtlsim with this PE and with master's PE: identical instructions and cycles (612,647 / 544,839 / 531,120). SimX against them: 612,634 / 545,141 / 531,056, gap ≤ 0.06%.
perf_gate n/a latency and results unchanged; no perf case moves (cycle-identical above)
Beacon logic_gate run tfu DUT and an NT8/16-warp core with VX_CFG_EXT_TFU_ENABLE, before/after above; no unit deeper. The default logic_gate builds do not enable the TFU.
synthesis (fpga_gate / asic_gate) run fpga_gate -b tfu, asic_gate -b tfu, logic_gate --tool beacon_asic -b tfu (results above)
XLEN 64 build not run the PE has no XLEN-dependent logic; CI's XLEN 64 TFU cases cover it

Self-check: ci/precheck.sh summary: precheck: 7 pass, 0 with findings, 0 fail, 0 not run

Departures from SHOULD rules: none

Design note: n/a

  • No test silenced (known_issue:, wider tolerance, smaller args, removed case) without a root-cause plan.
  • Golden data changed only through its update command; the commit names the command and who ran it (X-EV-1).
  • Cycle-moving RTL changes carry the matching SimX change, or the parity case that shows none moved.
  • A toolchain pin moves only after the prebuilt tag exists.

The PE's two deepest paths were not the polynomial: stage 1 was the ex2
and sin/cos range reduction (a subtract, compares and two barrel shifts,
then a full-width negate or add), and stage 5 was the lg2 sum followed by
a 41-bit add and a 40-bit negate in series. Beacon put the tfu DUT at 24
logic levels and a core with the TFU at 23, against 15 for the rest of
the core.

- ex2 and sin/cos share one shift of x_sig by x_e - 96, which over the
  exponents that matter is {x_e[7], x_e[4:0]}: no subtract, no compare.
- The ex2 negation becomes ~mag; its +1 is registered as two carries and
  applied in stage 2 (6-bit index, 18-bit fraction, exponent).
- The sin/cos exact +-1 test uses the registered ~idx/~xl in stage 2;
  only u[5:0] is tested in stage 1. The cos phase is two XORs.
- lg2 sums k * 2^30 + p and its negation in parallel instead of
  negating after the sum.

Results stay bit-identical to sw/common/tfu.cpp and the pipeline stays
7 stages, so SimX, cycles and perf baselines do not move. Beacon: tfu
24 -> 13 levels; 8-thread 16-warp core with TFU 23 -> 15. ASIC: Beacon
913 -> 1239 MHz, Yosys/STA 1055 -> 1252 MHz.
gate_asic judges tfu IMPROVED after the PE path rework (cells 15150 ->
14074, -7.1%, past the 5% band), so the win is recorded to lock it in.
Fmax 913.2 -> 1239.2 MHz, 36 -> 24 stages, flip-flops 1813 -> 1816.

Command: ci/logic_gate.py --tool beacon_asic -b tfu --update-baseline
(beacon 134d03b9e, CIRCT 90c5fd313, TOOLCHAIN_REV v3.0.4).
Re-recorded by: agent, authorized by jel221 2026-12-03.
@jel221
jel221 marked this pull request as ready for review December 3, 2026 21:51
@jel221 jel221 changed the title tfu: shorten the PE's stage 1 and stage 5 paths (same results, same latency) TFU timing fix Dec 3, 2026
@jel221
jel221 added this pull request to stack #589 December 4, 2026 08:28

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.

1 participant