-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Handle large imm values in ARMEmitter.EmitLDR #98433
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
Conversation
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsFixes pri0 test failure: Contributes to #97729
|
| uint constVal = (uint)offset & ~0xfffu; | ||
| uint mask32 = 0xff; | ||
| uint imm8 = 0; | ||
| int encode = 31; // 11111 | ||
|
|
||
| do | ||
| { | ||
| mask32 <<= 1; | ||
| if ((constVal & ~mask32) == 0) | ||
| { | ||
| imm8 = (constVal & mask32) >> (32 - encode); | ||
| break; | ||
| } | ||
| encode--; | ||
| } while (encode >= 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you are wondering, this part is shamelessly copied from the JIT:
runtime/src/coreclr/jit/emitarm.cpp
Lines 1349 to 1366 in c7c15f7
| mask32 = 0x00000ff; | |
| encode = 31; /* 11111 */ | |
| do | |
| { | |
| mask32 <<= 1; | |
| temp = uval32 & ~mask32; | |
| if (temp == 0) | |
| { | |
| imm8 = (uval32 & mask32) >> (32 - encode); | |
| assert((imm8 & 0x80) != 0); | |
| goto DONE; | |
| } | |
| encode--; | |
| } while (encode >= 8); | |
| assert(!"encodeModImmConst failed!"); | |
| return BAD_CODE; |
The instruction encoding has several forms. We want to use the one where we produce an immediate value and rotate it using the barrel shifter into the right position to get the right constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not look like that it can.
| { | ||
| Debug.Assert(IsValidReg(destination) && IsValidReg(source)); | ||
|
|
||
| if (offset >= 0x1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be ever called with large negative offset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the call sites and the only negative values seemed to be in the -PointerSize range.
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Fixes pri0 test failure:
Contributes to #97729