Skip to content

Commit 0031b02

Browse files
Add core_simd/tests/cast.rs
1 parent a991d48 commit 0031b02

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

crates/core_simd/tests/cast.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![feature(portable_simd)]
2+
macro_rules! cast_types {
3+
($start:ident, $($target:ident),*) => {
4+
mod $start {
5+
use core_simd::simd::Simd;
6+
type Vector<const N: usize> = Simd<$start, N>;
7+
$(
8+
mod $target {
9+
use super::*;
10+
test_helpers::test_lanes! {
11+
fn cast_as<const N: usize>() {
12+
test_helpers::test_unary_elementwise(
13+
&Vector::<N>::cast::<$target>,
14+
&|x| x as $target,
15+
&|_| true,
16+
)
17+
}
18+
}
19+
}
20+
)*
21+
}
22+
};
23+
}
24+
25+
// The hypothesis is that widening conversions aren't terribly interesting.
26+
cast_types!(f32, f64, i8, u8, usize, isize);
27+
cast_types!(f64, f32, i8, u8, usize, isize);
28+
cast_types!(i8, u8, f32);
29+
cast_types!(u8, i8, f32);
30+
cast_types!(i16, u16, i8, u8, f32);
31+
cast_types!(u16, i16, i8, u8, f32);
32+
cast_types!(i32, u32, i8, u8, f32, f64);
33+
cast_types!(u32, i32, i8, u8, f32, f64);
34+
cast_types!(i64, u64, i8, u8, isize, usize, f32, f64);
35+
cast_types!(u64, i64, i8, u8, isize, usize, f32, f64);
36+
cast_types!(isize, usize, i8, u8, f32, f64);
37+
cast_types!(usize, isize, i8, u8, f32, f64);

0 commit comments

Comments
 (0)