safe_arch icon indicating copy to clipboard operation
safe_arch copied to clipboard

[cpuid] Let the user perform runtime checks for CPU features

Open Lokathor opened this issue 5 years ago • 1 comments

Even if the user wants to enable features at compile time or not, it's helpful as an extra sanity check to be able to check at program start that the features really are available and maybe print an error message or something if the actual CPU isn't ready to handle what you're doing.


  • first call __get_cpuid_max(0) and check ret.0 for the max leaf.
  • If a leaf has sub-leaves you need to know the max of, call __get_cpuid_max(leaf) and check ret.1 for that max.
  • once you know your limits, particular features can be checked for by getting the info for a leaf and checking the bits of a particular return register. Which bit you need to look for in what register in what leaf is mostly covered in the CPUID wikipedia article.

Lokathor avatar May 06 '20 16:05 Lokathor

I think rust-cpuid crate can be used for this

Soveu avatar May 15 '20 08:05 Soveu