Skip to content

Fix Avx10 detection: cache CPUID bit before later queries overwrite cpuidInfo#126810

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-avx10-detection-issue
Open

Fix Avx10 detection: cache CPUID bit before later queries overwrite cpuidInfo#126810
Copilot wants to merge 3 commits intomainfrom
copilot/fix-avx10-detection-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Description

The AVX10 CPUID bit check (cpuidInfo[CPUID_EDX] & (1 << 19)) was reading stale data. The check at L432 expected leaf 7 sub-leaf 1 results (loaded at L380), but cpuidInfo had been overwritten by __cpuidex(cpuidInfo, 0x80000021, 0x0) at L423.

Changes:

  • Move the EDX bit 19 (Avx10) check into the leaf 7 sub-leaf 1 block alongside the AVX512-BF16 dependency check, where cpuidInfo still holds the correct data
  • Replace the raw CPUID read under maxCpuId >= 0x24 with the cached hasAvx10v1Dependencies bool — matching the established pattern used for hasAvx2Dependencies and hasApxDependencies
  • Remove the now-redundant inner hasAvx10v1Dependencies check from the AVX10 version detection block (already guarded by the outer if), and move the dependency comment to the outer guard with Avx10 appended at the end
// Before: checked after cpuidInfo was overwritten by 0x80000021 query
if (maxCpuId >= 0x24)
{
    if ((cpuidInfo[CPUID_EDX] & (1 << 19)) != 0)  // reads wrong leaf data
    { ... }
}

// After: bit cached while leaf 7 sub-leaf 1 data is still live
if (hasAvx10v1Dependencies)
{
    if (((cpuidInfo[CPUID_EAX] & (1 << 5)) == 0) ||   // AVX512-BF16
        ((cpuidInfo[CPUID_EDX] & (1 << 19)) == 0))     // Avx10
    {
        hasAvx10v1Dependencies = false;
    }
}
// ...later, after cpuidInfo is clobbered...
if (maxCpuId >= 0x24)
{
    if (hasAvx10v1Dependencies)                         // AVX512-BF16, AVX512-FP16, Avx10
    {
        __cpuidex(cpuidInfo, 0x00000024, 0x00000000);

        if (((cpuidInfo[CPUID_EBX] & (1 << 16)) != 0) &&   // Avx10/V128
            ((cpuidInfo[CPUID_EBX] & (1 << 17)) != 0) &&    // Avx10/V256
            ((cpuidInfo[CPUID_EBX] & (1 << 18)) != 0))      // Avx10/V512
        { ... }
    }
}

Copilot AI requested review from Copilot and removed request for Copilot April 12, 2026 16:50
Copilot AI linked an issue Apr 12, 2026 that may be closed by this pull request
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

…overwrite cpuidInfo

The check for `(cpuidInfo[CPUID_EDX] & (1 << 19)) != 0` was being performed
after a `__cpuidex(cpuidInfo, 0x80000021, 0x0)` call overwrote `cpuidInfo`,
causing the AVX10 bit check to read from the wrong CPUID leaf data.

Move the AVX10 bit check into the leaf 7 sub-leaf 1 block alongside the
AVX512-BF16 dependency check, and use the cached `hasAvx10v1Dependencies`
bool in the `maxCpuId >= 0x24` section instead.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/e73ed6c1-2b7b-4488-a920-6366304b4a23

Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 12, 2026 16:56
Copilot AI changed the title [WIP] Fix AVX10 detection issue due to recent changes in cpufeature.c Fix Avx10 detection: cache CPUID bit before later queries overwrite cpuidInfo Apr 12, 2026
Copilot AI requested a review from tannergooding April 12, 2026 16:58
Copilot AI requested review from Copilot and removed request for Copilot April 12, 2026 17:10
Copilot AI requested a review from tannergooding April 12, 2026 17:10
@tannergooding tannergooding marked this pull request as ready for review April 12, 2026 17:17
@tannergooding
Copy link
Copy Markdown
Member

Small fix to ensure AVX10v1 detection is still handled as expected.

Copy link
Copy Markdown
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

This PR fixes AVX10 feature detection in minipal_getcpufeatures by ensuring the AVX10 CPUID bit is checked/cached while leaf 7 sub-leaf 1 data is still valid, instead of reading cpuidInfo after it has been overwritten by a later CPUID query.

Changes:

  • Cache the AVX10 CPUID presence bit (leaf 7, sub-leaf 1, EDX[19]) alongside the existing AVX10 dependency checks while the correct cpuidInfo is live.
  • Gate the later AVX10 version detection (leaf 0x24) on the cached hasAvx10v1Dependencies boolean instead of re-reading cpuidInfo.
  • Remove a redundant hasAvx10v1Dependencies condition inside the leaf 0x24 version checks.

@tannergooding tannergooding enabled auto-merge (squash) April 12, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Avx10 cannot be detected

4 participants