Skip to content

perf(sharc): keep aliased-page and decode-watch accesses in the fast tier - #984

Merged
m-dwyer merged 2 commits into
mainfrom
perf/sharc-fast-alias-access
Dec 5, 2026
Merged

m-dwyer merged 2 commits into
mainfrom
perf/sharc-fast-alias-access

Conversation

@m-dwyer

@m-dwyer m-dwyer commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

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 aliased
per 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), so
the 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 as Mem::note_watched_n). The wasm flat-table
check (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 Mem path, only inside the kernel. A case the blocks do not cover still exits as
before. 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 alias
page 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:

cell (fixture) B/A host insns
DN2 trig1-hold (stock) 1.0005
DT2 dt2-sample-trig (stock) 1.0005
mw-d, ASCEND 0.7716
mw-b, Pluck x4 0.9323
mw-bc 0.9440
mw-e 0.9916

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 --emu and it is blocked on 0.17: the node host cannot
install the module services, so the install deletes services/fx.dks as unused, Pluck is
refused with unknown-hash for 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 there
are no 0.17 exit counts for sites mem_addr.rs@287 and @330, and no 0.17 A/B. The only counts
read 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/decode
watch 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 the
    dec_gen/code_gen assertion that could not fail; adds odd 2- and 4-byte stores that cross a
    decoded unit (the u0, u0+1, u1 selection, flat_access.rs).
  • flat_store_through_the_alias_tail_on_a_decode_watched_page: cold alias path then
    flat_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 and
    the overlay, and runs a conditional store through Miss::Cold with the condition true and false.

All 9 flat_ tests pass. Nits: flat_alias takes a Site struct (no clippy allow), DEC_WORDS
is private, findings line 1436 now lists three bases.

Wide accesses. 40/48-bit and long-word accesses never reach the flat path: Width::from_fields
returns 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 call flat_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.
  • Device proof, as printed (test-device--dn2, smoke, pins on emulator-sharc-tests,
    gate-smoke, gate-pins): 87 ok, 0 failed, 3114 s.
  • At merge the gate also runs one other-device half (emulator-reply-tests:test-device--dt2)
    and the smoke set; test:all is left for the merge queue.

🤖 Generated with Claude Code

Gate

mise run test:all: pass (exit 0).

  • selected: emulator-sharc-tests sharc-semantics.device.test.ts: test-device--dn2; emulator-reply-tests reply-inflight.device.test.ts: test-device--dt2; gate-device-smoke: device (17 halves); conformance: none selected
  • skipped: test:subset left to the full tier: 217 device halves and conformance tasks of 49 projects (core/digikit-menu-memory-tests 2, core/digikit-menu 2, core/dynfx 2, core/fx 1, core/input 2, core/introblank 2, core/plusdrive-write 4, core/runtime-boot-tests 9, ... 37 more projects)

m-dwyer and others added 2 commits December 5, 2026 17:20
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
m-dwyer force-pushed the perf/sharc-fast-alias-access branch from c2e47fd to 94d86f0 Compare December 5, 2026 08:04
@m-dwyer
m-dwyer merged commit 8faa8fc into main Dec 5, 2026
2 checks passed
@m-dwyer
m-dwyer deleted the perf/sharc-fast-alias-access branch December 5, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant