1 #![allow(clippy::undocumented_unsafe_blocks)]
2 #![allow(dead_code)]
3 // TODO: Remove once the transmutes are fixed
4 #![allow(unknown_lints)]
5 #![allow(clippy::missing_transmute_annotations)]
6 
7 use core::cmp::Ordering;
8 use core::hash::{Hash, Hasher};
9 
10 #[cfg(all(
11     not(all(target_family = "wasm", target_feature = "simd128")),
12     not(target_feature = "sse2"),
13     not(target_feature = "avx"),
14     not(target_feature = "avx2"),
15 ))]
16 mod default;
17 #[cfg(all(
18     not(all(target_family = "wasm", target_feature = "simd128")),
19     not(target_feature = "sse2"),
20     not(target_feature = "avx"),
21     not(target_feature = "avx2"),
22 ))]
23 pub use self::default::*;
24 
25 #[cfg(all(
26     any(target_arch = "x86", target_arch = "x86_64"),
27     target_feature = "sse2",
28     not(target_feature = "avx"),
29     not(target_feature = "avx2"),
30 ))]
31 mod sse2;
32 #[cfg(all(
33     any(target_arch = "x86", target_arch = "x86_64"),
34     target_feature = "sse2",
35     not(target_feature = "avx"),
36     not(target_feature = "avx2"),
37 ))]
38 pub use self::sse2::*;
39 
40 #[cfg(all(
41     any(target_arch = "x86", target_arch = "x86_64"),
42     target_feature = "avx",
43     not(target_feature = "avx2")
44 ))]
45 mod avx;
46 #[cfg(all(
47     any(target_arch = "x86", target_arch = "x86_64"),
48     target_feature = "avx",
49     not(target_feature = "avx2")
50 ))]
51 pub use self::avx::*;
52 
53 #[cfg(all(
54     any(target_arch = "x86", target_arch = "x86_64"),
55     target_feature = "avx2"
56 ))]
57 mod avx2;
58 #[cfg(all(
59     any(target_arch = "x86", target_arch = "x86_64"),
60     target_feature = "avx2"
61 ))]
62 pub use self::avx2::*;
63 
64 #[cfg(all(target_family = "wasm", target_feature = "simd128"))]
65 mod wasm;
66 #[cfg(all(target_family = "wasm", target_feature = "simd128"))]
67 pub use self::wasm::*;
68 
69 impl Block {
70     pub const USIZE_COUNT: usize = core::mem::size_of::<Self>() / core::mem::size_of::<usize>();
71     pub const NONE: Self = Self::from_usize_array([0; Self::USIZE_COUNT]);
72     pub const ALL: Self = Self::from_usize_array([usize::MAX; Self::USIZE_COUNT]);
73     pub const BITS: usize = core::mem::size_of::<Self>() * 8;
74 
75     #[inline]
into_usize_array(self) -> [usize; Self::USIZE_COUNT]76     pub fn into_usize_array(self) -> [usize; Self::USIZE_COUNT] {
77         unsafe { core::mem::transmute(self.0) }
78     }
79 
80     #[inline]
from_usize_array(array: [usize; Self::USIZE_COUNT]) -> Self81     pub const fn from_usize_array(array: [usize; Self::USIZE_COUNT]) -> Self {
82         Self(unsafe { core::mem::transmute(array) })
83     }
84 }
85 
86 impl Eq for Block {}
87 
88 impl PartialOrd for Block {
89     #[inline]
partial_cmp(&self, other: &Self) -> Option<Ordering>90     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
91         Some(self.cmp(other))
92     }
93 }
94 
95 impl Ord for Block {
96     #[inline]
cmp(&self, other: &Self) -> Ordering97     fn cmp(&self, other: &Self) -> Ordering {
98         self.into_usize_array().cmp(&other.into_usize_array())
99     }
100 }
101 
102 impl Default for Block {
103     #[inline]
default() -> Self104     fn default() -> Self {
105         Self::NONE
106     }
107 }
108 
109 impl Hash for Block {
110     #[inline]
hash<H: Hasher>(&self, hasher: &mut H)111     fn hash<H: Hasher>(&self, hasher: &mut H) {
112         Hash::hash_slice(&self.into_usize_array(), hasher);
113     }
114 }
115