From 9ea3074a9a2299d3ade4e173e414b3e1be67b26e Mon Sep 17 00:00:00 2001 From: arya dradjica Date: Wed, 22 Oct 2025 13:19:24 +0200 Subject: [PATCH] Make '__cpuid_count()' a pure function '__cpuid_count()' is implemented using inline assembly, because LLVM doesn't have an intrinsic for it. It's a pure operation, but this wasn't marked in the 'asm!' invocation; so calls to it couldn't be elided or deduplicated. This change makes it pure. CPUID does have _some_ less-than-pure effects -- e.g. it can be used as a serializing instruction (like a strong memory fence). Users who want to rely on that could use inline assembly themselves instead. --- crates/core_arch/src/x86/cpuid.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/core_arch/src/x86/cpuid.rs b/crates/core_arch/src/x86/cpuid.rs index 0634f10a99..5c95a0d5d2 100644 --- a/crates/core_arch/src/x86/cpuid.rs +++ b/crates/core_arch/src/x86/cpuid.rs @@ -67,7 +67,7 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult { inout("eax") leaf => eax, inout("ecx") sub_leaf => ecx, out("edx") edx, - options(nostack, preserves_flags), + options(nostack, nomem, pure, preserves_flags), ); } #[cfg(target_arch = "x86_64")] @@ -80,7 +80,7 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult { inout("eax") leaf => eax, inout("ecx") sub_leaf => ecx, out("edx") edx, - options(nostack, preserves_flags), + options(nostack, nomem, pure, preserves_flags), ); } CpuidResult { eax, ebx, ecx, edx }