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§
Sourceconst BYTE_WIDTH: usize
const BYTE_WIDTH: usize
Number of bytes per element.
Sourceconst SIGN_MASK: Self
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.
Required Methods§
Sourcefn scalar_fmadd(self, b: Self, c: Self) -> Self
fn scalar_fmadd(self, b: Self, c: Self) -> Self
Scalar fused multiply-add: (self * b) + c.
Sourcefn sqrt(self) -> Self
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.
Sourcefn count_ones(self) -> u32
fn count_ones(self) -> u32
Count set bits (population count).
Provided Methods§
Sourcefn min_scalar(self, other: Self) -> Selfwhere
Self: PartialOrd,
fn min_scalar(self, other: Self) -> Selfwhere
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.
Sourcefn max_scalar(self, other: Self) -> Selfwhere
Self: PartialOrd,
fn max_scalar(self, other: Self) -> Selfwhere
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.
Sourcefn saturating_add(self, rhs: Self) -> Self
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.
Sourcefn saturating_mul(self, rhs: Self) -> Self
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.
Sourcefn checked_add(self, rhs: Self) -> Option<Self>
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.
Sourcefn checked_mul(self, rhs: Self) -> Option<Self>
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
impl NumericElement for f32
Source§fn min_scalar(self, other: f32) -> f32
fn min_scalar(self, other: f32) -> f32
Use native f32::min which correctly handles NaN propagation.
Source§fn max_scalar(self, other: f32) -> f32
fn max_scalar(self, other: f32) -> f32
Use native f32::max which correctly handles NaN propagation.
const ZERO: f32 = 0.0_f32
const ONE: f32 = 1.0_f32
const NAN: f32 = f32::NAN
const INFINITY: f32 = f32::INFINITY
const BYTE_WIDTH: usize = 4
const ALL_ONES: f32
const SIGN_MASK: f32
const MIN_VALUE: f32 = f32::NEG_INFINITY
const MAX_VALUE: f32 = f32::INFINITY
fn abs(self) -> f32
fn scalar_fmadd(self, b: f32, c: f32) -> f32
fn sqrt(self) -> f32
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: f32) -> f32
fn bitor(self, rhs: f32) -> f32
fn bitxor(self, rhs: f32) -> f32
fn count_ones(self) -> u32
Source§impl NumericElement for f64
impl NumericElement for f64
Source§fn min_scalar(self, other: f64) -> f64
fn min_scalar(self, other: f64) -> f64
Use native f64::min which correctly handles NaN propagation.
Source§fn max_scalar(self, other: f64) -> f64
fn max_scalar(self, other: f64) -> f64
Use native f64::max which correctly handles NaN propagation.
const ZERO: f64 = 0.0_f64
const ONE: f64 = 1.0_f64
const NAN: f64 = f64::NAN
const INFINITY: f64 = f64::INFINITY
const BYTE_WIDTH: usize = 8
const ALL_ONES: f64
const SIGN_MASK: f64
const MIN_VALUE: f64 = f64::NEG_INFINITY
const MAX_VALUE: f64 = f64::INFINITY
fn abs(self) -> f64
fn scalar_fmadd(self, b: f64, c: f64) -> f64
fn sqrt(self) -> f64
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: f64) -> f64
fn bitor(self, rhs: f64) -> f64
fn bitxor(self, rhs: f64) -> f64
fn count_ones(self) -> u32
Source§impl NumericElement for i8
impl NumericElement for i8
const ZERO: i8 = 0
const ONE: i8 = 1
const NAN: i8 = 0
const INFINITY: i8 = 0
const BYTE_WIDTH: usize = 1
const ALL_ONES: i8 = -1
const SIGN_MASK: i8 = i8::MIN
const MIN_VALUE: i8 = i8::MIN
const MAX_VALUE: i8 = i8::MAX
fn abs(self) -> i8
fn scalar_fmadd(self, b: i8, c: i8) -> i8
fn sqrt(self) -> i8
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: i8) -> i8
fn bitor(self, rhs: i8) -> i8
fn bitxor(self, rhs: i8) -> i8
fn count_ones(self) -> u32
fn saturating_add(self, rhs: i8) -> i8
fn saturating_mul(self, rhs: i8) -> i8
fn checked_add(self, rhs: i8) -> Option<i8>
fn checked_mul(self, rhs: i8) -> Option<i8>
Source§impl NumericElement for i16
impl NumericElement for i16
const ZERO: i16 = 0
const ONE: i16 = 1
const NAN: i16 = 0
const INFINITY: i16 = 0
const BYTE_WIDTH: usize = 2
const ALL_ONES: i16 = -1
const SIGN_MASK: i16 = i16::MIN
const MIN_VALUE: i16 = i16::MIN
const MAX_VALUE: i16 = i16::MAX
fn abs(self) -> i16
fn scalar_fmadd(self, b: i16, c: i16) -> i16
fn sqrt(self) -> i16
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: i16) -> i16
fn bitor(self, rhs: i16) -> i16
fn bitxor(self, rhs: i16) -> i16
fn count_ones(self) -> u32
fn saturating_add(self, rhs: i16) -> i16
fn saturating_mul(self, rhs: i16) -> i16
fn checked_add(self, rhs: i16) -> Option<i16>
fn checked_mul(self, rhs: i16) -> Option<i16>
Source§impl NumericElement for i32
impl NumericElement for i32
const ZERO: i32 = 0
const ONE: i32 = 1
const NAN: i32 = 0
const INFINITY: i32 = 0
const BYTE_WIDTH: usize = 4
const ALL_ONES: i32 = -1
const SIGN_MASK: i32 = i32::MIN
const MIN_VALUE: i32 = i32::MIN
const MAX_VALUE: i32 = i32::MAX
fn abs(self) -> i32
fn scalar_fmadd(self, b: i32, c: i32) -> i32
fn sqrt(self) -> i32
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: i32) -> i32
fn bitor(self, rhs: i32) -> i32
fn bitxor(self, rhs: i32) -> i32
fn count_ones(self) -> u32
fn saturating_add(self, rhs: i32) -> i32
fn saturating_mul(self, rhs: i32) -> i32
fn checked_add(self, rhs: i32) -> Option<i32>
fn checked_mul(self, rhs: i32) -> Option<i32>
Source§impl NumericElement for i64
impl NumericElement for i64
const ZERO: i64 = 0
const ONE: i64 = 1
const NAN: i64 = 0
const INFINITY: i64 = 0
const BYTE_WIDTH: usize = 8
const ALL_ONES: i64 = -1
const SIGN_MASK: i64 = i64::MIN
const MIN_VALUE: i64 = i64::MIN
const MAX_VALUE: i64 = i64::MAX
fn abs(self) -> i64
fn scalar_fmadd(self, b: i64, c: i64) -> i64
fn sqrt(self) -> i64
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: i64) -> i64
fn bitor(self, rhs: i64) -> i64
fn bitxor(self, rhs: i64) -> i64
fn count_ones(self) -> u32
fn saturating_add(self, rhs: i64) -> i64
fn saturating_mul(self, rhs: i64) -> i64
fn checked_add(self, rhs: i64) -> Option<i64>
fn checked_mul(self, rhs: i64) -> Option<i64>
Source§impl NumericElement for isize
impl NumericElement for isize
const ZERO: isize = 0
const ONE: isize = 1
const NAN: isize = 0
const INFINITY: isize = 0
const BYTE_WIDTH: usize
const ALL_ONES: isize = -1
const SIGN_MASK: isize = isize::MIN
const MIN_VALUE: isize = isize::MIN
const MAX_VALUE: isize = isize::MAX
fn abs(self) -> isize
fn scalar_fmadd(self, b: isize, c: isize) -> isize
fn sqrt(self) -> isize
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: isize) -> isize
fn bitor(self, rhs: isize) -> isize
fn bitxor(self, rhs: isize) -> isize
fn count_ones(self) -> u32
fn saturating_add(self, rhs: isize) -> isize
fn saturating_mul(self, rhs: isize) -> isize
fn checked_add(self, rhs: isize) -> Option<isize>
fn checked_mul(self, rhs: isize) -> Option<isize>
Source§impl NumericElement for u8
impl NumericElement for u8
Source§fn saturating_add(self, rhs: u8) -> u8
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
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>
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>
fn checked_mul(self, rhs: u8) -> Option<u8>
Native checked_mul; see Self::checked_add for rationale.
const ZERO: u8 = 0
const ONE: u8 = 1
const NAN: u8 = 0
const INFINITY: u8 = 0
const BYTE_WIDTH: usize = 1
const ALL_ONES: u8
const SIGN_MASK: u8 = 0
const MIN_VALUE: u8 = u8::MIN
const MAX_VALUE: u8 = u8::MAX
fn abs(self) -> u8
fn scalar_fmadd(self, b: u8, c: u8) -> u8
fn sqrt(self) -> u8
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: u8) -> u8
fn bitor(self, rhs: u8) -> u8
fn bitxor(self, rhs: u8) -> u8
fn count_ones(self) -> u32
Source§impl NumericElement for u16
impl NumericElement for u16
Source§fn saturating_add(self, rhs: u16) -> u16
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
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>
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>
fn checked_mul(self, rhs: u16) -> Option<u16>
Native checked_mul; see Self::checked_add for rationale.
const ZERO: u16 = 0
const ONE: u16 = 1
const NAN: u16 = 0
const INFINITY: u16 = 0
const BYTE_WIDTH: usize = 2
const ALL_ONES: u16
const SIGN_MASK: u16 = 0
const MIN_VALUE: u16 = u16::MIN
const MAX_VALUE: u16 = u16::MAX
fn abs(self) -> u16
fn scalar_fmadd(self, b: u16, c: u16) -> u16
fn sqrt(self) -> u16
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: u16) -> u16
fn bitor(self, rhs: u16) -> u16
fn bitxor(self, rhs: u16) -> u16
fn count_ones(self) -> u32
Source§impl NumericElement for u32
impl NumericElement for u32
Source§fn saturating_add(self, rhs: u32) -> u32
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
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>
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>
fn checked_mul(self, rhs: u32) -> Option<u32>
Native checked_mul; see Self::checked_add for rationale.
const ZERO: u32 = 0
const ONE: u32 = 1
const NAN: u32 = 0
const INFINITY: u32 = 0
const BYTE_WIDTH: usize = 4
const ALL_ONES: u32
const SIGN_MASK: u32 = 0
const MIN_VALUE: u32 = u32::MIN
const MAX_VALUE: u32 = u32::MAX
fn abs(self) -> u32
fn scalar_fmadd(self, b: u32, c: u32) -> u32
fn sqrt(self) -> u32
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: u32) -> u32
fn bitor(self, rhs: u32) -> u32
fn bitxor(self, rhs: u32) -> u32
fn count_ones(self) -> u32
Source§impl NumericElement for u64
impl NumericElement for u64
Source§fn saturating_add(self, rhs: u64) -> u64
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
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>
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>
fn checked_mul(self, rhs: u64) -> Option<u64>
Native checked_mul; see Self::checked_add for rationale.
const ZERO: u64 = 0
const ONE: u64 = 1
const NAN: u64 = 0
const INFINITY: u64 = 0
const BYTE_WIDTH: usize = 8
const ALL_ONES: u64
const SIGN_MASK: u64 = 0
const MIN_VALUE: u64 = u64::MIN
const MAX_VALUE: u64 = u64::MAX
fn abs(self) -> u64
fn scalar_fmadd(self, b: u64, c: u64) -> u64
fn sqrt(self) -> u64
fn is_finite(self) -> bool
fn is_nan(self) -> bool
fn to_f64(self) -> f64
fn bitand(self, rhs: u64) -> u64
fn bitor(self, rhs: u64) -> u64
fn bitxor(self, rhs: u64) -> u64
fn count_ones(self) -> u32
Source§impl NumericElement for usize
impl NumericElement for usize
Source§fn saturating_add(self, rhs: usize) -> usize
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
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>
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>
fn checked_mul(self, rhs: usize) -> Option<usize>
Native checked_mul; see Self::checked_add for rationale.