Trait core::simd::SimdInt

source ·
pub trait SimdInt: Copy + Sealed {
    type Mask;
    type Scalar;

Show 15 methods // Required 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;
}
🔬This is a nightly-only experimental API. (portable_simd #86656)
Expand description

对有符号整数的 SIMD vectors 的操作。

Required Associated Types§

source

type Mask

🔬This is a nightly-only experimental API. (portable_simd #86656)

用于操作此 SIMD vector 类型的掩码类型。

source

type Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

此 SIMD vector 类型包含的标量类型。

Required Methods§

source

fn saturating_add(self, second: Self) -> Self

🔬This is a nightly-only experimental API. (portable_simd #86656)

Lanewise 饱和加法。

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]));
Run
source

fn saturating_sub(self, second: Self) -> Self

🔬This is a nightly-only experimental API. (portable_simd #86656)

Lanewise 饱和减法。

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]));
Run
source

fn abs(self) -> Self

🔬This is a nightly-only experimental API. (portable_simd #86656)

Lanewise 绝对值,在 Rust 中实现。 每个 lane 都成为它的绝对值。

Examples
use core::i32::{MIN, MAX};
let xs = Simd::from_array([MIN, MIN +1, -5, 0]);
assert_eq!(xs.abs(), Simd::from_array([MIN, MAX, 5, 0]));
Run
source

fn saturating_abs(self) -> Self

🔬This is a nightly-only experimental API. (portable_simd #86656)

Lanewise 饱和绝对值,在 Rust 中实现。 作为 abs(),除了 MIN 值变为 MAX 而不是它本身。

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]));
Run
source

fn saturating_neg(self) -> Self

🔬This is a nightly-only experimental API. (portable_simd #86656)

Lanewise 饱和否定,在 Rust 中实现。 作为 neg(),除了 MIN 值变为 MAX 而不是它本身。

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]));
Run
source

fn is_positive(self) -> Self::Mask

🔬This is a nightly-only experimental API. (portable_simd #86656)

对于每个正 lane 返回真,如果为零或负则返回假。

source

fn is_negative(self) -> Self::Mask

🔬This is a nightly-only experimental API. (portable_simd #86656)

对于每个负 lane 返回 true,如果为零或正则返回 false。

source

fn signum(self) -> Self

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回代表每个 lane 符号的数字。

  • 0 如果数字为零
  • 1 如果数字是正数
  • -1 如果数字是负数
source

fn reduce_sum(self) -> Self::Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回 vector 的 lane 总和,带包装加法。

Examples
let v = i32x4::from_array([1, 2, 3, 4]);
assert_eq!(v.reduce_sum(), 10);

// SIMD 整数加法总是换行
let v = i32x4::from_array([i32::MAX, 1, 0, 0]);
assert_eq!(v.reduce_sum(), i32::MIN);
Run
source

fn reduce_product(self) -> Self::Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回 vector 的 lane 的乘积,带包装乘法。

Examples
let v = i32x4::from_array([1, 2, 3, 4]);
assert_eq!(v.reduce_product(), 24);

// SIMD 整数乘法总是换行
let v = i32x4::from_array([i32::MAX, 2, 1, 1]);
assert!(v.reduce_product() < i32::MAX);
Run
source

fn reduce_max(self) -> Self::Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回 vector 中的最大 lane。

Examples
let v = i32x4::from_array([1, 2, 3, 4]);
assert_eq!(v.reduce_max(), 4);
Run
source

fn reduce_min(self) -> Self::Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回 vector 中的最小 lane。

Examples
let v = i32x4::from_array([1, 2, 3, 4]);
assert_eq!(v.reduce_min(), 1);
Run
source

fn reduce_and(self) -> Self::Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回跨 vector lane 的累积按位与。

source

fn reduce_or(self) -> Self::Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回跨 vector lane 的累积按位或。

source

fn reduce_xor(self) -> Self::Scalar

🔬This is a nightly-only experimental API. (portable_simd #86656)

返回跨 vector lane 的累积按位异或。

Implementors§

source§

impl<const LANES: usize> SimdInt for Simd<i8, LANES>where LaneCount<LANES>: SupportedLaneCount,

§

type Mask = Mask<<i8 as SimdElement>::Mask, LANES>

§

type Scalar = i8

source§

impl<const LANES: usize> SimdInt for Simd<i16, LANES>where LaneCount<LANES>: SupportedLaneCount,

§

type Mask = Mask<<i16 as SimdElement>::Mask, LANES>

§

type Scalar = i16

source§

impl<const LANES: usize> SimdInt for Simd<i32, LANES>where LaneCount<LANES>: SupportedLaneCount,

§

type Mask = Mask<<i32 as SimdElement>::Mask, LANES>

§

type Scalar = i32

source§

impl<const LANES: usize> SimdInt for Simd<i64, LANES>where LaneCount<LANES>: SupportedLaneCount,

§

type Mask = Mask<<i64 as SimdElement>::Mask, LANES>

§

type Scalar = i64

source§

impl<const LANES: usize> SimdInt for Simd<isize, LANES>where LaneCount<LANES>: SupportedLaneCount,

§

type Mask = Mask<<isize as SimdElement>::Mask, LANES>

§

type Scalar = isize