From d3eb8c9e31b5c13dfc01780c6dcc423162372c73 Mon Sep 17 00:00:00 2001 From: diegokingston Date: Fri, 24 Jul 2026 17:06:37 -0300 Subject: [PATCH] perf(target): enable unaligned-scalar-mem for riscv64im guests 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. --- executor/programs/riscv64im-lambda-vm-elf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/programs/riscv64im-lambda-vm-elf.json b/executor/programs/riscv64im-lambda-vm-elf.json index 994abbb35..4b10e33d0 100644 --- a/executor/programs/riscv64im-lambda-vm-elf.json +++ b/executor/programs/riscv64im-lambda-vm-elf.json @@ -5,7 +5,7 @@ "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", "eh-frame-header": false, "emit-debug-gdb-scripts": false, - "features": "+m", + "features": "+m,+unaligned-scalar-mem", "linker": "rust-lld", "linker-flavor": "gnu-lld", "llvm-abiname": "lp64",