Skip to content

[X86][APX] Update the CPUID check logics for APX.#124624

Open
Ruihan-Yin wants to merge 5 commits intodotnet:mainfrom
Ruihan-Yin:apx-cpuid-0218
Open

[X86][APX] Update the CPUID check logics for APX.#124624
Ruihan-Yin wants to merge 5 commits intodotnet:mainfrom
Ruihan-Yin:apx-cpuid-0218

Conversation

@Ruihan-Yin
Copy link
Member

This PR is to update the new APX CPUID bits as documented in the specification:
image

This PR is to introduce the new CPUID bit only, and it is not intended to change the JIT behavior based on the presence of the new bit. (APX_F bit will guarantee the new APX_NDD_NCI_NF bit on Intel processors as documented above). All the features and optimizations will be available as long as APX_F bit is set.

Copilot AI review requested due to automatic review settings February 19, 2026 23:21
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 19, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates x86/x64 APX feature detection in minipal_getcpufeatures to incorporate the new APX-related CPUID bit from the updated Intel APX documentation.

Changes:

  • Renames the existing APX CPUID bit comment to APX_F and adds a follow-up CPUID query (leaf 0x29) for APX_NCI_NDD_NF.
  • Requires both APX_F and CPUID.(EAX=29H,ECX=0):EBX[0] to be present before setting XArchIntrinsicConstants_Apx.
  • Re-issues CPUID.(EAX=07H,ECX=1H) after the new leaf 0x29 query to restore state for subsequent checks.

@Ruihan-Yin
Copy link
Member Author

Build Analysis is green, PR is ready for review.

@Ruihan-Yin Ruihan-Yin marked this pull request as ready for review February 23, 2026 19:07
Copilot AI review requested due to automatic review settings February 23, 2026 19:07
Copy link
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 1 comment.

@Ruihan-Yin
Copy link
Member Author

Failures look irrelevant

Hi @kg @tannergooding , could you please take a look at the PR :)

@tannergooding tannergooding requested a review from kg February 27, 2026 22:40
resolve comments

Co-authored-by: Tanner Gooding <tagoo@outlook.com>
Copilot AI review requested due to automatic review settings February 27, 2026 22:40
Copy link
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 4 comments.

Comment on lines +455 to +461
if (maxCpuId >= 0x29)
{
__cpuidex(cpuidInfo, 0x00000029, 0x00000000);
if (((cpuidInfo[CPUID_EBX] & (1 << 0)) != 0) && hasApxDependencies) // AMX-TILE
{
result |= XArchIntrinsicConstants_Apx;
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

The PR description says the new APX_NCI_NDD_NF bit is informational and should not change APX enablement (APX features should be available as long as APX_F is set). However, the current logic only sets XArchIntrinsicConstants_Apx when both APX_F and CPUID.(EAX=29h,ECX=0):EBX[0] are present, which can change behavior under CPUID filtering/virtualization or on non-Intel CPUs. Either update the implementation so APX availability remains gated only by APX_F + OS state support (and treat the new bit as supplemental), or update the PR description/expectations to reflect the new requirement.

Copilot uses AI. Check for mistakes.
if (maxCpuId >= 0x29)
{
__cpuidex(cpuidInfo, 0x00000029, 0x00000000);
if (((cpuidInfo[CPUID_EBX] & (1 << 0)) != 0) && hasApxDependencies) // AMX-TILE
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

The inline comment on this condition says // AMX-TILE, but this block is checking CPUID leaf 0x29 for the APX_NCI_NDD_NF-related bit (EBX[0]) before enabling APX. Please correct the comment so it matches what is actually being checked; misleading comments here make future maintenance/debugging harder.

Suggested change
if (((cpuidInfo[CPUID_EBX] & (1 << 0)) != 0) && hasApxDependencies) // AMX-TILE
if (((cpuidInfo[CPUID_EBX] & (1 << 0)) != 0) && hasApxDependencies) // APX_NCI_NDD_NF

Copilot uses AI. Check for mistakes.
Comment on lines +455 to +458
if (maxCpuId >= 0x29)
{
__cpuidex(cpuidInfo, 0x00000029, 0x00000000);
if (((cpuidInfo[CPUID_EBX] & (1 << 0)) != 0) && hasApxDependencies) // AMX-TILE
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

__cpuidex(..., 0x29, 0) runs whenever maxCpuId >= 0x29, even when hasApxDependencies is false. Since CPUID is serializing and this function runs at startup, consider guarding the entire leaf-0x29 query behind hasApxDependencies (or otherwise short-circuit) so we avoid an unnecessary CPUID call on machines where APX_F/OS state support isn't present.

Suggested change
if (maxCpuId >= 0x29)
{
__cpuidex(cpuidInfo, 0x00000029, 0x00000000);
if (((cpuidInfo[CPUID_EBX] & (1 << 0)) != 0) && hasApxDependencies) // AMX-TILE
if (hasApxDependencies && (maxCpuId >= 0x29))
{
__cpuidex(cpuidInfo, 0x00000029, 0x00000000);
if ((cpuidInfo[CPUID_EBX] & (1 << 0)) != 0) // AMX-TILE

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 2, 2026 03:30
Copy link
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Infrastructure community-contribution Indicates that the PR has been added by a community member

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants