Fix sign extend - #155
Open
alastairreid wants to merge 3 commits into
Open
Conversation
It appears that to zero extend from M to N bits, you first need to cast to uint(M) before casting to uint(N). This fixes a bug that was affecting 28 tests
The fix is for |
nikolaykosarev
approved these changes
Aug 24, 2026
| PP.fprintf fmt "((%a)%a)" | ||
| PP.fprintf fmt "((%a)(%a)%a)" | ||
| ty_uint n | ||
| ty_uint m |
There was a problem hiding this comment.
Would be good to skip this cast when n = m, to reduce the size of generated code.
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.
This fixes a bug in code generated for Sign_Extend where we were missing a cast.
Specifically, we were mis-compiling
Zero_Extend(not x, 64)because thenot xwas being performed at width 64 instead of at whatever the width of x is. This made the operation behave like a Sign_Extend.The fix is to add an additional cast in the generated C code to suppress the normal C type promotions.