blake2/simd/
simdty.rs
1#![allow(dead_code, non_camel_case_types)]
9
10use crate::as_bytes::Safe;
11
12#[cfg(feature = "simd")]
13macro_rules! decl_simd {
14 ($($decl:item)*) => {
15 $(
16 #[derive(Clone, Copy, Debug)]
17 #[repr(simd)]
18 $decl
19 )*
20 }
21}
22
23#[cfg(not(feature = "simd"))]
24macro_rules! decl_simd {
25 ($($decl:item)*) => {
26 $(
27 #[derive(Clone, Copy, Debug)]
28 #[repr(C)]
29 $decl
30 )*
31 }
32}
33
34decl_simd! {
35 pub struct Simd2<T>(pub T, pub T);
36 pub struct Simd4<T>(pub T, pub T, pub T, pub T);
37 pub struct Simd8<T>(pub T, pub T, pub T, pub T,
38 pub T, pub T, pub T, pub T);
39 pub struct Simd16<T>(pub T, pub T, pub T, pub T,
40 pub T, pub T, pub T, pub T,
41 pub T, pub T, pub T, pub T,
42 pub T, pub T, pub T, pub T);
43 pub struct Simd32<T>(pub T, pub T, pub T, pub T,
44 pub T, pub T, pub T, pub T,
45 pub T, pub T, pub T, pub T,
46 pub T, pub T, pub T, pub T,
47 pub T, pub T, pub T, pub T,
48 pub T, pub T, pub T, pub T,
49 pub T, pub T, pub T, pub T,
50 pub T, pub T, pub T, pub T);
51}
52
53pub type u64x2 = Simd2<u64>;
54
55pub type u32x4 = Simd4<u32>;
56pub type u64x4 = Simd4<u64>;
57
58pub type u16x8 = Simd8<u16>;
59pub type u32x8 = Simd8<u32>;
60
61pub type u8x16 = Simd16<u8>;
62pub type u16x16 = Simd16<u16>;
63
64pub type u8x32 = Simd32<u8>;
65
66impl<T> Simd4<T> {
67 #[inline(always)]
68 pub fn new(e0: T, e1: T, e2: T, e3: T) -> Simd4<T> {
69 Simd4(e0, e1, e2, e3)
70 }
71}
72
73unsafe impl<T: Safe> Safe for Simd2<T> {}
74unsafe impl<T: Safe> Safe for Simd4<T> {}
75unsafe impl<T: Safe> Safe for Simd8<T> {}
76unsafe impl<T: Safe> Safe for Simd16<T> {}
77unsafe impl<T: Safe> Safe for Simd32<T> {}