1 //! Vertical (lane-wise) vector-vector bitwise operations.
2 
3 macro_rules! impl_ops_vector_mask_bitwise {
4     (
5         [$elem_ty:ident; $elem_count:expr]:
6         $id:ident | $test_tt:tt |
7         ($true:expr, $false:expr)
8     ) => {
9         impl crate::ops::Not for $id {
10             type Output = Self;
11             #[inline]
12             fn not(self) -> Self {
13                 Self::splat($true) ^ self
14             }
15         }
16         impl crate::ops::BitXor for $id {
17             type Output = Self;
18             #[inline]
19             fn bitxor(self, other: Self) -> Self {
20                 use crate::llvm::simd_xor;
21                 unsafe { Simd(simd_xor(self.0, other.0)) }
22             }
23         }
24         impl crate::ops::BitAnd for $id {
25             type Output = Self;
26             #[inline]
27             fn bitand(self, other: Self) -> Self {
28                 use crate::llvm::simd_and;
29                 unsafe { Simd(simd_and(self.0, other.0)) }
30             }
31         }
32         impl crate::ops::BitOr for $id {
33             type Output = Self;
34             #[inline]
35             fn bitor(self, other: Self) -> Self {
36                 use crate::llvm::simd_or;
37                 unsafe { Simd(simd_or(self.0, other.0)) }
38             }
39         }
40         impl crate::ops::BitAndAssign for $id {
41             #[inline]
42             fn bitand_assign(&mut self, other: Self) {
43                 *self = *self & other;
44             }
45         }
46         impl crate::ops::BitOrAssign for $id {
47             #[inline]
48             fn bitor_assign(&mut self, other: Self) {
49                 *self = *self | other;
50             }
51         }
52         impl crate::ops::BitXorAssign for $id {
53             #[inline]
54             fn bitxor_assign(&mut self, other: Self) {
55                 *self = *self ^ other;
56             }
57         }
58 
59         test_if!{
60             $test_tt:
61             paste::item! {
62                 pub mod [<$id _ops_vector_mask_bitwise>] {
63                     use super::*;
64                     #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
65                     fn ops_vector_mask_bitwise() {
66                         let t = $id::splat(true);
67                         let f = $id::splat(false);
68                         assert!(t != f);
69                         assert!(!(t == f));
70 
71                         // Not:
72                         assert_eq!(!t, f);
73                         assert_eq!(t, !f);
74 
75                         // BitAnd:
76                         assert_eq!(t & f, f);
77                         assert_eq!(f & t, f);
78                         assert_eq!(t & t, t);
79                         assert_eq!(f & f, f);
80 
81                         // BitOr:
82                         assert_eq!(t | f, t);
83                         assert_eq!(f | t, t);
84                         assert_eq!(t | t, t);
85                         assert_eq!(f | f, f);
86 
87                         // BitXOR:
88                         assert_eq!(t ^ f, t);
89                         assert_eq!(f ^ t, t);
90                         assert_eq!(t ^ t, f);
91                         assert_eq!(f ^ f, f);
92 
93                         {
94                             // AndAssign:
95                             let mut v = f;
96                             v &= t;
97                             assert_eq!(v, f);
98                         }
99                         {
100                             // OrAssign:
101                             let mut v = f;
102                             v |= t;
103                             assert_eq!(v, t);
104                         }
105                         {
106                             // XORAssign:
107                             let mut v = f;
108                             v ^= t;
109                             assert_eq!(v, t);
110                         }
111                     }
112                 }
113             }
114         }
115     };
116 }
117