Skip to content

Fix sign extend - #155

Open
alastairreid wants to merge 3 commits into
masterfrom
areid-fix-sign-extend
Open

Fix sign extend#155
alastairreid wants to merge 3 commits into
masterfrom
areid-fix-sign-extend

Conversation

@alastairreid

Copy link
Copy Markdown

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 the not x was 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.

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
@nikolaykosarev

Copy link
Copy Markdown

This fixes a bug in code generated for Sign_Extend where we were missing a cast.

The fix is for Zero_Extend, right? Mentioning Sign_Extend here and in the commit messages is misleading.

Comment thread libISA/runtime_c23.ml
PP.fprintf fmt "((%a)%a)"
PP.fprintf fmt "((%a)(%a)%a)"
ty_uint n
ty_uint m

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would be good to skip this cast when n = m, to reduce the size of generated code.

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.

2 participants