-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Consider reworking how the x86 emitter handles the 'w' bit #35305
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
I'm going to move this to Future. |
Hi @tannergooding , I'm curious about the extent of the change for this issue and wanted to get some clarification. Are we looking to add new bits to the INS_FLAGS entry, say
or are we looking for a more extensive change that would ideally group up the logic for checking when a 'w' bit is needed in general, i.e., write some |
To start with, it would simply be correctly adding a flag to the instructions that require the More extensive changes would ideally come later to help simplify the initial PR and isolate the changes as much as possible.
|
Thanks @tannergooding . I've been inspecting the code and there is one edge case that I need a little clarification on. It's actually the above snippet unmodified. In else if (code & 0x00FF0000)
{
// BT supports 16 bit operands and this code doesn't handle the necessary 66 prefix.
assert(ins != INS_bt);
// Output the REX prefix
dst += emitOutputRexOrVexPrefixIfNeeded(ins, dst, code);
// Output the highest byte of the opcode
if (code & 0x00FF0000)
{
dst += emitOutputByte(dst, code >> 16);
code &= 0x0000FFFF;
}
// Use the large version if this is not a byte. This trick will not
// work in case of SSE2 and AVX instructions.
if ((size != EA_1BYTE) && (ins != INS_imul) && (ins != INS_bsf) && (ins != INS_bsr) && !IsSSEInstruction(ins) &&
!IsAVXInstruction(ins))
{
code++; // <--- HERE
}
} Here, I understand that checks for I think this complicates encoding the 'w' bit in the INS_Flags, as it would have to be done per mode. But, I think the overflow is the problem here, because
we would be ok, unless I have misunderstood why Is this the correct line of thinking here to simplify? |
Thanks for this. I see that we have an
|
@tannergooding I was re-reading your first comment,
and I wanted to clarify one point. These functions determine whether to emit the REX.W bit, and as part of a larger refactoring, we'll have to consider how that interplays with parts of the code that determine whether to emit the 'w' bit, but we are only talking about tracking the 'w' and 's' bits in the INS_FLAGS entry, not an additional 'REX.W' bit, correct? |
Right, that was me conflating two different |
@tannergooding I think we should close this out per the merged PR? |
As investigated on #34550 (comment), the emitter currently has some odd support for detecting whether a given instruction uses the 'w' and 's' encoding bits.
It would likely benefit from having this be an
INS_FLAGS
entry that can be trivially checked to statically determine the appropriate encoding that is required.category:implementation
theme:emitter
skill-level:intermediate
cost:medium
The text was updated successfully, but these errors were encountered: