perf(target): enable unaligned-scalar-mem for riscv64im guests#864
Open
diegokingston wants to merge 2 commits into
Open
perf(target): enable unaligned-scalar-mem for riscv64im guests#864diegokingston wants to merge 2 commits into
diegokingston wants to merge 2 commits into
Conversation
Add +unaligned-scalar-mem to the riscv64im-lambda-vm-elf target spec so
LLVM lowers potentially-unaligned u64 accesses (align-1 loads/stores, e.g.
u64::from_le_bytes on byte buffers, ptr::read_unaligned) to single ld/sd
instructions instead of byte-assembled lbu/slli/or and sb/srli chains.
Sound on this target: the VM tolerates unaligned doubleword accesses --
executor/src/vm/memory.rs load_doubleword/store_doubleword byte-assemble
them host-side at the same 1-instruction cost as aligned accesses.
Verified:
- Minimal no_std PoC (absorb-like *lane ^= u64::from_le_bytes(buf),
read_unaligned, write_unaligned): baseline emits 8x lbu + slli/or
chains (load) and 8x sb + srli chains (store); with the feature both
lower to a single ld / sd.
- executor/programs/rust/keccak guest rebuilt with the patched spec:
lbu 70 -> 50, sb 112 -> 104, slli/or reduced, widened to lh/lhu/lw.
- cargo test -p executor --test rust test_keccak passes with the
patched ELF (VM commits keccak256("hello world!") matching host
tiny-keccak); CLI execute succeeds with identical cycle count (7468)
vs baseline.
CI note: the ELF artifact cache keys in .github/workflows/pr_main.yaml
hash executor/programs/riscv64im-lambda-vm-elf.json, so cached guest
ELFs invalidate naturally on this change.
Collaborator
Author
|
/bench |
Collaborator
Author
|
/bench |
Benchmark — ethrex 20 transfers (median of 3)Table parallelism: auto (cores / 3)
Commit: c4e42b2 · Baseline: cached · Runner: self-hosted bench |
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.
Summary
Adds
+unaligned-scalar-memto theriscv64im-lambda-vm-elftarget spec. This lets LLVM lower potentially-unaligned u64 accesses (align-1 loads/stores, e.g.u64::from_le_byteson byte buffers in the keccak absorb path,ptr::read_unaligned) to singleld/sdinstructions instead of byte-assembledlbu/slli/orandsb/srlichains.Sound on this target: the VM tolerates unaligned doubleword accesses —
executor/src/vm/memory.rsload_doubleword/store_doublewordbyte-assemble them host-side at the same 1-instruction cost as aligned ones.Measured guest cycles (
cli execute --cycles, deterministic)The % shrinks with tx count as keccak/hashing becomes a smaller share of total cycles.
Verification
lbu+slli/orper lane to oneldper lane (disassembly of the built ethrex guest, before/after in commit body).*lane ^= u64::from_le_bytes(buf),read_unaligned,write_unaligned): baseline emits byte chains, patched emits singleld/sd.cargo test -p executor --test rust test_keccakpasses with a patched guest ELF; keccak guest cycle count unchanged (aligned workload)..github/workflows/pr_main.yamlhash the target JSON, so cached guest ELFs invalidate naturally.