@@ -42,38 +42,18 @@ macro_rules! swap_bytes {
4242}
4343
4444macro_rules! impl_to_bytes {
45- { $ty: tt, $size: tt } => {
46- impl_to_bytes! { $ty, $size * 1 }
47- impl_to_bytes! { $ty, $size * 2 }
48- impl_to_bytes! { $ty, $size * 4 }
49- impl_to_bytes! { $ty, $size * 8 }
50- impl_to_bytes! { $ty, $size * 16 }
51- impl_to_bytes! { $ty, $size * 32 }
52- impl_to_bytes! { $ty, $size * 64 }
53- } ;
54-
55- // multiply element size by number of elements
56- { $ty: tt, 1 * $elems: literal } => { impl_to_bytes! { @impl [ $ty; $elems] , $elems } } ;
57- { $ty: tt, $size: literal * 1 } => { impl_to_bytes! { @impl [ $ty; 1 ] , $size } } ;
58- { $ty: tt, 2 * 2 } => { impl_to_bytes! { @impl [ $ty; 2 ] , 4 } } ;
59- { $ty: tt, 2 * 4 } => { impl_to_bytes! { @impl [ $ty; 4 ] , 8 } } ;
60- { $ty: tt, 2 * 8 } => { impl_to_bytes! { @impl [ $ty; 8 ] , 16 } } ;
61- { $ty: tt, 2 * 16 } => { impl_to_bytes! { @impl [ $ty; 16 ] , 32 } } ;
62- { $ty: tt, 2 * 32 } => { impl_to_bytes! { @impl [ $ty; 32 ] , 64 } } ;
63- { $ty: tt, 4 * 2 } => { impl_to_bytes! { @impl [ $ty; 2 ] , 8 } } ;
64- { $ty: tt, 4 * 4 } => { impl_to_bytes! { @impl [ $ty; 4 ] , 16 } } ;
65- { $ty: tt, 4 * 8 } => { impl_to_bytes! { @impl [ $ty; 8 ] , 32 } } ;
66- { $ty: tt, 4 * 16 } => { impl_to_bytes! { @impl [ $ty; 16 ] , 64 } } ;
67- { $ty: tt, 8 * 2 } => { impl_to_bytes! { @impl [ $ty; 2 ] , 16 } } ;
68- { $ty: tt, 8 * 4 } => { impl_to_bytes! { @impl [ $ty; 4 ] , 32 } } ;
69- { $ty: tt, 8 * 8 } => { impl_to_bytes! { @impl [ $ty; 8 ] , 64 } } ;
70-
71- // unsupported number of lanes
72- { $ty: ty, $a: literal * $b: literal } => { } ;
73-
74- { @impl [ $ty: tt; $elem: literal] , $bytes: literal } => {
75- impl ToBytes for Simd <$ty, $elem> {
76- type Bytes = Simd <u8 , $bytes>;
45+ { $ty: tt, 1 } => { impl_to_bytes! { $ty, 1 * [ 1 , 2 , 4 , 8 , 16 , 32 , 64 ] } } ;
46+ { $ty: tt, 2 } => { impl_to_bytes! { $ty, 2 * [ 1 , 2 , 4 , 8 , 16 , 32 ] } } ;
47+ { $ty: tt, 4 } => { impl_to_bytes! { $ty, 4 * [ 1 , 2 , 4 , 8 , 16 ] } } ;
48+ { $ty: tt, 8 } => { impl_to_bytes! { $ty, 8 * [ 1 , 2 , 4 , 8 ] } } ;
49+ { $ty: tt, 16 } => { impl_to_bytes! { $ty, 16 * [ 1 , 2 , 4 ] } } ;
50+ { $ty: tt, 32 } => { impl_to_bytes! { $ty, 32 * [ 1 , 2 ] } } ;
51+ { $ty: tt, 64 } => { impl_to_bytes! { $ty, 64 * [ 1 ] } } ;
52+
53+ { $ty: tt, $size: literal * [ $( $elems: literal) ,* ] } => {
54+ $(
55+ impl ToBytes for Simd <$ty, $elems> {
56+ type Bytes = Simd <u8 , { $size * $elems } >;
7757
7858 #[ inline]
7959 fn to_ne_bytes( self ) -> Self :: Bytes {
@@ -123,6 +103,7 @@ macro_rules! impl_to_bytes {
123103 }
124104 }
125105 }
106+ ) *
126107 }
127108}
128109
0 commit comments