1use super::*;
2
3pick! {
4 if #[cfg(target_feature="sse2")] {
5 #[derive(Default, Clone, Copy, PartialEq, Eq)]
6 #[repr(C, align(16))]
7 pub struct u8x16 { pub(crate) sse: m128i }
8 } else if #[cfg(target_feature="simd128")] {
9 use core::arch::wasm32::*;
10
11 #[derive(Clone, Copy)]
12 #[repr(transparent)]
13 pub struct u8x16 { pub(crate) simd: v128 }
14
15 impl Default for u8x16 {
16 fn default() -> Self {
17 Self::splat(0)
18 }
19 }
20
21 impl PartialEq for u8x16 {
22 fn eq(&self, other: &Self) -> bool {
23 u8x16_all_true(u8x16_eq(self.simd, other.simd))
24 }
25 }
26
27 impl Eq for u8x16 { }
28 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
29 use core::arch::aarch64::*;
30 #[repr(C)]
31 #[derive(Copy, Clone)]
32 pub struct u8x16 { pub(crate) neon : uint8x16_t }
33
34 impl Default for u8x16 {
35 #[inline]
36 #[must_use]
37 fn default() -> Self {
38 Self::splat(0)
39 }
40 }
41
42 impl PartialEq for u8x16 {
43 #[inline]
44 #[must_use]
45 fn eq(&self, other: &Self) -> bool {
46 unsafe { vminvq_u8(vceqq_u8(self.neon, other.neon))==u8::MAX }
47 }
48 }
49
50 impl Eq for u8x16 { }
51 } else {
52 #[derive(Default, Clone, Copy, PartialEq, Eq)]
53 #[repr(C, align(16))]
54 pub struct u8x16 { pub(crate) arr: [u8;16] }
55 }
56}
57
58int_uint_consts!(u8, 16, u8x16, 128);
59
60unsafe impl Zeroable for u8x16 {}
61unsafe impl Pod for u8x16 {}
62
63impl Add for u8x16 {
64 type Output = Self;
65 #[inline]
66 #[must_use]
67 fn add(self, rhs: Self) -> Self::Output {
68 pick! {
69 if #[cfg(target_feature="sse2")] {
70 Self { sse: add_i8_m128i(self.sse, rhs.sse) }
71 } else if #[cfg(target_feature="simd128")] {
72 Self { simd: u8x16_add(self.simd, rhs.simd) }
73 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
74 unsafe { Self { neon: vaddq_u8(self.neon, rhs.neon) } }
75 } else {
76 Self { arr: [
77 self.arr[0].wrapping_add(rhs.arr[0]),
78 self.arr[1].wrapping_add(rhs.arr[1]),
79 self.arr[2].wrapping_add(rhs.arr[2]),
80 self.arr[3].wrapping_add(rhs.arr[3]),
81 self.arr[4].wrapping_add(rhs.arr[4]),
82 self.arr[5].wrapping_add(rhs.arr[5]),
83 self.arr[6].wrapping_add(rhs.arr[6]),
84 self.arr[7].wrapping_add(rhs.arr[7]),
85 self.arr[8].wrapping_add(rhs.arr[8]),
86 self.arr[9].wrapping_add(rhs.arr[9]),
87 self.arr[10].wrapping_add(rhs.arr[10]),
88 self.arr[11].wrapping_add(rhs.arr[11]),
89 self.arr[12].wrapping_add(rhs.arr[12]),
90 self.arr[13].wrapping_add(rhs.arr[13]),
91 self.arr[14].wrapping_add(rhs.arr[14]),
92 self.arr[15].wrapping_add(rhs.arr[15]),
93 ]}
94 }
95 }
96 }
97}
98
99impl Sub for u8x16 {
100 type Output = Self;
101 #[inline]
102 #[must_use]
103 fn sub(self, rhs: Self) -> Self::Output {
104 pick! {
105 if #[cfg(target_feature="sse2")] {
106 Self { sse: sub_i8_m128i(self.sse, rhs.sse) }
107 } else if #[cfg(target_feature="simd128")] {
108 Self { simd: u8x16_sub(self.simd, rhs.simd) }
109 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
110 unsafe {Self { neon: vsubq_u8(self.neon, rhs.neon) }}
111 } else {
112 Self { arr: [
113 self.arr[0].wrapping_sub(rhs.arr[0]),
114 self.arr[1].wrapping_sub(rhs.arr[1]),
115 self.arr[2].wrapping_sub(rhs.arr[2]),
116 self.arr[3].wrapping_sub(rhs.arr[3]),
117 self.arr[4].wrapping_sub(rhs.arr[4]),
118 self.arr[5].wrapping_sub(rhs.arr[5]),
119 self.arr[6].wrapping_sub(rhs.arr[6]),
120 self.arr[7].wrapping_sub(rhs.arr[7]),
121 self.arr[8].wrapping_sub(rhs.arr[8]),
122 self.arr[9].wrapping_sub(rhs.arr[9]),
123 self.arr[10].wrapping_sub(rhs.arr[10]),
124 self.arr[11].wrapping_sub(rhs.arr[11]),
125 self.arr[12].wrapping_sub(rhs.arr[12]),
126 self.arr[13].wrapping_sub(rhs.arr[13]),
127 self.arr[14].wrapping_sub(rhs.arr[14]),
128 self.arr[15].wrapping_sub(rhs.arr[15]),
129 ]}
130 }
131 }
132 }
133}
134
135impl Add<u8> for u8x16 {
136 type Output = Self;
137 #[inline]
138 #[must_use]
139 fn add(self, rhs: u8) -> Self::Output {
140 self.add(Self::splat(rhs))
141 }
142}
143
144impl Sub<u8> for u8x16 {
145 type Output = Self;
146 #[inline]
147 #[must_use]
148 fn sub(self, rhs: u8) -> Self::Output {
149 self.sub(Self::splat(rhs))
150 }
151}
152
153impl Add<u8x16> for u8 {
154 type Output = u8x16;
155 #[inline]
156 #[must_use]
157 fn add(self, rhs: u8x16) -> Self::Output {
158 u8x16::splat(self).add(rhs)
159 }
160}
161
162impl Sub<u8x16> for u8 {
163 type Output = u8x16;
164 #[inline]
165 #[must_use]
166 fn sub(self, rhs: u8x16) -> Self::Output {
167 u8x16::splat(self).sub(rhs)
168 }
169}
170
171impl BitAnd for u8x16 {
172 type Output = Self;
173 #[inline]
174 #[must_use]
175 fn bitand(self, rhs: Self) -> Self::Output {
176 pick! {
177 if #[cfg(target_feature="sse2")] {
178 Self { sse: bitand_m128i(self.sse, rhs.sse) }
179 } else if #[cfg(target_feature="simd128")] {
180 Self { simd: v128_and(self.simd, rhs.simd) }
181 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
182 unsafe {Self { neon: vandq_u8(self.neon, rhs.neon) }}
183 } else {
184 Self { arr: [
185 self.arr[0].bitand(rhs.arr[0]),
186 self.arr[1].bitand(rhs.arr[1]),
187 self.arr[2].bitand(rhs.arr[2]),
188 self.arr[3].bitand(rhs.arr[3]),
189 self.arr[4].bitand(rhs.arr[4]),
190 self.arr[5].bitand(rhs.arr[5]),
191 self.arr[6].bitand(rhs.arr[6]),
192 self.arr[7].bitand(rhs.arr[7]),
193 self.arr[8].bitand(rhs.arr[8]),
194 self.arr[9].bitand(rhs.arr[9]),
195 self.arr[10].bitand(rhs.arr[10]),
196 self.arr[11].bitand(rhs.arr[11]),
197 self.arr[12].bitand(rhs.arr[12]),
198 self.arr[13].bitand(rhs.arr[13]),
199 self.arr[14].bitand(rhs.arr[14]),
200 self.arr[15].bitand(rhs.arr[15]),
201 ]}
202 }
203 }
204 }
205}
206
207impl BitOr for u8x16 {
208 type Output = Self;
209 #[inline]
210 #[must_use]
211 fn bitor(self, rhs: Self) -> Self::Output {
212 pick! {
213 if #[cfg(target_feature="sse2")] {
214 Self { sse: bitor_m128i(self.sse, rhs.sse) }
215 } else if #[cfg(target_feature="simd128")] {
216 Self { simd: v128_or(self.simd, rhs.simd) }
217 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
218 unsafe {Self { neon: vorrq_u8(self.neon, rhs.neon) }}
219 } else {
220 Self { arr: [
221 self.arr[0].bitor(rhs.arr[0]),
222 self.arr[1].bitor(rhs.arr[1]),
223 self.arr[2].bitor(rhs.arr[2]),
224 self.arr[3].bitor(rhs.arr[3]),
225 self.arr[4].bitor(rhs.arr[4]),
226 self.arr[5].bitor(rhs.arr[5]),
227 self.arr[6].bitor(rhs.arr[6]),
228 self.arr[7].bitor(rhs.arr[7]),
229 self.arr[8].bitor(rhs.arr[8]),
230 self.arr[9].bitor(rhs.arr[9]),
231 self.arr[10].bitor(rhs.arr[10]),
232 self.arr[11].bitor(rhs.arr[11]),
233 self.arr[12].bitor(rhs.arr[12]),
234 self.arr[13].bitor(rhs.arr[13]),
235 self.arr[14].bitor(rhs.arr[14]),
236 self.arr[15].bitor(rhs.arr[15]),
237 ]}
238 }
239 }
240 }
241}
242
243impl BitXor for u8x16 {
244 type Output = Self;
245 #[inline]
246 #[must_use]
247 fn bitxor(self, rhs: Self) -> Self::Output {
248 pick! {
249 if #[cfg(target_feature="sse2")] {
250 Self { sse: bitxor_m128i(self.sse, rhs.sse) }
251 } else if #[cfg(target_feature="simd128")] {
252 Self { simd: v128_xor(self.simd, rhs.simd) }
253 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
254 unsafe {Self { neon: veorq_u8(self.neon, rhs.neon) }}
255 } else {
256 Self { arr: [
257 self.arr[0].bitxor(rhs.arr[0]),
258 self.arr[1].bitxor(rhs.arr[1]),
259 self.arr[2].bitxor(rhs.arr[2]),
260 self.arr[3].bitxor(rhs.arr[3]),
261 self.arr[4].bitxor(rhs.arr[4]),
262 self.arr[5].bitxor(rhs.arr[5]),
263 self.arr[6].bitxor(rhs.arr[6]),
264 self.arr[7].bitxor(rhs.arr[7]),
265 self.arr[8].bitxor(rhs.arr[8]),
266 self.arr[9].bitxor(rhs.arr[9]),
267 self.arr[10].bitxor(rhs.arr[10]),
268 self.arr[11].bitxor(rhs.arr[11]),
269 self.arr[12].bitxor(rhs.arr[12]),
270 self.arr[13].bitxor(rhs.arr[13]),
271 self.arr[14].bitxor(rhs.arr[14]),
272 self.arr[15].bitxor(rhs.arr[15]),
273 ]}
274 }
275 }
276 }
277}
278
279impl u8x16 {
280 #[inline]
281 #[must_use]
282 pub const fn new(array: [u8; 16]) -> Self {
283 unsafe { core::intrinsics::transmute(array) }
284 }
285 #[inline]
286 #[must_use]
287 pub fn cmp_eq(self, rhs: Self) -> Self {
288 pick! {
289 if #[cfg(target_feature="sse2")] {
290 Self { sse: cmp_eq_mask_i8_m128i(self.sse, rhs.sse) }
291 } else if #[cfg(target_feature="simd128")] {
292 Self { simd: u8x16_eq(self.simd, rhs.simd) }
293 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
294 unsafe {Self { neon: vceqq_u8(self.neon, rhs.neon) }}
295 } else {
296 Self { arr: [
297 if self.arr[0] == rhs.arr[0] { u8::MAX } else { 0 },
298 if self.arr[1] == rhs.arr[1] { u8::MAX } else { 0 },
299 if self.arr[2] == rhs.arr[2] { u8::MAX } else { 0 },
300 if self.arr[3] == rhs.arr[3] { u8::MAX } else { 0 },
301 if self.arr[4] == rhs.arr[4] { u8::MAX } else { 0 },
302 if self.arr[5] == rhs.arr[5] { u8::MAX } else { 0 },
303 if self.arr[6] == rhs.arr[6] { u8::MAX } else { 0 },
304 if self.arr[7] == rhs.arr[7] { u8::MAX } else { 0 },
305 if self.arr[8] == rhs.arr[8] { u8::MAX } else { 0 },
306 if self.arr[9] == rhs.arr[9] { u8::MAX } else { 0 },
307 if self.arr[10] == rhs.arr[10] { u8::MAX } else { 0 },
308 if self.arr[11] == rhs.arr[11] { u8::MAX } else { 0 },
309 if self.arr[12] == rhs.arr[12] { u8::MAX } else { 0 },
310 if self.arr[13] == rhs.arr[13] { u8::MAX } else { 0 },
311 if self.arr[14] == rhs.arr[14] { u8::MAX } else { 0 },
312 if self.arr[15] == rhs.arr[15] { u8::MAX } else { 0 },
313 ]}
314 }
315 }
316 }
317 #[inline]
318 #[must_use]
319 pub fn blend(self, t: Self, f: Self) -> Self {
320 pick! {
321 if #[cfg(target_feature="sse4.1")] {
322 Self { sse: blend_varying_i8_m128i(f.sse, t.sse, self.sse) }
323 } else if #[cfg(target_feature="simd128")] {
324 Self { simd: v128_bitselect(t.simd, f.simd, self.simd) }
325 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
326 unsafe {Self { neon: vbslq_u8(self.neon, t.neon, f.neon) }}
327 } else {
328 generic_bit_blend(self, t, f)
329 }
330 }
331 }
332 #[inline]
333 #[must_use]
334 pub fn max(self, rhs: Self) -> Self {
335 pick! {
336 if #[cfg(target_feature="sse2")] {
337 Self { sse: max_u8_m128i(self.sse, rhs.sse) }
338 } else if #[cfg(target_feature="simd128")] {
339 Self { simd: u8x16_max(self.simd, rhs.simd) }
340 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
341 unsafe {Self { neon: vmaxq_u8(self.neon, rhs.neon) }}
342 } else {
343 Self { arr: [
344 self.arr[0].max(rhs.arr[0]),
345 self.arr[1].max(rhs.arr[1]),
346 self.arr[2].max(rhs.arr[2]),
347 self.arr[3].max(rhs.arr[3]),
348 self.arr[4].max(rhs.arr[4]),
349 self.arr[5].max(rhs.arr[5]),
350 self.arr[6].max(rhs.arr[6]),
351 self.arr[7].max(rhs.arr[7]),
352 self.arr[8].max(rhs.arr[8]),
353 self.arr[9].max(rhs.arr[9]),
354 self.arr[10].max(rhs.arr[10]),
355 self.arr[11].max(rhs.arr[11]),
356 self.arr[12].max(rhs.arr[12]),
357 self.arr[13].max(rhs.arr[13]),
358 self.arr[14].max(rhs.arr[14]),
359 self.arr[15].max(rhs.arr[15]),
360 ]}
361 }
362 }
363 }
364 #[inline]
365 #[must_use]
366 pub fn min(self, rhs: Self) -> Self {
367 pick! {
368 if #[cfg(target_feature="sse2")] {
369 Self { sse: min_u8_m128i(self.sse, rhs.sse) }
370 } else if #[cfg(target_feature="simd128")] {
371 Self { simd: u8x16_min(self.simd, rhs.simd) }
372 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
373 unsafe {Self { neon: vminq_u8(self.neon, rhs.neon) }}
374 } else {
375 Self { arr: [
376 self.arr[0].min(rhs.arr[0]),
377 self.arr[1].min(rhs.arr[1]),
378 self.arr[2].min(rhs.arr[2]),
379 self.arr[3].min(rhs.arr[3]),
380 self.arr[4].min(rhs.arr[4]),
381 self.arr[5].min(rhs.arr[5]),
382 self.arr[6].min(rhs.arr[6]),
383 self.arr[7].min(rhs.arr[7]),
384 self.arr[8].min(rhs.arr[8]),
385 self.arr[9].min(rhs.arr[9]),
386 self.arr[10].min(rhs.arr[10]),
387 self.arr[11].min(rhs.arr[11]),
388 self.arr[12].min(rhs.arr[12]),
389 self.arr[13].min(rhs.arr[13]),
390 self.arr[14].min(rhs.arr[14]),
391 self.arr[15].min(rhs.arr[15]),
392 ]}
393 }
394 }
395 }
396
397 #[inline]
398 #[must_use]
399 pub fn saturating_add(self, rhs: Self) -> Self {
400 pick! {
401 if #[cfg(target_feature="sse2")] {
402 Self { sse: add_saturating_u8_m128i(self.sse, rhs.sse) }
403 } else if #[cfg(target_feature="simd128")] {
404 Self { simd: u8x16_add_sat(self.simd, rhs.simd) }
405 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
406 unsafe {Self { neon: vqaddq_u8(self.neon, rhs.neon) }}
407 } else {
408 Self { arr: [
409 self.arr[0].saturating_add(rhs.arr[0]),
410 self.arr[1].saturating_add(rhs.arr[1]),
411 self.arr[2].saturating_add(rhs.arr[2]),
412 self.arr[3].saturating_add(rhs.arr[3]),
413 self.arr[4].saturating_add(rhs.arr[4]),
414 self.arr[5].saturating_add(rhs.arr[5]),
415 self.arr[6].saturating_add(rhs.arr[6]),
416 self.arr[7].saturating_add(rhs.arr[7]),
417 self.arr[8].saturating_add(rhs.arr[8]),
418 self.arr[9].saturating_add(rhs.arr[9]),
419 self.arr[10].saturating_add(rhs.arr[10]),
420 self.arr[11].saturating_add(rhs.arr[11]),
421 self.arr[12].saturating_add(rhs.arr[12]),
422 self.arr[13].saturating_add(rhs.arr[13]),
423 self.arr[14].saturating_add(rhs.arr[14]),
424 self.arr[15].saturating_add(rhs.arr[15]),
425 ]}
426 }
427 }
428 }
429 #[inline]
430 #[must_use]
431 pub fn saturating_sub(self, rhs: Self) -> Self {
432 pick! {
433 if #[cfg(target_feature="sse2")] {
434 Self { sse: sub_saturating_u8_m128i(self.sse, rhs.sse) }
435 } else if #[cfg(target_feature="simd128")] {
436 Self { simd: u8x16_sub_sat(self.simd, rhs.simd) }
437 } else if #[cfg(all(target_feature="neon",target_arch="aarch64"))]{
438 unsafe { Self { neon: vqsubq_u8(self.neon, rhs.neon) } }
439 } else {
440 Self { arr: [
441 self.arr[0].saturating_sub(rhs.arr[0]),
442 self.arr[1].saturating_sub(rhs.arr[1]),
443 self.arr[2].saturating_sub(rhs.arr[2]),
444 self.arr[3].saturating_sub(rhs.arr[3]),
445 self.arr[4].saturating_sub(rhs.arr[4]),
446 self.arr[5].saturating_sub(rhs.arr[5]),
447 self.arr[6].saturating_sub(rhs.arr[6]),
448 self.arr[7].saturating_sub(rhs.arr[7]),
449 self.arr[8].saturating_sub(rhs.arr[8]),
450 self.arr[9].saturating_sub(rhs.arr[9]),
451 self.arr[10].saturating_sub(rhs.arr[10]),
452 self.arr[11].saturating_sub(rhs.arr[11]),
453 self.arr[12].saturating_sub(rhs.arr[12]),
454 self.arr[13].saturating_sub(rhs.arr[13]),
455 self.arr[14].saturating_sub(rhs.arr[14]),
456 self.arr[15].saturating_sub(rhs.arr[15]),
457 ]}
458 }
459 }
460 }
461
462 #[inline]
464 #[must_use]
465 pub fn unpack_low(lhs: u8x16, rhs: u8x16) -> u8x16 {
466 pick! {
467 if #[cfg(target_feature = "sse2")] {
468 u8x16 { sse: unpack_low_i8_m128i(lhs.sse, rhs.sse) }
469 } else if #[cfg(target_feature = "simd128")] {
470 u8x16 { simd: u8x16_shuffle::<0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23>(lhs.simd, rhs.simd) }
471 } else if #[cfg(all(target_feature = "neon", target_arch = "aarch64"))] {
472 let lhs = unsafe { vget_low_u8(lhs.neon) };
473 let rhs = unsafe { vget_low_u8(rhs.neon) };
474
475 let zipped = unsafe { vzip_u8(lhs, rhs) };
476 u8x16 { neon: unsafe { vcombine_u8(zipped.0, zipped.1) } }
477 } else {
478 u8x16::new([
479 lhs.as_array_ref()[0], rhs.as_array_ref()[0],
480 lhs.as_array_ref()[1], rhs.as_array_ref()[1],
481 lhs.as_array_ref()[2], rhs.as_array_ref()[2],
482 lhs.as_array_ref()[3], rhs.as_array_ref()[3],
483 lhs.as_array_ref()[4], rhs.as_array_ref()[4],
484 lhs.as_array_ref()[5], rhs.as_array_ref()[5],
485 lhs.as_array_ref()[6], rhs.as_array_ref()[6],
486 lhs.as_array_ref()[7], rhs.as_array_ref()[7],
487 ])
488 }
489 }
490 }
491
492 #[inline]
494 #[must_use]
495 pub fn unpack_high(lhs: u8x16, rhs: u8x16) -> u8x16 {
496 pick! {
497 if #[cfg(target_feature = "sse2")] {
498 u8x16 { sse: unpack_high_i8_m128i(lhs.sse, rhs.sse) }
499 } else if #[cfg(target_feature = "simd128")] {
500 u8x16 { simd: u8x16_shuffle::<8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31>(lhs.simd, rhs.simd) }
501 } else if #[cfg(all(target_feature = "neon", target_arch = "aarch64"))] {
502 let lhs = unsafe { vget_high_u8(lhs.neon) };
503 let rhs = unsafe { vget_high_u8(rhs.neon) };
504
505 let zipped = unsafe { vzip_u8(lhs, rhs) };
506 u8x16 { neon: unsafe { vcombine_u8(zipped.0, zipped.1) } }
507 } else {
508 u8x16::new([
509 lhs.as_array_ref()[8], rhs.as_array_ref()[8],
510 lhs.as_array_ref()[9], rhs.as_array_ref()[9],
511 lhs.as_array_ref()[10], rhs.as_array_ref()[10],
512 lhs.as_array_ref()[11], rhs.as_array_ref()[11],
513 lhs.as_array_ref()[12], rhs.as_array_ref()[12],
514 lhs.as_array_ref()[13], rhs.as_array_ref()[13],
515 lhs.as_array_ref()[14], rhs.as_array_ref()[14],
516 lhs.as_array_ref()[15], rhs.as_array_ref()[15],
517 ])
518 }
519 }
520 }
521
522 #[inline]
524 #[must_use]
525 pub fn narrow_i16x8(lhs: i16x8, rhs: i16x8) -> Self {
526 pick! {
527 if #[cfg(target_feature = "sse2")] {
528 u8x16 { sse: pack_i16_to_u8_m128i(lhs.sse, rhs.sse) }
529 } else if #[cfg(target_feature = "simd128")] {
530 u8x16 { simd: u8x16_narrow_i16x8(lhs.simd, rhs.simd) }
531 } else if #[cfg(all(target_feature = "neon", target_arch = "aarch64"))] {
532 let lhs = unsafe { vqmovun_s16(lhs.neon) };
533 let rhs = unsafe { vqmovun_s16(rhs.neon) };
534 u8x16 { neon: unsafe { vcombine_u8(lhs, rhs) } }
535 } else {
536 fn clamp(a: i16) -> u8 {
537 if a < u8::MIN as i16 {
538 u8::MIN
539 } else if a > u8::MAX as i16 {
540 u8::MAX
541 } else {
542 a as u8
543 }
544 }
545
546 Self { arr: [
547 clamp(lhs.as_array_ref()[0]),
548 clamp(lhs.as_array_ref()[1]),
549 clamp(lhs.as_array_ref()[2]),
550 clamp(lhs.as_array_ref()[3]),
551 clamp(lhs.as_array_ref()[4]),
552 clamp(lhs.as_array_ref()[5]),
553 clamp(lhs.as_array_ref()[6]),
554 clamp(lhs.as_array_ref()[7]),
555 clamp(rhs.as_array_ref()[0]),
556 clamp(rhs.as_array_ref()[1]),
557 clamp(rhs.as_array_ref()[2]),
558 clamp(rhs.as_array_ref()[3]),
559 clamp(rhs.as_array_ref()[4]),
560 clamp(rhs.as_array_ref()[5]),
561 clamp(rhs.as_array_ref()[6]),
562 clamp(rhs.as_array_ref()[7]),
563 ]}
564 }
565 }
566 }
567
568 #[inline]
569 pub fn to_array(self) -> [u8; 16] {
570 cast(self)
571 }
572
573 #[inline]
574 pub fn as_array_ref(&self) -> &[u8; 16] {
575 cast_ref(self)
576 }
577
578 #[inline]
579 pub fn as_array_mut(&mut self) -> &mut [u8; 16] {
580 cast_mut(self)
581 }
582}