| 1 |
use crate::vector::{V128, V256, V512, V64}; |
| 2 |
|
| 3 |
pub unsafe trait POD: Copy + 'static { |
| 4 |
const ID: PodTypeId; |
| 5 |
} |
| 6 |
|
| 7 |
macro_rules! mark_pod { |
| 8 |
($($ty:ident),*) => { |
| 9 |
$( |
| 10 |
unsafe impl POD for $ty { |
| 11 |
const ID: PodTypeId = PodTypeId::$ty; |
| 12 |
} |
| 13 |
)* |
| 14 |
}; |
| 15 |
} |
| 16 |
|
| 17 |
mark_pod!(u8, u16, u32, u64, u128, usize); |
| 18 |
mark_pod!(i8, i16, i32, i64, i128, isize); |
| 19 |
mark_pod!(f32, f64); |
| 20 |
mark_pod!(V64, V128, V256, V512); |
| 21 |
|
| 22 |
#[inline(always)] |
| 23 |
pub fn align<T: POD, U: POD>(slice: &[T]) -> (&[T], &[U], &[T]) { |
| 24 |
unsafe { slice.align_to() } |
| 25 |
} |
| 26 |
|
| 27 |
#[allow(non_camel_case_types)] |
| 28 |
#[derive(Debug, Clone, Copy)] |
| 29 |
pub enum PodTypeId { |
| 30 |
u8, |
| 31 |
u16, |
| 32 |
u32, |
| 33 |
u64, |
| 34 |
u128, |
| 35 |
usize, |
| 36 |
|
| 37 |
i8, |
| 38 |
i16, |
| 39 |
i32, |
| 40 |
i64, |
| 41 |
i128, |
| 42 |
isize, |
| 43 |
|
| 44 |
f32, |
| 45 |
f64, |
| 46 |
|
| 47 |
V64, |
| 48 |
V128, |
| 49 |
V256, |
| 50 |
V512, |
| 51 |
} |
| 52 |
|
| 53 |
#[macro_export] |
| 54 |
macro_rules! is_pod_type { |
| 55 |
($self:ident, $x:ident $(| $xs:ident)*) => {{ |
| 56 |
// TODO: inline const |
| 57 |
use $crate::pod::POD; |
| 58 |
struct IsPodType<T>(T); |
| 59 |
impl <T: POD> IsPodType<T> { |
| 60 |
const VALUE: bool = { matches!(<T as POD>::ID, $crate::pod::PodTypeId::$x $(| $crate::pod::PodTypeId::$xs)*) }; |
| 61 |
} |
| 62 |
IsPodType::<$self>::VALUE |
| 63 |
}}; |
| 64 |
} |