Skip to main content

f16

Struct f16 

Source
pub struct f16(/* private fields */);
Expand description

A 16-bit floating point number, stored in IEEE 754 half-precision format.

Implementations§

Source§

impl f16

Source

pub const fn from_bits(bits: u16) -> Self

Create an f16 from its raw bit pattern.

Source

pub const fn to_bits(self) -> u16

Return the raw bit pattern of this value.

Source

pub fn from_f32(x: f32) -> Self

Convert an f32 to the nearest f16, rounding ties to even.

Source

pub fn to_f32(self) -> f32

Convert this value to an f32.

This conversion is always exact, since every f16 value is representable as an f32.

Trait Implementations§

Source§

impl BitOps<f16> for Avx2Isa

Source§

type Simd = F16x16

SIMD vector containing lanes of type T.
Source§

fn len(self) -> usize

Return the number of elements in the vector.
Source§

fn prefetch(self, ptr: *const <F16x16 as Simd>::Elem)

Pre-fetch the cache line containing ptr for reading.
Source§

fn prefetch_write(self, ptr: *mut <F16x16 as Simd>::Elem)

Pre-fetch the cache line containing ptr for writing.
Source§

fn and(self, x: F16x16, y: F16x16) -> F16x16

Return the bitwise AND of x and y.
Source§

fn or(self, x: F16x16, y: F16x16) -> F16x16

Return the bitwise OR of x and y.
Source§

fn xor(self, x: F16x16, y: F16x16) -> F16x16

Return the bitwise XOR of x and y.
Source§

fn not(self, x: F16x16) -> F16x16

Return the bitwise NOT of x.
Source§

fn first_n_mask(self, n: usize) -> M16

Return a mask with the first n lanes set to true.
Source§

fn splat(self, x: f16) -> F16x16

Create a new vector with all lanes set to x.
Source§

unsafe fn load_ptr(self, ptr: *const f16) -> F16x16

Load vector of elements from ptr. Read more
Source§

fn select(self, x: F16x16, y: F16x16, mask: M16) -> F16x16

Select elements from x or y according to a mask. Read more
Source§

unsafe fn store_ptr(self, x: F16x16, ptr: *mut f16)

Store the values in this vector to a memory location. Read more
Source§

unsafe fn load_ptr_mask(self, ptr: *const f16, mask: M16) -> F16x16

Load vector elements from ptr using a mask. Read more
Source§

unsafe fn store_ptr_mask(self, x: F16x16, ptr: *mut f16, mask: M16)

Store the values in this vector to a memory location, where the corresponding mask element is set. Read more
Source§

fn from_bits(self, x: <<Self::Simd as Simd>::Isa as Isa>::Bits) -> Self::Simd

Convert x to an untyped vector of the same width.
Source§

fn zero(self) -> Self::Simd

Create a new vector with all lanes set to zero.
Source§

fn broadcast_lane<const LANE: i32>(self, x: Self::Simd) -> Self::Simd

Broadcast the element from one lane of a vector to all lanes of a new vector.
Source§

fn fold_splat<F: Fn(T, T) -> T>( self, x: Self::Simd, accum: T, f: F, ) -> Self::Simd

Reduce the elements in x to a single value using f, then return a new vector with the accumulated value broadcast to each lane.
Source§

fn load(self, xs: &[T]) -> Self::Simd

Load the first self.len() elements from a slice into a vector. Read more
Source§

fn load_many<const N: usize>(self, xs: &[T]) -> [Self::Simd; N]

Load N vectors from consecutive sub-slices of xs. Read more
Source§

fn load_pad(self, xs: &[T]) -> (Self::Simd, <Self::Simd as Simd>::Mask)

Load elements from xs into a vector. Read more
Source§

fn store(self, x: Self::Simd, xs: &mut [T])

Store x into the first self.len() elements of xs.
Source§

fn store_uninit(self, x: Self::Simd, xs: &mut [MaybeUninit<T>]) -> &mut [T]

Store x into the first self.len() elements of xs. Read more
Source§

fn store_many_uninit<const N: usize>( self, vecs: [Self::Simd; N], xs: &mut [MaybeUninit<T>], ) -> &mut [T]

Store N vectors into consecutive sub-slices of xs, returning the initialized portion. Read more
Source§

impl BitOps<f16> for Avx512Isa

Source§

type Simd = F16x32

SIMD vector containing lanes of type T.
Source§

fn len(self) -> usize

Return the number of elements in the vector.
Source§

fn first_n_mask(self, n: usize) -> __mmask32

Return a mask with the first n lanes set to true.
Source§

fn prefetch(self, ptr: *const <F16x32 as Simd>::Elem)

Pre-fetch the cache line containing ptr for reading.
Source§

fn prefetch_write(self, ptr: *mut <F16x32 as Simd>::Elem)

Pre-fetch the cache line containing ptr for writing.
Source§

fn and(self, x: F16x32, y: F16x32) -> F16x32

Return the bitwise AND of x and y.
Source§

fn or(self, x: F16x32, y: F16x32) -> F16x32

Return the bitwise OR of x and y.
Source§

fn xor(self, x: F16x32, y: F16x32) -> F16x32

Return the bitwise XOR of x and y.
Source§

fn not(self, x: F16x32) -> F16x32

Return the bitwise NOT of x.
Source§

fn splat(self, x: f16) -> F16x32

Create a new vector with all lanes set to x.
Source§

unsafe fn load_ptr(self, ptr: *const f16) -> F16x32

Load vector of elements from ptr. Read more
Source§

fn select(self, x: F16x32, y: F16x32, mask: <F16x32 as Simd>::Mask) -> F16x32

Select elements from x or y according to a mask. Read more
Source§

unsafe fn store_ptr(self, x: F16x32, ptr: *mut f16)

Store the values in this vector to a memory location. Read more
Source§

unsafe fn load_ptr_mask(self, ptr: *const f16, mask: __mmask32) -> F16x32

Load vector elements from ptr using a mask. Read more
Source§

unsafe fn store_ptr_mask(self, x: F16x32, ptr: *mut f16, mask: __mmask32)

Store the values in this vector to a memory location, where the corresponding mask element is set. Read more
Source§

fn from_bits(self, x: <<Self::Simd as Simd>::Isa as Isa>::Bits) -> Self::Simd

Convert x to an untyped vector of the same width.
Source§

fn zero(self) -> Self::Simd

Create a new vector with all lanes set to zero.
Source§

fn broadcast_lane<const LANE: i32>(self, x: Self::Simd) -> Self::Simd

Broadcast the element from one lane of a vector to all lanes of a new vector.
Source§

fn fold_splat<F: Fn(T, T) -> T>( self, x: Self::Simd, accum: T, f: F, ) -> Self::Simd

Reduce the elements in x to a single value using f, then return a new vector with the accumulated value broadcast to each lane.
Source§

fn load(self, xs: &[T]) -> Self::Simd

Load the first self.len() elements from a slice into a vector. Read more
Source§

fn load_many<const N: usize>(self, xs: &[T]) -> [Self::Simd; N]

Load N vectors from consecutive sub-slices of xs. Read more
Source§

fn load_pad(self, xs: &[T]) -> (Self::Simd, <Self::Simd as Simd>::Mask)

Load elements from xs into a vector. Read more
Source§

fn store(self, x: Self::Simd, xs: &mut [T])

Store x into the first self.len() elements of xs.
Source§

fn store_uninit(self, x: Self::Simd, xs: &mut [MaybeUninit<T>]) -> &mut [T]

Store x into the first self.len() elements of xs. Read more
Source§

fn store_many_uninit<const N: usize>( self, vecs: [Self::Simd; N], xs: &mut [MaybeUninit<T>], ) -> &mut [T]

Store N vectors into consecutive sub-slices of xs, returning the initialized portion. Read more
Source§

impl BitOps<f16> for GenericIsa

Source§

type Simd = F16x8

SIMD vector containing lanes of type T.
Source§

fn len(self) -> usize

Return the number of elements in the vector.
Source§

fn first_n_mask(self, n: usize) -> M16

Return a mask with the first n lanes set to true.
Source§

unsafe fn load_ptr_mask( self, ptr: *const <F16x8 as Simd>::Elem, mask: <F16x8 as Simd>::Mask, ) -> F16x8

Load vector elements from ptr using a mask. Read more
Source§

unsafe fn store_ptr_mask( self, x: F16x8, ptr: *mut <F16x8 as Simd>::Elem, mask: <F16x8 as Simd>::Mask, )

Store the values in this vector to a memory location, where the corresponding mask element is set. Read more
Source§

fn splat(self, x: f16) -> F16x8

Create a new vector with all lanes set to x.
Source§

unsafe fn load_ptr(self, ptr: *const f16) -> F16x8

Load vector of elements from ptr. Read more
Source§

fn select(self, x: F16x8, y: F16x8, mask: <F16x8 as Simd>::Mask) -> F16x8

Select elements from x or y according to a mask. Read more
Source§

unsafe fn store_ptr(self, x: F16x8, ptr: *mut f16)

Store the values in this vector to a memory location. Read more
Source§

fn and(self, x: F16x8, y: F16x8) -> F16x8

Return the bitwise AND of x and y.
Source§

fn not(self, x: F16x8) -> F16x8

Return the bitwise NOT of x.
Source§

fn or(self, x: F16x8, y: F16x8) -> F16x8

Return the bitwise OR of x and y.
Source§

fn xor(self, x: F16x8, y: F16x8) -> F16x8

Return the bitwise XOR of x and y.
Source§

fn from_bits(self, x: <<Self::Simd as Simd>::Isa as Isa>::Bits) -> Self::Simd

Convert x to an untyped vector of the same width.
Source§

fn zero(self) -> Self::Simd

Create a new vector with all lanes set to zero.
Source§

fn broadcast_lane<const LANE: i32>(self, x: Self::Simd) -> Self::Simd

Broadcast the element from one lane of a vector to all lanes of a new vector.
Source§

fn fold_splat<F: Fn(T, T) -> T>( self, x: Self::Simd, accum: T, f: F, ) -> Self::Simd

Reduce the elements in x to a single value using f, then return a new vector with the accumulated value broadcast to each lane.
Source§

fn load(self, xs: &[T]) -> Self::Simd

Load the first self.len() elements from a slice into a vector. Read more
Source§

fn load_many<const N: usize>(self, xs: &[T]) -> [Self::Simd; N]

Load N vectors from consecutive sub-slices of xs. Read more
Source§

fn load_pad(self, xs: &[T]) -> (Self::Simd, <Self::Simd as Simd>::Mask)

Load elements from xs into a vector. Read more
Source§

fn store(self, x: Self::Simd, xs: &mut [T])

Store x into the first self.len() elements of xs.
Source§

fn store_uninit(self, x: Self::Simd, xs: &mut [MaybeUninit<T>]) -> &mut [T]

Store x into the first self.len() elements of xs. Read more
Source§

fn store_many_uninit<const N: usize>( self, vecs: [Self::Simd; N], xs: &mut [MaybeUninit<T>], ) -> &mut [T]

Store N vectors into consecutive sub-slices of xs, returning the initialized portion. Read more
Source§

fn prefetch(self, ptr: *const T)

Pre-fetch the cache line containing ptr for reading.
Source§

fn prefetch_write(self, ptr: *mut T)

Pre-fetch the cache line containing ptr for writing.
Source§

impl Clone for f16

Source§

fn clone(&self) -> f16

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for f16

Source§

impl Debug for f16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for f16

Source§

fn default() -> f16

Returns the “default value” for a type. Read more
Source§

impl Elem for f16

Source§

fn one() -> Self

Return the 1 value of this type.
Source§

impl Extend<f16> for Avx2Isa

Source§

type Output = F32x8

SIMD vector type with elements that have twice the bit-width of those in Self::SIMD.
Source§

fn extend_low(self, x: F16x16) -> F32x8

Extend each lane in the low half of the input to a type with twice the width.
Source§

fn extend_high(self, x: F16x16) -> F32x8

Extend each lane in the high half of the input to a type with twice the width.
Source§

impl Extend<f16> for Avx512Isa

Source§

type Output = F32x16

SIMD vector type with elements that have twice the bit-width of those in Self::SIMD.
Source§

fn extend_low(self, x: F16x32) -> F32x16

Extend each lane in the low half of the input to a type with twice the width.
Source§

fn extend_high(self, x: F16x32) -> F32x16

Extend each lane in the high half of the input to a type with twice the width.
Source§

impl Extend<f16> for GenericIsa

Source§

type Output = F32x4

SIMD vector type with elements that have twice the bit-width of those in Self::SIMD.
Source§

fn extend_low(self, x: F16x8) -> F32x4

Extend each lane in the low half of the input to a type with twice the width.
Source§

fn extend_high(self, x: F16x8) -> F32x4

Extend each lane in the high half of the input to a type with twice the width.
Source§

impl From<f16> for f32

Source§

fn from(x: f16) -> f32

Converts to this type from the input type.
Source§

impl From<f32> for f16

Source§

fn from(x: f32) -> f16

Converts to this type from the input type.
Source§

impl GetBitOps for f16

Source§

fn bit_ops<I: Isa>( isa: I, ) -> impl BitOps<Self, Simd = <Self as GetSimd>::Simd<I>>

Return the BitOps implementation from a SIMD Isa that provides operations on vectors containing elements of type Self.
Source§

impl GetSimd for f16

Source§

type Simd<I: Isa> = <I as Isa>::F16

Source§

impl NarrowSaturate<f32, f16> for Avx2Isa

Source§

type Output = F16x16

Source§

fn narrow_saturate(self, low: F32x8, high: F32x8) -> F16x16

Narrow each lane in a pair of vectors to one with half the bit-width. Read more
Source§

impl NarrowSaturate<f32, f16> for Avx512Isa

Source§

type Output = F16x32

Source§

fn narrow_saturate(self, low: F32x16, high: F32x16) -> F16x32

Narrow each lane in a pair of vectors to one with half the bit-width. Read more
Source§

impl NarrowSaturate<f32, f16> for GenericIsa

Source§

type Output = F16x8

Source§

fn narrow_saturate(self, low: F32x4, high: F32x4) -> F16x8

Narrow each lane in a pair of vectors to one with half the bit-width. Read more
Source§

impl PartialEq for f16

Source§

fn eq(&self, other: &f16) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for f16

Auto Trait Implementations§

§

impl Freeze for f16

§

impl RefUnwindSafe for f16

§

impl Send for f16

§

impl Sync for f16

§

impl Unpin for f16

§

impl UnsafeUnpin for f16

§

impl UnwindSafe for f16

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.