Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86 __get_cpuid_max documentation invalid #1718

Open
jethrogb opened this issue Feb 18, 2025 · 0 comments
Open

x86 __get_cpuid_max documentation invalid #1718

jethrogb opened this issue Feb 18, 2025 · 0 comments

Comments

@jethrogb
Copy link
Contributor

The documentation for __get_cpuid_max states:

If cpuid is supported, and leaf is zero, then the first tuple argument
contains the highest leaf value that cpuid supports. For leafs
containing sub-leafs, the second tuple argument contains the
highest-supported sub-leaf value.

The second sentence is invalid. The function basically does CPUID(EAX=leaf, ECX=0) and returns (EAX, EBX). I haven't found any leaf that behaves like described. Here are some variable subleaf CPUIDs, and how to determine which subleafs are valid (see Intel SDM, CPUID instruction):

  • 0x0b: repeat until you get ECX[15:08]=0
  • 0x0d: valid for every bit index set in EAX/EDX when ECX=0
  • 0x12: undefined, but practically until you get EAX[03:00]=0

So, none of these return “the highest-supported sub-leaf value” in EBX.

The GCC source code does have it and states:

Return highest supported input value for cpuid instruction. ext can
be either 0x0 or 0x80000000 to return highest supported value for
basic or extended cpuid information. Function returns 0 if cpuid
is not supported or whatever cpuid returns in eax register. If sig
pointer is non-null, then first four bytes of the signature
(as found in ebx register) are returned in location pointed by sig.

This does seem to accurately describe the function's behavior, but it's clearly not what Rust documents.

It's not entirely clear to me where this function comes from. It doesn't appear in the Intel Intrisics Guide or the Intel SDM. You practically need to read the documentation anyway to understand any CPUID output, so it's not clear why Rust includes this function which is just a different way to call __cpuid.

cc @gnzlbg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant