Implement Zama16b misaligned atomicity - #1893
Open
davidharrishmc wants to merge 5 commits into
Open
davidharrishmc wants to merge 5 commits into
davidharrishmc wants to merge 5 commits into
Conversation
Zama16b makes a misaligned load, store or AMO that lies within one naturally aligned 16 byte granule atomic. Misaligned loads and stores already run through the Zicclsm hardware path; this adds the AMO case, which previously took a store/AMO access fault along with the granule crossing ones. The whole implementation is one term in the MMU's misaligned access fault: a misaligned atomic to cacheable memory no longer faults when it stays inside its granule. CrossesGranuleM comes out of the decoder that already computes DataMisalignedM, so it costs a few gates beside the existing check and nothing on the address path, and it folds away in configs without the extension. riscvassertions_wally requires a cache line of at least 128 bits so a granule never spans two lines, and riscvassertions requires Zicclsm, without which the misaligned access has no hardware path. tests/coverage/zama16b.S checks both halves: a doubleword AMO at offset 4 completes and updates memory, while one at offset 12 still faults and is skipped, leaving memory untouched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
align.sv splits an access only when it runs off the end of a cache line, so everything within a line is a single cache access and already atomic. Fault only on the line crossing rather than on a 16 byte granule, which gives a wider guarantee than Zama16b asks for and matches what the LSU actually does. The condition mirrors PotentialSpillM in align.sv. Extend the test with an AMO at offset 12, which crosses a 16 byte boundary inside the line and must now complete, and move the faulting case to offset 60, which runs off the end of a 64 byte line. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The signal declaration and the fault assignment already say it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…hardware Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Zama16b, which makes a misaligned load, store or AMO that lies within one naturally aligned 16-byte granule atomic. RVA23 requires it.
Misaligned loads and stores already run through the Zicclsm hardware path. What was missing was the AMO case:
mmu.svfaulted every misaligned atomic to cacheable memory, on the grounds that atomics are "never handled in hardware".The change
One term in the MMU's misaligned access fault:
CrossesLineMcomes out of the decoder that already computesDataMisalignedM, so it is three gate terms beside an existing check, nothing on the address path, and it folds away entirely when the parameter is 0.Why the granule is the cache line, not 16 bytes
align.svsplits an access into two cache accesses exactly when it runs off the end of a cache line (OFFSET_BIT_POS = $clog2(DCACHE_LINELENINBITS/8),align.sv:61). Anything within a line is one cache access and is therefore already atomic. SoCrossesLineMmirrorsPotentialSpillM, and Wally's atomicity granule is the whole 64-byte line on rv64gc — a superset of the 16 bytes Zama16b guarantees, which the architecture permits.Configuration and assertions
ZAMA16B_SUPPORTEDis added tocvw.sv,parameter-defs.vhand all six configs, set on rv64gc, which is also the only config with Zicclsm.riscvassertions_wally.sv: the cache line must be at least 128 bits, so a line always covers the 16 bytes the extension guarantees.riscvassertions.sv: Zama16b requires Zicclsm, without which there is no hardware path for the misaligned access and the parameter would silently do nothing.Testing
tests/coverage/zama16b.S(usingWALLY-selfcheck.h) checks all three cases on a 64-byte-aligned buffer: a doubleword AMO at offset 4 completes and updates memory; one at offset 12, which crosses a 16-byte boundary but stays in the line, also completes; one at offset 60 runs off the line and still takes a store/AMO access fault, which the handler skips, leaving memory untouched.ZAMA16B_SUPPORTEDtests/coverage/zama16b.SZama16bsuite on cvw-rv64gcAlso Verilator lint clean on all six configs, and
arch64a_amo,arch64d,arch64i,arch32a_amounchanged.Companion ACT change needed.
config/cores/cvw/cvw-rv64gccurrently declares"Zama16b": {"supported": false}, so the suite does not run against Wally in CI. Enabling it also requiresmisaligned_atomicity_granule_size_expon the 0x80000000 main memory region to move from 0 to 6 (the 64-byte line), or Sail rejects the config. I ran the suite above with those two edits applied locally; they should land as a riscv-arch-test PR alongside this one.🤖 Generated with Claude Code