| 1 |
use wide::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn size_align() { |
| 5 |
assert_eq!(core::mem::size_of::<u8x32>(), 32); |
| 6 |
assert_eq!(core::mem::align_of::<u8x32>(), 32); |
| 7 |
} |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn impl_add_for_u8x32() { |
| 11 |
crate::test_random_vector_vs_scalar( |
| 12 |
|a: u8x32, b| a + b, |
| 13 |
|a, b| a.wrapping_add(b), |
| 14 |
); |
| 15 |
} |
| 16 |
|
| 17 |
#[test] |
| 18 |
fn impl_sub_for_u8x32() { |
| 19 |
crate::test_random_vector_vs_scalar( |
| 20 |
|a: u8x32, b| a - b, |
| 21 |
|a, b| a.wrapping_sub(b), |
| 22 |
); |
| 23 |
} |
| 24 |
|
| 25 |
#[test] |
| 26 |
fn impl_saturating_add_for_u8x32() { |
| 27 |
crate::test_random_vector_vs_scalar( |
| 28 |
|a: u8x32, b| a.saturating_add(b), |
| 29 |
|a, b| a.saturating_add(b), |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
#[test] |
| 34 |
fn impl_saturating_sub_for_u8x32() { |
| 35 |
crate::test_random_vector_vs_scalar( |
| 36 |
|a: u8x32, b| a.saturating_sub(b), |
| 37 |
|a, b| a.saturating_sub(b), |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
#[test] |
| 42 |
fn impl_bitand_for_u8x32() { |
| 43 |
let a = u8x32::from([ |
| 44 |
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
| 45 |
0, 1, 1, 0, 0, 1, 1, |
| 46 |
]); |
| 47 |
let b = u8x32::from([ |
| 48 |
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
| 49 |
0, 1, 1, 0, 0, 1, 1, |
| 50 |
]); |
| 51 |
let expected = u8x32::from([ |
| 52 |
0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
| 53 |
0, 1, 1, 0, 0, 1, 1, |
| 54 |
]); |
| 55 |
let actual = a & b; |
| 56 |
assert_eq!(expected, actual); |
| 57 |
} |
| 58 |
|
| 59 |
#[test] |
| 60 |
fn impl_bitor_for_u8x32() { |
| 61 |
let a = u8x32::from([ |
| 62 |
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
| 63 |
0, 1, 1, 0, 0, 1, 1, |
| 64 |
]); |
| 65 |
let b = u8x32::from([ |
| 66 |
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, |
| 67 |
1, 0, 1, 0, 1, 0, 1, |
| 68 |
]); |
| 69 |
let expected = u8x32::from([ |
| 70 |
0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, |
| 71 |
1, 1, 1, 0, 1, 1, 1, |
| 72 |
]); |
| 73 |
let actual = a | b; |
| 74 |
assert_eq!(expected, actual); |
| 75 |
} |
| 76 |
|
| 77 |
#[test] |
| 78 |
fn impl_bitxor_for_u8x32() { |
| 79 |
let a = u8x32::from([ |
| 80 |
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
| 81 |
0, 1, 1, 0, 0, 1, 1, |
| 82 |
]); |
| 83 |
let b = u8x32::from([ |
| 84 |
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
| 85 |
0, 1, 1, 0, 0, 1, 1, |
| 86 |
]); |
| 87 |
let expected = u8x32::from([ |
| 88 |
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 89 |
0, 0, 0, 0, 0, 0, 0, |
| 90 |
]); |
| 91 |
let actual = a ^ b; |
| 92 |
assert_eq!(expected, actual); |
| 93 |
} |
| 94 |
|
| 95 |
#[test] |
| 96 |
fn impl_u8x32_cmp_eq() { |
| 97 |
let a = u8x32::from([ |
| 98 |
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, |
| 99 |
2, 3, 4, 1, 2, 3, 4, |
| 100 |
]); |
| 101 |
let b = u8x32::from([2_u8; 32]); |
| 102 |
let expected = u8x32::from([ |
| 103 |
0, 0xff, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0, 0, |
| 104 |
0, 0xff, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0, 0, |
| 105 |
]); |
| 106 |
let actual = a.cmp_eq(b); |
| 107 |
assert_eq!(expected, actual); |
| 108 |
} |
| 109 |
|
| 110 |
#[test] |
| 111 |
fn impl_u8x32_blend() { |
| 112 |
let use_t: u8 = 0xff; |
| 113 |
let t = u8x32::from([ |
| 114 |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127, 1, 2, 3, 4, 5, 6, |
| 115 |
7, 8, 9, 10, 11, 12, 13, 14, 126, 127, |
| 116 |
]); |
| 117 |
let f = u8x32::from([ |
| 118 |
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1, 17, 18, 19, |
| 119 |
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1, |
| 120 |
]); |
| 121 |
let mask = u8x32::from([ |
| 122 |
use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, |
| 123 |
use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, |
| 124 |
use_t, 0, use_t, 0, |
| 125 |
]); |
| 126 |
let expected = u8x32::from([ |
| 127 |
1, 18, 3, 20, 5, 22, 7, 24, 9, 26, 11, 28, 13, 30, 126, 1, 1, 18, 3, 20, 5, |
| 128 |
22, 7, 24, 9, 26, 11, 28, 13, 30, 126, 1, |
| 129 |
]); |
| 130 |
let actual = mask.blend(t, f); |
| 131 |
assert_eq!(expected, actual); |
| 132 |
} |
| 133 |
|
| 134 |
#[test] |
| 135 |
fn impl_u8x32_max() { |
| 136 |
crate::test_random_vector_vs_scalar(|a: u8x32, b| a.max(b), |a, b| a.max(b)); |
| 137 |
} |
| 138 |
|
| 139 |
#[test] |
| 140 |
fn impl_u8x32_min() { |
| 141 |
crate::test_random_vector_vs_scalar(|a: u8x32, b| a.min(b), |a, b| a.min(b)); |
| 142 |
} |
| 143 |
|
| 144 |
#[test] |
| 145 |
fn test_u8x32_move_mask() { |
| 146 |
let a = u8x32::from([ |
| 147 |
0xff, 0, 0x82, 0x83, 0xff, 0, 0x82, 0x83, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, |
| 148 |
0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0xff, 0, 0xff, 0, 0xff, 0, |
| 149 |
0xff, 0, |
| 150 |
]); |
| 151 |
let expected = 0b01010101011111110101010111011101; |
| 152 |
let actual = a.move_mask(); |
| 153 |
assert_eq!(expected, actual); |
| 154 |
} |
| 155 |
|
| 156 |
#[test] |
| 157 |
fn test_u8x32_any() { |
| 158 |
let a = u8x32::from([ |
| 159 |
0, 0, 0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 160 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 161 |
]); |
| 162 |
assert!(a.any()); |
| 163 |
|
| 164 |
let a = u8x32::from([ |
| 165 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 166 |
0, 0, 0, 0xff, 0, 0, 0, |
| 167 |
]); |
| 168 |
assert!(a.any()); |
| 169 |
|
| 170 |
// |
| 171 |
let a = u8x32::from([0; 32]); |
| 172 |
assert!(!a.any()); |
| 173 |
} |
| 174 |
|
| 175 |
#[test] |
| 176 |
fn test_u8x32_all() { |
| 177 |
let a = u8x32::from([ |
| 178 |
0, 0, 0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 179 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 180 |
]); |
| 181 |
assert!(!a.all()); |
| 182 |
// |
| 183 |
let a = u8x32::from([0xff; 32]); |
| 184 |
assert!(a.all()); |
| 185 |
} |
| 186 |
|
| 187 |
#[test] |
| 188 |
fn test_u8x32_none() { |
| 189 |
let a = u8x32::from([ |
| 190 |
0, 0, 0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 191 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 192 |
]); |
| 193 |
assert!(!a.none()); |
| 194 |
|
| 195 |
let a = u8x32::from([ |
| 196 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 197 |
0, 0, 0, 0xff, 0, 0, 0, |
| 198 |
]); |
| 199 |
assert!(!a.none()); |
| 200 |
|
| 201 |
// |
| 202 |
let a = u8x32::from([0; 32]); |
| 203 |
assert!(a.none()); |
| 204 |
} |
| 205 |
|
| 206 |
#[cfg(feature = "serde")] |
| 207 |
#[test] |
| 208 |
fn impl_u8x32_ser_de_roundtrip() { |
| 209 |
let serialized = |
| 210 |
bincode::serialize(&u8x32::ZERO).expect("serialization failed"); |
| 211 |
let deserialized = |
| 212 |
bincode::deserialize(&serialized).expect("deserializaion failed"); |
| 213 |
assert_eq!(u8x32::ZERO, deserialized); |
| 214 |
} |