Skip to content

Commit 5ff7e1a

Browse files
committed
Added ui tests for volatile and nearby intrinsics
1 parent 9a3a31a commit 5ff7e1a

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_type = "lib"]
2+
#![feature(core_intrinsics)]
3+
4+
use std::intrinsics::*;
5+
6+
pub unsafe fn test_volatile_order() {
7+
let mut a: Box<u8> = Box::new(0);
8+
// CHECK: load volatile
9+
let x = volatile_load(&*a);
10+
// CHECK: load volatile
11+
let x = volatile_load(&*a);
12+
// CHECK: store volatile
13+
volatile_store(&mut *a, 12);
14+
// CHECK: store volatile
15+
unaligned_volatile_store(&mut *a, 12);
16+
// CHECK: llvm.memset.p0i8
17+
volatile_set_memory(&mut *a, 12, 1)
18+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-pass
2+
#![feature(core_intrinsics)]
3+
4+
use std::intrinsics::*;
5+
6+
fn main() {
7+
unsafe {
8+
assert_eq!(nearbyintf32(5.234f32), 5f32);
9+
assert_eq!(nearbyintf64(6.777f64), 7f64);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// run-pass
2+
#![feature(core_intrinsics)]
3+
4+
use std::intrinsics::*;
5+
6+
pub fn main() {
7+
unsafe {
8+
let mut x: Box<u8> = Box::new(0);
9+
let mut y: Box<u8> = Box::new(0);
10+
11+
// test volatile load
12+
assert_eq!(volatile_load(&*x), 0);
13+
*x = 1;
14+
assert_eq!(volatile_load(&*x), 1);
15+
16+
// test volatile store
17+
volatile_store(&mut *x, 2);
18+
assert_eq!(*x, 2);
19+
20+
// test volatile copy memory
21+
volatile_copy_memory(&mut *y, &*x, 1);
22+
assert_eq!(*y, 2);
23+
24+
// test volatile copy non-overlapping memory
25+
*x = 3;
26+
volatile_copy_nonoverlapping_memory(&mut *y, &*x, 1);
27+
assert_eq!(*y, 3);
28+
29+
// test volatile set memory
30+
volatile_set_memory(&mut *x, 4, 1);
31+
assert_eq!(*x, 4);
32+
33+
// test unaligned volatile load
34+
let arr: [u8; 3] = [1, 2, 3];
35+
let ptr = arr[1..].as_ptr() as *const u16;
36+
assert_eq!(unaligned_volatile_load(ptr), u16::from_ne_bytes([arr[1], arr[2]]));
37+
38+
// test unaligned volatile store
39+
let ptr = arr[1..].as_ptr() as *mut u16;
40+
unaligned_volatile_store(ptr, 0);
41+
assert_eq!(arr, [1, 0, 0]);
42+
}
43+
}

0 commit comments

Comments
 (0)