Skip to content

Have IDIV/DIV REX2 and EVEX compatible - #128668

Merged
tannergooding merged 6 commits into
dotnet:mainfrom
Ruihan-Yin:apx-div-exception
Jun 22, 2026
Merged

tannergooding merged 6 commits into
dotnet:mainfrom
Ruihan-Yin:apx-div-exception

Conversation

@Ruihan-Yin

Copy link
Copy Markdown
Member

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.

…for DivByZero or Overflow can handle REX2/EVEX prefixed IDIV/DIV.
Copilot AI review requested due to automatic review settings May 27, 2026 22:05
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label May 27, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CONTEXT and 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.

Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/pal/src/thread/context.cpp Resolved
@teo-tsirpanis teo-tsirpanis added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI apx Related to the Intel Advanced Performance Extensions (APX) and removed area-PAL-coreclr only for closed issues labels May 27, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/pal/src/thread/context.cpp Resolved
Copilot AI review requested due to automatic review settings May 28, 2026 18:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings May 29, 2026 22:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
Comment thread src/coreclr/vm/exceptionhandling.cpp Resolved
@Ruihan-Yin

Copy link
Copy Markdown
Member Author

Build analysis is green, PR is ready for review.
Hi, @tannergooding, please take a look, thanks :).

Comment thread src/coreclr/pal/src/thread/context.cpp Resolved

@tannergooding tannergooding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. CC. @dotnet/jit-contrib for secondary review

@Ruihan-Yin

Copy link
Copy Markdown
Member Author

Kindly pinging @dotnet/jit-contrib for a secondary review, thanks :)

@tannergooding

Copy link
Copy Markdown
Member

CC. @dhartglassMSFT for secondary review

@Ruihan-Yin

Copy link
Copy Markdown
Member Author

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!

@dhartglassMSFT

Copy link
Copy Markdown
Contributor

Hi Ruihan, the JIT changes LGTM

@tannergooding
tannergooding merged commit a438371 into dotnet:main Jun 22, 2026
142 of 144 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
@Ruihan-Yin

Copy link
Copy Markdown
Member Author

Thanks all for the reviews and suggestions!

eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
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]>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

apx Related to the Intel Advanced Performance Extensions (APX) area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants