Skip to content

Commit 3552af6

Browse files
committed
[xsave] fix tests
1 parent e53d9a7 commit 3552af6

File tree

3 files changed

+92
-86
lines changed

3 files changed

+92
-86
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ matrix:
1717
- env: DOCUMENTATION
1818
install: true
1919
script: ci/dox.sh
20+
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu
21+
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu
2022
allow_failures:
2123
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu
2224
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu

coresimd/src/x86/i586/xsave.rs

Lines changed: 8 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ extern "C" {
1717
fn xgetbv(x: u32) -> i64;
1818
#[link_name = "llvm.x86.xsaveopt"]
1919
fn xsaveopt(p: *mut u8, hi: u32, lo: u32) -> ();
20-
#[link_name = "llvm.x86.xsavec"]
21-
fn xsavec(p: *mut u8, hi: u32, lo: u32) -> ();
22-
#[link_name = "llvm.x86.xsaves"]
23-
fn xsaves(p: *mut u8, hi: u32, lo: u32) -> ();
24-
#[link_name = "llvm.x86.xrstors"]
25-
fn xrstors(p: *const u8, hi: u32, lo: u32) -> ();
2620
}
2721

2822
/// Perform a full or partial save of the enabled processor states to memory at
@@ -71,6 +65,12 @@ pub unsafe fn _xsetbv(a: u32, val: u64) -> () {
7165

7266
/// Reads the contents of the extended control register `XCR`
7367
/// specified in `xcr_no`.
68+
///
69+
/// This instruction must be executed at privilege level `0` or in real-address
70+
/// mode; otherwise, a general protection exception `#GP(0)` is generated.
71+
/// Specifying a reserved or unimplemented XCR in ECX will also cause a general
72+
/// protection exception. The processor will also generate a general protection
73+
/// exception if software attempts to write to reserved bits in an XCR.
7474
#[inline(always)]
7575
#[target_feature = "+xsave"]
7676
#[cfg_attr(test, assert_instr(xgetbv))]
@@ -92,49 +92,6 @@ pub unsafe fn _xsaveopt(mem_addr: *mut u8, save_mask: u64) -> () {
9292
xsaveopt(mem_addr, (save_mask >> 32) as u32, save_mask as u32);
9393
}
9494

95-
/// Perform a full or partial save of the enabled processor states to memory
96-
/// at `mem_addr`.
97-
///
98-
/// `xsavec` differs from `xsave` in that it uses compaction and that it may
99-
/// use init optimization. State is saved based on bits [62:0] in `save_mask`
100-
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
101-
#[inline(always)]
102-
#[target_feature = "+xsave,+xsavec"]
103-
#[cfg_attr(test, assert_instr(xsavec))]
104-
pub unsafe fn _xsavec(mem_addr: *mut u8, save_mask: u64) -> () {
105-
xsavec(mem_addr, (save_mask >> 32) as u32, save_mask as u32);
106-
}
107-
108-
/// Perform a full or partial save of the enabled processor states to memory at
109-
/// `mem_addr`
110-
///
111-
/// `xsaves` differs from xsave in that it can save state components
112-
/// corresponding to bits set in `IA32_XSS` `MSR` and that it may use the
113-
/// modified optimization. State is saved based on bits [62:0] in `save_mask`
114-
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
115-
#[inline(always)]
116-
#[target_feature = "+xsave,+xsaves"]
117-
#[cfg_attr(test, assert_instr(xsaves))]
118-
pub unsafe fn _xsaves(mem_addr: *mut u8, save_mask: u64) -> () {
119-
xsaves(mem_addr, (save_mask >> 32) as u32, save_mask as u32);
120-
}
121-
122-
/// Perform a full or partial restore of the enabled processor states using the
123-
/// state information stored in memory at `mem_addr`.
124-
///
125-
/// `xrstors` differs from `xrstor` in that it can restore state components
126-
/// corresponding to bits set in the `IA32_XSS` `MSR`; `xrstors` cannot restore
127-
/// from an `xsave` area in which the extended region is in the standard form.
128-
/// State is restored based on bits [62:0] in `rs_mask`, `XCR0`, and
129-
/// `mem_addr.HEADER.XSTATE_BV`. `mem_addr` must be aligned on a 64-byte
130-
/// boundary.
131-
#[inline(always)]
132-
#[target_feature = "+xsave,+xsaves"]
133-
#[cfg_attr(test, assert_instr(xrstors))]
134-
pub unsafe fn _xrstors(mem_addr: *const u8, rs_mask: u64) -> () {
135-
xrstors(mem_addr, (rs_mask >> 32) as u32, rs_mask as u32);
136-
}
137-
13895
#[cfg(test)]
13996
mod tests {
14097
use x86::i586::xsave;
@@ -183,8 +140,7 @@ mod tests {
183140
}
184141
}
185142

186-
// FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/209
187-
/*
143+
#[cfg(not(feature = "intel_sde"))]
188144
#[simd_test = "xsave"]
189145
unsafe fn xsave() {
190146
let m = 0xFFFFFFFFFFFFFFFF_u64; //< all registers
@@ -196,7 +152,6 @@ mod tests {
196152
xsave::_xsave(b.ptr(), m);
197153
assert_eq!(a, b);
198154
}
199-
*/
200155

201156
#[simd_test = "xsave"]
202157
unsafe fn xgetbv_xsetbv() {
@@ -211,8 +166,7 @@ mod tests {
211166
assert_eq!(xcr, xcr_cpy);
212167
}
213168

214-
// FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/209
215-
/*
169+
#[cfg(not(feature = "intel_sde"))]
216170
#[simd_test = "xsave,xsaveopt"]
217171
unsafe fn xsaveopt() {
218172
let m = 0xFFFFFFFFFFFFFFFF_u64; //< all registers
@@ -224,34 +178,4 @@ mod tests {
224178
xsave::_xsaveopt(b.ptr(), m);
225179
assert_eq!(a, b);
226180
}
227-
*/
228-
229-
// FIXME: this looks like a bug in Intel's SDE:
230-
#[cfg(not(feature = "intel_sde"))]
231-
#[simd_test = "xsave,xsavec"]
232-
unsafe fn xsavec() {
233-
let m = 0xFFFFFFFFFFFFFFFF_u64; //< all registers
234-
let mut a = XsaveArea::new();
235-
let mut b = XsaveArea::new();
236-
237-
xsave::_xsavec(a.ptr(), m);
238-
xsave::_xrstor(a.ptr(), m);
239-
xsave::_xsavec(b.ptr(), m);
240-
assert_eq!(a, b);
241-
}
242-
243-
// FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/209
244-
/*
245-
#[simd_test = "xsave,xsaves"]
246-
unsafe fn xsaves() {
247-
let m = 0xFFFFFFFFFFFFFFFF_u64; //< all registers
248-
let mut a = XsaveArea::new();
249-
let mut b = XsaveArea::new();
250-
251-
xsave::_xsaves(a.ptr(), m);
252-
xsave::_xrstors(a.ptr(), m);
253-
xsave::_xsaves(b.ptr(), m);
254-
assert_eq!(a, b);
255-
}
256-
*/
257181
}

coresimd/src/x86/x86_64/xsave.rs

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ extern "C" {
1919
fn xsaves64(p: *mut u8, hi: u32, lo: u32) -> ();
2020
#[link_name = "llvm.x86.xrstors64"]
2121
fn xrstors64(p: *const u8, hi: u32, lo: u32) -> ();
22+
#[link_name = "llvm.x86.xsavec"]
23+
fn xsavec(p: *mut u8, hi: u32, lo: u32) -> ();
24+
#[link_name = "llvm.x86.xsaves"]
25+
fn xsaves(p: *mut u8, hi: u32, lo: u32) -> ();
26+
#[link_name = "llvm.x86.xrstors"]
27+
fn xrstors(p: *const u8, hi: u32, lo: u32) -> ();
2228
}
2329

2430
/// Perform a full or partial save of the enabled processor states to memory at
@@ -106,10 +112,53 @@ pub unsafe fn _xrstors64(mem_addr: *const u8, rs_mask: u64) -> () {
106112
xrstors64(mem_addr, (rs_mask >> 32) as u32, rs_mask as u32);
107113
}
108114

115+
/// Perform a full or partial save of the enabled processor states to memory
116+
/// at `mem_addr`.
117+
///
118+
/// `xsavec` differs from `xsave` in that it uses compaction and that it may
119+
/// use init optimization. State is saved based on bits [62:0] in `save_mask`
120+
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
121+
#[inline(always)]
122+
#[target_feature = "+xsave,+xsavec"]
123+
#[cfg_attr(test, assert_instr(xsavec))]
124+
pub unsafe fn _xsavec(mem_addr: *mut u8, save_mask: u64) -> () {
125+
xsavec(mem_addr, (save_mask >> 32) as u32, save_mask as u32);
126+
}
127+
128+
/// Perform a full or partial save of the enabled processor states to memory at
129+
/// `mem_addr`
130+
///
131+
/// `xsaves` differs from xsave in that it can save state components
132+
/// corresponding to bits set in `IA32_XSS` `MSR` and that it may use the
133+
/// modified optimization. State is saved based on bits [62:0] in `save_mask`
134+
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
135+
#[inline(always)]
136+
#[target_feature = "+xsave,+xsaves"]
137+
#[cfg_attr(test, assert_instr(xsaves))]
138+
pub unsafe fn _xsaves(mem_addr: *mut u8, save_mask: u64) -> () {
139+
xsaves(mem_addr, (save_mask >> 32) as u32, save_mask as u32);
140+
}
141+
142+
/// Perform a full or partial restore of the enabled processor states using the
143+
/// state information stored in memory at `mem_addr`.
144+
///
145+
/// `xrstors` differs from `xrstor` in that it can restore state components
146+
/// corresponding to bits set in the `IA32_XSS` `MSR`; `xrstors` cannot restore
147+
/// from an `xsave` area in which the extended region is in the standard form.
148+
/// State is restored based on bits [62:0] in `rs_mask`, `XCR0`, and
149+
/// `mem_addr.HEADER.XSTATE_BV`. `mem_addr` must be aligned on a 64-byte
150+
/// boundary.
151+
#[inline(always)]
152+
#[target_feature = "+xsave,+xsaves"]
153+
#[cfg_attr(test, assert_instr(xrstors))]
154+
pub unsafe fn _xrstors(mem_addr: *const u8, rs_mask: u64) -> () {
155+
xrstors(mem_addr, (rs_mask >> 32) as u32, rs_mask as u32);
156+
}
157+
109158
// FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/209
110159
// All these tests fail with Intel SDE.
111-
/*
112160
#[cfg(test)]
161+
#[cfg(not(feature = "intel_sde"))]
113162
mod tests {
114163
use x86::x86_64::xsave;
115164
use stdsimd_test::simd_test;
@@ -194,6 +243,8 @@ mod tests {
194243
assert_eq!(a, b);
195244
}
196245

246+
// This test requires CPL = 0 (ring 0)
247+
/*
197248
#[simd_test = "xsave,xsaves"]
198249
unsafe fn xsaves64() {
199250
let m = 0xFFFFFFFFFFFFFFFF_u64; //< all registers
@@ -205,5 +256,34 @@ mod tests {
205256
xsave::_xsaves64(b.ptr(), m);
206257
assert_eq!(a, b);
207258
}
259+
*/
260+
261+
#[simd_test = "xsave,xsavec"]
262+
unsafe fn xsavec() {
263+
use x86::i586::_xrstor;
264+
265+
let m = 0xFFFFFFFFFFFFFFFF_u64; //< all registers
266+
let mut a = XsaveArea::new();
267+
let mut b = XsaveArea::new();
268+
269+
xsave::_xsavec(a.ptr(), m);
270+
_xrstor(a.ptr(), m);
271+
xsave::_xsavec(b.ptr(), m);
272+
assert_eq!(a, b);
273+
}
274+
275+
// This test requires CPL = 0 (ring 0)
276+
/*
277+
#[simd_test = "xsave,xsaves"]
278+
unsafe fn xsaves() {
279+
let m = 0xFFFFFFFFFFFFFFFF_u64; //< all registers
280+
let mut a = XsaveArea::new();
281+
let mut b = XsaveArea::new();
282+
283+
xsave::_xsaves(a.ptr(), m);
284+
xsave::_xrstors(a.ptr(), m);
285+
xsave::_xsaves(b.ptr(), m);
286+
assert_eq!(a, b);
287+
}
288+
*/
208289
}
209-
*/

0 commit comments

Comments
 (0)