Skip to content

Commit

Permalink
Document what the xcr0 masks do
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg authored and TheIronBorn committed Jun 29, 2018
1 parent 0e53438 commit 192c1c2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions stdsimd/arch/detect/os/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@ fn detect_features() -> cache::Initializer {

if cpu_osxsave {
// 2. The OS must have signaled the CPU that it supports saving and
// restoring the SSE and AVX registers by setting `XCR0.SSE[1]` and
// `XCR0.AVX[2]` to `1`.
// restoring the:
//
// * SSE -> `XCR0.SSE[1]`
// * AVX -> `XCR0.AVX[2]`
// * AVX-512 -> `XCR0.AVX-512[7:5]`.
//
// by setting the corresponding bits of `XCR0` to `1`.
//
// This is safe because the CPU supports `xsave`
// and the OS has set `osxsave`.
let xcr0 = unsafe { _xgetbv(0) };
// Test `XCR0.SSE[1]` and `XCR0.AVX[2]` with the mask `0b110 == 6`:
let os_avx_support = xcr0 & 6 == 6;
// Test `XCR0.AVX-512[7:5]` with the mask `0b1110_0000 == 224`:
let os_avx512_support = xcr0 & 224 == 224;

// Only if the OS and the CPU support saving/restoring the AVX
Expand Down

0 comments on commit 192c1c2

Please sign in to comment.