| 1 |
use wide::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn size_align() { |
| 5 |
assert_eq!(core::mem::size_of::<u8x16>(), 16); |
| 6 |
assert_eq!(core::mem::align_of::<u8x16>(), 16); |
| 7 |
} |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn basic_traits() { |
| 11 |
crate::test_basic_traits::<u8x16, _, 16>(); |
| 12 |
} |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn impl_add_for_u8x16() { |
| 16 |
let a = |
| 17 |
u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 250, 250]); |
| 18 |
let b = |
| 19 |
u8x16::from([17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 5, 6]); |
| 20 |
let expected = u8x16::from([ |
| 21 |
18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 255, 0, |
| 22 |
]); |
| 23 |
let actual = a + b; |
| 24 |
assert_eq!(expected, actual); |
| 25 |
|
| 26 |
crate::test_random_vector_vs_scalar( |
| 27 |
|a: u8x16, b| a + b, |
| 28 |
|a, b| a.wrapping_add(b), |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn impl_sub_for_u8x16() { |
| 34 |
let a = u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 0]); |
| 35 |
let b = |
| 36 |
u8x16::from([170, 18, 10, 200, 241, 2, 93, 4, 12, 8, 27, 28, 29, 30, 1, 1]); |
| 37 |
let expected = u8x16::from([ |
| 38 |
87, |
| 39 |
240, |
| 40 |
249, |
| 41 |
60, |
| 42 |
20, |
| 43 |
4, |
| 44 |
170, |
| 45 |
4, |
| 46 |
253, |
| 47 |
2, |
| 48 |
240, |
| 49 |
240, |
| 50 |
240, |
| 51 |
240, |
| 52 |
0, |
| 53 |
u8::MAX, |
| 54 |
]); |
| 55 |
let actual = a - b; |
| 56 |
assert_eq!(expected, actual); |
| 57 |
|
| 58 |
crate::test_random_vector_vs_scalar( |
| 59 |
|a: u8x16, b| a - b, |
| 60 |
|a, b| a.wrapping_sub(b), |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
#[test] |
| 65 |
fn impl_saturating_add_for_u8x16() { |
| 66 |
let a = |
| 67 |
u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 250, 250]); |
| 68 |
let b = |
| 69 |
u8x16::from([17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 5, 6]); |
| 70 |
let expected = u8x16::from([ |
| 71 |
18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 255, 255, |
| 72 |
]); |
| 73 |
let actual = a.saturating_add(b); |
| 74 |
assert_eq!(expected, actual); |
| 75 |
|
| 76 |
crate::test_random_vector_vs_scalar( |
| 77 |
|a: u8x16, b| a.saturating_add(b), |
| 78 |
|a, b| a.saturating_add(b), |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
#[test] |
| 83 |
fn impl_saturating_sub_for_u8x16() { |
| 84 |
let a = u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 0]); |
| 85 |
let b = |
| 86 |
u8x16::from([170, 18, 10, 200, 241, 2, 93, 4, 12, 8, 27, 28, 29, 30, 1, 1]); |
| 87 |
let expected = u8x16::from([0, 0, 0, 0, 0, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0, 0]); |
| 88 |
let actual = a.saturating_sub(b); |
| 89 |
assert_eq!(expected, actual); |
| 90 |
|
| 91 |
crate::test_random_vector_vs_scalar( |
| 92 |
|a: u8x16, b| a.saturating_sub(b), |
| 93 |
|a, b| a.saturating_sub(b), |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
#[test] |
| 98 |
fn impl_bitand_for_u8x16() { |
| 99 |
let a = u8x16::from([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); |
| 100 |
let b = u8x16::from([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]); |
| 101 |
let expected = u8x16::from([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]); |
| 102 |
let actual = a & b; |
| 103 |
assert_eq!(expected, actual); |
| 104 |
|
| 105 |
crate::test_random_vector_vs_scalar(|a: u8x16, b| a & b, |a, b| a & b); |
| 106 |
} |
| 107 |
|
| 108 |
#[test] |
| 109 |
fn impl_bitor_for_u8x16() { |
| 110 |
let a = u8x16::from([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); |
| 111 |
let b = u8x16::from([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]); |
| 112 |
let expected = u8x16::from([0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1]); |
| 113 |
let actual = a | b; |
| 114 |
assert_eq!(expected, actual); |
| 115 |
|
| 116 |
crate::test_random_vector_vs_scalar(|a: u8x16, b| a | b, |a, b| a | b); |
| 117 |
} |
| 118 |
|
| 119 |
#[test] |
| 120 |
fn impl_bitxor_for_u8x16() { |
| 121 |
let a = u8x16::from([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); |
| 122 |
let b = u8x16::from([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]); |
| 123 |
let expected = u8x16::from([0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]); |
| 124 |
let actual = a ^ b; |
| 125 |
assert_eq!(expected, actual); |
| 126 |
|
| 127 |
crate::test_random_vector_vs_scalar(|a: u8x16, b| a ^ b, |a, b| a ^ b); |
| 128 |
} |
| 129 |
|
| 130 |
#[test] |
| 131 |
fn impl_u8x16_cmp_eq() { |
| 132 |
let a = u8x16::from([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); |
| 133 |
let b = u8x16::from([2_u8; 16]); |
| 134 |
let expected = u8x16::from([ |
| 135 |
0, |
| 136 |
u8::MAX, |
| 137 |
0, |
| 138 |
0, |
| 139 |
0, |
| 140 |
u8::MAX, |
| 141 |
0, |
| 142 |
0, |
| 143 |
0, |
| 144 |
u8::MAX, |
| 145 |
0, |
| 146 |
0, |
| 147 |
0, |
| 148 |
u8::MAX, |
| 149 |
0, |
| 150 |
0, |
| 151 |
]); |
| 152 |
let actual = a.cmp_eq(b); |
| 153 |
assert_eq!(expected, actual); |
| 154 |
} |
| 155 |
|
| 156 |
#[test] |
| 157 |
fn impl_u8x16_blend() { |
| 158 |
let use_t: u8 = u8::MAX; |
| 159 |
let t = |
| 160 |
u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127]); |
| 161 |
let f = |
| 162 |
u8x16::from([17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1]); |
| 163 |
let mask = u8x16::from([ |
| 164 |
use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, |
| 165 |
use_t, 0, |
| 166 |
]); |
| 167 |
let expected = |
| 168 |
u8x16::from([1, 18, 3, 20, 5, 22, 7, 24, 9, 26, 11, 28, 13, 30, 126, 1]); |
| 169 |
let actual = mask.blend(t, f); |
| 170 |
assert_eq!(expected, actual); |
| 171 |
} |
| 172 |
|
| 173 |
#[test] |
| 174 |
fn impl_u8x16_max() { |
| 175 |
let a = |
| 176 |
u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 250, 250]); |
| 177 |
let b = |
| 178 |
u8x16::from([17, 18, 19, 20, 2, 2, 2, 24, 25, 26, 27, 28, 29, 30, 5, 6]); |
| 179 |
let expected = u8x16::from([ |
| 180 |
17, 18, 19, 20, 5, 6, 7, 24, 25, 26, 27, 28, 29, 30, 250, 250, |
| 181 |
]); |
| 182 |
let actual = a.max(b); |
| 183 |
assert_eq!(expected, actual); |
| 184 |
|
| 185 |
crate::test_random_vector_vs_scalar(|a: u8x16, b| a.max(b), |a, b| a.max(b)); |
| 186 |
} |
| 187 |
|
| 188 |
#[test] |
| 189 |
fn impl_u8x16_min() { |
| 190 |
let a = |
| 191 |
u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 250, 250]); |
| 192 |
let b = |
| 193 |
u8x16::from([17, 18, 19, 20, 2, 2, 2, 24, 25, 26, 27, 28, 29, 30, 5, 6]); |
| 194 |
let expected = |
| 195 |
u8x16::from([1, 2, 3, 4, 2, 2, 2, 8, 9, 10, 11, 12, 13, 14, 5, 6]); |
| 196 |
let actual = a.min(b); |
| 197 |
assert_eq!(expected, actual); |
| 198 |
|
| 199 |
crate::test_random_vector_vs_scalar(|a: u8x16, b| a.min(b), |a, b| a.min(b)); |
| 200 |
} |
| 201 |
|
| 202 |
#[test] |
| 203 |
fn impl_unpack_low_u8() { |
| 204 |
let a = u8x16::from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); |
| 205 |
let b = |
| 206 |
u8x16::from([12, 11, 22, 13, 99, 15, 16, 17, 8, 19, 2, 21, 22, 3, 24, 127]); |
| 207 |
let c: [u8; 16] = u8x16::unpack_low(a, b).into(); |
| 208 |
assert_eq!(c, [0, 12, 1, 11, 2, 22, 3, 13, 4, 99, 5, 15, 6, 16, 7, 17]); |
| 209 |
} |
| 210 |
|
| 211 |
#[test] |
| 212 |
fn impl_unpack_high_u8() { |
| 213 |
let a = u8x16::from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); |
| 214 |
let b = |
| 215 |
u8x16::from([12, 11, 22, 13, 99, 15, 16, 17, 8, 19, 2, 21, 22, 3, 24, 127]); |
| 216 |
let c: [u8; 16] = u8x16::unpack_high(a, b).into(); |
| 217 |
assert_eq!(c, [8, 8, 9, 19, 10, 2, 11, 21, 12, 22, 13, 3, 14, 24, 15, 127]); |
| 218 |
} |
| 219 |
|
| 220 |
#[test] |
| 221 |
fn impl_narrow_i16x8() { |
| 222 |
let a = i16x8::from([-1, 2, -3, 4, -5, 6, -7, 8]); |
| 223 |
let b = i16x8::from([9, 10, 11, 12, 13, -14, 15, -16]); |
| 224 |
let c: [u8; 16] = u8x16::narrow_i16x8(a, b).into(); |
| 225 |
assert_eq!(c, [0, 2, 0, 4, 0, 6, 0, 8, 9, 10, 11, 12, 13, 0, 15, 0]); |
| 226 |
} |
| 227 |
|
| 228 |
#[cfg(feature = "serde")] |
| 229 |
#[test] |
| 230 |
fn impl_u8x16_ser_de_roundtrip() { |
| 231 |
let serialized = |
| 232 |
bincode::serialize(&u8x16::ZERO).expect("serialization failed"); |
| 233 |
let deserialized = |
| 234 |
bincode::deserialize(&serialized).expect("deserializaion failed"); |
| 235 |
assert_eq!(u8x16::ZERO, deserialized); |
| 236 |
} |