Open gnzlbg opened 6 years ago
It turns out that not all x86 cpus have the cpuid instruction
While technically true...
[CPUID] was introduced by Intel in 1993 when it introduced the Pentium and SL-enhanced 486 processors. - Wikipedia
I was under the impression that it was basically impossible to target processors of this age with Rust / LLVM. Is it truly possible to compile for them?
LLVM can target i386
and you can run the binaries on QEMU, but this does not mean that you don't have a point. The stdsimd
crate uses conditional compilation to always return true
on x86_64
which is what most users have nowadays.
It turns out that not all
x86
cpus have thecpuid
instruction, so one should probably check whether the CPU supports it before using it by checking whether the ID bit of the EFLAGS register can be written.The
stdsimd
crate has a PR with the__readeflags
and__writeeflags
intrinsics that can be used to check this, and will hopefully also expose ahas_cpuid() -> bool
that does the check for you.FWIW the PR also exposes the
__cpuid
and__cpuid_count
intrinsics. That might allow you to remove inline assembly, at least on nightly rust (and hopefully on stable someday).