Skip to content

Commit a3673cf

Browse files
committed
[runtime] bug fix: abm and tbm detection
1 parent 4d8c69e commit a3673cf

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/x86/runtime.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ fn test_bit(x: usize, bit: u32) -> bool {
159159
/// [intel64_ref]: http://www.intel.de/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf
160160
/// [amd64_ref]: http://support.amd.com/TechDocs/24594.pdf
161161
fn detect_features() -> usize {
162-
let extended_features_ebx;
163-
let proc_info_ecx;
164-
let proc_info_edx;
162+
let extended_features_ebx: u32;
163+
let proc_info_ecx: u32;
164+
let proc_info_edx: u32;
165+
let extended_proc_info_ecx: u32;
165166

166167
unsafe {
167168
/// To obtain all feature flags we need two CPUID queries:
@@ -181,8 +182,20 @@ fn detect_features() -> usize {
181182
: "={ebx}"(extended_features_ebx)
182183
: "{eax}"(0x0000_0007_u32), "{ecx}"(0 as u32)
183184
: :);
185+
186+
/// 3. EAX=80000001h: Queries "Extended Processor Info and
187+
/// Feature Bits"
188+
asm!("cpuid"
189+
: "={ecx}"(extended_proc_info_ecx)
190+
: "{eax}"(0x8000_0001_u32), "{ecx}"(0 as u32)
191+
: :);
184192
}
185193

194+
let extended_features_ebx = extended_features_ebx as usize;
195+
let proc_info_ecx = proc_info_ecx as usize;
196+
let proc_info_edx = proc_info_edx as usize;
197+
let extended_proc_info_ecx = extended_proc_info_ecx as usize;
198+
186199
let mut value: usize = 0;
187200

188201
if test_bit(extended_features_ebx, 3) {
@@ -195,9 +208,6 @@ fn detect_features() -> usize {
195208
if test_bit(proc_info_ecx, 0) {
196209
value = set_bit(value, __Feature::sse3 as u32);
197210
}
198-
if test_bit(proc_info_ecx, 5) {
199-
value = set_bit(value, __Feature::abm as u32);
200-
}
201211
if test_bit(proc_info_ecx, 9) {
202212
value = set_bit(value, __Feature::ssse3 as u32);
203213
}
@@ -254,7 +264,11 @@ fn detect_features() -> usize {
254264
}
255265
}
256266

257-
if test_bit(proc_info_ecx, 21) && is_amd() {
267+
if test_bit(extended_proc_info_ecx, 5) {
268+
value = set_bit(value, __Feature::abm as u32);
269+
}
270+
271+
if test_bit(extended_proc_info_ecx, 21) && is_amd() {
258272
value = set_bit(value, __Feature::tbm as u32);
259273
}
260274

tests/cpu-detection.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn works() {
2424
assert_eq!(cfg_feature_enabled!("bmi"), information.bmi1());
2525
assert_eq!(cfg_feature_enabled!("bmi2"), information.bmi2());
2626
assert_eq!(cfg_feature_enabled!("popcnt"), information.popcnt());
27-
28-
// TODO: tbm, abm, lzcnt
27+
// assert_eq!(cfg_feature_enabled!("tbm"), information.tbm());
28+
assert_eq!(cfg_feature_enabled!("lzcnt"), information.lzcnt());
29+
assert_eq!(cfg_feature_enabled!("abm"), information.lzcnt());
2930
}

0 commit comments

Comments
 (0)