-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Currently the emitter support for APX instructions is a bit complex and it can make the logic hard to follow.
In particular, APX comes with two basic types of encoding changes:
- The 2-byte REX2 prefix
- Extensions to the 4-byte EVEX prefix
For the former, we generally have flagged the relevant instructions in instrsxarch.h with a new Encoding_REX2 flag. This is simple to recognize and fits in with the existing model used for Encoding_VEX and Encoding_EVEX.
The extended EVEX prefix, however, is quite a bit more complex and doesn't cleanly integrate with the existing IsEvexEncodableInstruction and/or TakesEvexPrefix support. Rather there is a separate TakesApxExtendedEvexPrefix query and no IsApxExtendedEvexEncodableInstruction. This leads to a lot of duplicated checks and logic between the APX Extended EVEX and regular EVEX spaces.
I believe it would be beneficial to have some separate Encoding_* flag (potentially Encoding_APX) to differentiate the EVEX support that is APX only, rather than using the existing Encoding_EVEX flag. We should then likely continue using the regular TakesEvexPrefix and IsEvexEncodableInstruction paths for all EVEX usage, including APX Extended EVEX, ensuring that the latter does the appropriate UseApxEncoding() check for such instructions. -- This is notably what we do for cases like AVX-VNNI and AVX-IFMA which can have VEX-only, EVEX-only, or VEX+EVEX support.
This should reduce the total number of checks being done and keep the encoding logic contained to the relevant code paths. It should also make it simpler to do things like forcing APX usage or lighting up APX in other profitable scenarios, not just those that require features like NDD or extended register support.