Repository navigation
Have IDIV/DIV REX2 and EVEX compatible - #128668
Conversation
…for DivByZero or Overflow can handle REX2/EVEX prefixed IDIV/DIV.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR extends AMD64 exception/context handling and JIT metadata to support APX (extended GPRs and new prefix encodings), and adjusts PAL context save/restore paths to handle APX state more independently of AVX-512.
Changes:
- Add support for accessing R16–R31 in
CONTEXTand for decoding APX-related prefix forms (EVEX map 4 / REX2) when analyzing DIV/IDIV faults. - Adjust PAL context conversion/restore logic to handle APX registers without being gated by AVX-512 handling, and refine OS gating for APX support checks.
- Update JIT instruction metadata and register-availability usage to accommodate APX/REX2-related encoding needs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/exceptionhandling.cpp | Adds APX-aware register access (R16–R31), ModRM/SIB decoding extensions for 5-bit indices, and EVEX/REX2 prefix handling for DIV/IDIV analysis. |
| src/coreclr/pal/src/thread/context.cpp | Changes APX support OS gating and moves APX register copy logic so it is not implicitly dependent on AVX-512 state handling. |
| src/coreclr/pal/src/arch/amd64/context2.S | Ensures APX restore check runs even when AVX-512 restore is skipped; adjusts mask test width for APX. |
| src/coreclr/jit/lsraxarch.cpp | Uses availableIntRegs instead of lowGprRegs when building delayed-free uses for div/mod sequences. |
| src/coreclr/jit/instrsxarch.h | Marks div/idiv as supporting REX2 encoding and NF flag metadata. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
Build analysis is green, PR is ready for review. |
tannergooding
left a comment
There was a problem hiding this comment.
LGTM. CC. @dotnet/jit-contrib for secondary review
|
Kindly pinging @dotnet/jit-contrib for a secondary review, thanks :) |
|
CC. @dhartglassMSFT for secondary review |
|
Hi @dhartglassMSFT, just kindly checking in to see if you've had a chance to look at this, as our upcoming work depends on it. Thanks! |
|
Hi Ruihan, the JIT changes LGTM |
|
Thanks all for the reviews and suggestions! |
Teach VM to handle DivByZero and Overflow exception with REX2 and EVEX prefixed IDIV/DIV Fixed a few bugs in CONTEXT save and restores - context2.S/context.cpp Adjusted the jump destination when AVX512 is not available, this caused APX region is skipped in restore if AVX512 is not available. Adjusted the check logic for XSTATE_MASK_APX (1 << 19), use a DWORD PTR to make sure the value is properly handled. For some reason, HAVE_MACH_EXCEPTIONS is defined under x64 Linux, redefined the guard in a helper to make sure it is valid under Linux but not on OSX. --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Teach VM to handle DivByZero and Overflow exception with REX2 and EVEX prefixed IDIV/DIV
Fixed a few bugs in CONTEXT save and restores - context2.S/context.cpp
Adjusted the jump destination when AVX512 is not available, this caused APX region is skipped in restore if AVX512 is not available.
Adjusted the check logic for XSTATE_MASK_APX (1 << 19), use a DWORD PTR to make sure the value is properly handled.
For some reason, HAVE_MACH_EXCEPTIONS is defined under x64 Linux, redefined the guard in a helper to make sure it is valid under Linux but not on OSX.