Skip to content

Commit 938c587

Browse files
committed
[x86] expose __cpuid, __cpuid_count, xgetbv, __readeflags, __writeeflags
Expose the `__cpuid` and `_xgetby` `x86`/`x86_64` intrinsics. The `__cpuid` and `__cpuid_count` intrinsics are not available on all `x86` CPUs. The `has_cpuid() -> bool` intrinsic detect this on non `x86_64` hosts. For convenience, this is exposed on `x86_64` as well but there it always returns `true`. These are exposed by Clang and GCC. The `__readeflags` and `__writeeflags` intrinsics, which read/write the `EFLAGS` register and are required to implement `has_cpuid`, are exposed as well. GCC and Clang exposes them too. When doing run-time feature detection for `x86`/`x86_64` we now properly check whether the `cpuid` instruction is available before using it. If it is not available, are features are exposes as "not available". One TODO: - The `_xgetbv` intrinsic requires the `xsave` target feature but this is not currently exposed by rustc, see #167 .
1 parent 1fd0066 commit 938c587

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/x86/xsave.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use stdsimd_test::assert_instr;
99
// #[target_feature = "+xsave"] // FIXME: see
1010
// https://github.com/rust-lang-nursery/stdsimd/issues/167
1111
#[cfg_attr(test, assert_instr(xgetbv))]
12-
pub unsafe fn _xgetbv(xcr_no: u32) -> u64 {
12+
pub unsafe fn _xgetbv(xcr_no: u32) -> i64 {
1313
let eax: u32;
1414
let edx: u32;
1515

@@ -18,5 +18,5 @@ pub unsafe fn _xgetbv(xcr_no: u32) -> u64 {
1818
: "{ecx}"(xcr_no)
1919
: :);
2020

21-
((edx as u64) << 32) | (eax as u64)
21+
(((edx as u64) << 32) | (eax as u64)) as i64
2222
}

0 commit comments

Comments
 (0)