Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions library/portable-simd/crates/core_simd/src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ alias! {
usizex64 64
}

f16 = {
f16x1 1
f16x2 2
f16x4 4
f16x8 8
f16x16 16
f16x32 32
f16x64 64
}

f32 = {
f32x1 1
f32x2 2
Expand Down
5 changes: 5 additions & 0 deletions library/portable-simd/crates/core_simd/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl SimdCast for u64 {}
unsafe impl Sealed for usize {}
impl SimdCast for usize {}
// Safety: primitive number types can be cast to other primitive number types

unsafe impl Sealed for f16 {}

impl SimdCast for f16 {}
// Safety: primitive number types can be cast to other primitive number types
unsafe impl Sealed for f32 {}
impl SimdCast for f32 {}
// Safety: primitive number types can be cast to other primitive number types
Expand Down
1 change: 1 addition & 0 deletions library/portable-simd/crates/core_simd/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ macro_rules! impl_traits {
}
}

impl_traits! { f16 }
impl_traits! { f32 }
impl_traits! { f64 }
impl_traits! { u8 }
Expand Down
1 change: 1 addition & 0 deletions library/portable-simd/crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
convert_float_to_int,
core_intrinsics,
decl_macro,
f16_and_f128,
intra_doc_pointers,
repr_simd,
simd_ffi,
Expand Down
2 changes: 1 addition & 1 deletion library/portable-simd/crates/core_simd/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ for_base_ops! {
// We don't need any special precautions here:
// Floats always accept arithmetic ops, but may become NaN.
for_base_ops! {
T = (f32, f64);
T = (f16, f32, f64);
type Lhs = Simd<T, N>;
type Rhs = Simd<T, N>;
type Output = Self;
Expand Down
2 changes: 2 additions & 0 deletions library/portable-simd/crates/core_simd/src/ops/unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ macro_rules! neg {
}

neg! {
impl<const N: usize> Neg for Simd<f16, N>

impl<const N: usize> Neg for Simd<f32, N>

impl<const N: usize> Neg for Simd<f64, N>
Expand Down
2 changes: 1 addition & 1 deletion library/portable-simd/crates/core_simd/src/simd/cmp/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ macro_rules! impl_number {
}
}

impl_number! { f32, f64, u8, u16, u32, u64, usize, i8, i16, i32, i64, isize }
impl_number! { f16, f32, f64, u8, u16, u32, u64, usize, i8, i16, i32, i64, isize }

macro_rules! impl_mask {
{ $($integer:ty),* } => {
Expand Down
2 changes: 1 addition & 1 deletion library/portable-simd/crates/core_simd/src/simd/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ macro_rules! impl_float {
}
}

impl_float! { f32, f64 }
impl_float! { f16, f32, f64 }

macro_rules! impl_mask {
{ $($integer:ty),* } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,4 @@ macro_rules! impl_trait {
}
}

impl_trait! { f32 { bits: u32, mask: i32 }, f64 { bits: u64, mask: i64 } }
impl_trait! { f16 { bits: u16, mask: i16 }, f32 { bits: u32, mask: i32 }, f64 { bits: u64, mask: i64 } }
2 changes: 2 additions & 0 deletions library/portable-simd/crates/core_simd/src/to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub trait ToBytes: Sealed {
}

macro_rules! swap_bytes {
{ f16, $x:expr } => { Simd::from_bits($x.to_bits().swap_bytes()) };
{ f32, $x:expr } => { Simd::from_bits($x.to_bits().swap_bytes()) };
{ f64, $x:expr } => { Simd::from_bits($x.to_bits().swap_bytes()) };
{ $ty:ty, $x:expr } => { $x.swap_bytes() }
Expand Down Expand Up @@ -141,5 +142,6 @@ impl_to_bytes! { isize, 4 }
#[cfg(target_pointer_width = "64")]
impl_to_bytes! { isize, 8 }

impl_to_bytes! { f16, 2 }
impl_to_bytes! { f32, 4 }
impl_to_bytes! { f64, 8 }
7 changes: 7 additions & 0 deletions library/portable-simd/crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,13 @@ unsafe impl SimdElement for isize {
type Mask = isize;
}

impl Sealed for f16 {}

// Safety: f16 is a valid SIMD element type, and is supported by this API
unsafe impl SimdElement for f16 {
type Mask = i16;
}

impl Sealed for f32 {}

// Safety: f32 is a valid SIMD element type, and is supported by this API
Expand Down
18 changes: 18 additions & 0 deletions library/portable-simd/crates/std_float/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,31 @@ pub trait StdFloat: Sealed + Sized {
fn fract(self) -> Self;
}

impl<const N: usize> Sealed for Simd<f16, N> where LaneCount<N>: SupportedLaneCount {}
impl<const N: usize> Sealed for Simd<f32, N> where LaneCount<N>: SupportedLaneCount {}
impl<const N: usize> Sealed for Simd<f64, N> where LaneCount<N>: SupportedLaneCount {}

macro_rules! impl_float {
{
$($fn:ident: $intrinsic:ident,)*
} => {
impl<const N: usize> StdFloat for Simd<f16, N>
where
LaneCount<N>: SupportedLaneCount,
{
#[inline]
fn fract(self) -> Self {
self - self.trunc()
}

$(
#[inline]
fn $fn(self) -> Self {
unsafe { intrinsics::$intrinsic(self) }
}
)*
}

impl<const N: usize> StdFloat for Simd<f32, N>
where
LaneCount<N>: SupportedLaneCount,
Expand Down
Loading