@@ -96,73 +96,6 @@ pub unsafe fn __cpuid(leaf: u32) -> CpuidResult {
96
96
__cpuid_count ( leaf, 0 )
97
97
}
98
98
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
-
166
99
/// Returns the highest-supported `leaf` (`EAX`) and sub-leaf (`ECX`) `cpuid`
167
100
/// values.
168
101
///
@@ -179,22 +112,3 @@ pub unsafe fn __get_cpuid_max(leaf: u32) -> (u32, u32) {
179
112
let CpuidResult { eax, ebx, .. } = __cpuid ( leaf) ;
180
113
( eax, ebx)
181
114
}
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
- }
0 commit comments