Repository navigation
RISC-V: the generated crate's instructions as bytes, not one directive each - #5099
Merged
Merged
Conversation
…e each The emitter writes each run of encoded instructions of x86 and PPC64LE as one `.base64` line (`Rust.packRun`), and joins AArch64's `.inst` words eight to a line. RISC-V's `.insn` lines were neither: its crate was 919,461 directives, one an instruction, 24.8 MB of Rust for rustc to lex and expand and for the assembler to parse. `Rust.insnLine?` reads a `.insn 4, 0x…` or `.insn 2, 0x…` line's bytes (little-endian parcels), so `packRun` packs RISC-V's runs too. Branches, jumps, calls and `lla` stay text, as before. The test binaries' `.text` and `.rodata` are byte for byte what they were (riscv64gc-unknown-linux-gnu, GNU ld). The crate's source is 12.1 MB, and compiling it takes 0.46 s rather than 0.83 s on x86-64; on the RISC-V runner it took 12 s of CPU and 9 s, of which every other crate of the test build waits for the first 6. Trust: a change to the printer (`TCB/Rust.lean`), which no proof imports. The object's mapping symbols now mark the packed runs as data (`$d`) where `.insn` marked instructions (`$x`), so a disassembler of a riscv64 object prints them as words; their text is in `assembly/`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFazY8ZqFFZT1uMZF5
alex
pushed a commit
that referenced
this pull request
Nov 15, 2026
The RISC-V crate's generated vg_rsa_keygen_candidate.rs conflicted after #5099, which prints each straight-line instruction as bytes: it takes main's side, and the crate is regenerated with the full emitter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
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.
The emitter writes each run of encoded instructions of x86 and PPC64LE as one
.base64line (Rust.packRun), and joins AArch64's.instwords eight to a line. RISC-V's.insnlines were neither packed nor joined:crates/verified-garbage-asm-riscv64/srcwas 919,461 directives, one per instruction, 24.8 MB of Rust for rustc to lex and expand and for the assembler to parse.Rust.insnLine?reads the bytes of a.insn 4, 0x…or.insn 2, 0x…line (little-endian parcels), sopackRunpacks RISC-V's runs as it does the others'. Branches, jumps, calls andllastay text, as before.Trust change (
TCB/Rust.lean)This changes the printer, which no proof imports (only
TCB/Emit.leanand the tests do), and regenerates the riscv64 crate with it. What it emits is the same machine code:.textand.rodataof all three test binaries (lib,tests,cavp), built forriscv64gc-unknown-linux-gnuand linked with GNU ld, are byte for byte whatmain's are.lake env lean --run Emit.lean --checkpasses, and only the riscv64 crate'ssrc/changed (381 files);assembly/is untouched.One visible difference: the object's mapping symbols (RISC-V ELF psABI, "Mapping Symbol") now mark the packed runs as data (
$d) where.insnmarked them as instructions ($x). A disassembler of a riscv64 object therefore prints those runs as words rather than mnemonics; their text is inassembly/, as for every target. This is the reason AArch64 keeps.inst, so it is a judgment call here: say so if you would rather keep the marking and I will close this.What it saves
Measured on an x86-64 host, cross-compiling for riscv64 with CI's flags:
On the RISC-V runner, before this change, the crate takes 12 s of CPU and 9 s of wall time: expansion 2.3 s, codegen 2.2 s, assembling 2.7 s (measurement run,
time-passes). The rest of the test build waits only for the crate's metadata, so of this only the expansion is on the build's critical path: by the ratios above, expect about 1.5 s off the 81 s build and about 5 s less CPU.Not measured on the runner. This PR's own
Rust (Linux, RISC-V, host)job cannot show it: it ran on a slower runner than the baseline's (the tests, whose machine code is identical, took 35 s, 7.4 s and 87 s against 32 s, 5.5 s and 64 s), and a 1.5 s change is below that noise.Checks run locally
Every step of
Static checks,lake build,Emit.lean --check,check_lean_public_imports.pyon the two edited modules,cargo fmt --check, Clippy for riscv64, and the riscv64cavpand RFC tests under qemu-user.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFazY8ZqFFZT1uMZF5