Skip to main content

SimdScalar

Trait SimdScalar 

Source
pub trait SimdScalar:
    Sealed
    + Copy
    + Default
    + Send
    + Sync
    + 'static
    + PartialOrd
    + PartialEq
    + Debug
    + Add<Output = Self>
    + AddAssign
    + Sub<Output = Self>
    + SubAssign
    + Mul<Output = Self>
    + MulAssign
    + Div<Output = Self>
    + CastFrom<i32> {
    const ZERO: Self;
    const ONE: Self;
    const NAN: Self;
    const INFINITY: Self;
    const BYTE_WIDTH: usize;
    const ALL_ONES: Self;
    const SIGN_MASK: Self;
    const MIN_VALUE: Self;
    const MAX_VALUE: Self;
Show 16 methods // Required methods fn abs(self) -> Self; fn scalar_fmadd(self, b: Self, c: Self) -> Self; fn sqrt(self) -> Self; fn is_finite(self) -> bool; fn is_nan(self) -> bool; fn to_f64(self) -> f64; fn bitand(self, rhs: Self) -> Self; fn bitor(self, rhs: Self) -> Self; fn bitxor(self, rhs: Self) -> Self; fn count_ones(self) -> u32; // Provided methods fn min_scalar(self, other: Self) -> Self where Self: PartialOrd { ... } fn max_scalar(self, other: Self) -> Self where Self: PartialOrd { ... } fn saturating_add(self, rhs: Self) -> Self { ... } fn saturating_mul(self, rhs: Self) -> Self { ... } fn checked_add(self, rhs: Self) -> Option<Self> { ... } fn checked_mul(self, rhs: Self) -> Option<Self> { ... }
}
Expand description

Core numeric element trait. The main extension point for monomorphized operations across all precisions.

§Source constructors

from_f64 lives on FloatElement (precision-correct for F16 and Bf16). Integer callers use the literal v as Self truncating cast natively. There is no generic from_usize on NumericElement for the same reason — the per-type route is selected explicitly so callers express precision-correct construction (literal cast for ints, FloatElement::from_f64(v as f64) round-trip for floats).

Required Associated Constants§

Source

const ZERO: Self

Additive identity.

Source

const ONE: Self

Multiplicative identity.

Source

const NAN: Self

IEEE 754 not-a-number sentinel.

Source

const INFINITY: Self

IEEE 754 positive infinity.

Source

const BYTE_WIDTH: usize

Number of bytes per element.

Source

const ALL_ONES: Self

Bitwise representation with all bits set to 1.

Source

const SIGN_MASK: Self

IEEE 754 sign-bit mask: only the most-significant bit is set.

XOR-ing any value with this mask negates it (flips the sign bit). Used by the default SimdKernel::neg implementation (hermes-simd-core) to avoid subtraction, which is not universally available across SIMD backends.

Source

const MIN_VALUE: Self

The minimum representable finite value (negative infinity or i32::MIN).

Used as the identity element for Max reductions.

Source

const MAX_VALUE: Self

The maximum representable finite value (positive infinity or i32::MAX).

Used as the identity element for Min reductions.

Required Methods§

Source

fn abs(self) -> Self

Absolute value.

Source

fn scalar_fmadd(self, b: Self, c: Self) -> Self

Scalar fused multiply-add: (self * b) + c.

Source

fn sqrt(self) -> Self

Square root. Floats follow IEEE 754 (NaN for negative inputs); integers return the exact floor integer square root (isqrt), with negative signed inputs defined to return 0 (integers have no NaN to signal the domain error). No f64 round-trip, so the integer result is exact for all operands.

Source

fn is_finite(self) -> bool

Returns true if finite.

Source

fn is_nan(self) -> bool

Returns true if NaN.

Source

fn to_f64(self) -> f64

Cast to f64.

Source

fn bitand(self, rhs: Self) -> Self

Bitwise AND.

Source

fn bitor(self, rhs: Self) -> Self

Bitwise OR.

Source

fn bitxor(self, rhs: Self) -> Self

Bitwise XOR.

Source

fn count_ones(self) -> u32

Count set bits (population count).

Provided Methods§

Source

fn min_scalar(self, other: Self) -> Self
where Self: PartialOrd,

Elementwise minimum: returns self if self <= other, else other.

Default: uses PartialOrd comparison. Concrete impls (e.g. f32, f64) may override with a hardware intrinsic.

Source

fn max_scalar(self, other: Self) -> Self
where Self: PartialOrd,

Elementwise maximum: returns self if self >= other, else other.

Default: uses PartialOrd comparison. Concrete impls (e.g. f32, f64) may override with a hardware intrinsic.

Source

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

Saturating addition.

For floats this is identical to + (IEEE 754 already saturates at ±∞). Integer implementations must override this with the native saturating_add; the default self + rhs would silently wrap in release / panic in debug on integer overflow — which is the bug ATLAS-EUNOMIA-044 closed. Every primitive integer and integer-wrapper impl in this crate already overrides; treat that as a hard rule when adding a new NumericElement impl for an integer type.

Source

fn saturating_mul(self, rhs: Self) -> Self

Saturating multiplication.

For floats this is identical to * (IEEE 754 already saturates at ±∞). Integer implementations must override this with the native saturating_mul; see Self::saturating_add for the rationale and the ATLAS-EUNOMIA-044 history.

Source

fn checked_add(self, rhs: Self) -> Option<Self>

Checked addition: returns Some(self + rhs) or None on integer overflow.

Float types always return Some since their arithmetic never overflows to undefined behaviour (they produce ±∞ or NaN instead). Integer implementations must override this with the native checked_add; the default Some(self + rhs) would silently wrap in release / panic in debug on integer overflow. Every primitive integer and integer-wrapper impl in this crate already overrides; treat that as a hard rule when adding a new NumericElement impl for an integer type.

Source

fn checked_mul(self, rhs: Self) -> Option<Self>

Checked multiplication: returns Some(self * rhs) or None on integer overflow.

Float types always return Some (see NumericElement::checked_add). Integer implementations must override with the native checked_mul; see NumericElement::checked_add for the rationale.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl NumericElement for f32

Source§

fn min_scalar(self, other: f32) -> f32

Use native f32::min which correctly handles NaN propagation.

Source§

fn max_scalar(self, other: f32) -> f32

Use native f32::max which correctly handles NaN propagation.

Source§

const ZERO: f32 = 0.0_f32

Source§

const ONE: f32 = 1.0_f32

Source§

const NAN: f32 = f32::NAN

Source§

const INFINITY: f32 = f32::INFINITY

Source§

const BYTE_WIDTH: usize = 4

Source§

const ALL_ONES: f32

Source§

const SIGN_MASK: f32

Source§

const MIN_VALUE: f32 = f32::NEG_INFINITY

Source§

const MAX_VALUE: f32 = f32::INFINITY

Source§

fn abs(self) -> f32

Source§

fn scalar_fmadd(self, b: f32, c: f32) -> f32

Source§

fn sqrt(self) -> f32

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: f32) -> f32

Source§

fn bitor(self, rhs: f32) -> f32

Source§

fn bitxor(self, rhs: f32) -> f32

Source§

fn count_ones(self) -> u32

Source§

impl NumericElement for f64

Source§

fn min_scalar(self, other: f64) -> f64

Use native f64::min which correctly handles NaN propagation.

Source§

fn max_scalar(self, other: f64) -> f64

Use native f64::max which correctly handles NaN propagation.

Source§

const ZERO: f64 = 0.0_f64

Source§

const ONE: f64 = 1.0_f64

Source§

const NAN: f64 = f64::NAN

Source§

const INFINITY: f64 = f64::INFINITY

Source§

const BYTE_WIDTH: usize = 8

Source§

const ALL_ONES: f64

Source§

const SIGN_MASK: f64

Source§

const MIN_VALUE: f64 = f64::NEG_INFINITY

Source§

const MAX_VALUE: f64 = f64::INFINITY

Source§

fn abs(self) -> f64

Source§

fn scalar_fmadd(self, b: f64, c: f64) -> f64

Source§

fn sqrt(self) -> f64

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: f64) -> f64

Source§

fn bitor(self, rhs: f64) -> f64

Source§

fn bitxor(self, rhs: f64) -> f64

Source§

fn count_ones(self) -> u32

Source§

impl NumericElement for i8

Source§

const ZERO: i8 = 0

Source§

const ONE: i8 = 1

Source§

const NAN: i8 = 0

Source§

const INFINITY: i8 = 0

Source§

const BYTE_WIDTH: usize = 1

Source§

const ALL_ONES: i8 = -1

Source§

const SIGN_MASK: i8 = i8::MIN

Source§

const MIN_VALUE: i8 = i8::MIN

Source§

const MAX_VALUE: i8 = i8::MAX

Source§

fn abs(self) -> i8

Source§

fn scalar_fmadd(self, b: i8, c: i8) -> i8

Source§

fn sqrt(self) -> i8

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: i8) -> i8

Source§

fn bitor(self, rhs: i8) -> i8

Source§

fn bitxor(self, rhs: i8) -> i8

Source§

fn count_ones(self) -> u32

Source§

fn saturating_add(self, rhs: i8) -> i8

Source§

fn saturating_mul(self, rhs: i8) -> i8

Source§

fn checked_add(self, rhs: i8) -> Option<i8>

Source§

fn checked_mul(self, rhs: i8) -> Option<i8>

Source§

impl NumericElement for i16

Source§

const ZERO: i16 = 0

Source§

const ONE: i16 = 1

Source§

const NAN: i16 = 0

Source§

const INFINITY: i16 = 0

Source§

const BYTE_WIDTH: usize = 2

Source§

const ALL_ONES: i16 = -1

Source§

const SIGN_MASK: i16 = i16::MIN

Source§

const MIN_VALUE: i16 = i16::MIN

Source§

const MAX_VALUE: i16 = i16::MAX

Source§

fn abs(self) -> i16

Source§

fn scalar_fmadd(self, b: i16, c: i16) -> i16

Source§

fn sqrt(self) -> i16

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: i16) -> i16

Source§

fn bitor(self, rhs: i16) -> i16

Source§

fn bitxor(self, rhs: i16) -> i16

Source§

fn count_ones(self) -> u32

Source§

fn saturating_add(self, rhs: i16) -> i16

Source§

fn saturating_mul(self, rhs: i16) -> i16

Source§

fn checked_add(self, rhs: i16) -> Option<i16>

Source§

fn checked_mul(self, rhs: i16) -> Option<i16>

Source§

impl NumericElement for i32

Source§

const ZERO: i32 = 0

Source§

const ONE: i32 = 1

Source§

const NAN: i32 = 0

Source§

const INFINITY: i32 = 0

Source§

const BYTE_WIDTH: usize = 4

Source§

const ALL_ONES: i32 = -1

Source§

const SIGN_MASK: i32 = i32::MIN

Source§

const MIN_VALUE: i32 = i32::MIN

Source§

const MAX_VALUE: i32 = i32::MAX

Source§

fn abs(self) -> i32

Source§

fn scalar_fmadd(self, b: i32, c: i32) -> i32

Source§

fn sqrt(self) -> i32

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: i32) -> i32

Source§

fn bitor(self, rhs: i32) -> i32

Source§

fn bitxor(self, rhs: i32) -> i32

Source§

fn count_ones(self) -> u32

Source§

fn saturating_add(self, rhs: i32) -> i32

Source§

fn saturating_mul(self, rhs: i32) -> i32

Source§

fn checked_add(self, rhs: i32) -> Option<i32>

Source§

fn checked_mul(self, rhs: i32) -> Option<i32>

Source§

impl NumericElement for i64

Source§

const ZERO: i64 = 0

Source§

const ONE: i64 = 1

Source§

const NAN: i64 = 0

Source§

const INFINITY: i64 = 0

Source§

const BYTE_WIDTH: usize = 8

Source§

const ALL_ONES: i64 = -1

Source§

const SIGN_MASK: i64 = i64::MIN

Source§

const MIN_VALUE: i64 = i64::MIN

Source§

const MAX_VALUE: i64 = i64::MAX

Source§

fn abs(self) -> i64

Source§

fn scalar_fmadd(self, b: i64, c: i64) -> i64

Source§

fn sqrt(self) -> i64

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: i64) -> i64

Source§

fn bitor(self, rhs: i64) -> i64

Source§

fn bitxor(self, rhs: i64) -> i64

Source§

fn count_ones(self) -> u32

Source§

fn saturating_add(self, rhs: i64) -> i64

Source§

fn saturating_mul(self, rhs: i64) -> i64

Source§

fn checked_add(self, rhs: i64) -> Option<i64>

Source§

fn checked_mul(self, rhs: i64) -> Option<i64>

Source§

impl NumericElement for isize

Source§

const ZERO: isize = 0

Source§

const ONE: isize = 1

Source§

const NAN: isize = 0

Source§

const INFINITY: isize = 0

Source§

const BYTE_WIDTH: usize

Source§

const ALL_ONES: isize = -1

Source§

const SIGN_MASK: isize = isize::MIN

Source§

const MIN_VALUE: isize = isize::MIN

Source§

const MAX_VALUE: isize = isize::MAX

Source§

fn abs(self) -> isize

Source§

fn scalar_fmadd(self, b: isize, c: isize) -> isize

Source§

fn sqrt(self) -> isize

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: isize) -> isize

Source§

fn bitor(self, rhs: isize) -> isize

Source§

fn bitxor(self, rhs: isize) -> isize

Source§

fn count_ones(self) -> u32

Source§

fn saturating_add(self, rhs: isize) -> isize

Source§

fn saturating_mul(self, rhs: isize) -> isize

Source§

fn checked_add(self, rhs: isize) -> Option<isize>

Source§

fn checked_mul(self, rhs: isize) -> Option<isize>

Source§

impl NumericElement for u8

Source§

fn saturating_add(self, rhs: u8) -> u8

Native saturating_add replaces the trait’s float default self + rhs, which would wrap in release / panic in debug on uint overflow. The native op saturates to MAX_VALUE/MIN_VALUE.

Source§

fn saturating_mul(self, rhs: u8) -> u8

Native saturating_mul; see Self::saturating_add for rationale.

Source§

fn checked_add(self, rhs: u8) -> Option<u8>

Native checked_add returns None on uint overflow instead of silently wrapping (the trait float default returns Some(self + rhs), which is wrong for integers).

Source§

fn checked_mul(self, rhs: u8) -> Option<u8>

Native checked_mul; see Self::checked_add for rationale.

Source§

const ZERO: u8 = 0

Source§

const ONE: u8 = 1

Source§

const NAN: u8 = 0

Source§

const INFINITY: u8 = 0

Source§

const BYTE_WIDTH: usize = 1

Source§

const ALL_ONES: u8

Source§

const SIGN_MASK: u8 = 0

Source§

const MIN_VALUE: u8 = u8::MIN

Source§

const MAX_VALUE: u8 = u8::MAX

Source§

fn abs(self) -> u8

Source§

fn scalar_fmadd(self, b: u8, c: u8) -> u8

Source§

fn sqrt(self) -> u8

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: u8) -> u8

Source§

fn bitor(self, rhs: u8) -> u8

Source§

fn bitxor(self, rhs: u8) -> u8

Source§

fn count_ones(self) -> u32

Source§

impl NumericElement for u16

Source§

fn saturating_add(self, rhs: u16) -> u16

Native saturating_add replaces the trait’s float default self + rhs, which would wrap in release / panic in debug on uint overflow. The native op saturates to MAX_VALUE/MIN_VALUE.

Source§

fn saturating_mul(self, rhs: u16) -> u16

Native saturating_mul; see Self::saturating_add for rationale.

Source§

fn checked_add(self, rhs: u16) -> Option<u16>

Native checked_add returns None on uint overflow instead of silently wrapping (the trait float default returns Some(self + rhs), which is wrong for integers).

Source§

fn checked_mul(self, rhs: u16) -> Option<u16>

Native checked_mul; see Self::checked_add for rationale.

Source§

const ZERO: u16 = 0

Source§

const ONE: u16 = 1

Source§

const NAN: u16 = 0

Source§

const INFINITY: u16 = 0

Source§

const BYTE_WIDTH: usize = 2

Source§

const ALL_ONES: u16

Source§

const SIGN_MASK: u16 = 0

Source§

const MIN_VALUE: u16 = u16::MIN

Source§

const MAX_VALUE: u16 = u16::MAX

Source§

fn abs(self) -> u16

Source§

fn scalar_fmadd(self, b: u16, c: u16) -> u16

Source§

fn sqrt(self) -> u16

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: u16) -> u16

Source§

fn bitor(self, rhs: u16) -> u16

Source§

fn bitxor(self, rhs: u16) -> u16

Source§

fn count_ones(self) -> u32

Source§

impl NumericElement for u32

Source§

fn saturating_add(self, rhs: u32) -> u32

Native saturating_add replaces the trait’s float default self + rhs, which would wrap in release / panic in debug on uint overflow. The native op saturates to MAX_VALUE/MIN_VALUE.

Source§

fn saturating_mul(self, rhs: u32) -> u32

Native saturating_mul; see Self::saturating_add for rationale.

Source§

fn checked_add(self, rhs: u32) -> Option<u32>

Native checked_add returns None on uint overflow instead of silently wrapping (the trait float default returns Some(self + rhs), which is wrong for integers).

Source§

fn checked_mul(self, rhs: u32) -> Option<u32>

Native checked_mul; see Self::checked_add for rationale.

Source§

const ZERO: u32 = 0

Source§

const ONE: u32 = 1

Source§

const NAN: u32 = 0

Source§

const INFINITY: u32 = 0

Source§

const BYTE_WIDTH: usize = 4

Source§

const ALL_ONES: u32

Source§

const SIGN_MASK: u32 = 0

Source§

const MIN_VALUE: u32 = u32::MIN

Source§

const MAX_VALUE: u32 = u32::MAX

Source§

fn abs(self) -> u32

Source§

fn scalar_fmadd(self, b: u32, c: u32) -> u32

Source§

fn sqrt(self) -> u32

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: u32) -> u32

Source§

fn bitor(self, rhs: u32) -> u32

Source§

fn bitxor(self, rhs: u32) -> u32

Source§

fn count_ones(self) -> u32

Source§

impl NumericElement for u64

Source§

fn saturating_add(self, rhs: u64) -> u64

Native saturating_add replaces the trait’s float default self + rhs, which would wrap in release / panic in debug on uint overflow. The native op saturates to MAX_VALUE/MIN_VALUE.

Source§

fn saturating_mul(self, rhs: u64) -> u64

Native saturating_mul; see Self::saturating_add for rationale.

Source§

fn checked_add(self, rhs: u64) -> Option<u64>

Native checked_add returns None on uint overflow instead of silently wrapping (the trait float default returns Some(self + rhs), which is wrong for integers).

Source§

fn checked_mul(self, rhs: u64) -> Option<u64>

Native checked_mul; see Self::checked_add for rationale.

Source§

const ZERO: u64 = 0

Source§

const ONE: u64 = 1

Source§

const NAN: u64 = 0

Source§

const INFINITY: u64 = 0

Source§

const BYTE_WIDTH: usize = 8

Source§

const ALL_ONES: u64

Source§

const SIGN_MASK: u64 = 0

Source§

const MIN_VALUE: u64 = u64::MIN

Source§

const MAX_VALUE: u64 = u64::MAX

Source§

fn abs(self) -> u64

Source§

fn scalar_fmadd(self, b: u64, c: u64) -> u64

Source§

fn sqrt(self) -> u64

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: u64) -> u64

Source§

fn bitor(self, rhs: u64) -> u64

Source§

fn bitxor(self, rhs: u64) -> u64

Source§

fn count_ones(self) -> u32

Source§

impl NumericElement for usize

Source§

fn saturating_add(self, rhs: usize) -> usize

Native saturating_add replaces the trait’s float default self + rhs, which would wrap in release / panic in debug on uint overflow. The native op saturates to MAX_VALUE/MIN_VALUE.

Source§

fn saturating_mul(self, rhs: usize) -> usize

Native saturating_mul; see Self::saturating_add for rationale.

Source§

fn checked_add(self, rhs: usize) -> Option<usize>

Native checked_add returns None on uint overflow instead of silently wrapping (the trait float default returns Some(self + rhs), which is wrong for integers).

Source§

fn checked_mul(self, rhs: usize) -> Option<usize>

Native checked_mul; see Self::checked_add for rationale.

Source§

const ZERO: usize = 0

Source§

const ONE: usize = 1

Source§

const NAN: usize = 0

Source§

const INFINITY: usize = 0

Source§

const BYTE_WIDTH: usize

Source§

const ALL_ONES: usize

Source§

const SIGN_MASK: usize = 0

Source§

const MIN_VALUE: usize = usize::MIN

Source§

const MAX_VALUE: usize = usize::MAX

Source§

fn abs(self) -> usize

Source§

fn scalar_fmadd(self, b: usize, c: usize) -> usize

Source§

fn sqrt(self) -> usize

Source§

fn is_finite(self) -> bool

Source§

fn is_nan(self) -> bool

Source§

fn to_f64(self) -> f64

Source§

fn bitand(self, rhs: usize) -> usize

Source§

fn bitor(self, rhs: usize) -> usize

Source§

fn bitxor(self, rhs: usize) -> usize

Source§

fn count_ones(self) -> u32

Implementors§

Source§

impl NumericElement for Bf4

Source§

impl NumericElement for Bf8

Source§

impl NumericElement for Bf16

Source§

const ZERO: Bf16 = Bf16::ZERO

Source§

const ONE: Bf16 = Bf16::ONE

Source§

const NAN: Bf16 = Bf16::NAN

Source§

const INFINITY: Bf16 = Bf16::INFINITY

Source§

const MIN_VALUE: Bf16 = Bf16::NEG_INFINITY

Source§

const MAX_VALUE: Bf16 = Bf16::INFINITY

Source§

const BYTE_WIDTH: usize = 2

Source§

const ALL_ONES: Bf16

Source§

const SIGN_MASK: Bf16

Source§

impl NumericElement for F4

Source§

impl NumericElement for F8

Source§

impl NumericElement for F16

Source§

const ZERO: F16 = F16::ZERO

Source§

const ONE: F16 = F16::ONE

Source§

const NAN: F16 = F16::NAN

Source§

const INFINITY: F16 = F16::INFINITY

Source§

const MIN_VALUE: F16 = F16::NEG_INFINITY

Source§

const MAX_VALUE: F16 = F16::INFINITY

Source§

const BYTE_WIDTH: usize = 2

Source§

const ALL_ONES: F16

Source§

const SIGN_MASK: F16

Source§

impl NumericElement for F32

Source§

impl NumericElement for F64

Source§

impl NumericElement for I8

Source§

impl NumericElement for I16

Source§

impl NumericElement for I32

Source§

impl<T> NumericElement for Complex<T>
where T: NumericElement + CastFrom<i32> + Neg<Output = T>,