]> git.proxmox.com Git - rustc.git/blame - vendor/packed_simd_2/src/api/ops/scalar_mask_bitwise.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / vendor / packed_simd_2 / src / api / ops / scalar_mask_bitwise.rs
CommitLineData
f20569fa
XL
1//! Vertical (lane-wise) vector-vector bitwise operations.
2
3macro_rules! impl_ops_scalar_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::BitXor<bool> for $id {
10 type Output = Self;
11 #[inline]
12 fn bitxor(self, other: bool) -> Self {
13 self ^ $id::splat(other)
14 }
15 }
16 impl crate::ops::BitXor<$id> for bool {
17 type Output = $id;
18 #[inline]
19 fn bitxor(self, other: $id) -> $id {
20 $id::splat(self) ^ other
21 }
22 }
23
24 impl crate::ops::BitAnd<bool> for $id {
25 type Output = Self;
26 #[inline]
27 fn bitand(self, other: bool) -> Self {
28 self & $id::splat(other)
29 }
30 }
31 impl crate::ops::BitAnd<$id> for bool {
32 type Output = $id;
33 #[inline]
34 fn bitand(self, other: $id) -> $id {
35 $id::splat(self) & other
36 }
37 }
38
39 impl crate::ops::BitOr<bool> for $id {
40 type Output = Self;
41 #[inline]
42 fn bitor(self, other: bool) -> Self {
43 self | $id::splat(other)
44 }
45 }
46 impl crate::ops::BitOr<$id> for bool {
47 type Output = $id;
48 #[inline]
49 fn bitor(self, other: $id) -> $id {
50 $id::splat(self) | other
51 }
52 }
53
54 impl crate::ops::BitAndAssign<bool> for $id {
55 #[inline]
56 fn bitand_assign(&mut self, other: bool) {
57 *self = *self & other;
58 }
59 }
60 impl crate::ops::BitOrAssign<bool> for $id {
61 #[inline]
62 fn bitor_assign(&mut self, other: bool) {
63 *self = *self | other;
64 }
65 }
66 impl crate::ops::BitXorAssign<bool> for $id {
67 #[inline]
68 fn bitxor_assign(&mut self, other: bool) {
69 *self = *self ^ other;
70 }
71 }
72
73 test_if!{
74 $test_tt:
75 paste::item! {
76 pub mod [<$id _ops_scalar_mask_bitwise>] {
77 use super::*;
78 #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
79 fn ops_scalar_mask_bitwise() {
80 let ti = true;
81 let fi = false;
82 let t = $id::splat(ti);
83 let f = $id::splat(fi);
84 assert!(t != f);
85 assert!(!(t == f));
86
87 // BitAnd:
88 assert_eq!(ti & f, f);
89 assert_eq!(t & fi, f);
90 assert_eq!(fi & t, f);
91 assert_eq!(f & ti, f);
92 assert_eq!(ti & t, t);
93 assert_eq!(t & ti, t);
94 assert_eq!(fi & f, f);
95 assert_eq!(f & fi, f);
96
97 // BitOr:
98 assert_eq!(ti | f, t);
99 assert_eq!(t | fi, t);
100 assert_eq!(fi | t, t);
101 assert_eq!(f | ti, t);
102 assert_eq!(ti | t, t);
103 assert_eq!(t | ti, t);
104 assert_eq!(fi | f, f);
105 assert_eq!(f | fi, f);
106
107 // BitXOR:
108 assert_eq!(ti ^ f, t);
109 assert_eq!(t ^ fi, t);
110 assert_eq!(fi ^ t, t);
111 assert_eq!(f ^ ti, t);
112 assert_eq!(ti ^ t, f);
113 assert_eq!(t ^ ti, f);
114 assert_eq!(fi ^ f, f);
115 assert_eq!(f ^ fi, f);
116
117 {
118 // AndAssign:
119 let mut v = f;
120 v &= ti;
121 assert_eq!(v, f);
122 }
123 {
124 // OrAssign:
125 let mut v = f;
126 v |= ti;
127 assert_eq!(v, t);
128 }
129 {
130 // XORAssign:
131 let mut v = f;
132 v ^= ti;
133 assert_eq!(v, t);
134 }
135 }
136 }
137 }
138 }
139 };
140}