Repository navigation
Conversation
greenhat
requested review from
Firestar99,
LegNeato and
eddyb
as code owners
November 15, 2026 12:21
greenhat
force-pushed
the
fix-rotate-width
branch
from
November 16, 2026 13:35
d7498a1 to
20b5f86
Compare
Firestar99
force-pushed
the
fix-rotate-width
branch
from
November 16, 2026 13:50
20b5f86 to
61fafdc
Compare
Firestar99
approved these changes
Nov 16, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 16, 2026
`Builder::rotate` took the bit width from the type of the shift amount, which is `u32` for every value type. So 64-bit values were rotated modulo 32, and 8 and 16-bit values were shifted by amounts at or above their bit width. Take the bit width from the type of the rotated value instead. Add the difftest `lang/core/intrinsics/rotate` that runs 8, 16, 32 and 64-bit rotates in a shader and compares the results with the CPU.
Firestar99
force-pushed
the
fix-rotate-width
branch
from
November 16, 2026 17:28
61fafdc to
25cd314
Compare
This branch has not been deployed
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.
Builder::rotate(builder/mod.rs) took the bit width from the type of the shift amount instead of the type of the rotated value. The shift amount is alwaysu32, so every rotate was done modulo 32.0x9ABCDEF0_12345678u64.rotate_left(1)returns0x3579BDE1_3579BDF0instead of0x3579BDE0_2468ACF1.This takes the bit width from the rotated value. The new difftest
lang/core/intrinsics/rotateruns 8, 16, 32 and 64-bit rotates in a shader and compares the results with the CPU. It fails without the fix.The fix and the test were written with an AI coding agent. I reviewed and checked every line.
Details
The code emitted for a
u64before the fix:The constants are now 63 and 64 for
u64, 15 and 16 foru16, 7 and 8 foru8. The code emitted foru32does not change (the expected output ofui/dis/issue-1062is the same).u8andu16gave the right values on lavapipe, but they were shifted by amounts at or above their bit width, and the result of such a shift is not defined in SPIR-V.The constants keep the type of the shift amount, since they are combined with it.
OpShiftLeftLogical/OpShiftRightLogicaldo not requireShiftto have the bit width ofBase.The test reads the amounts from a buffer (below, at and above each bit width). Without the fix 242 of the 448 output words differ, all of them in the 64-bit results. It follows
trailing_zeros_64: Ash backend (it needsInt8,Int16andInt64), skipped on macOS. I ran it on lavapipe only.I removed the
TODO: Definitely add tests to make sure this impl is right.comment onrotate, since there is a test now.