Add int32 fast lane to the raw-double remainder sites#2671
Merged
Conversation
TryCompoundUnboxed, TryAssignNumeric and ModuloEqualityLane computed JS % as double % double - a native fmod call - even for the dominant integral loop-counter shapes, while the shared Remainder helper already had an integer fast path for boxed Integer operands. Route all three through a shared RemainderUnboxed helper: int32 round-trip gate (NaN/Infinity/fractional/out-of-range/zero-divisor operands defer to fmod), remainder in long math (int.MinValue % -1 would raise a hardware overflow in 32-bit division), and a zero remainder takes the dividend's sign bit so negative and -0 dividends produce the spec -0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lahma
enabled auto-merge (squash)
July 13, 2026 13:45
This was referenced Jul 15, 2026
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.
Summary
Three raw-double lanes compute JS
%asdouble % double— a native fmod call — even for the dominant integral loop-counter shapes, while the sharedRemainderhelper already has an integer fast path for boxed Integer operands:JintAssignmentExpression.TryCompoundUnboxed, thex %= yarmSimpleAssignmentExpression.TryAssignNumeric, thelhs = a % barmJintBinaryExpression.ModuloEqualityLane, the fusedx % c === cstopwatch if-chain shapeRoute all three through a shared
RemainderUnboxed(double, double)helper: an int32 round-trip gate (NaN, ±Infinity, fractional values, out-of-int32-range operands and zero divisors all fail the round-trip equality and defer to the IEEE 754%, which matches the ECMAScript algorithm for those cases), remainder computed in long math (int.MinValue % -1would raise a hardware overflow in 32-bit division), and a zero remainder takes the dividend's sign bit — so negative and-0dividends produce the spec-0.Benchmarks (default jobs, adjacent A/B on latest main)
Allocations unchanged on every row.
Correctness
New
IntegerRemainderLanesPreserveSignAndSpecialCasestest: 63 assertions × 3 loop passes (cache-armed lanes) across all three shapes — dividend-sign results,Object.is(x, -0)for negative and-0dividends,% 0 → NaN, fractional fallback,int.MinValue % -1 → -0.Gates
🤖 Generated with Claude Code