Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 66d6e11

Browse files
authoredJul 14, 2020
Rollup merge of #74285 - wangtheo:issue-71669, r=lcnr
#71669: add ui, codegen tests for volatile + nearby int intrinsics Added some tests for intrinsics. See #71669.
2 parents 37b2615 + 8df79fc commit 66d6e11

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed
 

‎src/test/codegen/intrinsics/nearby.rs

+18
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+
// CHECK-LABEL: @nearbyintf32
7+
#[no_mangle]
8+
pub unsafe fn nearbyintf32(a: f32) -> f32 {
9+
// CHECK: llvm.nearbyint.f32
10+
intrinsics::nearbyintf32(a)
11+
}
12+
13+
// CHECK-LABEL: @nearbyintf64
14+
#[no_mangle]
15+
pub unsafe fn nearbyintf64(a: f64) -> f64 {
16+
// CHECK: llvm.nearbyint.f64
17+
intrinsics::nearbyintf64(a)
18+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
#![feature(core_intrinsics)]
5+
6+
use std::intrinsics;
7+
8+
// CHECK-LABEL: @volatile_copy_memory
9+
#[no_mangle]
10+
pub unsafe fn volatile_copy_memory(a: *mut u8, b: *const u8) {
11+
// CHECK: llvm.memmove.p0i8.p0i8.{{\w*(.*true)}}
12+
intrinsics::volatile_copy_memory(a, b, 1)
13+
}
14+
15+
// CHECK-LABEL: @volatile_copy_nonoverlapping_memory
16+
#[no_mangle]
17+
pub unsafe fn volatile_copy_nonoverlapping_memory(a: *mut u8, b: *const u8) {
18+
// CHECK: llvm.memcpy.p0i8.p0i8.{{\w*(.*true)}}
19+
intrinsics::volatile_copy_nonoverlapping_memory(a, b, 1)
20+
}
21+
22+
// CHECK-LABEL: @volatile_set_memory
23+
#[no_mangle]
24+
pub unsafe fn volatile_set_memory(a: *mut u8, b: u8) {
25+
// CHECK: llvm.memset.p0i8.{{\w*(.*true)}}
26+
intrinsics::volatile_set_memory(a, b, 1)
27+
}
28+
29+
// CHECK-LABEL: @volatile_load
30+
#[no_mangle]
31+
pub unsafe fn volatile_load(a: *const u8) -> u8 {
32+
// CHECK: load volatile
33+
intrinsics::volatile_load(a)
34+
}
35+
36+
// CHECK-LABEL: @volatile_store
37+
#[no_mangle]
38+
pub unsafe fn volatile_store(a: *mut u8, b: u8) {
39+
// CHECK: store volatile
40+
intrinsics::volatile_store(a, b)
41+
}
42+
43+
// CHECK-LABEL: @unaligned_volatile_load
44+
#[no_mangle]
45+
pub unsafe fn unaligned_volatile_load(a: *const u8) -> u8 {
46+
// CHECK: load volatile
47+
intrinsics::unaligned_volatile_load(a)
48+
}
49+
50+
// CHECK-LABEL: @unaligned_volatile_store
51+
#[no_mangle]
52+
pub unsafe fn unaligned_volatile_store(a: *mut u8, b: u8) {
53+
// CHECK: store volatile
54+
intrinsics::unaligned_volatile_store(a, b)
55+
}
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,44 @@
1+
// run-pass
2+
3+
#![feature(core_intrinsics)]
4+
5+
use std::intrinsics::*;
6+
7+
pub fn main() {
8+
unsafe {
9+
let mut x: Box<u8> = Box::new(0);
10+
let mut y: Box<u8> = Box::new(0);
11+
12+
// test volatile load
13+
assert_eq!(volatile_load(&*x), 0);
14+
*x = 1;
15+
assert_eq!(volatile_load(&*x), 1);
16+
17+
// test volatile store
18+
volatile_store(&mut *x, 2);
19+
assert_eq!(*x, 2);
20+
21+
// test volatile copy memory
22+
volatile_copy_memory(&mut *y, &*x, 1);
23+
assert_eq!(*y, 2);
24+
25+
// test volatile copy non-overlapping memory
26+
*x = 3;
27+
volatile_copy_nonoverlapping_memory(&mut *y, &*x, 1);
28+
assert_eq!(*y, 3);
29+
30+
// test volatile set memory
31+
volatile_set_memory(&mut *x, 4, 1);
32+
assert_eq!(*x, 4);
33+
34+
// test unaligned volatile load
35+
let arr: [u8; 3] = [1, 2, 3];
36+
let ptr = arr[1..].as_ptr() as *const u16;
37+
assert_eq!(unaligned_volatile_load(ptr), u16::from_ne_bytes([arr[1], arr[2]]));
38+
39+
// test unaligned volatile store
40+
let ptr = arr[1..].as_ptr() as *mut u16;
41+
unaligned_volatile_store(ptr, 0);
42+
assert_eq!(arr, [1, 0, 0]);
43+
}
44+
}

0 commit comments

Comments
 (0)
Please sign in to comment.