Skip to content

Commit

Permalink
Reimplement _xgetbv with inline assembly (rust-lang#333)
Browse files Browse the repository at this point in the history
Looks like LLVM 6 may have removed the intrinsic, and this implementation is
modeled after clang's.
  • Loading branch information
alexcrichton authored Feb 27, 2018
1 parent 524c896 commit d0a6c2c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions coresimd/x86/i586/xsave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ extern "C" {
fn xrstor(p: *const u8, hi: u32, lo: u32) -> ();
#[link_name = "llvm.x86.xsetbv"]
fn xsetbv(v: u32, hi: u32, lo: u32) -> ();
#[link_name = "llvm.x86.xgetbv"]
fn xgetbv(x: u32) -> i64;
#[link_name = "llvm.x86.xsaveopt"]
fn xsaveopt(p: *mut u8, hi: u32, lo: u32) -> ();
#[link_name = "llvm.x86.xsavec"]
Expand Down Expand Up @@ -75,7 +73,10 @@ pub unsafe fn _xsetbv(a: u32, val: u64) {
#[target_feature(enable = "xsave")]
#[cfg_attr(test, assert_instr(xgetbv))]
pub unsafe fn _xgetbv(xcr_no: u32) -> u64 {
xgetbv(xcr_no) as u64
let eax: u32;
let edx: u32;
asm!("xgetbv" : "={eax}"(eax), "={edx}"(edx) : "{ecx}"(xcr_no));
((edx as u64) << 32) | (eax as u64)
}

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

0 comments on commit d0a6c2c

Please sign in to comment.