From a51a3ab28941e29da2f11036733d7400c769ce8d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sat, 23 Jun 2018 13:05:15 +0200 Subject: [PATCH] Fixes has_cpuid implementation https://github.com/rust-lang/rust/issues/51691 --- library/stdarch/coresimd/x86/cpuid.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/stdarch/coresimd/x86/cpuid.rs b/library/stdarch/coresimd/x86/cpuid.rs index 7e000625ce81..af9f88fce0a0 100644 --- a/library/stdarch/coresimd/x86/cpuid.rs +++ b/library/stdarch/coresimd/x86/cpuid.rs @@ -96,7 +96,7 @@ pub fn has_cpuid() -> bool { let eflags: u32 = __readeflags(); // Invert the ID bit in EFLAGS: - let eflags_mod: u32 = eflags | 0x0020_0000; + let eflags_mod: u32 = eflags ^ 0x0020_0000; // Store the modified EFLAGS (ID bit may or may not be inverted) __writeeflags(eflags_mod); @@ -138,6 +138,11 @@ mod tests { assert!(cpuid::has_cpuid()); } + #[test] + fn test_has_cpuid_idempotent() { + assert_eq!(cpuid::has_cpuid(), cpuid::has_cpuid()); + } + #[cfg(target_arch = "x86")] #[test] fn test_has_cpuid() {