Skip to content

Commit 24ebae8

Browse files
Merge pull request rust-lang#83 from rust-lang/feature/reductions
Add reductions
2 parents 2fa62b9 + 04ee107 commit 24ebae8

File tree

12 files changed

+464
-119
lines changed

12 files changed

+464
-119
lines changed

crates/core_simd/src/intrinsics.rs

+11
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,15 @@ extern "platform-intrinsic" {
7373

7474
// {s,u}sub.sat
7575
pub(crate) fn simd_saturating_sub<T>(x: T, y: T) -> T;
76+
77+
// reductions
78+
pub(crate) fn simd_reduce_add_ordered<T, U>(x: T, y: U) -> U;
79+
pub(crate) fn simd_reduce_mul_ordered<T, U>(x: T, y: U) -> U;
80+
pub(crate) fn simd_reduce_all<T>(x: T) -> bool;
81+
pub(crate) fn simd_reduce_any<T>(x: T) -> bool;
82+
pub(crate) fn simd_reduce_max<T, U>(x: T) -> U;
83+
pub(crate) fn simd_reduce_min<T, U>(x: T) -> U;
84+
pub(crate) fn simd_reduce_and<T, U>(x: T) -> U;
85+
pub(crate) fn simd_reduce_or<T, U>(x: T) -> U;
86+
pub(crate) fn simd_reduce_xor<T, U>(x: T) -> U;
7687
}

crates/core_simd/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ mod first;
1111
mod permute;
1212
#[macro_use]
1313
mod transmute;
14+
#[macro_use]
15+
mod reduction;
1416

1517
mod comparisons;
1618
mod fmt;

crates/core_simd/src/masks/bitmask.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::LanesAtMost32;
22

33
/// A mask where each lane is represented by a single bit.
4-
#[derive(Copy, Clone, Debug)]
4+
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Hash)]
55
#[repr(transparent)]
66
pub struct BitMask<const LANES: usize>(u64)
77
where
@@ -14,7 +14,7 @@ where
1414
/// Construct a mask by setting all lanes to the given value.
1515
pub fn splat(value: bool) -> Self {
1616
if value {
17-
Self(u64::MAX)
17+
Self(u64::MAX >> (64 - LANES))
1818
} else {
1919
Self(u64::MIN)
2020
}

0 commit comments

Comments
 (0)