Skip to content

Commit f44444e

Browse files
authored
Add 'volatile' to cpuid inline asm (#994)
1 parent 982ffb9 commit f44444e

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

crates/core_arch/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(unused_features)]
55
#![allow(incomplete_features)]
66
#![feature(
7+
asm,
78
const_fn,
89
const_fn_union,
910
const_fn_transmute,

crates/core_arch/src/x86/cpuid.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,33 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
5555
let ebx;
5656
let ecx;
5757
let edx;
58+
5859
#[cfg(target_arch = "x86")]
5960
{
60-
llvm_asm!("cpuid"
61-
: "={eax}"(eax), "={ebx}"(ebx), "={ecx}"(ecx), "={edx}"(edx)
62-
: "{eax}"(leaf), "{ecx}"(sub_leaf)
63-
: :);
61+
asm!(
62+
"cpuid",
63+
inlateout("eax") leaf => eax,
64+
lateout("ebx") ebx,
65+
inlateout("ecx") sub_leaf => ecx,
66+
lateout("edx") edx,
67+
options(nostack, preserves_flags),
68+
);
6469
}
6570
#[cfg(target_arch = "x86_64")]
6671
{
67-
// x86-64 uses %rbx as the base register, so preserve it.
72+
// x86-64 uses `rbx` as the base register, so preserve it.
6873
// This works around a bug in LLVM with ASAN enabled:
6974
// https://bugs.llvm.org/show_bug.cgi?id=17907
70-
llvm_asm!(r#"
71-
mov %rbx, %rsi
72-
cpuid
73-
xchg %rbx, %rsi
74-
"#
75-
: "={eax}"(eax), "={esi}"(ebx), "={ecx}"(ecx), "={edx}"(edx)
76-
: "{eax}"(leaf), "{ecx}"(sub_leaf)
77-
: :);
75+
asm!(
76+
"mov rsi, rbx",
77+
"cpuid",
78+
"xchg rsi, rbx",
79+
inlateout("eax") leaf => eax,
80+
lateout("esi") ebx,
81+
inlateout("ecx") sub_leaf => ecx,
82+
lateout("edx") edx,
83+
options(nostack, preserves_flags),
84+
);
7885
}
7986
CpuidResult { eax, ebx, ecx, edx }
8087
}

0 commit comments

Comments
 (0)