Skip to content

Commit f3bb4f4

Browse files
authored
Reimplement _xgetbv with LLVM intrinsics (#958)
`_xgetbv` was reimplemented to use inline assembly in #333 since LLVM 3.9 didn't export the intrinsic we needed to use. LLVM 4.0 has since rectified that issue, and since rust's minimum supported version of LLVM is 8.0, this change can be reverted.
1 parent a129c40 commit f3bb4f4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

crates/core_arch/src/x86/xsave.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ extern "C" {
1212
fn xrstor(p: *const u8, hi: u32, lo: u32);
1313
#[link_name = "llvm.x86.xsetbv"]
1414
fn xsetbv(v: u32, hi: u32, lo: u32);
15+
#[link_name = "llvm.x86.xgetbv"]
16+
fn xgetbv(v: u32) -> i64;
1517
#[link_name = "llvm.x86.xsaveopt"]
1618
fn xsaveopt(p: *mut u8, hi: u32, lo: u32);
1719
#[link_name = "llvm.x86.xsavec"]
@@ -85,10 +87,7 @@ pub unsafe fn _xsetbv(a: u32, val: u64) {
8587
#[cfg_attr(test, assert_instr(xgetbv))]
8688
#[stable(feature = "simd_x86", since = "1.27.0")]
8789
pub unsafe fn _xgetbv(xcr_no: u32) -> u64 {
88-
let eax: u32;
89-
let edx: u32;
90-
llvm_asm!("xgetbv" : "={eax}"(eax), "={edx}"(edx) : "{ecx}"(xcr_no));
91-
((edx as u64) << 32) | (eax as u64)
90+
xgetbv(xcr_no) as u64
9291
}
9392

9493
/// Performs a full or partial save of the enabled processor states to memory at

0 commit comments

Comments
 (0)