Repository navigation
Conversation
Qard
force-pushed
the
perf/loop-constants
branch
from
November 24, 2026 01:08
bcd2ae1 to
79f2775
Compare
Exact integer constants held as int64 are no longer written to their home where they are defined. A use with an immediate form reads the value instead: - int64 addition and subtraction of a 12-bit magnitude, optionally shifted by 12 (negative addends flip ADD and SUB); - int64 multiplication by 2^k (LSL) or 2^k + 1 (ADD, shifted); - int64 comparisons against such a magnitude on the right (CMN for negative constants); - 32-bit `&`, `|` and `^` with a logical immediate (new AND, ORR, EOR and ANDS immediate encodings), or the identities `| 0`, `^ 0` and `& -1` as a W move; - Math.imul by 2^k, 2^k + 1 or 2^k - 1 (LSL, shifted ADD, LSL + SUB); - stores to integer slots, built directly in the slot's home. Every other use writes the constant to its home just before that use. value() rejects a home access to a constant still deferred, so a path that misses the materialization fails compilation instead of reading an unwritten home; type queries use typeOf(). In main's typedArrays loops each constant cost `mov x9, #k; mov xN, x9` plus a register operand per iteration; they now compile to forms such as `cmp x28, #1, lsl #12`, `add x20, x28, #1` and `and w21, w19, #0xff`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qard
force-pushed
the
perf/loop-constants
branch
from
November 24, 2026 01:23
79f2775 to
16ef273
Compare
The logical-immediate rejection test passed "sp" as a data register directly, which the test typecheck rejects (TS2322); cast it as the other register-role rejection cases do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qard
marked this pull request as ready for review
November 24, 2026 03:16
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.
Standalone codegen PR for the loop-constant items of the #17 kernel-parity plan. It is based on
mainand does not depend on #17 or #18. It is now ready to merge, pending CI.Commits
16ef2735c)&,|and^with logical immediates (new AND/ORR/EOR/ANDS immediate encodings), plus|0,^0and&-1as a plain moveMath.imulby 2^k, 2^k+1 or 2^k−1value()throws if anything reads a constant that hasn't been written out yet, so a missed path fails compilation instead of reading garbage.4b41dad17): fixes a test typecheck error.Dropped by measurement:
numeric'simulconstant, and it is not on the loop-carried chain. Hoisting it would need a register held across the loop, which this emitter does not have.Results (15 interleaved rounds, Node 26.13.1, timing lock)
Frozen v7, main vs this PR:
68c11052…)Typed suite, main vs this PR, in ms:
numeric46.2 → 45.2strings25.2 → 24.6typedArrays47.9 → 46.8stringBuild53.3 → 52.3calls50.2 → 49.7allocation,compiler,closures,arrays,escapestringEquality12.3 → 12.4: every code change in that kernel is an instruction removed, and the copies shifted by 16/48 bytes measured 12.5.mapSet46.6 → 47.0: the intervals overlap, and the shifted copies measured 47.1/46.8.__text−1.8%.#18 string bench, #18 head vs #18 with this PR cherry-picked (one trivial conflict). Three placement variants of this PR were measured: unshifted, and code shifted by 16 and 48 bytes.
codeUnits: 14.1 → 12.2 / 12.5 / 12.1 mscodeUnitsTwoByte: 13.2 → 11.1 / 11.5 / 11.2 msMath.imul(c, 31)on the loop-carried chain is now LSL+SUB, and no constants are materialized in the loop.utf8TwoByte: 5.1 → 5.3 / 5.4 / 5.1. The 48-byte-shifted copy matches base, so this is placement; the codec's code is strictly shorter.Alignment (function entries 32/64, innermost loop headers 32/64, and both together):
arrays7% slower, and function+loop-64 makescalls5% slower.stringEquality(13.5 vs 12.6 ms) and 2.6% oncalls. The noise comes from coarser placement (page or predictor aliasing), which alignment does not control.Validation
check:concurrentlocally: typecheck, test-file classification, boundaries and format all pass. 6,123 concurrent tests pass; the one failure needs a local Test262 checkout, which CI has.value()never threw a deferred-constant error across the full compiler build, the typed suite, the string bench or frozen v7.tools/native-integer-immediates.test.tspasses under LLDB and matches Node. It covers:imulby 2^k, 2^k±1, 2^31 and −1🤖 Generated with Claude Code