Lokathor/safe_arch

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

Opened this issue · 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.
Soveu commented

I think rust-cpuid crate can be used for this