Skip to content

core: 64-bit atomics on a 32-bit hart (AMO64, register pairs) - #564

Merged
tinebp merged 1 commit into
masterfrom
feat/amo64
Dec 4, 2026
Merged

tinebp merged 1 commit into
masterfrom
feat/amo64

Conversation

@tinebp

@tinebp tinebp commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Base: fix/master-bugfixes (#560). Head: 6942507 (2 commits: the feature and a baseline re-stamp).

Rebased 2026-12-01 onto fix/master-bugfixes 2dafca1 (master cba70a4). The tree equals the tested tree plus only master's pipeline-isolation rules commit and #560's comment-only commit, so every result below carries over.
Depends on: fix/master-bugfixes. A misaligned pair atomic traps through F5's trap path; its HI uop follows the atomic slice by slice.
Related: test/vulkan-atomic64 holds the Vulkan int64-atomic tests. They need this PR and feat/vulkan-graphics; merge them after both.

With VX_CFG_EXT_AMO64_ENABLE (off by default; requires A and XLEN 32), a 32-bit hart runs the .D read-modify-write atomics and AMOCAS.D on even-aligned register pairs. This is the pairing Zacas defines for amocas.d on RV32, and it lets Vulkan offer VK_KHR_shader_atomic_int64.

  • Uop sequencer. It splits a pair atomic into CMP, AMO and HI uops under the slot's issue lock (VX_uop_packld; SimX LsuUopGen). With .aq/.rl the burst carries its own fences, so VX_uop_amo leaves a pair atomic alone.
  • Memory side.
    • The LSU issues one thread per request on its even/odd lane pair, and the dcache coalescer fuses the pair into one 8-byte atomic.
    • The local memory serves it in one pass on two banks with a registered 64-bit read-modify-write.
    • The LLC computes 64-bit.
  • Decode. It refuses what a 32-bit hart cannot run (LR.D/SC.D, odd pairs, RV64 loads/stores, .D without AMO64) with the illegal-instruction trap.
  • ISA bit. VX_ISA_EXT_AMO64 (misa ext bit 32+17) reports the extension.

Tests: tests/regression/amo amo64_* with the amo64* and parity-amo64* CI cases.

Default behaviour: none. The pair paths are behind EXT_AMO64; with it off, instructions and cycles are unchanged.

Verification

Results name the commit they ran on. The tested trees differ from the final ones only by fix/master-bugfixes' own rebase onto master 7470f62: the tree delta from ce24c6f9c to 02ea9a6 (the feature commit) is byte-identical to fix/master-bugfixes' delta 22198fdea → 4bdefdb (normalized-patch md5 68e275b1).

check commit result
isa amo64 cases, simx x32 ce24c6f9c 6/6 PASS
isa amo64 cases, rtlsim x32 ce24c6f9c 6/6 PASS
model_parity amo64 (parity-amo64*) x32 ce24c6f9c 3/3 PASS
amo64-simd (32 warps / SIMD 4 / 8 threads, full list incl. misaligned pairs) simx + rtlsim ce24c6f9c tree PASS
perf_gate shards 1+2 (default config, EXT_AMO64 off) amo64 on fix/master-bugfixes 18/18 entries = fix/master-bugfixes' values (instrs and cycles)
tip build x32 (sw, simx, rtlsim, xrtsim) + lint b569f64 tree PASS, 0 warnings; lint 1074 OK, change_impact 133 passed / 1 skipped, synth_gate_ref 6, boundaries OK

Baselines

Commit b569f64, data only: perf_gate only. AMO64 adds VX_types/VX_config entries, so the resolved config_hash changes (core:vecadd-nt4 8843ab5c). With EXT_AMO64 off nothing simulated changes, so each entry keeps fix/master-bugfixes' cycles and instructions and gets the new hash. Shards 1 and 2 of a full re-record (18 entries) reproduced fix/master-bugfixes' values exactly.

No logic_gate change: no Beacon re-run (user order: Beacon only for failing entries; AMO64 is off in every gate DUT).

Merge notes

feat/vulkan-graphics also adds VX_ISA_EXT_AMO64 to sw/runtime/include/vortex2.h, next to its VX_ISA_EXT_ZACAS. When the second of the two lands, keep one definition.

CI on this PR inherits master's red jobs from run 46477391253 until fix/master-bugfixes merges; rebase after it lands.

🤖 Generated with Claude Code

@tinebp tinebp left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review of #564: core 64-bit atomics on a 32-bit hart (AMO64, register pairs)

Head 6942507, own commits 5fe2504 (AMO64) and 6942507 (baselines). The PR is stacked on an unpushed rebase of #560, so its GitHub diff also shows #560's commits and 2dafca1. Static review: nothing built or run. Rules: master 3fb83fd (incl. coding_guidelines_verilog §13 and the review policy v5). Each recommendation carries a 1-5 rating (5 = must fix) beside the policy F0-F3.

Summary

AMO64 runs .D atomics and AMOCAS.D on even-aligned register pairs on a 32-bit hart, behind VX_CFG_EXT_AMO64_ENABLE (off by default). Most of the design attaches at the right places:

  • the uop sequencer splits a pair atomic into CMP / AMO / HI under the issue lock (extension point 3);
  • decode refuses what a 32-bit hart cannot run (extension point 2);
  • the LSU, the coalescer, the local memory and the LLC carry the 8-byte operation, gated by the knob;
  • SimX moves with it, and three parity-amo64* cases cover it.

Three things need work: the dispatcher part extends #560's F5 fault tracking inside a shared stage; the perf goldens are hand-restamped; and the ungated decode legality change has no Beacon evidence.

R3: pipeline-stage (VX_dispatcher, SimX core), config-knobs, installed-api, isa-decoder, golden-values. Verdict: land after the [5] and [4] changes, and after #560's F5 is settled, since this PR builds on its trap path.

Recommended changes

[5] F2 high static-proof · 6942507 ci/baselines/perf/*.json — 49 config_hashes restamped by hand

What: The commit keeps #560's cycles and instructions and writes this branch's config_hash into all 49 entries. Only 18 were re-recorded (shards 1 and 2). Golden data is never hand-edited (AGENTS.md §4), even when the values are expected to hold.
Alternative: Run pytest ci -m perf_gate --update-baselines for all 49 entries under CI's toolchain. With AMO64 off the diff is hash-only by construction, and the re-record proves that instead of asserting it. Separately, as a follow-up on master, have config_hash skip keys that resolve to their off default. Adding a default-off knob would then stop invalidating every golden.
Why better: It keeps the golden-data rule intact. The follow-up removes the cause, so a no-op knob no longer forces a 49-entry re-record.

[4] F2 high static-proof · hw/rtl/core/VX_dispatcher.sv:57-100 (and SimX Core::amo_check) — pair-atomic fault tracking inside the dispatcher

What: hi_fault_r and fault_sid_r[PER_ISSUE_WARPS][SIMD_IDX_W] make the HI uop follow its atomic's fault, slice by slice, in a shared stage (§13.3.2). This builds on #560's F5 dispatcher logic (#560 review, P1).
Alternative: Let the LSU decide it. The LSU already sees the pair's AMO slices before the HI uop: they are adjacent under the issue lock, and HI "retires with the atomic's response". The LSU block can therefore hold one faulted-pair bit per block and retire the HI slice through the same no-response path req_fault uses. If #560's F5 moves its fault decision into the LSU as recommended there, this falls out for free.
Why better: No per-warp state in the dispatcher, no stage edit to justify under §13.4, and the fault logic lives in one unit.

[3] F2 medium missing-test · hw/rtl/core/VX_decode.sv (ld_ok/st_ok/amo_ok, lsa_illegal) — ungated decode change without Beacon

What: The RV32 legality checks (ld/lwu/sd, FLEN-wide FP loads and stores, funct5 legality) are built in every configuration and feed the illegal flag. The PR skips Beacon because "AMO64 is off in every gate DUT", but this part is not behind AMO64. It also changes the default build's behaviour: an RV32 ld now traps, so it is a fix in its own right.
Alternative: Split the RV32 legality checks into their own commit, a decode correctness fix with its own test, and run Beacon core against the merge base for it, quoting decode's depth.
Why better: It attributes any default-configuration depth change to the right commit (bug_fixes §6.8: problems found on the way are separate changes). The comment says the check was written to stay off the arms' data path; Beacon confirms that in minutes.

[2] F1 medium reasoned-risk · sw/runtime/include/vortex2.h — VX_ISA_EXT_AMO64 (installed API)

What: A new capability bit that vortexpipe (Mesa) reads to offer VK_KHR_shader_atomic_int64.
Alternative: State the landing order in the PR: this PR first, the Mesa change and the prebuilt refresh after (AGENTS.md §2). Or confirm that Mesa only reads the bit when present.
Why better: It meets the installed-api obligation (the consumer builds) explicitly.

Checked, no finding

  • lsu_args_t gains amo_pair in the last padding bit, so INST_ARGS_BITS is unchanged here (it depends on #560 F5's widening). If F5's widening becomes EXT_A-gated, as recommended there, AMO64 (which requires A) is covered.
  • AMO_CMP_BITS widens the comparand only under AMO64, with PACKAGE_ASSERTs on XLEN 32 and A.
  • VX_lmem_bank's new wide_* ports are constant 0 without AMO64, so the default local memory is unchanged by constant propagation, and UNUSED_VAR covers the non-AMO build.
  • The perf_gate shards that were run (18/18) match with AMO64 off.

Not reviewed

VX_lsu_block's pair path (+245) and VX_lmem_unit's 64-bit read-modify-write (+166) line by line; the SimX lsu_unit.cpp pair path beyond its parity coverage.

@tinebp
tinebp force-pushed the fix/master-bugfixes branch from 2dafca1 to 96ded66 Compare December 3, 2026 10:38
Base automatically changed from fix/master-bugfixes to master December 3, 2026 10:39
…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
tinebp merged commit 4763e25 into master Dec 4, 2026
1 of 10 checks passed
@tinebp
tinebp deleted the feat/amo64 branch December 4, 2026 04:53
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