Skip to content

core: a misaligned atomic traps precisely (address-misaligned) instead of touching memory - #569

Merged
tinebp merged 1 commit into
masterfrom
fix/amo-misaligned-trap
Dec 3, 2026
Merged

tinebp merged 1 commit into
masterfrom
fix/amo-misaligned-trap

Conversation

@tinebp

@tinebp tinebp commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Base: master 3fb83fd. Head: fe58030 (1 commit).
Depends on: nothing. It is #560's F5 (the misaligned-atomic trap), split out of #560 and redesigned at the pipeline's extension points, as the #560 review asked (P1).
Merge order: independent of #560 at the code level. feat/amo64 (#564) stacks on it. A version on top of #560 is on branch rev2/amo-trap-b560 (e1371cf4b): same change, the test files merged with #560's amo tests.

The bug

An atomic (AMO, LR, SC, compare-and-swap) with an active lane whose address is not aligned to its size:

  • RTL: asserts "misaligned memory access" in simulation; on hardware it writes through a misaligned word.
  • SimX: aborts.

RISC-V says it raises address-misaligned: store/AMO (mcause 6), or load (4) for LR.

The fix: a precise trap, at the extension points only

The warp traps with mcause 6 (4 for LR), mepc = the atomic, mtval read-only zero. No instruction after the atomic runs before the handler, and the handler may return to mepc + 4.

  • Decode (extension point 2) marks every atomic wstall, as it does a branch. EXT_A only.
  • The uop sequencer (extension point 3, VX_uop_amo) expands every atomic: check [release fence] atomic [acquire fence].
    • The check is an ALU branch-port uop on rs1, on two spare branch codes (INST_BR_AMOCHK, INST_BR_LRCHK).
    • It targets PC + 4, so taken or not it does not redirect. It reads the trap pseudo-register, as ECALL does, so an older mtvec write has landed.
  • The trap goes through the branch port's is_trap (extension point 4). VX_alu_int (EXT_A only) raises it when an active lane is misaligned.
    • The scheduler's existing trap path writes mepc, mcause and mstatus. The check's br_hit releases the warp's fetch.
    • The check's SIMD slices and packets reach an ALU block back to back (the lane dispatcher's invariant), so one flop holds a misaligned lane of an earlier one until the last.
  • The LSU decides the same on its own (VX_lsu_block, EXT_A only), from rs1: no fault bit travels in op_args.
  • SimX in lockstep: the check is uop 0 (BrType::AMOCHK); the sequencer gives a wstall uop its macro's fetch release; AluUnit holds a misaligned lane per block and calls Scheduler::raise_trap; LsuUnit drops the atomic from the faulted packet on.
  • No VX_types change. The causes are local literals, as the ALU's other trap causes are. The resolved config hash is unchanged, so no perf golden needs re-recording.

Semantics, stated: with one LSU packet per warp (the default shape) a misaligned atomic performs no access. With several, the lanes of packets ahead of the first misaligned one perform their atomics. F5 used SIMD slices as the unit instead; the test checks the packet rule.

Cost

The atomic stalls its warp's fetch until the check resolves, as a branch does.

x32 cycles, control = master 3fb83fd with this commit's amo test text, so only the hardware and model differ (meas/pctl_, meas/pb_):

case simx rtlsim
amoadd 5875 → 8211 (+39.8%) 5888 → 8224 (+39.7%)
contended 7505 → 8721 (+16.2%) 7522 → 8738 (+16.2%)
contended-l2 37487 → 33539 (−10.5%) 37491 → 37641 (+0.4%)
zacas-simd 20239 → 22129 (+9.3%) 21523 → 21337 (−0.9%)
amo list w/o trap 58579 → 61244 (+4.5%) 62238 → 66286 (+6.5%)
sgemm 113803 → 113803 (0.0%) 113814 → 113814 (0.0%)

On top of #560 (branch rev2/amo-trap-b560 e1371cf4b; control = rev1/b560's tree with this commit's amo test text). #560 adds scatter and cas_counter and fixes SimX's LLC atomic timing (F7). meas/p5ctl_s2, p5b_s2, p5ctl_r, p5b_r:

case simx rtlsim simx / rtlsim, this change
amoadd 5877 → 8213 (+39.7%) 5890 → 8226 (+39.7%) -0.2%
contended 7509 → 8725 (+16.2%) 7526 → 8742 (+16.2%) -0.2%
contended-l2 36497 → 38453 (+5.4%) 37495 → 37645 (+0.4%) +2.1%
scatter 4995 → 5102 (+2.1%) 5057 → 5400 (+6.8%) -5.5% (see Known gaps)
cas_counter 254758 → 255455 (+0.3%) 252420 → 253308 (+0.4%) +0.8%
zacas-simd (cas_ladder, cas_lmem) 21094 → 22231 (+5.4%) 21521 → 21445 (-0.4%) +3.7%
zacas-simd, F5's list (+ cas_counter, cas_counter_lmem) 2001842 → 2215587 (+10.7%) 1716340 → 1721505 (+0.3%) +28.7%
amo list w/o trap 100941 → 98388 (-2.5%) 98607 → 102898 (+4.4%) -4.4%
sgemm 113803 → 113803 (+0.0%) 113814 → 113814 (+0.0%) -0.0%

Against the two F5 forms (measured on F8 in #560, so read the percentages, not the cycles):

This change costs about what the precise form cost: amoadd +39.7% here against +38.0% there (rtlsim), contended +16.2% against +15.4%.

Three forms considered (§13.4); the maintainer chose P

The maintainer chose P, this PR (2026-12-01): precise and with no shared-stage change, at the measured cost below.

EXT_A is off by default (VX_config.toml, VX_CFG_EXT_A_ENABLE = false), so the default configuration is unaffected by any of the three: every change is behind EXT_A.

P: this PR, precise D: deferred, isolated F5: #560's imprecise
where decode wstall, uop sequencer check, branch-port is_trap, ALU/LSU under EXT_A uop sequencer check, ALU/LSU under EXT_A; no wstall new scheduler port sched_amo_t, PC override, dispatcher fault marking (9 shared stages)
shared stages touched none none 9, and INST_ARGS_BITS +1 (gated later under EXT_A)
trap taken at the atomic; the warp fetched nothing after it at the warp's next branch-port op (branch, jump, ECALL, MRET, illegal); every non-branch instruction before it runs as the atomic leaves operand collection; younger instructions already past decode may complete
mepc / mtval the atomic / 0 the atomic / 0 the atomic / 0
handler may return to mepc + 4 yes (tested) no no
other limits none the trap can be taken after the handler is replaced (a csrw mtvec before the next branch); a warp that exits with no branch in between loses it, and the pending state stays with that warp slot a warp that retires before the trap lands loses it (#560 review F1)
amoadd, rtlsim +39.7% +0.0% 0.00%
contended, rtlsim +16.2% +0.9% 0.00%
amo list w/o trap, rtlsim +6.5% +2.7% 0.00%
sgemm 0.0% 0.0% 0.00%
Beacon core A on, U55C LUT −47, FF +3, 15 → 15 lv LUT +64, FF +67, LUTRAM +18, 15 → 15 lv +860 LUT, 15 → 15 lv (#560 body)
Beacon core A on, ASIC cells −487, FF +3, 30 → 30 cells −53, FF +299, 30 → 30 +0.17% cells, 29 stages
Beacon core A off identical (both flows) identical (both flows) +733 LUT on core before its EXT_A fixup 1f2df1a82; identical after it (#560 notes)

D was built and measured for this comparison only (branch rev2/amo-trap-deferred b9286af28, not proposed as is). x32, control = master with D's test text (meas/pDc_, pD_):

case simx rtlsim
amoadd 5876 → 5877 (+0.0%) 5889 → 5890 (+0.0%)
contended 7513 → 7578 (+0.9%) 7530 → 7595 (+0.9%)
contended-l2 37494 → 36833 (−1.8%) 37498 → 37647 (+0.4%)
zacas-simd 20204 → 21800 (+7.9%) 21240 → 21431 (+0.9%)
amo list w/o trap 58529 → 60257 (+3.0%) 62183 → 63843 (+2.7%)
sgemm 113803 → 113803 (0.0%) 113814 → 113814 (0.0%)

D's own test (the atomic followed only by a jump, the handler returning to the continuation) passes: SimX 4403 / RTL 4268 cycles, SIMD-4 shape RTL 6850. This PR's precise test fails on D, on both models: the late trap lands after the test restores mtvec, so the warp traps to address 0 (SimX "no trap handler (mtvec=0)", RTL fetch assertion; meas/dprec).

What remains of D's cost: the check uop (one ALU issue per atomic) and the uop sequencer's first-uop bubble, now paid by every atomic.

Area and depth (Beacon, CI's v3.0.3 bundle, against master 3fb83fd)

entry EXT_A U55C ASIC
core off identical: LUT 120383, FF 137138, 15 levels identical: 723387 cells, 94018 FF, 30 stages
core on LUT 127131 → 127084, FF 140274 → 140277, 15 → 15 levels 745720 → 745233 cells, FF 95842 → 95845, 30 → 30 stages
lmem on identical (18880 LUT, 9 levels) identical (120296 cells, 17 stages)

Units that moved with A on (U55C): uop_amo LUT 832 → 720, uop_sequencer 3152 → 3168, lsu_block 907 → 939 (+1 FF), alu_int 2966 → 2978 (+1 FF), its response buffer +1 FF. No path got deeper.
(The A-off rows use measurement-only entries, core without -DVX_CFG_EXT_A_ENABLE; the ASIC core entry builds with A on.)

Pipeline isolation (docs/coding_guidelines_verilog.md §13)

No shared stage (§13.1) changes, in RTL or SimX. The classifier marks the PR R3 for isa-localparams (the two branch codes), isa-decoder (BrType::AMOCHK) and test-coverage, not pipeline-stage.

It does change two shared units, the ALU and the LSU, for the atomics extension. The rules for that (§13.1) are those of a shared stage, so the six §13.4 items:

  1. Goal. A misaligned atomic must trap precisely instead of touching memory. Only the ALU raises a trap (the branch port's is_trap); only the LSU sees the atomic's packets. The ALU part decides the trap; the LSU part keeps the atomic from performing.
  2. The isolated alternative. This is it: decode, the uop sequencer, the branch-port trap hook, and a check inside the LSU's EXT_A path. Measured above.
  3. The gain against the other designs. The imprecise F5 costs 0.00% cycles, but it added a scheduler port, a PC override and dispatcher logic in nine shared stages, and widened INST_ARGS_BITS in every configuration. This change costs +39.7% on amoadd (rtlsim) and 0.0% off atomics, with no shared-stage change. The precise F5 cost about the same (+38.0% amoadd, rtlsim).
  4. The cost to every configuration. None: with EXT_A off, core is identical in Beacon (U55C and ASIC). With A on: U55C core −47 LUT, +3 FF, no path deeper; ASIC −487 cells, +3 FF, 30 → 30 stages.
  5. Knob-off identity. Beacon core with A off equals master on both flows (table above). With A off the RTL adds no logic (every hunk is under VX_CFG_EXT_A_ENABLE or folds to a constant), and SimX runs no new code; non-atomic cycles are unchanged (sgemm 0.00% on both simulators).
  6. Approval. The maintainer chose this form (P) over D and the imprecise F5 on 2026-12-01.

Changes to master code

All atomic behaviour needs EXT_A, which is off by default.

  • hw/rtl/VX_gpu_pkg.sv (1 hunk): INST_BR_AMOCHK, INST_BR_LRCHK on the spare branch codes 0001 and 0011.
  • hw/rtl/VX_trace_pkg.sv (1): their trace names.
  • hw/rtl/core/VX_decode.sv (1, under EXT_A): an atomic is wstall.
  • hw/rtl/core/VX_uop_sequencer.sv (1, under EXT_A): every atomic goes through VX_uop_amo, which now owns the DCACHE_SHARED_LLC fence rule.
  • hw/rtl/core/VX_uop_amo.sv (2): the check uop.
  • hw/rtl/core/VX_alu_int.sv (4): the check, under EXT_A; with A off chk_trap_r is a constant 0.
  • hw/rtl/core/VX_lsu_block.sv (7): the fault, under EXT_A; the bypass, hold and header mask fold away with A off (req_fault = 0).
  • SimX: types.h (2), decode.cpp (2), sequencer.cpp (1: a wstall uop takes its macro's fetch release; no existing uop is wstall), alu_unit.{h,cpp} (2, 5), lsu_unit.{h,cpp} (3, 6).
  • Tests: tests/regression/amo (common.h, kernel.cpp, testcases.h: the new amo_misaligned case), ci/testcases/isa/amo.yaml (2 cases, touches).
  • Docs: atomic_memory_operations.md, lsu_pipeline_design.md, trap_and_exception_foundation.md.

Verification

check commit result
lint / change_impact / synth_gate_ref / boundaries b20ad6b09 (RTL = fe58030) lint 1033 OK; change_impact 140 passed / 1 skipped; synth_gate_ref 6 passed; sw↔sim, simx-mt, config boundaries OK
amo_misaligned x32, default shape fe58030 simx 4734 / rtlsim 4623 cycles (+2.4%), instrs 1652 = 1652: PASS
amo_misaligned x32, 8 threads / SIMD 4 / ALU and LSU lanes 2 fe58030 simx 8298 / rtlsim 7894: PASS
amo list x32 (19 tests incl. amo_misaligned) fe58030 rtlsim 19/19 PASS
amo list and amo_misaligned x64 fe58030 tree simx 19/19, base 17/17, rtlsim 19/19; amo_misaligned simx 4923 / rtlsim 4790 (meas/pb64_s2, pb64_r)
amo.yaml cells (isa category, -k amo) fe58030 tree rtlsim x32 11/11, simx x32 11/11 PASS (cells/b_isa_r32, b_isa_s32)
cost vs master + test text, simx + rtlsim fe58030 table above
Beacon core / core A off / lmem, U55C + ASIC b20ad6b09 (RTL = fe58030) table above, all PASS

Default-behaviour impact

None. Every change needs EXT_A; with A off Beacon core equals master and sgemm's cycles are unchanged.

Known gaps (not fixed here)

🤖 Generated with Claude Code

tinebp added a commit that referenced this pull request Dec 3, 2026
…#560)

Bug fixes to master found while integrating the Vulkan graphics stack. Each
fix carries its trigger test.

- F10 common: util.h's __assert macro is VX_ASSERT, so EL9 (glibc 2.34) debug
  builds compile again; the uses #574 added are renamed too.
- F3 trap_order: master orders a trap entry behind an earlier mcause write
  since #574 (the same XREG_2 slot); this adds the trigger test,
  tests/regression/trap_order and the trap-simd CI case.
- F1 core: a workgroup barrier also drains the warp's memory requests,
  including those waiting at the local memory's block inputs (two LSU blocks
  at >= 32 warps let a peer read the old value). RTL: lsu_store_empty reaches
  VX_wctl_unit through VX_warp_ctl_if. SimX: the SFU gates BAR on the warp's
  pending level and the LSU's drained level (the ports #574 added) and on
  Core::mem_req_drained (switch wires, coalescer or lane adapter, local-memory
  inputs, MMU). A barrier arrival stalls its warp until it executes. Tests:
  bar_vis (bar-vis, -shared, -bank, -lmem-input(-timed),
  model_parity-bar-vis).
- F2 lsu, simx: a fence goes out on every lane and holds the block's input
  until answered. Tests: fence_mp cases, vm-release.
- F6 amo: compare-and-swap counters from a nonzero base, global and local
  memory (cas_counter, cas_counter_lmem); drops the stale note that the RTL has
  no local-memory AMO path.
- F7 simx/cache: LLC and passthrough atomics are timed as VX_cache_amo does
  (parity-amo-contended(-l2), parity-amo-scatter).
- F8 cache: a write-back bank admits against an exact bound of the writebacks
  it can still owe (#557 follow-ups): sgemv-nt16 back from #557's +2.3%, and
  the range assert no longer fires on a 4-core write-back L2 with two sectors
  per line (cache:wb_drain-l2-1).

The misaligned-atomic trap (F5) is not here: #569 replaces it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…d of touching memory

An atomic (AMO, LR, SC, compare-and-swap) whose active lane names an address
not aligned to its size now raises the RISC-V address-misaligned exception:
store/AMO address misaligned (6), load address misaligned (4) for LR, mepc
the atomic, mtval read-only zero. On master the RTL asserts in simulation (on
hardware it writes through a misaligned word) and SimX aborts.

The trap is precise: no instruction after the atomic runs before the handler,
and the handler may return to mepc + 4. It uses the pipeline's extension
points only; no shared stage changes (coding guidelines §13).
- Decode marks every atomic wstall (EXT_A only), as it does a branch.
- The uop sequencer (VX_uop_amo) puts an alignment check ahead of every
  atomic: check [release fence] atomic [acquire fence]. The check is an ALU
  branch-port uop on rs1 (INST_BR_AMOCHK, INST_BR_LRCHK, two spare branch
  codes) that targets PC + 4 and reads the trap pseudo-register, as ECALL
  does, so an older mtvec write has landed when it traps.
- VX_alu_int (EXT_A only) raises is_trap with cause 6 or 4 and dest = the
  atomic's PC when an active lane is misaligned. The check's SIMD slices and
  packets reach a block back to back, so one flop holds a misaligned lane of
  an earlier one until the last. The branch port's existing trap path writes
  mepc, mcause and mstatus and redirects the stalled warp; its br_hit
  releases the warp's fetch.
- VX_lsu_block (EXT_A only) decides the same from rs1 on its own: from the
  packet holding the first misaligned lane on, the atomic's packets retire
  through the no-response path writing nothing (as a fence's skipped packets
  do); packets ahead of it have gone to memory. A faulted end-of-instruction
  packet waits for those packets' responses (fault_hold), so the next packet
  does not start in a slot still counting them.
- SimX in lockstep: decode marks the atomic macro wstall; LsuUopGen emits the
  check (BrType::AMOCHK) as uop 0; the sequencer gives a wstall uop its
  macro's fetch release; AluUnit holds a misaligned lane per block and calls
  Scheduler::raise_trap; LsuUnit drops the atomic from the faulted packet on
  and holds behind a partly faulted one.
- No VX_types change (the causes are local literals, as the ALU's other
  trap causes), so the resolved config and every perf golden are unchanged.

Cost: the atomic stalls its warp's fetch until the check resolves, as a
branch does. x32 cycles, control = master 3fb83fd with this commit's amo
test text, so only the hardware and model differ:

  case               simx                      rtlsim
  amoadd              5875 ->  8211 (+39.8%)    5888 ->  8224 (+39.7%)
  contended           7505 ->  8721 (+16.2%)    7522 ->  8738 (+16.2%)
  contended-l2       37487 -> 33539 (-10.5%)   37491 -> 37641  (+0.4%)
  zacas-simd         20239 -> 22129  (+9.3%)   21523 -> 21337  (-0.9%)
  amo list w/o trap  58579 -> 61244  (+4.5%)   62238 -> 66286  (+6.5%)
  sgemm             113803 -> 113803  (0.0%)   113814 -> 113814  (0.0%)

With EXT_A off (the default) nothing changes: Beacon (v3.0.3) core and
lmem with A off are identical to master on U55C (LUT 120383, FF 137138,
15 levels) and ASIC (723387 cells, 94018 FF, 30 stages). With A on: U55C
core LUT 127131 -> 127084, FF 140274 -> 140277, 15 -> 15 levels; ASIC core
745720 -> 745233 cells, FF 95842 -> 95845, 30 -> 30 stages.

Trigger test: tests/regression/amo amo_misaligned (amoadd.w, lr.w, sc.w,
amocas.w at misaligned addresses; lane 1 alone misaligned; a misaligned lane
opening the second LSU packet and the second SIMD slice; an aligned atomic),
checking mcause, mepc ^ mtval, rd, every word of memory, and that the
instruction after the atomic runs exactly once, after the handler. CI cases
parity-amo-misaligned and misaligned-simd-packets (8 threads, SIMD 4, ALU and
LSU lanes 2); the base, zacas, wb, threads8 and mc amo cases run it too. On
master the RTL asserts "misaligned memory access" and SimX aborts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tinebp
tinebp force-pushed the fix/amo-misaligned-trap branch from fe58030 to 8944ea8 Compare December 3, 2026 11:21
@tinebp
tinebp merged commit 923d4e2 into master Dec 3, 2026
1 of 10 checks passed
@tinebp
tinebp deleted the fix/amo-misaligned-trap branch December 3, 2026 11:21
tinebp added a commit that referenced this pull request Dec 3, 2026
…hain v3.0.4

Toolchain v3.0.4 (#566) moved the Beacon version and some instruction
counts, so every golden is re-recorded on the final tree of the #560..#569
merge series, by the gates' own --update-baseline(s):

- logic_gate U55C (16 entries) and beacon_asic (14): no build deeper or
  slower than its previous golden; LUT flat except raster +1%.
- perf_gate (51 x32 entries): geomean +0.52% cycles.
  - dxa/wgmma (accepted): wgmma-dxa-mcast-nt4 +6.7%, copy-nt16/-nt4 +3.6%
    (+8 instructions), wgmma-dxa-mcast-nt16 +2.0%, wgmma-sparse +1.5%,
    the rest of dxa and wgmma under +1%.
  - core:sgemm2-wide +4.74% (313459 -> 328310, instructions equal): from #560,
    whose barrier and fence now drain the warp's memory requests (a
    correctness fix). rtlsim before #560 313459, after 328310; SimX moves
    the same way (312426 -> 324923). Later merges leave it unchanged (#569:
    328310; #568 equal on SimX).
  - sgemmx +0.4%, sgemm2-fp16 +0.3%, softmax -0.2% (-6,144 instructions);
    all other entries within +/-0.1%.

Not re-recorded (skipped for time): fpga_gate, asic_gate, and the opt-in
gpu logic_gate entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tinebp added a commit that referenced this pull request Dec 3, 2026
…E_ENABLE at FLEN 64) (#568)

VX_CFG_EXT_LDST_WIDE_ENABLE required FLEN 32, where vx_flw.d/.q are macro-ops
of 2 or 4 flw uops. With 64-bit FP registers a vx_flw.d/.q is now one LSU
instruction, as NVIDIA's LDS.128 and AMD's DS_READ_B128 are: each lane reads
its 8 or 16 bytes in one memory access and one writeback writes the 2 or 4
registers, each word NaN-boxed in its own register. The address must be
naturally aligned (8 / 16 B). vx_fsw.d/.q stay fsw uops.

- RTL: decode carries the group size; the scoreboard reserves the aligned
  group; LSU lanes are 16 B with one addressed word in the low half; the LMEM
  engine reads whole lanes for a quad; VX_lsu_dcache_narrow (new) sends a quad
  to the D-cache in two half-lane passes; result/commit/writeback carry the
  upper 64 bits.
- SimX: the same model (IntrLsuArgs::wide, group scoreboard, one writeback,
  local memory serving a quad lane's two banks in one pass, two half-lane
  coalescer passes).
- Everything is under the derived LSU_WIDE_ENABLE (the extension on at
  FLEN 64); every other configuration elaborates master's logic.
- Profiles: on in the NVIDIA and AMD root profiles (derived ones inherit);
  tinygpu unchanged. a100, one core, SimX: sgemm -n64 -18.4%, sgemm2 -n64 -t4
  -24.0% cycles.
- Tests: tests/ldst_wide covers FLEN 64 (NaN-boxing, junk upper halves, end of
  the read-only words); parity-ldst-wide-x64 is a 64-bit model_parity case
  (testcase.py lets a model_parity case name its own xlen).

Rebased onto master after #565, #566 and #569: the LSU alignment assertion
keeps #569's fault exemption on both the wide and the normal path. On the
final tree: parity-ldst-wide-x64 instructions equal, cycle gap 0.01%.

CI goldens, re-recorded on this tree with toolchain v3.0.4 (#566 moved some
instruction counts and the Beacon version) by the gates' own update flags:
- logic_gate U55C (16 entries) and beacon_asic (14 entries): no build deeper
  or slower than its previous golden; LUT flat except raster +1%.
- perf_gate (51 x32 entries): geomean +0.52% cycles; dxa/wgmma up to +6.7%
  (accepted); core:sgemm2-wide +4.74% from #560's barrier/fence memory drain
  (a correctness fix; SimX moves the same way); everything else within
  +/-0.4%.
- parity on the paths where the merged PRs meet (atomics, fences, ldst-wide,
  ldst-matrix, lmem, barriers, traps): 13 of 14 pass. isa:parity-amo-scatter is
  5.52% (> 5%) on master since #569: the RTL uop sequencer spends a start
  cycle on every macro-op, which SimX does not model, and #569 made every
  atomic a macro-op. Fixed separately.
fpga_gate, asic_gate and the gpu logic_gate entries were not re-recorded
(skipped for time).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tinebp added a commit that referenced this pull request Dec 4, 2026
…uop_amo (VX_CFG_EXT_AMO64_ENABLE)

A 32-bit hart with VX_CFG_EXT_AMO64_ENABLE runs the .D read-modify-write
atomics and AMOCAS.D on even-aligned register pairs, the pairing Zacas defines
for amocas.d on RV32. The knob is off by default.

Five registers in and two out exceed one instruction's operand slots, so the
atomic expander VX_uop_amo (SimX LsuUopGen) emits the atomic as
check [release fence] CMP AMO HI [acquire fence]:
- CMP reads rd/rd+1 and stages them in the LSU as the 64-bit comparand;
  reading rd+1 also orders the burst behind an older pending write of rd+1.
- AMO sends one thread per request on the thread's even/odd lane pair. The
  dcache coalescer fuses the pair into one 8-byte atomic; local memory serves
  it in one pass on two banks with a 64-bit read-modify-write; the LLC uses a
  64-bit AMO ALU. Its response retires twice: the old low word into rd, the
  old high word into rd+1.
- HI reserves rd+1 and is dropped at the LSU. rd+1 is released by whichever
  of HI and the last high-word response reaches the LSU last, so the release
  can never come before the reservation, and the response path never waits on
  HI.
- A misaligned pair atomic is trapped by the check uop and dropped by the LSU
  like a word atomic; the LSU keeps one fault bit per staging entry so HI
  retires writing nothing exactly for the packets the AMO dropped.

This is #564 reworked onto master's misaligned-atomic design (#569): #564
expanded pair atomics in VX_uop_packld and detected faults in the dispatcher,
neither of which exists on master any more.

Timing (Beacon against c6deb1c): the default build has no deeper register
(core +279 LUTs for the decode checks). With AMO64 on, core 15 -> 16 levels
and cache 13 -> 16. For that, the LSU picks a pair's operands within its own
lane pair rather than through a NUM_LANES-wide mux, computes the "last
request" flag one request ahead, and sets the high word's address bit instead
of adding 1. The 64-bit AMO ALU builds its sum and compares from two 32-bit
halves; this also applies to RV64's LLC/local-memory AMO ALU, which is
logically unchanged. The 32-bit ALU keeps its form.

Default-build changes:
- Decode on RV32 now raises the illegal-instruction trap for the RV64 LD, LWU
  and SD encodings, FLD/FSD when FLEN is 32, LR.D/SC.D, and odd register
  pairs (new VX_TRAP_CAUSE_ILLEGAL_INSTR; MISA bit 32+17 for AMO64).
- SimX no longer reserves x0 for a uop whose destination is x0, as RTL never
  does. This changes SimX timing for word atomics with rd = x0.
- VX_config.toml/VX_types.toml gain the AMO64 knob, so every perf baseline's
  config_hash moves. The 51 baselines get their new config_hash from
  perf_baseline.config_hash (the same function reproduces master's hashes on
  a master build); cycles and instruction counts are unchanged, and the PR's
  rtlsim perf_gate cells check them exactly.

Tests: tests/regression/amo gains the amo64_* cases (arith, bits, CAS, WAR on
rd+1, store-then-atomic order, x0 pairs, local memory streams, illegal
encodings, misaligned pairs across packets, slices and warps); ci/testcases
adds the amo64 SimX/RTL legs and parity-amo64, -lmem and -misaligned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tinebp added a commit that referenced this pull request Dec 4, 2026
…uop_amo (VX_CFG_EXT_AMO64_ENABLE) (#564)

A 32-bit hart with VX_CFG_EXT_AMO64_ENABLE runs the .D read-modify-write
atomics and AMOCAS.D on even-aligned register pairs, the pairing Zacas defines
for amocas.d on RV32. The knob is off by default.

Five registers in and two out exceed one instruction's operand slots, so the
atomic expander VX_uop_amo (SimX LsuUopGen) emits the atomic as
check [release fence] CMP AMO HI [acquire fence]:
- CMP reads rd/rd+1 and stages them in the LSU as the 64-bit comparand;
  reading rd+1 also orders the burst behind an older pending write of rd+1.
- AMO sends one thread per request on the thread's even/odd lane pair. The
  dcache coalescer fuses the pair into one 8-byte atomic; local memory serves
  it in one pass on two banks with a 64-bit read-modify-write; the LLC uses a
  64-bit AMO ALU. Its response retires twice: the old low word into rd, the
  old high word into rd+1.
- HI reserves rd+1 and is dropped at the LSU. rd+1 is released by whichever
  of HI and the last high-word response reaches the LSU last, so the release
  can never come before the reservation, and the response path never waits on
  HI.
- A misaligned pair atomic is trapped by the check uop and dropped by the LSU
  like a word atomic; the LSU keeps one fault bit per staging entry so HI
  retires writing nothing exactly for the packets the AMO dropped.

This is #564 reworked onto master's misaligned-atomic design (#569): #564
expanded pair atomics in VX_uop_packld and detected faults in the dispatcher,
neither of which exists on master any more.

Timing (Beacon against c6deb1c): the default build has no deeper register
(core +279 LUTs for the decode checks). With AMO64 on, core 15 -> 16 levels
and cache 13 -> 16. For that, the LSU picks a pair's operands within its own
lane pair rather than through a NUM_LANES-wide mux, computes the "last
request" flag one request ahead, and sets the high word's address bit instead
of adding 1. The 64-bit AMO ALU builds its sum and compares from two 32-bit
halves; this also applies to RV64's LLC/local-memory AMO ALU, which is
logically unchanged. The 32-bit ALU keeps its form.

Default-build changes:
- Decode on RV32 now raises the illegal-instruction trap for the RV64 LD, LWU
  and SD encodings, FLD/FSD when FLEN is 32, LR.D/SC.D, and odd register
  pairs (new VX_TRAP_CAUSE_ILLEGAL_INSTR; MISA bit 32+17 for AMO64).
- SimX no longer reserves x0 for a uop whose destination is x0, as RTL never
  does. This changes SimX timing for word atomics with rd = x0.
- VX_config.toml/VX_types.toml gain the AMO64 knob, so every perf baseline's
  config_hash moves. The 51 baselines get their new config_hash from
  perf_baseline.config_hash (the same function reproduces master's hashes on
  a master build); cycles and instruction counts are unchanged, and the PR's
  rtlsim perf_gate cells check them exactly.

Tests: tests/regression/amo gains the amo64_* cases (arith, bits, CAS, WAR on
rd+1, store-then-atomic order, x0 pairs, local memory streams, illegal
encodings, misaligned pairs across packets, slices and warps); ci/testcases
adds the amo64 SimX/RTL legs and parity-amo64, -lmem and -misaligned.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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