Repository navigation
perf(sharc): keep aliased-page and decode-watch accesses in the fast tier - #984
Merged
Merged
Conversation
The engine aliases a direct low DM address byte by byte: when the first byte is absent at the address it reads SW_ALIAS_BASE + address. The fast tier's flat access aliased per page only, so every access to the tail of a partly loader-backed page (module state above the loader image end, e.g. 0x2001ab7c..) left the kernel. A store on a decode-watched page also left even when it overlapped no decoded unit. The checks now branch to cold blocks placed after the kernel body, so the hot path adds no operation. The alias block takes the alias page when the raw first byte is absent and the address lies below the alias base, then repeats the bitmap, watch and exact decode-unit tests there. A store on a decode-watched page stays in the kernel unless it overlaps a decoded unit (the same rule as Mem::note_watched_n). The wasm flat-table check knows the decode table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aliased pages Replace the dec_gen/code_gen assertion that could not fail with a whole-effect comparison against the interpreter (bytes, present and dirty bits, overlay, code and decode watch notes). New cases: the cold alias path with a decode watch, code-watched pages natively, odd 2- and 4-byte stores across a decoded unit, and conditional stores through the cold alias block (true and false). Group the alias arguments of flat_alias into a Site, make DEC_WORDS private and name the decode bitmaps in the findings note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m-dwyer
force-pushed
the
perf/sharc-fast-alias-access
branch
from
December 5, 2026 08:04
c2e47fd to
94d86f0
Compare
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.
Problem
The SHARC engine aliases a direct low DM address byte by byte: when the first byte is absent at
an address it reads
SW_ALIAS_BASE + address(0x4801xxxx). The fast tier's flat access aliasedper page only, so every access to page 0x2001 above the loader image end (0x2001ab7c, module
state of loaded modules) left the kernel. The per-page decode-watch guard also left the kernel
on any store to a watched page, even when the store overlapped no decoded unit.
Design
The checks branch to cold blocks placed after the kernel body (
fast/lower/flat_access.rs), sothe hot path adds no operation. The alias block takes the alias page when the raw first byte is
absent and the address is below the alias base, then repeats the bitmap, watch and exact
decode-unit tests there. A store on a decode-watched page stays in the kernel unless it overlaps
a decoded unit (
CTX_FLAT_DEC; the same rule asMem::note_watched_n). The wasm flat-tablecheck (
check_window) knows the decode table.Why it is exact
The cold blocks apply the same address decision, watch test and decode-unit overlap test as the
interpreter's
Mempath, only inside the kernel. A case the blocks do not cover still exits asbefore. The parity columns below are PCM, DSP state and ColdFire state against main at the same
length.
Tests
flat_access_check.mjs(the wasm flat-table check) and the fast-tier unit tests cover the aliaspage and the decode-watch overlap rule. Parity "=" in every measured cell.
Measurement
sharc_cells, A = main, B = branch, each label with its own core, lengths 20 and 24 s, parity"=" everywhere:
The mw-* fixtures predate runtime 0.17 and #969 (heap-only memory).
Not measured on runtime 0.17. The mw-mod key sequence does not engage the modules on fresh
0.17 fixtures (they load, but never run). I tried to drive ASCEND and Pluck without panel keys
through
wb profile calibrate run --emuand it is blocked on 0.17: the node host cannotinstall the module services, so the install deletes
services/fx.dksas unused, Pluck isrefused with
unknown-hashfor the machines service, and ASCEND fails to load with result -48.ASCEND has no
calibration.toml, and its target-test needs a panel-prepared project. So thereare no 0.17 exit counts for sites
mem_addr.rs@287and@330, and no 0.17 A/B. The only countsread on 0.17 come from the stock hold-note case, where each site shows 2 to 3 exits over the
whole run: near zero. Whether today's modules reach the aliased tail is therefore open, and the
gain above applies to the old fixtures. Until it is measured, treat this as an exactness and
robustness fix (accesses to a half-backed page and the decode-watch guard stay in the kernel
and match the interpreter), with a gain for code that keeps state there.
Stock cost: +0.05% (1.0005 on both stock cells), accepted. Probable cause: the new cold
blocks sit after the kernel body, which shifts code layout and slightly enlarges each kernel;
no operation is added to the hot path.
Review follow-up tests
Each compares the kernel store (plus the interpreter store as fallback after an exit) with the
interpreter alone on memory, present/dirty bits, overlay (undo log
touched) and code/decodewatch notes, on the interpreter and native backends (
sharc/src/fast/lower/mod.rs):flat_store_on_a_decode_watched_page_leaves_only_on_a_decoded_unit: replaces thedec_gen/code_genassertion that could not fail; adds odd 2- and 4-byte stores that cross adecoded unit (the
u0,u0+1,u1selection,flat_access.rs).flat_store_through_the_alias_tail_on_a_decode_watched_page: cold alias path thenflat_watched_store, same cases through the 0x2001 alias tail.flat_store_on_a_code_watched_page_always_leaves: WATCH_CODE natively, plain and alias tail,inside and outside the span, and with a decode watch on the page too.
flat_access_follows_the_alias_of_a_partly_backed_page: now also checks present/dirty bits andthe overlay, and runs a conditional store through
Miss::Coldwith the condition true and false.All 9
flat_tests pass. Nits:flat_aliastakes aSitestruct (no clippy allow),DEC_WORDSis private, findings line 1436 now lists three bases.
Wide accesses. 40/48-bit and long-word accesses never reach the flat path:
Width::from_fieldsreturns None for them (
mem_addr.rs:46-53) and the 3a/3b/3d/4b forms refuse(
mem_addr.rs:323,345,371,mem_imm.rs:85-87). Only widths 1, 2 and 4 callflat_access(
mem_addr.rs:150,mod.rs:1430,1436); callret uses 4.Gate
mise run test:changed: unit and static tasks passed (33 tasks); rig preflight: 19 halves,0 problems.
test-device--dn2,smoke,pinsonemulator-sharc-tests,gate-smoke,gate-pins): 87 ok, 0 failed, 3114 s.emulator-reply-tests:test-device--dt2)and the smoke set;
test:allis left for the merge queue.🤖 Generated with Claude Code
Gate
mise run test:all: pass (exit 0).