rust/tests/ui/simd/issue-89193.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.4 KiB
Rust
Raw Normal View History

//@ run-pass
2021-09-27 07:18:22 -05:00
// 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);
2023-02-12 13:37:09 -06:00
let all_set = u8::MAX as i8; // aka -1
let mask = x4(all_set, all_set, all_set, all_set);
2021-09-27 07:18:22 -05:00
let expected = x4(10_usize, 11, 12, 13);
2021-09-27 08:08:15 -05:00
2021-09-27 07:18:22 -05:00
unsafe {
2023-02-12 13:37:09 -06:00
let pointer = x.as_ptr();
2021-09-27 07:18:22 -05:00
let pointers = x4(
2023-02-12 13:37:09 -06:00
pointer.offset(0),
2021-09-27 07:18:22 -05:00
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);
2021-09-27 08:08:15 -05:00
2021-09-27 07:18:22 -05:00
unsafe {
2023-02-12 13:37:09 -06:00
let pointer = x.as_ptr();
2021-09-27 07:18:22 -05:00
let pointers = x4(
2023-02-12 13:37:09 -06:00
pointer.offset(0),
2021-09-27 07:18:22 -05:00
pointer.offset(1),
pointer.offset(2),
pointer.offset(3)
);
let result = simd_gather(default, pointers, mask);
assert_eq!(result, expected);
}
}