Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[SPIR-V] Fix OpBitFieldExtract emulation for unsigned integer #7167

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

LLJJDD
Copy link
Contributor

@LLJJDD LLJJDD commented Feb 28, 2025

For an unsigned integer, we should OpShiftRightLogical instead of OpShiftRightArithmetic. Otherwise the value may be extended incorrectly.

For example:

struct S {
  uint16_t m1 : 8;
  uint16_t m2 : 8;
};

void main() {
  S s;
  s.m1 = 0xff;
  s.m2 = 0xff;
  uint16_t result = s.m1;
}

If we do OpShiftRightArithmetic here, the result will be 0xffff.

For an unsigned integer, we should OpShiftRightLogical instead of
OpShiftRightArithmetic. Otherwise the value may be extended incorrectly.

For example:
```
struct S {
  uint16_t m1 : 8;
  uint16_t m2 : 8;
};

void main() {
  S s;
  s.m1 = 0xff;
  s.m2 = 0xff;
  uint16_t result = s.m1;
}
```

If we do OpShiftRightArithmetic here, the result will be 0xffff.
@LLJJDD LLJJDD requested a review from a team as a code owner February 28, 2025 07:29
@s-perron s-perron requested a review from Keenuts February 28, 2025 14:54
@s-perron s-perron enabled auto-merge (squash) February 28, 2025 14:55
Copy link
Collaborator

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Good catch

@s-perron s-perron merged commit 1500f12 into microsoft:main Feb 28, 2025
13 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants