Skip to content

Commit 105a74a

Browse files
workingjubileeAmanieu
authored andcommitted
Remove has_cpuid
1 parent 87158e6 commit 105a74a

File tree

3 files changed

+2
-93
lines changed

3 files changed

+2
-93
lines changed

crates/core_arch/src/x86/cpuid.rs

-86
Original file line numberDiff line numberDiff line change
@@ -96,73 +96,6 @@ pub unsafe fn __cpuid(leaf: u32) -> CpuidResult {
9696
__cpuid_count(leaf, 0)
9797
}
9898

99-
/// Does the host support the `cpuid` instruction?
100-
#[inline]
101-
#[unstable(feature = "stdarch_x86_has_cpuid", issue = "60123")]
102-
pub fn has_cpuid() -> bool {
103-
#[cfg(target_env = "sgx")]
104-
{
105-
false
106-
}
107-
#[cfg(all(not(target_env = "sgx"), target_arch = "x86_64"))]
108-
{
109-
true
110-
}
111-
#[cfg(all(not(target_env = "sgx"), target_arch = "x86"))]
112-
{
113-
// Optimization for i586 and i686 Rust targets which SSE enabled
114-
// and support cpuid:
115-
#[cfg(target_feature = "sse")]
116-
{
117-
true
118-
}
119-
120-
// If SSE is not enabled, detect whether cpuid is available:
121-
#[cfg(not(target_feature = "sse"))]
122-
unsafe {
123-
// On `x86` the `cpuid` instruction is not always available.
124-
// This follows the approach indicated in:
125-
// http://wiki.osdev.org/CPUID#Checking_CPUID_availability
126-
// https://software.intel.com/en-us/articles/using-cpuid-to-detect-the-presence-of-sse-41-and-sse-42-instruction-sets/
127-
// which detects whether `cpuid` is available by checking whether
128-
// the 21st bit of the EFLAGS register is modifiable or not.
129-
// If it is, then `cpuid` is available.
130-
let result: u32;
131-
asm!(
132-
// Read eflags and save a copy of it
133-
"pushfd",
134-
"pop {result}",
135-
"mov {result}, {saved_flags}",
136-
// Flip 21st bit of the flags
137-
"xor $0x200000, {result}",
138-
// Load the modified flags and read them back.
139-
// Bit 21 can only be modified if cpuid is available.
140-
"push {result}",
141-
"popfd",
142-
"pushfd",
143-
"pop {result}",
144-
// Use xor to find out whether bit 21 has changed
145-
"xor {saved_flags}, {result}",
146-
result = out(reg) result,
147-
saved_flags = out(reg) _,
148-
options(nomem, att_syntax),
149-
);
150-
// There is a race between popfd (A) and pushfd (B)
151-
// where other bits beyond 21st may have been modified due to
152-
// interrupts, a debugger stepping through the asm, etc.
153-
//
154-
// Therefore, explicitly check whether the 21st bit
155-
// was modified or not.
156-
//
157-
// If the result is zero, the cpuid bit was not modified.
158-
// If the result is `0x200000` (non-zero), then the cpuid
159-
// was correctly modified and the CPU supports the cpuid
160-
// instruction:
161-
(result & 0x200000) != 0
162-
}
163-
}
164-
}
165-
16699
/// Returns the highest-supported `leaf` (`EAX`) and sub-leaf (`ECX`) `cpuid`
167100
/// values.
168101
///
@@ -179,22 +112,3 @@ pub unsafe fn __get_cpuid_max(leaf: u32) -> (u32, u32) {
179112
let CpuidResult { eax, ebx, .. } = __cpuid(leaf);
180113
(eax, ebx)
181114
}
182-
183-
#[cfg(test)]
184-
mod tests {
185-
use crate::core_arch::x86::*;
186-
187-
#[test]
188-
#[cfg_attr(miri, ignore)] // Uses inline assembly
189-
fn test_always_has_cpuid() {
190-
// all currently-tested targets have the instruction
191-
// FIXME: add targets without `cpuid` to CI
192-
assert!(cpuid::has_cpuid());
193-
}
194-
195-
#[test]
196-
#[cfg_attr(miri, ignore)] // Uses inline assembly
197-
fn test_has_cpuid_idempotent() {
198-
assert_eq!(cpuid::has_cpuid(), cpuid::has_cpuid());
199-
}
200-
}

crates/std_detect/src/detect/os/x86.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ use crate::detect::{bit, cache, Feature};
2828
pub(crate) fn detect_features() -> cache::Initializer {
2929
let mut value = cache::Initializer::default();
3030

31-
// If the x86 CPU does not support the CPUID instruction then it is too
32-
// old to support any of the currently-detectable features.
33-
if !has_cpuid() {
31+
if cfg!(target_env = "sgx") {
32+
// doesn't support this because it is untrusted data
3433
return value;
3534
}
3635

crates/std_detect/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
#![cfg_attr(test, allow(unused_imports))]
2121
#![no_std]
2222
#![allow(internal_features)]
23-
#![cfg_attr(
24-
any(target_arch = "x86", target_arch = "x86_64"),
25-
feature(stdarch_x86_has_cpuid)
26-
)]
2723

2824
#[cfg(test)]
2925
#[macro_use]

0 commit comments

Comments
 (0)