Fix x86 encoder to use 64-bit type to accumulate opcode/prefix bits#8382
Fix x86 encoder to use 64-bit type to accumulate opcode/prefix bits#8382BruceForstall merged 1 commit intodotnet:masterfrom
Conversation
|
@sivarv PTAL |
src/jit/emitxarch.h
Outdated
| /************************************************************************/ | ||
|
|
||
| // code_t is a type used to accumulate bits of opcode + prefixes. On amd64, | ||
| // it must be 64 bits to the REX prefixes. On both x86 and amd64, it must be |
There was a problem hiding this comment.
Typo: Probably you want to mean
"On amd64 it must be 64-bits to support REX prefixes"
| typedef size_t code_t; | ||
| #else // !defined(LEGACY_BACKEND) | ||
| typedef unsigned __int64 code_t; | ||
| #endif // !defined(LEGACY_BACKEND) |
There was a problem hiding this comment.
I am thinking whether the right #ifdef here should be FEATURE_AVX_SUPPORT instead of LEGACY_BACKEND.
There was a problem hiding this comment.
I thought about it, although currently FEATURE_AVX_SUPPORT == !LEGACY_BACKEND for xarch.
| // SSE2: separate 1-byte prefix gets added before opcode. | ||
| // AVX: specific bits within VEX prefix need to be set in bit-inverted form. | ||
| size_t emitter::AddRexWPrefix(instruction ins, size_t code) | ||
| emitter::code_t emitter::AddRexWPrefix(instruction ins, code_t code) |
There was a problem hiding this comment.
emitter::code_t [](start = 0, length = 15)
Can't we use code_t here instead of emitter::code_t?
There was a problem hiding this comment.
Nope; the compiler requires the class prefix for the return value.
| unsigned emitter::emitOutputRexOrVexPrefixIfNeeded(instruction ins, BYTE* dst, code_t& code) | ||
| { | ||
| #ifdef _TARGET_AMD64_ // TODO-x86: This needs to be enabled for AVX support on x86. | ||
| #ifdef FEATURE_AVX_SUPPORT |
There was a problem hiding this comment.
We don't need this #ifdef since hasVexPrefix() returns false if FEATURE_AVX_SUPPORT is not defined.
| else if (code > 0x00FFFFFFFFLL) | ||
| #endif // FEATURE_AVX_SUPPORT | ||
|
|
||
| #ifdef _TARGET_AMD64_ |
There was a problem hiding this comment.
I thought this logic is needed for emitting 3/4 byte SSE instructions. Isn't this required for x86 as well?
There was a problem hiding this comment.
The REX prefixes are only used for AMD64. When set in the AVX prefix, they are only used for extended register usage.
| #endif | ||
| if (code & REX_PREFIX_MASK) | ||
|
|
||
| #ifdef _TARGET_AMD64_ |
There was a problem hiding this comment.
#ifdef _TARGET_AMD64 [](start = 0, length = 20)
Isn't this required for x86 ryujit as well?
There was a problem hiding this comment.
I see call to this method is under amd64. But we might have to change it for x86 ryujit given SSE2 is require?
In reply to: 90312158 [](ancestors = 90312158)
|
|
|
Looks good. |
The encoder was using size_t, a 32-bit type on x86, to accumulate opcode and prefix bits to emit. AVX support uses 3 bytes for prefixes that are higher than the 32-bit type can handle. So, change all code byte related types from size_t to a new code_t, defined as "unsigned __int64" on RyuJIT x86 (there is precedence for this type on the ARM architectures). Fixes #8331
74906c6 to
b90516f
Compare
Fix x86 encoder to use 64-bit type to accumulate opcode/prefix bits Commit migrated from dotnet/coreclr@392748e
No description provided.