2021-05-24 07:37:15 -05:00
|
|
|
macro_rules! impl_to_bytes {
|
2021-07-27 23:19:31 -05:00
|
|
|
{ $name:ident, $size:literal } => {
|
2021-05-24 07:37:15 -05:00
|
|
|
impl<const LANES: usize> crate::$name<LANES>
|
|
|
|
where
|
2021-07-23 21:54:19 -05:00
|
|
|
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
2021-07-27 23:19:31 -05:00
|
|
|
crate::LaneCount<{{ $size * LANES }}>: crate::SupportedLaneCount,
|
2021-05-24 07:37:15 -05:00
|
|
|
{
|
|
|
|
/// Return the memory representation of this integer as a byte array in native byte
|
|
|
|
/// order.
|
2021-07-27 23:19:31 -05:00
|
|
|
pub fn to_ne_bytes(self) -> crate::SimdU8<{{ $size * LANES }}> {
|
|
|
|
unsafe { core::mem::transmute_copy(&self) }
|
|
|
|
}
|
2021-05-24 07:37:15 -05:00
|
|
|
|
|
|
|
/// Create a native endian integer value from its memory representation as a byte array
|
|
|
|
/// in native endianness.
|
2021-07-27 23:19:31 -05:00
|
|
|
pub fn from_ne_bytes(bytes: crate::SimdU8<{{ $size * LANES }}>) -> Self {
|
|
|
|
unsafe { core::mem::transmute_copy(&bytes) }
|
|
|
|
}
|
2021-05-24 07:37:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 23:19:31 -05:00
|
|
|
impl_to_bytes! { SimdU8, 1 }
|
|
|
|
impl_to_bytes! { SimdU16, 2 }
|
|
|
|
impl_to_bytes! { SimdU32, 4 }
|
|
|
|
impl_to_bytes! { SimdU64, 8 }
|
2021-05-24 07:37:15 -05:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
2021-07-27 23:19:31 -05:00
|
|
|
impl_to_bytes! { SimdUsize, 4 }
|
2021-05-24 07:37:15 -05:00
|
|
|
#[cfg(target_pointer_width = "64")]
|
2021-07-27 23:19:31 -05:00
|
|
|
impl_to_bytes! { SimdUsize, 8 }
|
2021-05-24 07:37:15 -05:00
|
|
|
|
2021-07-27 23:19:31 -05:00
|
|
|
impl_to_bytes! { SimdI8, 1 }
|
|
|
|
impl_to_bytes! { SimdI16, 2 }
|
|
|
|
impl_to_bytes! { SimdI32, 4 }
|
|
|
|
impl_to_bytes! { SimdI64, 8 }
|
2021-05-24 07:37:15 -05:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
2021-07-27 23:19:31 -05:00
|
|
|
impl_to_bytes! { SimdIsize, 4 }
|
2021-05-24 07:37:15 -05:00
|
|
|
#[cfg(target_pointer_width = "64")]
|
2021-07-27 23:19:31 -05:00
|
|
|
impl_to_bytes! { SimdIsize, 8 }
|