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
59 /// Produces the sum of the lanes of the vector.
61 pub fn sum(self) -> $scalar {
62 unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0.) }
65 /// Produces the sum of the lanes of the vector.
67 pub fn product(self) -> $scalar {
68 unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1.) }
71 /// Returns the maximum lane in the vector.
73 /// Returns values based on equality, so a vector containing both `0.` and `-0.` may
74 /// return either. This function will not return `NaN` unless all lanes are `NaN`.
76 pub fn max_lane(self) -> $scalar {
77 unsafe { crate::intrinsics::simd_reduce_max(self) }
80 /// Returns the minimum lane in the vector.
82 /// Returns values based on equality, so a vector containing both `0.` and `-0.` may
83 /// return either. This function will not return `NaN` unless all lanes are `NaN`.
85 pub fn min_lane(self) -> $scalar {
86 unsafe { crate::intrinsics::simd_reduce_min(self) }
92 macro_rules! impl_full_mask_reductions {
93 { $name:ident, $inner:ident } => {
94 impl<const LANES: usize> crate::$name<LANES>
96 crate::$inner<LANES>: crate::LanesAtMost32
98 /// Returns true if any lane is set, or false otherwise.
100 pub fn any(self) -> bool {
101 unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) }
104 /// Returns true if all lanes are set, or false otherwise.
106 pub fn all(self) -> bool {
107 unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) }
113 macro_rules! impl_opaque_mask_reductions {
114 { $name:ident, $inner:ident, $bits_ty:ident } => {
115 impl<const LANES: usize> $name<LANES>
117 $bits_ty<LANES>: crate::LanesAtMost32
119 /// Returns true if any lane is set, or false otherwise.
121 pub fn any(self) -> bool {
125 /// Returns true if all lanes are set, or false otherwise.
127 pub fn all(self) -> bool {
134 impl<const LANES: usize> crate::BitMask<LANES>
136 crate::BitMask<LANES>: crate::LanesAtMost32,
138 /// Returns true if any lane is set, or false otherwise.
140 pub fn any(self) -> bool {
141 self != Self::splat(false)
144 /// Returns true if all lanes are set, or false otherwise.
146 pub fn all(self) -> bool {
147 self == Self::splat(true)