Skip to content

Commit e127586

Browse files
committed
Improve function names and docs
1 parent e2fa502 commit e127586

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

crates/core_simd/src/reduction.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,48 @@ macro_rules! impl_integer_reductions {
44
where
55
Self: crate::LanesAtMost32
66
{
7-
/// Produces the sum of the lanes of the vector, with wrapping addition.
7+
/// Horizontal wrapping add. Computes the sum of the lanes of the vector, with wrapping addition.
88
#[inline]
99
pub fn wrapping_sum(self) -> $scalar {
1010
unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0) }
1111
}
1212

13-
/// Produces the sum of the lanes of the vector, with wrapping multiplication.
13+
/// Horizontal wrapping multiply. Computes the product of the lanes of the vector, with wrapping multiplication.
1414
#[inline]
1515
pub fn wrapping_product(self) -> $scalar {
1616
unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1) }
1717
}
1818

19-
/// Sequentially performs bitwise "and" between the lanes of the vector.
19+
/// Horizontal bitwise "and". Computes the cumulative bitwise "and" across the lanes of
20+
/// the vector.
2021
#[inline]
21-
pub fn and_lanes(self) -> $scalar {
22+
pub fn horizontal_and(self) -> $scalar {
2223
unsafe { crate::intrinsics::simd_reduce_and(self) }
2324
}
2425

25-
/// Sequentially performs bitwise "or" between the lanes of the vector.
26+
/// Horizontal bitwise "or". Computes the cumulative bitwise "or" across the lanes of
27+
/// the vector.
2628
#[inline]
27-
pub fn or_lanes(self) -> $scalar {
29+
pub fn horizontal_or(self) -> $scalar {
2830
unsafe { crate::intrinsics::simd_reduce_or(self) }
2931
}
3032

31-
/// Sequentially performs bitwise "xor" between the lanes of the vector.
33+
/// Horizontal bitwise "xor". Computes the cumulative bitwise "xor" across the lanes of
34+
/// the vector.
3235
#[inline]
33-
pub fn xor_lanes(self) -> $scalar {
36+
pub fn horizontal_xor(self) -> $scalar {
3437
unsafe { crate::intrinsics::simd_reduce_xor(self) }
3538
}
3639

37-
/// Returns the maximum lane in the vector.
40+
/// Horizontal maximum. Computes the maximum lane in the vector.
3841
#[inline]
39-
pub fn max_lane(self) -> $scalar {
42+
pub fn horizontal_max(self) -> $scalar {
4043
unsafe { crate::intrinsics::simd_reduce_max(self) }
4144
}
4245

43-
/// Returns the minimum lane in the vector.
46+
/// Horizontal minimum. Computes the minimum lane in the vector.
4447
#[inline]
45-
pub fn min_lane(self) -> $scalar {
48+
pub fn horizontal_min(self) -> $scalar {
4649
unsafe { crate::intrinsics::simd_reduce_min(self) }
4750
}
4851
}
@@ -56,7 +59,7 @@ macro_rules! impl_float_reductions {
5659
Self: crate::LanesAtMost32
5760
{
5861

59-
/// Produces the sum of the lanes of the vector.
62+
/// Horizontal add. Computes the sum of the lanes of the vector.
6063
#[inline]
6164
pub fn sum(self) -> $scalar {
6265
// LLVM sum is inaccurate on i586
@@ -67,7 +70,7 @@ macro_rules! impl_float_reductions {
6770
}
6871
}
6972

70-
/// Produces the sum of the lanes of the vector.
73+
/// Horizontal multiply. Computes the sum of the lanes of the vector.
7174
#[inline]
7275
pub fn product(self) -> $scalar {
7376
// LLVM product is inaccurate on i586
@@ -78,21 +81,21 @@ macro_rules! impl_float_reductions {
7881
}
7982
}
8083

81-
/// Returns the maximum lane in the vector.
84+
/// Horizontal maximum. Computes the maximum lane in the vector.
8285
///
8386
/// Returns values based on equality, so a vector containing both `0.` and `-0.` may
8487
/// return either. This function will not return `NaN` unless all lanes are `NaN`.
8588
#[inline]
86-
pub fn max_lane(self) -> $scalar {
89+
pub fn horizontal_max(self) -> $scalar {
8790
unsafe { crate::intrinsics::simd_reduce_max(self) }
8891
}
8992

90-
/// Returns the minimum lane in the vector.
93+
/// Horizontal minimum. Computes the minimum lane in the vector.
9194
///
9295
/// Returns values based on equality, so a vector containing both `0.` and `-0.` may
9396
/// return either. This function will not return `NaN` unless all lanes are `NaN`.
9497
#[inline]
95-
pub fn min_lane(self) -> $scalar {
98+
pub fn horizontal_min(self) -> $scalar {
9699
unsafe { crate::intrinsics::simd_reduce_min(self) }
97100
}
98101
}

crates/core_simd/tests/ops_macros.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,50 +160,50 @@ macro_rules! impl_common_integer_tests {
160160
});
161161
}
162162

163-
fn and_lanes<const LANES: usize>() {
163+
fn horizontal_and<const LANES: usize>() {
164164
test_helpers::test_1(&|x| {
165165
test_helpers::prop_assert_biteq! (
166-
$vector::<LANES>::from_array(x).and_lanes(),
166+
$vector::<LANES>::from_array(x).horizontal_and(),
167167
x.iter().copied().fold(-1i8 as $scalar, <$scalar as core::ops::BitAnd>::bitand),
168168
);
169169
Ok(())
170170
});
171171
}
172172

173-
fn or_lanes<const LANES: usize>() {
173+
fn horizontal_or<const LANES: usize>() {
174174
test_helpers::test_1(&|x| {
175175
test_helpers::prop_assert_biteq! (
176-
$vector::<LANES>::from_array(x).or_lanes(),
176+
$vector::<LANES>::from_array(x).horizontal_or(),
177177
x.iter().copied().fold(0 as $scalar, <$scalar as core::ops::BitOr>::bitor),
178178
);
179179
Ok(())
180180
});
181181
}
182182

183-
fn xor_lanes<const LANES: usize>() {
183+
fn horizontal_xor<const LANES: usize>() {
184184
test_helpers::test_1(&|x| {
185185
test_helpers::prop_assert_biteq! (
186-
$vector::<LANES>::from_array(x).xor_lanes(),
186+
$vector::<LANES>::from_array(x).horizontal_xor(),
187187
x.iter().copied().fold(0 as $scalar, <$scalar as core::ops::BitXor>::bitxor),
188188
);
189189
Ok(())
190190
});
191191
}
192192

193-
fn max_lane<const LANES: usize>() {
193+
fn horizontal_max<const LANES: usize>() {
194194
test_helpers::test_1(&|x| {
195195
test_helpers::prop_assert_biteq! (
196-
$vector::<LANES>::from_array(x).max_lane(),
196+
$vector::<LANES>::from_array(x).horizontal_max(),
197197
x.iter().copied().max().unwrap(),
198198
);
199199
Ok(())
200200
});
201201
}
202202

203-
fn min_lane<const LANES: usize>() {
203+
fn horizontal_min<const LANES: usize>() {
204204
test_helpers::test_1(&|x| {
205205
test_helpers::prop_assert_biteq! (
206-
$vector::<LANES>::from_array(x).min_lane(),
206+
$vector::<LANES>::from_array(x).horizontal_min(),
207207
x.iter().copied().min().unwrap(),
208208
);
209209
Ok(())
@@ -499,9 +499,9 @@ macro_rules! impl_float_tests {
499499
});
500500
}
501501

502-
fn max_lane<const LANES: usize>() {
502+
fn horizontal_max<const LANES: usize>() {
503503
test_helpers::test_1(&|x| {
504-
let vmax = Vector::<LANES>::from_array(x).max_lane();
504+
let vmax = Vector::<LANES>::from_array(x).horizontal_max();
505505
let smax = x.iter().copied().fold(Scalar::NAN, Scalar::max);
506506
// 0 and -0 are treated the same
507507
if !(x.contains(&0.) && x.contains(&-0.) && vmax.abs() == 0. && smax.abs() == 0.) {
@@ -511,9 +511,9 @@ macro_rules! impl_float_tests {
511511
});
512512
}
513513

514-
fn min_lane<const LANES: usize>() {
514+
fn horizontal_min<const LANES: usize>() {
515515
test_helpers::test_1(&|x| {
516-
let vmax = Vector::<LANES>::from_array(x).min_lane();
516+
let vmax = Vector::<LANES>::from_array(x).horizontal_min();
517517
let smax = x.iter().copied().fold(Scalar::NAN, Scalar::min);
518518
// 0 and -0 are treated the same
519519
if !(x.contains(&0.) && x.contains(&-0.) && vmax.abs() == 0. && smax.abs() == 0.) {

0 commit comments

Comments
 (0)