1 macro_rules! impl_integer_reductions {
2 { $name:ident, $scalar:ty } => {
3 impl<const LANES: usize> crate::$name<LANES>
5 Self: crate::LanesAtMost32
7 /// Produces the sum of the lanes of the vector, with wrapping addition.
9 pub fn wrapping_sum(self) -> $scalar {
10 unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0) }
13 /// Produces the sum of the lanes of the vector, with wrapping multiplication.
15 pub fn wrapping_product(self) -> $scalar {
16 unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1) }
19 /// Sequentially performs bitwise "and" between the lanes of the vector.
21 pub fn and_lanes(self) -> $scalar {
22 unsafe { crate::intrinsics::simd_reduce_and(self) }
25 /// Sequentially performs bitwise "or" between the lanes of the vector.
27 pub fn or_lanes(self) -> $scalar {
28 unsafe { crate::intrinsics::simd_reduce_or(self) }
31 /// Sequentially performs bitwise "xor" between the lanes of the vector.
33 pub fn xor_lanes(self) -> $scalar {
34 unsafe { crate::intrinsics::simd_reduce_xor(self) }
37 /// Returns the maximum lane in the vector.
39 pub fn max_lane(self) -> $scalar {
40 unsafe { crate::intrinsics::simd_reduce_max(self) }
43 /// Returns the minimum lane in the vector.
45 pub fn min_lane(self) -> $scalar {
46 unsafe { crate::intrinsics::simd_reduce_min(self) }
52 macro_rules! impl_float_reductions {
53 { $name:ident, $scalar:ty } => {
54 impl<const LANES: usize> crate::$name<LANES>
56 Self: crate::LanesAtMost32
58 /// Produces the sum of the lanes of the vector.
60 pub fn sum(self) -> $scalar {
61 unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0.) }
64 /// Produces the sum of the lanes of the vector.
66 pub fn product(self) -> $scalar {
67 unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1.) }
70 /// Returns the maximum lane in the vector.
72 pub fn max_lane(self) -> $scalar {
73 unsafe { crate::intrinsics::simd_reduce_max(self) }
76 /// Returns the minimum lane in the vector.
78 pub fn min_lane(self) -> $scalar {
79 unsafe { crate::intrinsics::simd_reduce_min(self) }
85 macro_rules! impl_full_mask_reductions {
86 { $name:ident, $inner:ident } => {
87 impl<const LANES: usize> crate::$name<LANES>
89 crate::$inner<LANES>: crate::LanesAtMost32
91 /// Returns true if any lane is set, or false otherwise.
93 pub fn any(self) -> bool {
94 unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) }
97 /// Returns true if all lanes are set, or false otherwise.
99 pub fn all(self) -> bool {
100 unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) }
106 macro_rules! impl_opaque_mask_reductions {
107 { $name:ident, $inner:ident, $bits_ty:ident } => {
108 impl<const LANES: usize> $name<LANES>
110 $bits_ty<LANES>: crate::LanesAtMost32
112 /// Returns true if any lane is set, or false otherwise.
114 pub fn any(self) -> bool {
118 /// Returns true if all lanes are set, or false otherwise.
120 pub fn all(self) -> bool {
127 impl<const LANES: usize> crate::BitMask<LANES>
129 crate::BitMask<LANES>: crate::LanesAtMost32,
131 /// Returns true if any lane is set, or false otherwise.
133 pub fn any(self) -> bool {
134 self != Self::splat(false)
137 /// Returns true if all lanes are set, or false otherwise.
139 pub fn all(self) -> bool {
140 self == Self::splat(true)