pub trait SimdInt<S: Simd>:
SimdBase<S, Element: SimdIntElement>
+ Seal
+ BitAnd<Output = Self>
+ BitAndAssign
+ BitAnd<Self::Element, Output = Self>
+ BitAndAssign<Self::Element>
+ BitOr<Output = Self>
+ BitOrAssign
+ BitOr<Self::Element, Output = Self>
+ BitOrAssign<Self::Element>
+ BitXor<Output = Self>
+ BitXorAssign
+ BitXor<Self::Element, Output = Self>
+ BitXorAssign<Self::Element>
+ Not<Output = Self>
+ Shl<u32, Output = Self>
+ ShlAssign<u32>
+ Shl<Output = Self>
+ ShlAssign
+ Shr<u32, Output = Self>
+ ShrAssign<u32>
+ Shr<Output = Self>
+ ShrAssign {
type Unsigned: SimdInt<S, Element = <Self::Element as SimdIntElement>::Unsigned, ByteVector = Self::ByteVector, Unsigned = Self::Unsigned, Signed = Self::Signed, Mask = Self::Mask>;
type Signed: SimdInt<S, Element = <Self::Element as SimdIntElement>::Signed, ByteVector = Self::ByteVector, Unsigned = Self::Unsigned, Signed = Self::Signed, Mask = Self::Mask>;
// Required methods
fn count_ones(self) -> Self;
fn count_zeros(self) -> Self;
fn swap_bytes(self) -> Self;
fn reverse_bits(self) -> Self;
fn saturating_add(self, rhs: impl SimdInto<Self, S>) -> Self;
fn saturating_sub(self, rhs: impl SimdInto<Self, S>) -> Self;
// Provided methods
fn cast_signed(self) -> Self::Signed { ... }
fn cast_unsigned(self) -> Self::Unsigned { ... }
fn to_float<T: SimdCvtFloat<Self>>(self) -> T { ... }
fn unsigned_abs(self) -> Self::Unsigned { ... }
}Expand description
Functionality implemented by (signed and unsigned) integer SIMD vectors.
Required Associated Types§
Sourcetype Unsigned: SimdInt<S, Element = <Self::Element as SimdIntElement>::Unsigned, ByteVector = Self::ByteVector, Unsigned = Self::Unsigned, Signed = Self::Signed, Mask = Self::Mask>
type Unsigned: SimdInt<S, Element = <Self::Element as SimdIntElement>::Unsigned, ByteVector = Self::ByteVector, Unsigned = Self::Unsigned, Signed = Self::Signed, Mask = Self::Mask>
Corresponding unsigned integer SIMD vector type. E.g. u8x16 for i8x16.
This type is Self if the SIMD vector is already unsigned.
Sourcetype Signed: SimdInt<S, Element = <Self::Element as SimdIntElement>::Signed, ByteVector = Self::ByteVector, Unsigned = Self::Unsigned, Signed = Self::Signed, Mask = Self::Mask>
type Signed: SimdInt<S, Element = <Self::Element as SimdIntElement>::Signed, ByteVector = Self::ByteVector, Unsigned = Self::Unsigned, Signed = Self::Signed, Mask = Self::Mask>
Corresponding signed integer SIMD vector type. E.g. i8x16 for u8x16.
This type is Self if the SIMD vector is already signed.
Required Methods§
Sourcefn count_ones(self) -> Self
fn count_ones(self) -> Self
Return the number of ones in the binary representation of each element.
Sourcefn count_zeros(self) -> Self
fn count_zeros(self) -> Self
Return the number of zeros in the binary representation of each element.
Sourcefn swap_bytes(self) -> Self
fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
§Examples
let a = u16x8::from_slice(simd, &[0x00_01, 0x02_03, 0x04_05, 0x06_07, 0x08_09, 0x0A_0B, 0x0C_0D, 0x0E_0F]);
assert_eq!(*a.swap_bytes(), [0x01_00, 0x03_02, 0x05_04, 0x07_06, 0x09_08, 0x0B_0A, 0x0D_0C, 0x0F_0E]);
let b = u32x4::from_slice(simd, &[0x00_01_02_03, 0x04_05_06_07, 0x08_09_0A_0B, 0x0C_0D_0E_0F]);
assert_eq!(*b.swap_bytes(), [0x03_02_01_00, 0x07_06_05_04, 0x0B_0A_09_08, 0x0F_0E_0D_0C]);
let c = u64x2::from_slice(simd, &[0x00_01_02_03_04_05_06_07, 0x08_09_0A_0B_0C_0D_0E_0F]);
assert_eq!(*c.swap_bytes(), [0x07_06_05_04_03_02_01_00, 0x0F_0E_0D_0C_0B_0A_09_08]);Sourcefn reverse_bits(self) -> Self
fn reverse_bits(self) -> Self
Reverses the order bits in an integer. I.e. the least significant bit becomes the most significant bit and vice versa.
§Examples
let i = u32x4::from_slice(simd, &[0x01_23_45_67, 0x89_AB_CD_EF, 0x08_09_0A_0B, 0x0C_0D_0E_0F]);
assert_eq!(*i.reverse_bits(), [0xE6_A2_C4_80, 0xF7_B3_D5_91, 0xD0_50_90_10, 0xF0_70_B0_30]);Sourcefn saturating_add(self, rhs: impl SimdInto<Self, S>) -> Self
fn saturating_add(self, rhs: impl SimdInto<Self, S>) -> Self
Add two vectors element-wise, saturating on overflow.
“Saturating” means that if the result is not representable, the closest representable value (either Element::MAX or Element::MIN) is returned.
On x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping addition on x86.
Sourcefn saturating_sub(self, rhs: impl SimdInto<Self, S>) -> Self
fn saturating_sub(self, rhs: impl SimdInto<Self, S>) -> Self
Subtract two vectors element-wise, saturating on overflow.
“Saturating” means that if the result is not representable, the closest representable value (either Element::MAX or Element::MIN) is returned.
On x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86.
Provided Methods§
Sourcefn cast_signed(self) -> Self::Signed
fn cast_signed(self) -> Self::Signed
Reinterpret this integer SIMD vector as its corresponding signed type.
Sourcefn cast_unsigned(self) -> Self::Unsigned
fn cast_unsigned(self) -> Self::Unsigned
Reinterpret this integer SIMD vector as its corresponding unsigned type.
Sourcefn to_float<T: SimdCvtFloat<Self>>(self) -> T
fn to_float<T: SimdCvtFloat<Self>>(self) -> T
Convert this integer type to a floating-point type. This is a convenience method
that delegates to SimdCvtFloat::float_from, and can only be called if there
actually exists a target type of the same bit width (f32 or f64).
Sourcefn unsigned_abs(self) -> Self::Unsigned
fn unsigned_abs(self) -> Self::Unsigned
Return the absolute value of self without any wrapping.
If Self is an unsigned SIMD vector, this always produces the same result as self.abs().
§Example
let i = i32x4::from_slice(simd, &[100, -100, i32::MAX, i32::MIN]);
assert_eq!(
*i.unsigned_abs(),
[100, 100, 2147483647, 2147483648],
);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".