Skip to content

Commit d0a6c2c

Browse files
authored
Reimplement _xgetbv with inline assembly (#333)
Looks like LLVM 6 may have removed the intrinsic, and this implementation is modeled after clang's.
1 parent 524c896 commit d0a6c2c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

coresimd/x86/i586/xsave.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ extern "C" {
1313
fn xrstor(p: *const u8, hi: u32, lo: u32) -> ();
1414
#[link_name = "llvm.x86.xsetbv"]
1515
fn xsetbv(v: u32, hi: u32, lo: u32) -> ();
16-
#[link_name = "llvm.x86.xgetbv"]
17-
fn xgetbv(x: u32) -> i64;
1816
#[link_name = "llvm.x86.xsaveopt"]
1917
fn xsaveopt(p: *mut u8, hi: u32, lo: u32) -> ();
2018
#[link_name = "llvm.x86.xsavec"]
@@ -75,7 +73,10 @@ pub unsafe fn _xsetbv(a: u32, val: u64) {
7573
#[target_feature(enable = "xsave")]
7674
#[cfg_attr(test, assert_instr(xgetbv))]
7775
pub unsafe fn _xgetbv(xcr_no: u32) -> u64 {
78-
xgetbv(xcr_no) as u64
76+
let eax: u32;
77+
let edx: u32;
78+
asm!("xgetbv" : "={eax}"(eax), "={edx}"(edx) : "{ecx}"(xcr_no));
79+
((edx as u64) << 32) | (eax as u64)
7980
}
8081

8182
/// Perform a full or partial save of the enabled processor states to memory at

0 commit comments

Comments
 (0)