Skip to content

Reimplement _xgetbv with inline assembly #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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