Skip to content

[HandshakeOptimizeBitwidths] Fix forward logic for shrui#812

Merged
zero9178 merged 5 commits intomainfrom
users/zero9179/shrui-bitwidth
Mar 27, 2026
Merged

[HandshakeOptimizeBitwidths] Fix forward logic for shrui#812
zero9178 merged 5 commits intomainfrom
users/zero9179/shrui-bitwidth

Conversation

@zero9178
Copy link
Copy Markdown
Collaborator

The previous logic for shrui for the forward pass did not properly handle sign-extension for shrui, resulting in sign-extension of the result often being performed in cases where the shifting should fill in 0 bits. Furthermore, if the constant was larger than the minimal input bitwidth, integer overflow would occur in the implementation causing crashes.

This PR fixes that issue by splitting the forward pass for shrui out of the common shift pattern and taking both zero-extension and sign-extension of the input into account. I believe the logic of shrui and shrsi to likely be different enough to require different forwarding patterns. The older generic ArithShift pattern remains in use for the backward pass.

Fixes #792

Depends on #802 to function

The previous logic for `shrui` for the forward pass did not properly handle sign-extension for `shrui`, resulting in sign-extension of the result often being performed in cases where the shifting should fill in 0 bits.
Furthermore, if the constant was larger than the minimal input bitwidth, integer overflow would occur in the implementation causing crashes.

This PR fixes that issue by splitting the forward pass for `shrui` out of the common shift pattern and taking both zero-extension and sign-extension of the input into account.
I believe the logic of `shrui` and `shrsi` to likely be different enough to require different forwarding patterns.
The older generic `ArithShift` pattern remains in use for the backward pass.

Fixes #792
@zero9178 zero9178 force-pushed the users/zero9179/shrui-bitwidth branch from f9fdbee to e3a5d9b Compare March 26, 2026 12:39
@zero9178 zero9178 changed the base branch from users/zero9179/ext-constant-canon to main March 26, 2026 12:39
@zero9178 zero9178 requested a review from Jiahui17 March 27, 2026 11:55
@zero9178 zero9178 merged commit a91b53a into main Mar 27, 2026
8 checks passed
@zero9178 zero9178 deleted the users/zero9179/shrui-bitwidth branch March 27, 2026 14:08
zero9178 added a commit that referenced this pull request Mar 29, 2026
The previous logic for `shrsi` for the forward pass often crashed in
edge cases such as the shift amount was larger than the bitwidth.

This PR rewrites the forward logic for `shrsi` into a dedicated pattern.
In the case of the input of `shrsi` being zero-extended we just optimize
it to a `shrui` and reuse the existing optimization logic there.

Fixes #792

Depends on #812
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.

integer bitwidth is limited to 16777215 bits crash

2 participants