pub trait SimdInt: Copy + Sealed {
type Mask;
type Scalar;
Show 15 methods
fn saturating_add(self, second: Self) -> Self;
fn saturating_sub(self, second: Self) -> Self;
fn abs(self) -> Self;
fn saturating_abs(self) -> Self;
fn saturating_neg(self) -> Self;
fn is_positive(self) -> Self::Mask;
fn is_negative(self) -> Self::Mask;
fn signum(self) -> Self;
fn reduce_sum(self) -> Self::Scalar;
fn reduce_product(self) -> Self::Scalar;
fn reduce_max(self) -> Self::Scalar;
fn reduce_min(self) -> Self::Scalar;
fn reduce_and(self) -> Self::Scalar;
fn reduce_or(self) -> Self::Scalar;
fn reduce_xor(self) -> Self::Scalar;
}
Expand description
Operations on SIMD vectors of signed integers.
Required Associated Types
Mask type used for manipulating this SIMD vector type.
Required Methods
fn saturating_add(self, second: Self) -> Self
fn saturating_add(self, second: Self) -> Self
Lanewise saturating add.
Examples
use core::i32::{MIN, MAX};
let x = Simd::from_array([MIN, 0, 1, MAX]);
let max = Simd::splat(MAX);
let unsat = x + max;
let sat = x.saturating_add(max);
assert_eq!(unsat, Simd::from_array([-1, MAX, MIN, -2]));
assert_eq!(sat, Simd::from_array([-1, MAX, MAX, MAX]));
Runfn saturating_sub(self, second: Self) -> Self
fn saturating_sub(self, second: Self) -> Self
Lanewise saturating subtract.
Examples
use core::i32::{MIN, MAX};
let x = Simd::from_array([MIN, -2, -1, MAX]);
let max = Simd::splat(MAX);
let unsat = x - max;
let sat = x.saturating_sub(max);
assert_eq!(unsat, Simd::from_array([1, MAX, MIN, 0]));
assert_eq!(sat, Simd::from_array([MIN, MIN, MIN, 0]));
Runfn saturating_abs(self) -> Self
fn saturating_abs(self) -> Self
Lanewise saturating absolute value, implemented in Rust. As abs(), except the MIN value becomes MAX instead of itself.
Examples
use core::i32::{MIN, MAX};
let xs = Simd::from_array([MIN, -2, 0, 3]);
let unsat = xs.abs();
let sat = xs.saturating_abs();
assert_eq!(unsat, Simd::from_array([MIN, 2, 0, 3]));
assert_eq!(sat, Simd::from_array([MAX, 2, 0, 3]));
Runfn saturating_neg(self) -> Self
fn saturating_neg(self) -> Self
Lanewise saturating negation, implemented in Rust. As neg(), except the MIN value becomes MAX instead of itself.
Examples
use core::i32::{MIN, MAX};
let x = Simd::from_array([MIN, -2, 3, MAX]);
let unsat = -x;
let sat = x.saturating_neg();
assert_eq!(unsat, Simd::from_array([MIN, 2, -3, MIN + 1]));
assert_eq!(sat, Simd::from_array([MAX, 2, -3, MIN + 1]));
Runfn is_positive(self) -> Self::Mask
fn is_positive(self) -> Self::Mask
Returns true for each positive lane and false if it is zero or negative.
fn is_negative(self) -> Self::Mask
fn is_negative(self) -> Self::Mask
Returns true for each negative lane and false if it is zero or positive.
Returns numbers representing the sign of each lane.
0
if the number is zero1
if the number is positive-1
if the number is negative
fn reduce_sum(self) -> Self::Scalar
fn reduce_sum(self) -> Self::Scalar
fn reduce_product(self) -> Self::Scalar
fn reduce_product(self) -> Self::Scalar
Returns the product of the lanes of the vector, with wrapping multiplication.
Examples
let v = i32x4::from_array([1, 2, 3, 4]);
assert_eq!(v.reduce_product(), 24);
// SIMD integer multiplication is always wrapping
let v = i32x4::from_array([i32::MAX, 2, 1, 1]);
assert!(v.reduce_product() < i32::MAX);
Runfn reduce_max(self) -> Self::Scalar
fn reduce_max(self) -> Self::Scalar
fn reduce_min(self) -> Self::Scalar
fn reduce_min(self) -> Self::Scalar
fn reduce_and(self) -> Self::Scalar
fn reduce_and(self) -> Self::Scalar
Returns the cumulative bitwise “and” across the lanes of the vector.
Returns the cumulative bitwise “or” across the lanes of the vector.
fn reduce_xor(self) -> Self::Scalar
fn reduce_xor(self) -> Self::Scalar
Returns the cumulative bitwise “xor” across the lanes of the vector.