|
1 | | -/// Provides implementations of `From<$a> for $b` and `From<$b> for $a` that transmutes the value. |
2 | | -macro_rules! from_transmute { |
3 | | - { unsafe $a:ty => $b:ty } => { |
4 | | - from_transmute!{ @impl $a => $b } |
5 | | - from_transmute!{ @impl $b => $a } |
6 | | - }; |
7 | | - { @impl $from:ty => $to:ty } => { |
8 | | - impl core::convert::From<$from> for $to { |
9 | | - #[inline] |
10 | | - fn from(value: $from) -> $to { |
11 | | - unsafe { core::mem::transmute(value) } |
12 | | - } |
13 | | - } |
14 | | - }; |
15 | | -} |
16 | | - |
17 | | -/// Provides implementations of `From<$generic> for core::arch::{x86, x86_64}::$intel` and |
18 | | -/// vice-versa that transmutes the value. |
19 | | -macro_rules! from_transmute_x86 { |
20 | | - { unsafe $generic:ty => $intel:ident } => { |
21 | | - #[cfg(target_arch = "x86")] |
22 | | - from_transmute! { unsafe $generic => core::arch::x86::$intel } |
23 | | - |
24 | | - #[cfg(target_arch = "x86_64")] |
25 | | - from_transmute! { unsafe $generic => core::arch::x86_64::$intel } |
26 | | - } |
27 | | -} |
28 | | - |
29 | 1 | /// Implements common traits on the specified vector `$name`, holding multiple `$lanes` of `$type`. |
30 | 2 | macro_rules! impl_vector { |
31 | 3 | { $name:ident, $type:ty } => { |
@@ -150,69 +122,3 @@ macro_rules! impl_vector { |
150 | 122 | impl_shuffle_2pow_lanes!{ $name } |
151 | 123 | } |
152 | 124 | } |
153 | | - |
154 | | -/// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`. |
155 | | -macro_rules! impl_integer_vector { |
156 | | - { $name:ident, $type:ty } => { |
157 | | - impl_vector! { $name, $type } |
158 | | - |
159 | | - impl<const LANES: usize> Eq for $name<LANES> where Self: crate::LanesAtMost64 {} |
160 | | - |
161 | | - impl<const LANES: usize> Ord for $name<LANES> where Self: crate::LanesAtMost64 { |
162 | | - #[inline] |
163 | | - fn cmp(&self, other: &Self) -> core::cmp::Ordering { |
164 | | - // TODO use SIMD cmp |
165 | | - self.to_array().cmp(other.as_ref()) |
166 | | - } |
167 | | - } |
168 | | - |
169 | | - impl<const LANES: usize> core::hash::Hash for $name<LANES> where Self: crate::LanesAtMost64 { |
170 | | - #[inline] |
171 | | - fn hash<H>(&self, state: &mut H) |
172 | | - where |
173 | | - H: core::hash::Hasher |
174 | | - { |
175 | | - self.as_slice().hash(state) |
176 | | - } |
177 | | - } |
178 | | - } |
179 | | -} |
180 | | - |
181 | | -/// Implements inherent methods for a float vector `$name` containing multiple |
182 | | -/// `$lanes` of float `$type`, which uses `$bits_ty` as its binary |
183 | | -/// representation. Called from `define_float_vector!`. |
184 | | -macro_rules! impl_float_vector { |
185 | | - { $name:ident, $type:ty, $bits_ty:ident } => { |
186 | | - impl_vector! { $name, $type } |
187 | | - |
188 | | - impl<const LANES: usize> $name<LANES> |
189 | | - where |
190 | | - Self: crate::LanesAtMost64, |
191 | | - crate::$bits_ty<LANES>: crate::LanesAtMost64, |
192 | | - { |
193 | | - /// Raw transmutation to an unsigned integer vector type with the |
194 | | - /// same size and number of lanes. |
195 | | - #[inline] |
196 | | - pub fn to_bits(self) -> crate::$bits_ty<LANES> { |
197 | | - assert_eq!(core::mem::size_of::<Self>(), core::mem::size_of::<crate::$bits_ty<LANES>>()); |
198 | | - unsafe { core::mem::transmute_copy(&self) } |
199 | | - } |
200 | | - |
201 | | - /// Raw transmutation from an unsigned integer vector type with the |
202 | | - /// same size and number of lanes. |
203 | | - #[inline] |
204 | | - pub fn from_bits(bits: crate::$bits_ty<LANES>) -> Self { |
205 | | - assert_eq!(core::mem::size_of::<Self>(), core::mem::size_of::<crate::$bits_ty<LANES>>()); |
206 | | - unsafe { core::mem::transmute_copy(&bits) } |
207 | | - } |
208 | | - |
209 | | - /// Produces a vector where every lane has the absolute value of the |
210 | | - /// equivalently-indexed lane in `self`. |
211 | | - #[inline] |
212 | | - pub fn abs(self) -> Self { |
213 | | - let no_sign = crate::$bits_ty::splat(!0 >> 1); |
214 | | - Self::from_bits(self.to_bits() & no_sign) |
215 | | - } |
216 | | - } |
217 | | - }; |
218 | | -} |
0 commit comments