-
-
Notifications
You must be signed in to change notification settings - Fork 161
codegen: affine window hoist + accumulator array axis — matmul 2× faster than node; fixes a live OOB read in the #9294 mixed-array guard #9337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
proggeramlug
merged 1 commit into
PerryTS:main
from
proggeramlug:fix/affine-window-hoist
Sep 1, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| **`16_matrix_multiply` is now twice as fast as node** (100 ms → 16 ms against | ||
| node's 32 on an idle machine; checksums identical) — the last benchmark in | ||
| the suite crosses parity, via two changes and one guard fix. | ||
|
|
||
| **The affine window is proven at the loop's endpoints.** An index tree linear | ||
| in the counter takes its extremes at the interval's ends, so the entry guard | ||
| evaluates each recorded tree at `start` and at `bound − 1` (wrap-free by the | ||
| magnitude bound) and unsigned-compares both against the live length — two | ||
| compares per tree, once per loop entry, for any coefficient sign. Reads under | ||
| a proven window drop both the range clamp and the per-read bounds check, | ||
| leaving a bare `trunc` and raw load. Non-linear trees (`k * k`) keep their | ||
| per-read checks. | ||
|
|
||
| **The accumulator walk takes the guarded array set.** The old single-array | ||
| restriction was why `sum = sum + a[..] * b[..]` never earned its number | ||
| proof: every k-iteration wrote `sum` through a boxed shadow-slot store with a | ||
| barrier, which profiling showed was the actual bottleneck once the guards | ||
| were hoisted — removing the per-read checks alone moved nothing. Every array | ||
| in the set is validated by the same AND-reduced entry guard, so a read of any | ||
| of them inside the clone is a Number by the same argument that held for one; | ||
| affine reads qualify as numeric leaves through the same shared predicate the | ||
| matcher and the lowering use (`affine_leaf_admissible`), so the three cannot | ||
| drift. | ||
|
|
||
| **A guard hole in the #9294 arm is closed.** Its receiver-only `continue` | ||
| also fired for arrays with BOTH counter-offset and affine accesses, skipping | ||
| the windowed guard while the counter fact still said `window_validated: | ||
| true` — `a[k + 1]` alongside `a[i * size + k]` then read one raw slot past | ||
| the loop's window at the boundary. Mixed arrays now fall through to the | ||
| windowed guard, with the affine endpoint proof appended to either path, and | ||
| a test pins the mixed shape to node's NaN under both collector modes. |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Restore the
emit_affine_index_i64re-export.Line 792 calls
emit_affine_index_i64, but this changed import list does not bring that function into scope. The crate will fail to compile.Proposed fix
pub(crate) use foreign_counter::{ - affine_counter_occurrences, affine_index_fits_i64, emit_affine_index_i64_with, + affine_counter_occurrences, affine_index_fits_i64, emit_affine_index_i64, + emit_affine_index_i64_with, packed_f64_loop_index_parts, };📝 Committable suggestion
🤖 Prompt for AI Agents