Skip to content

[spirv] Fix firstbithigh/low signedness #5665

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
merged 1 commit into from
Sep 8, 2023

Conversation

sudonatalie
Copy link
Collaborator

The SPIR-V backend was incorrectly choosing to emit either FindSMsb or FindUMsb based on whether the result type of the call expression was signed or unsigned. Since the AST result type was always unsigned (and wrapped in a cast if necessary), this meant FindSMsb was never generated. FindSMsB should however be generated when the argument type is signed. This is indicated by the HLSL intrinsic op code (firstbithigh for signed and ufirstbithigh for unsigned). The SPIR-V generated now matches the DXIL generated.

This bug was discovered while investigating #4702, so at the same time some error checking is added to make unimplemented cases explicit. Because the underlying GLSL.std.450 instructions FindSMsb, FindUMsb and FindILsB are currently limited to 32-bit width components, we now emit an error messages when this would otherwise result in invalid SPIR-V.

The SPIR-V backend was incorrectly choosing to emit either FindSMsb or
FindUMsb based on whether the result type of the call expression was
signed or unsigned. Since the AST result type was always unsigned (and
wrapped in a cast if necessary), this meant FindSMsb was never
generated. FindSMsB should however be generated when the argument type
is signed. This is indicated by the HLSL intrinsic op code
(firstbithigh for signed and ufirstbithigh for unsigned). The SPIR-V
generated now matches the DXIL generated.

This bug was discovered while investigating microsoft#4702, so at the same time
some error checking is added to make unimplemented cases explicit.
Because the underlying GLSL.std.450 instructions FindSMsb, FindUMsb and
FindILsB are currently limited to 32-bit width components, we now emit
an error messages when this would otherwise result in invalid SPIR-V.
@sudonatalie sudonatalie merged commit b7a50ba into microsoft:main Sep 8, 2023
@sudonatalie sudonatalie deleted the issue-4702 branch September 8, 2023 13:09
ShchchowAMD pushed a commit to ShchchowAMD/DirectXShaderCompiler that referenced this pull request Sep 11, 2023
The SPIR-V backend was incorrectly choosing to emit either FindSMsb or
FindUMsb based on whether the result type of the call expression was
signed or unsigned. Since the AST result type was always unsigned (and
wrapped in a cast if necessary), this meant FindSMsb was never
generated. FindSMsB should however be generated when the argument type
is signed. This is indicated by the HLSL intrinsic op code (firstbithigh
for signed and ufirstbithigh for unsigned). The SPIR-V generated now
matches the DXIL generated.

This bug was discovered while investigating microsoft#4702, so at the same time
some error checking is added to make unimplemented cases explicit.
Because the underlying GLSL.std.450 instructions FindSMsb, FindUMsb and
FindILsB are currently limited to 32-bit width components, we now emit
an error messages when this would otherwise result in invalid SPIR-V.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants