1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// run-pass
// Test that simd gather instructions on slice of usize don't cause crash
// See issue #89183 - https://github.com/rust-lang/rust/issues/89193
#![feature(repr_simd, platform_intrinsics)]
#![allow(non_camel_case_types)]
#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
struct x4<T>(pub T, pub T, pub T, pub T);
extern "platform-intrinsic" {
fn simd_gather<T, U, V>(x: T, y: U, z: V) -> T;
}
fn main() {
let x: [usize; 4] = [10, 11, 12, 13];
let default = x4(0_usize, 1, 2, 3);
let all_set = u8::MAX as i8; // aka -1
let mask = x4(all_set, all_set, all_set, all_set);
let expected = x4(10_usize, 11, 12, 13);
unsafe {
let pointer = x.as_ptr();
let pointers = x4(
pointer.offset(0),
pointer.offset(1),
pointer.offset(2),
pointer.offset(3)
);
let result = simd_gather(default, pointers, mask);
assert_eq!(result, expected);
}
// and again for isize
let x: [isize; 4] = [10, 11, 12, 13];
let default = x4(0_isize, 1, 2, 3);
let expected = x4(10_isize, 11, 12, 13);
unsafe {
let pointer = x.as_ptr();
let pointers = x4(
pointer.offset(0),
pointer.offset(1),
pointer.offset(2),
pointer.offset(3)
);
let result = simd_gather(default, pointers, mask);
assert_eq!(result, expected);
}
}
|