]> git.proxmox.com Git - rustc.git/blob - vendor/packed_simd/src/api/from/from_vector.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / vendor / packed_simd / src / api / from / from_vector.rs
1 //! Implements `From` and `Into` for vector types.
2
3 macro_rules! impl_from_vector {
4 ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt
5 | $source:ident) => {
6 impl From<$source> for $id {
7 #[inline]
8 fn from(source: $source) -> Self {
9 fn static_assert_same_number_of_lanes<T, U>()
10 where
11 T: crate::sealed::Simd,
12 U: crate::sealed::Simd<LanesType = T::LanesType>,
13 {
14 }
15 use crate::llvm::simd_cast;
16 static_assert_same_number_of_lanes::<$id, $source>();
17 Simd(unsafe { simd_cast(source.0) })
18 }
19 }
20
21 // FIXME: `Into::into` is not inline, but due to the blanket impl in
22 // `std`, which is not marked `default`, we cannot override it here
23 // with specialization.
24
25 /*
26 impl Into<$id> for $source {
27 #[inline]
28 fn into(self) -> $id {
29 unsafe { simd_cast(self) }
30 }
31 }
32 */
33
34 test_if! {
35 $test_tt:
36 paste::item! {
37 pub mod [<$id _from_ $source>] {
38 use super::*;
39 #[cfg_attr(not(target_arch = "wasm32"), test)]
40 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
41 fn from() {
42 assert_eq!($id::lanes(), $source::lanes());
43 let source: $source = Default::default();
44 let vec: $id = Default::default();
45
46 let e = $id::from(source);
47 assert_eq!(e, vec);
48
49 let e: $id = source.into();
50 assert_eq!(e, vec);
51 }
52 }
53 }
54 }
55 };
56 }
57
58 macro_rules! impl_from_vectors {
59 ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt
60 | $($source:ident),*) => {
61 $(
62 impl_from_vector!(
63 [$elem_ty; $elem_count]: $id | $test_tt | $source
64 );
65 )*
66 }
67 }