Skip to content

Commit ebcfa48

Browse files
committed
[tbm] correctly check tbm features
1 parent 4d8c69e commit ebcfa48

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: src/x86/runtime.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,17 @@ fn detect_features() -> usize {
254254
}
255255
}
256256

257-
if test_bit(proc_info_ecx, 21) && is_amd() {
258-
value = set_bit(value, __Feature::tbm as u32);
257+
if is_amd() {
258+
let extended_proc_info_ecx: u32;
259+
/// 3. EAX=80000001h: Queries "Extended Processor Info and Feature Bits"
260+
asm!("cpuid"
261+
: "={ecx}"(extended_proc_info_ecx)
262+
: "{eax}"(0x8000_0001_u32), "{ecx}"(0 as u32)
263+
: :);
264+
265+
if test_bit(extended_proc_info_ecx as usize, 21) {
266+
value = set_bit(value, __Feature::tbm as u32);
267+
}
259268
}
260269

261270
value

Diff for: 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+
// TODO: abm
2930
}

0 commit comments

Comments
 (0)