Skip to content

Commit

Permalink
Merge pull request rust-lang#83 from rust-lang/feature/reductions
Browse files Browse the repository at this point in the history
Add reductions
  • Loading branch information
workingjubilee authored Apr 22, 2021
2 parents 2fa62b9 + 04ee107 commit 24ebae8
Show file tree
Hide file tree
Showing 12 changed files with 464 additions and 119 deletions.
11 changes: 11 additions & 0 deletions crates/core_simd/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,15 @@ extern "platform-intrinsic" {

// {s,u}sub.sat
pub(crate) fn simd_saturating_sub<T>(x: T, y: T) -> T;

// reductions
pub(crate) fn simd_reduce_add_ordered<T, U>(x: T, y: U) -> U;
pub(crate) fn simd_reduce_mul_ordered<T, U>(x: T, y: U) -> U;
pub(crate) fn simd_reduce_all<T>(x: T) -> bool;
pub(crate) fn simd_reduce_any<T>(x: T) -> bool;
pub(crate) fn simd_reduce_max<T, U>(x: T) -> U;
pub(crate) fn simd_reduce_min<T, U>(x: T) -> U;
pub(crate) fn simd_reduce_and<T, U>(x: T) -> U;
pub(crate) fn simd_reduce_or<T, U>(x: T) -> U;
pub(crate) fn simd_reduce_xor<T, U>(x: T) -> U;
}
2 changes: 2 additions & 0 deletions crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod first;
mod permute;
#[macro_use]
mod transmute;
#[macro_use]
mod reduction;

mod comparisons;
mod fmt;
Expand Down
4 changes: 2 additions & 2 deletions crates/core_simd/src/masks/bitmask.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::LanesAtMost32;

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

0 comments on commit 24ebae8

Please sign in to comment.