]> git.proxmox.com Git - rustc.git/blame - vendor/packed_simd/src/api/reductions/mask.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / vendor / packed_simd / src / api / reductions / mask.rs
CommitLineData
f20569fa
XL
1//! Implements portable horizontal mask reductions.
2
3macro_rules! impl_reduction_mask {
4 ([$elem_ty:ident; $elem_count:expr]: $id:ident | $test_tt:tt) => {
5 impl $id {
6 /// Are `all` vector lanes `true`?
7 #[inline]
8 pub fn all(self) -> bool {
9 unsafe { crate::codegen::reductions::mask::All::all(self) }
10 }
11 /// Is `any` vector lane `true`?
12 #[inline]
13 pub fn any(self) -> bool {
14 unsafe { crate::codegen::reductions::mask::Any::any(self) }
15 }
16 /// Are `all` vector lanes `false`?
17 #[inline]
18 pub fn none(self) -> bool {
19 !self.any()
20 }
21 }
22
23 test_if!{
24 $test_tt:
25 paste::item! {
26 pub mod [<$id _reduction>] {
27 use super::*;
28 #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
29 fn all() {
30 let a = $id::splat(true);
31 assert!(a.all());
32 let a = $id::splat(false);
33 assert!(!a.all());
34
35 if $id::lanes() > 1 {
36 for i in 0..$id::lanes() {
37 let mut a = $id::splat(true);
38 a = a.replace(i, false);
39 assert!(!a.all());
40 let mut a = $id::splat(false);
41 a = a.replace(i, true);
42 assert!(!a.all());
43 }
44 }
45 }
46 #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
47 fn any() {
48 let a = $id::splat(true);
49 assert!(a.any());
50 let a = $id::splat(false);
51 assert!(!a.any());
52
53 if $id::lanes() > 1 {
54 for i in 0..$id::lanes() {
55 let mut a = $id::splat(true);
56 a = a.replace(i, false);
57 assert!(a.any());
58 let mut a = $id::splat(false);
59 a = a.replace(i, true);
60 assert!(a.any());
61 }
62 }
63 }
64 #[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
65 fn none() {
66 let a = $id::splat(true);
67 assert!(!a.none());
68 let a = $id::splat(false);
69 assert!(a.none());
70
71 if $id::lanes() > 1 {
72 for i in 0..$id::lanes() {
73 let mut a = $id::splat(true);
74 a = a.replace(i, false);
75 assert!(!a.none());
76 let mut a = $id::splat(false);
77 a = a.replace(i, true);
78 assert!(!a.none());
79 }
80 }
81 }
82 }
83 }
84 }
85 };
86}