Skip to content

Commit

Permalink
documents arithmetic reduction semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Mar 20, 2018
1 parent 8b5843e commit 6ac8341
Show file tree
Hide file tree
Showing 3 changed files with 507 additions and 17 deletions.
68 changes: 56 additions & 12 deletions coresimd/ppsv/api/arithmetic_reductions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ macro_rules! impl_arithmetic_reductions {
impl $id {
/// Lane-wise addition of the vector elements.
///
/// FIXME: document guarantees with respect to:
/// * integers: overflow behavior
/// * floats: order and NaNs
/// The intrinsic performs a tree-reduction of the vector elements.
/// That is, for an 8 element vector:
///
/// > ((x0 + x1) + (x2 + x3)) + ((x4 + x5) + (x6 + x7))
///
/// # Integer vectors
///
/// If an operation overflows it returns the mathematical result
/// modulo `2^n` where `n` is the number of times it overflows.
///
/// # Floating-point vectors
///
/// If one of the vector element is `NaN` the reduction returns
/// `NaN`.
#[cfg(not(target_arch = "aarch64"))]
#[inline]
pub fn sum(self) -> $elem_ty {
Expand All @@ -19,9 +30,20 @@ macro_rules! impl_arithmetic_reductions {
}
/// Lane-wise addition of the vector elements.
///
/// FIXME: document guarantees with respect to:
/// * integers: overflow behavior
/// * floats: order and NaNs
/// The intrinsic performs a tree-reduction of the vector elements.
/// That is, for an 8 element vector:
///
/// > ((x0 + x1) + (x2 + x3)) + ((x4 + x5) + (x6 + x7))
///
/// # Integer vectors
///
/// If an operation overflows it returns the mathematical result
/// modulo `2^n` where `n` is the number of times it overflows.
///
/// # Floating-point vectors
///
/// If one of the vector element is `NaN` the reduction returns
/// `NaN`.
#[cfg(target_arch = "aarch64")]
#[inline]
pub fn sum(self) -> $elem_ty {
Expand All @@ -36,9 +58,20 @@ macro_rules! impl_arithmetic_reductions {

/// Lane-wise multiplication of the vector elements.
///
/// FIXME: document guarantees with respect to:
/// * integers: overflow behavior
/// * floats: order and NaNs
/// The intrinsic performs a tree-reduction of the vector elements.
/// That is, for an 8 element vector:
///
/// > ((x0 * x1) * (x2 * x3)) * ((x4 * x5) * (x6 * x7))
///
/// # Integer vectors
///
/// If an operation overflows it returns the mathematical result
/// modulo `2^n` where `n` is the number of times it overflows.
///
/// # Floating-point vectors
///
/// If one of the vector element is `NaN` the reduction returns
/// `NaN`.
#[cfg(not(target_arch = "aarch64"))]
#[inline]
pub fn product(self) -> $elem_ty {
Expand All @@ -49,9 +82,20 @@ macro_rules! impl_arithmetic_reductions {
}
/// Lane-wise multiplication of the vector elements.
///
/// FIXME: document guarantees with respect to:
/// * integers: overflow behavior
/// * floats: order and NaNs
/// The intrinsic performs a tree-reduction of the vector elements.
/// That is, for an 8 element vector:
///
/// > ((x0 * x1) * (x2 * x3)) * ((x4 * x5) * (x6 * x7))
///
/// # Integer vectors
///
/// If an operation overflows it returns the mathematical result
/// modulo `2^n` where `n` is the number of times it overflows.
///
/// # Floating-point vectors
///
/// If one of the vector element is `NaN` the reduction returns
/// `NaN`.
#[cfg(target_arch = "aarch64")]
#[inline]
pub fn product(self) -> $elem_ty {
Expand Down
34 changes: 29 additions & 5 deletions coresimd/ppsv/api/minmax_reductions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ macro_rules! impl_minmax_reductions {
impl $id {
/// Largest vector value.
///
/// FIXME: document behavior for float vectors with NaNs.
/// # Floating-point behvior
///
/// If the vector contains only `NaN` values,
/// the result is a `NaN`.
///
/// Otherwise, if the vector contains `NaN` values, either the
/// largest element of the vector or a `NaN` is returned.
#[cfg(not(target_arch = "aarch64"))]
#[inline]
pub fn max(self) -> $elem_ty {
Expand All @@ -15,9 +21,16 @@ macro_rules! impl_minmax_reductions {
simd_reduce_max(self)
}
}

/// Largest vector value.
///
/// FIXME: document behavior for float vectors with NaNs.
/// # Floating-point behvior
///
/// If the vector contains only `NaN` values,
/// the result is a `NaN`.
///
/// Otherwise, if the vector contains `NaN` values, either the
/// largest element of the vector or a `NaN` is returned.
#[cfg(target_arch = "aarch64")]
#[allow(unused_imports)]
#[inline]
Expand All @@ -35,7 +48,13 @@ macro_rules! impl_minmax_reductions {

/// Smallest vector value.
///
/// FIXME: document behavior for float vectors with NaNs.
/// # Floating-point behvior
///
/// If the vector contains only `NaN` values,
/// the result is a `NaN`.
///
/// Otherwise, if the vector contains `NaN` values, either the
/// smallest element of the vector or a `NaN` is returned.
#[cfg(not(target_arch = "aarch64"))]
#[inline]
pub fn min(self) -> $elem_ty {
Expand All @@ -44,9 +63,14 @@ macro_rules! impl_minmax_reductions {
simd_reduce_min(self)
}
}
/// Smallest vector value.

/// # Floating-point behvior
///
/// If the vector contains only `NaN` values,
/// the result is a `NaN`.
///
/// FIXME: document behavior for float vectors with NaNs.
/// Otherwise, if the vector contains `NaN` values, either the
/// smallest element of the vector or a `NaN` is returned.
#[cfg(target_arch = "aarch64")]
#[allow(unused_imports)]
#[inline]
Expand Down
Loading

0 comments on commit 6ac8341

Please sign in to comment.