Skip to content

Commit 7504252

Browse files
committed
So many test updates x_x
1 parent 9535fee commit 7504252

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+790
-1030
lines changed

tests/auxiliary/minisimd.rs

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//! Auxiliary crate for tests that need SIMD types.
2+
//!
3+
//! Historically the tests just made their own, but projections into simd types
4+
//! was banned by <https://github.com/rust-lang/compiler-team/issues/838>, which
5+
//! breaks `derive(Clone)`, so this exists to give easily-usable types that can
6+
//! be used without copy-pasting the definitions of the helpers everywhere.
7+
//!
8+
//! This makes no attempt to guard against ICEs. Using it with proper types
9+
//! and such is your responsibility in the tests you write.
10+
11+
#![allow(unused)]
12+
#![allow(non_camel_case_types)]
13+
14+
// The field is currently left `pub` for convenience in porting tests, many of
15+
// which attempt to just construct it directly. That still works; it's just the
16+
// `.0` projection that doesn't.
17+
#[repr(simd)]
18+
#[derive(Copy, Eq)]
19+
pub struct Simd<T, const N: usize>(pub [T; N]);
20+
21+
impl<T: Copy, const N: usize> Clone for Simd<T, N> {
22+
fn clone(&self) -> Self {
23+
*self
24+
}
25+
}
26+
27+
impl<T: PartialEq, const N: usize> PartialEq for Simd<T, N> {
28+
fn eq(&self, other: &Self) -> bool {
29+
self.as_array() == other.as_array()
30+
}
31+
}
32+
33+
impl<T: core::fmt::Debug, const N: usize> core::fmt::Debug for Simd<T, N> {
34+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
35+
<[T; N] as core::fmt::Debug>::fmt(self.as_array(), f)
36+
}
37+
}
38+
39+
impl<T, const N: usize> core::ops::Index<usize> for Simd<T, N> {
40+
type Output = T;
41+
fn index(&self, i: usize) -> &T {
42+
&self.as_array()[i]
43+
}
44+
}
45+
46+
impl<T, const N: usize> Simd<T, N> {
47+
pub const fn from_array(a: [T; N]) -> Self {
48+
Simd(a)
49+
}
50+
pub fn as_array(&self) -> &[T; N] {
51+
let p: *const Self = self;
52+
unsafe { &*p.cast::<[T; N]>() }
53+
}
54+
pub fn into_array(self) -> [T; N]
55+
where
56+
T: Copy,
57+
{
58+
*self.as_array()
59+
}
60+
}
61+
62+
pub type u8x2 = Simd<u8, 2>;
63+
pub type u8x4 = Simd<u8, 4>;
64+
pub type u8x8 = Simd<u8, 8>;
65+
pub type u8x16 = Simd<u8, 16>;
66+
pub type u8x32 = Simd<u8, 32>;
67+
pub type u8x64 = Simd<u8, 64>;
68+
69+
pub type u16x2 = Simd<u16, 2>;
70+
pub type u16x4 = Simd<u16, 4>;
71+
pub type u16x8 = Simd<u16, 8>;
72+
pub type u16x16 = Simd<u16, 16>;
73+
pub type u16x32 = Simd<u16, 32>;
74+
75+
pub type u32x2 = Simd<u32, 2>;
76+
pub type u32x4 = Simd<u32, 4>;
77+
pub type u32x8 = Simd<u32, 8>;
78+
pub type u32x16 = Simd<u32, 16>;
79+
80+
pub type u64x2 = Simd<u64, 2>;
81+
pub type u64x4 = Simd<u64, 4>;
82+
pub type u64x8 = Simd<u64, 8>;
83+
84+
pub type u128x2 = Simd<u128, 2>;
85+
pub type u128x4 = Simd<u128, 4>;
86+
87+
pub type i8x2 = Simd<i8, 2>;
88+
pub type i8x4 = Simd<i8, 4>;
89+
pub type i8x8 = Simd<i8, 8>;
90+
pub type i8x16 = Simd<i8, 16>;
91+
pub type i8x32 = Simd<i8, 32>;
92+
pub type i8x64 = Simd<i8, 64>;
93+
94+
pub type i16x2 = Simd<i16, 2>;
95+
pub type i16x4 = Simd<i16, 4>;
96+
pub type i16x8 = Simd<i16, 8>;
97+
pub type i16x16 = Simd<i16, 16>;
98+
pub type i16x32 = Simd<i16, 32>;
99+
100+
pub type i32x2 = Simd<i32, 2>;
101+
pub type i32x4 = Simd<i32, 4>;
102+
pub type i32x8 = Simd<i32, 8>;
103+
pub type i32x16 = Simd<i32, 16>;
104+
105+
pub type i64x2 = Simd<i64, 2>;
106+
pub type i64x4 = Simd<i64, 4>;
107+
pub type i64x8 = Simd<i64, 8>;
108+
109+
pub type i128x2 = Simd<i128, 2>;
110+
pub type i128x4 = Simd<i128, 4>;
111+
112+
pub type f32x2 = Simd<f32, 2>;
113+
pub type f32x4 = Simd<f32, 4>;
114+
pub type f32x8 = Simd<f32, 8>;
115+
pub type f32x16 = Simd<f32, 16>;
116+
117+
pub type f64x2 = Simd<f64, 2>;
118+
pub type f64x4 = Simd<f64, 4>;
119+
pub type f64x8 = Simd<f64, 8>;
120+
121+
// The field is currently left `pub` for convenience in porting tests, many of
122+
// which attempt to just construct it directly. That still works; it's just the
123+
// `.0` projection that doesn't.
124+
#[repr(simd, packed)]
125+
#[derive(Copy)]
126+
pub struct PackedSimd<T, const N: usize>(pub [T; N]);
127+
128+
impl<T: Copy, const N: usize> Clone for PackedSimd<T, N> {
129+
fn clone(&self) -> Self {
130+
*self
131+
}
132+
}
133+
134+
impl<T: PartialEq, const N: usize> PartialEq for PackedSimd<T, N> {
135+
fn eq(&self, other: &Self) -> bool {
136+
self.as_array() == other.as_array()
137+
}
138+
}
139+
140+
impl<T: core::fmt::Debug, const N: usize> core::fmt::Debug for PackedSimd<T, N> {
141+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
142+
<[T; N] as core::fmt::Debug>::fmt(self.as_array(), f)
143+
}
144+
}
145+
146+
impl<T, const N: usize> PackedSimd<T, N> {
147+
pub const fn from_array(a: [T; N]) -> Self {
148+
PackedSimd(a)
149+
}
150+
pub fn as_array(&self) -> &[T; N] {
151+
let p: *const Self = self;
152+
unsafe { &*p.cast::<[T; N]>() }
153+
}
154+
pub fn into_array(self) -> [T; N]
155+
where
156+
T: Copy,
157+
{
158+
*self.as_array()
159+
}
160+
}

tests/codegen/const-vector.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,9 @@
1616
#![feature(mips_target_feature)]
1717
#![allow(non_camel_case_types)]
1818

19-
// Setting up structs that can be used as const vectors
20-
#[repr(simd)]
21-
#[derive(Clone)]
22-
pub struct i8x2([i8; 2]);
23-
24-
#[repr(simd)]
25-
#[derive(Clone)]
26-
pub struct f32x2([f32; 2]);
27-
28-
#[repr(simd, packed)]
29-
#[derive(Copy, Clone)]
30-
pub struct Simd<T, const N: usize>([T; N]);
19+
#[path = "../auxiliary/minisimd.rs"]
20+
mod minisimd;
21+
use minisimd::{PackedSimd as Simd, f32x2, i8x2};
3122

3223
// The following functions are required for the tests to ensure
3324
// that they are called with a const vector
@@ -45,7 +36,7 @@ extern "unadjusted" {
4536

4637
// Ensure the packed variant of the simd struct does not become a const vector
4738
// if the size is not a power of 2
48-
// CHECK: %"Simd<i32, 3>" = type { [3 x i32] }
39+
// CHECK: %"minisimd::PackedSimd<i32, 3>" = type { [3 x i32] }
4940

5041
#[cfg_attr(target_family = "wasm", target_feature(enable = "simd128"))]
5142
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
@@ -74,7 +65,7 @@ pub fn do_call() {
7465
// CHECK: call void @test_simd(<4 x i32> <i32 2, i32 4, i32 6, i32 8>
7566
test_simd(const { Simd::<i32, 4>([2, 4, 6, 8]) });
7667

77-
// CHECK: call void @test_simd_unaligned(%"Simd<i32, 3>" %1
68+
// CHECK: call void @test_simd_unaligned(%"minisimd::PackedSimd<i32, 3>" %1
7869
test_simd_unaligned(const { Simd::<i32, 3>([2, 4, 6]) });
7970
}
8071
}

tests/codegen/simd-intrinsic/simd-intrinsic-float-abs.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@
44
#![feature(repr_simd, core_intrinsics)]
55
#![allow(non_camel_case_types)]
66

7-
use std::intrinsics::simd::simd_fabs;
8-
9-
#[repr(simd)]
10-
#[derive(Copy, Clone, PartialEq, Debug)]
11-
pub struct f32x2(pub [f32; 2]);
12-
13-
#[repr(simd)]
14-
#[derive(Copy, Clone, PartialEq, Debug)]
15-
pub struct f32x4(pub [f32; 4]);
16-
17-
#[repr(simd)]
18-
#[derive(Copy, Clone, PartialEq, Debug)]
19-
pub struct f32x8(pub [f32; 8]);
7+
#[path = "../../auxiliary/minisimd.rs"]
8+
mod minisimd;
9+
use minisimd::*;
2010

21-
#[repr(simd)]
22-
#[derive(Copy, Clone, PartialEq, Debug)]
23-
pub struct f32x16(pub [f32; 16]);
11+
use std::intrinsics::simd::simd_fabs;
2412

2513
// CHECK-LABEL: @fabs_32x2
2614
#[no_mangle]
@@ -50,18 +38,6 @@ pub unsafe fn fabs_32x16(a: f32x16) -> f32x16 {
5038
simd_fabs(a)
5139
}
5240

53-
#[repr(simd)]
54-
#[derive(Copy, Clone, PartialEq, Debug)]
55-
pub struct f64x2(pub [f64; 2]);
56-
57-
#[repr(simd)]
58-
#[derive(Copy, Clone, PartialEq, Debug)]
59-
pub struct f64x4(pub [f64; 4]);
60-
61-
#[repr(simd)]
62-
#[derive(Copy, Clone, PartialEq, Debug)]
63-
pub struct f64x8(pub [f64; 8]);
64-
6541
// CHECK-LABEL: @fabs_64x4
6642
#[no_mangle]
6743
pub unsafe fn fabs_64x4(a: f64x4) -> f64x4 {

tests/codegen/simd-intrinsic/simd-intrinsic-float-ceil.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@
44
#![feature(repr_simd, core_intrinsics)]
55
#![allow(non_camel_case_types)]
66

7-
use std::intrinsics::simd::simd_ceil;
8-
9-
#[repr(simd)]
10-
#[derive(Copy, Clone, PartialEq, Debug)]
11-
pub struct f32x2(pub [f32; 2]);
12-
13-
#[repr(simd)]
14-
#[derive(Copy, Clone, PartialEq, Debug)]
15-
pub struct f32x4(pub [f32; 4]);
16-
17-
#[repr(simd)]
18-
#[derive(Copy, Clone, PartialEq, Debug)]
19-
pub struct f32x8(pub [f32; 8]);
7+
#[path = "../../auxiliary/minisimd.rs"]
8+
mod minisimd;
9+
use minisimd::*;
2010

21-
#[repr(simd)]
22-
#[derive(Copy, Clone, PartialEq, Debug)]
23-
pub struct f32x16(pub [f32; 16]);
11+
use std::intrinsics::simd::simd_ceil;
2412

2513
// CHECK-LABEL: @ceil_32x2
2614
#[no_mangle]
@@ -50,18 +38,6 @@ pub unsafe fn ceil_32x16(a: f32x16) -> f32x16 {
5038
simd_ceil(a)
5139
}
5240

53-
#[repr(simd)]
54-
#[derive(Copy, Clone, PartialEq, Debug)]
55-
pub struct f64x2(pub [f64; 2]);
56-
57-
#[repr(simd)]
58-
#[derive(Copy, Clone, PartialEq, Debug)]
59-
pub struct f64x4(pub [f64; 4]);
60-
61-
#[repr(simd)]
62-
#[derive(Copy, Clone, PartialEq, Debug)]
63-
pub struct f64x8(pub [f64; 8]);
64-
6541
// CHECK-LABEL: @ceil_64x4
6642
#[no_mangle]
6743
pub unsafe fn ceil_64x4(a: f64x4) -> f64x4 {

tests/codegen/simd-intrinsic/simd-intrinsic-float-cos.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@
44
#![feature(repr_simd, core_intrinsics)]
55
#![allow(non_camel_case_types)]
66

7-
use std::intrinsics::simd::simd_fcos;
8-
9-
#[repr(simd)]
10-
#[derive(Copy, Clone, PartialEq, Debug)]
11-
pub struct f32x2(pub [f32; 2]);
12-
13-
#[repr(simd)]
14-
#[derive(Copy, Clone, PartialEq, Debug)]
15-
pub struct f32x4(pub [f32; 4]);
16-
17-
#[repr(simd)]
18-
#[derive(Copy, Clone, PartialEq, Debug)]
19-
pub struct f32x8(pub [f32; 8]);
7+
#[path = "../../auxiliary/minisimd.rs"]
8+
mod minisimd;
9+
use minisimd::*;
2010

21-
#[repr(simd)]
22-
#[derive(Copy, Clone, PartialEq, Debug)]
23-
pub struct f32x16(pub [f32; 16]);
11+
use std::intrinsics::simd::simd_fcos;
2412

2513
// CHECK-LABEL: @fcos_32x2
2614
#[no_mangle]
@@ -50,18 +38,6 @@ pub unsafe fn fcos_32x16(a: f32x16) -> f32x16 {
5038
simd_fcos(a)
5139
}
5240

53-
#[repr(simd)]
54-
#[derive(Copy, Clone, PartialEq, Debug)]
55-
pub struct f64x2(pub [f64; 2]);
56-
57-
#[repr(simd)]
58-
#[derive(Copy, Clone, PartialEq, Debug)]
59-
pub struct f64x4(pub [f64; 4]);
60-
61-
#[repr(simd)]
62-
#[derive(Copy, Clone, PartialEq, Debug)]
63-
pub struct f64x8(pub [f64; 8]);
64-
6541
// CHECK-LABEL: @fcos_64x4
6642
#[no_mangle]
6743
pub unsafe fn fcos_64x4(a: f64x4) -> f64x4 {

tests/codegen/simd-intrinsic/simd-intrinsic-float-exp.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@
44
#![feature(repr_simd, core_intrinsics)]
55
#![allow(non_camel_case_types)]
66

7-
use std::intrinsics::simd::simd_fexp;
8-
9-
#[repr(simd)]
10-
#[derive(Copy, Clone, PartialEq, Debug)]
11-
pub struct f32x2(pub [f32; 2]);
12-
13-
#[repr(simd)]
14-
#[derive(Copy, Clone, PartialEq, Debug)]
15-
pub struct f32x4(pub [f32; 4]);
16-
17-
#[repr(simd)]
18-
#[derive(Copy, Clone, PartialEq, Debug)]
19-
pub struct f32x8(pub [f32; 8]);
7+
#[path = "../../auxiliary/minisimd.rs"]
8+
mod minisimd;
9+
use minisimd::*;
2010

21-
#[repr(simd)]
22-
#[derive(Copy, Clone, PartialEq, Debug)]
23-
pub struct f32x16(pub [f32; 16]);
11+
use std::intrinsics::simd::simd_fexp;
2412

2513
// CHECK-LABEL: @exp_32x2
2614
#[no_mangle]
@@ -50,18 +38,6 @@ pub unsafe fn exp_32x16(a: f32x16) -> f32x16 {
5038
simd_fexp(a)
5139
}
5240

53-
#[repr(simd)]
54-
#[derive(Copy, Clone, PartialEq, Debug)]
55-
pub struct f64x2(pub [f64; 2]);
56-
57-
#[repr(simd)]
58-
#[derive(Copy, Clone, PartialEq, Debug)]
59-
pub struct f64x4(pub [f64; 4]);
60-
61-
#[repr(simd)]
62-
#[derive(Copy, Clone, PartialEq, Debug)]
63-
pub struct f64x8(pub [f64; 8]);
64-
6541
// CHECK-LABEL: @exp_64x4
6642
#[no_mangle]
6743
pub unsafe fn exp_64x4(a: f64x4) -> f64x4 {

0 commit comments

Comments
 (0)