Skip to content

Commit f23fdf3

Browse files
committed
Add support for f16
1 parent 03d7ad7 commit f23fdf3

File tree

12 files changed

+49
-4
lines changed

12 files changed

+49
-4
lines changed

library/portable-simd/crates/core_simd/src/alias.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ alias! {
153153
usizex64 64
154154
}
155155

156+
f16 = {
157+
f16x1 1
158+
f16x2 2
159+
f16x4 4
160+
f16x8 8
161+
f16x16 16
162+
f16x32 32
163+
f16x64 64
164+
}
165+
156166
f32 = {
157167
f32x1 1
158168
f32x2 2

library/portable-simd/crates/core_simd/src/cast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ impl SimdCast for u64 {}
4444
unsafe impl Sealed for usize {}
4545
impl SimdCast for usize {}
4646
// Safety: primitive number types can be cast to other primitive number types
47+
48+
unsafe impl Sealed for f16 {}
49+
50+
impl SimdCast for f16 {}
51+
// Safety: primitive number types can be cast to other primitive number types
4752
unsafe impl Sealed for f32 {}
4853
impl SimdCast for f32 {}
4954
// Safety: primitive number types can be cast to other primitive number types

library/portable-simd/crates/core_simd/src/iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ macro_rules! impl_traits {
4848
}
4949
}
5050

51+
impl_traits! { f16 }
5152
impl_traits! { f32 }
5253
impl_traits! { f64 }
5354
impl_traits! { u8 }

library/portable-simd/crates/core_simd/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
convert_float_to_int,
55
core_intrinsics,
66
decl_macro,
7+
f16_and_f128,
78
intra_doc_pointers,
89
repr_simd,
910
simd_ffi,

library/portable-simd/crates/core_simd/src/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ for_base_ops! {
248248
// We don't need any special precautions here:
249249
// Floats always accept arithmetic ops, but may become NaN.
250250
for_base_ops! {
251-
T = (f32, f64);
251+
T = (f16, f32, f64);
252252
type Lhs = Simd<T, N>;
253253
type Rhs = Simd<T, N>;
254254
type Output = Self;

library/portable-simd/crates/core_simd/src/ops/unary.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ macro_rules! neg {
2020
}
2121

2222
neg! {
23+
impl<const N: usize> Neg for Simd<f16, N>
24+
2325
impl<const N: usize> Neg for Simd<f32, N>
2426

2527
impl<const N: usize> Neg for Simd<f64, N>

library/portable-simd/crates/core_simd/src/simd/cmp/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! impl_number {
4444
}
4545
}
4646

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

4949
macro_rules! impl_mask {
5050
{ $($integer:ty),* } => {

library/portable-simd/crates/core_simd/src/simd/cmp/ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ macro_rules! impl_float {
150150
}
151151
}
152152

153-
impl_float! { f32, f64 }
153+
impl_float! { f16, f32, f64 }
154154

155155
macro_rules! impl_mask {
156156
{ $($integer:ty),* } => {

library/portable-simd/crates/core_simd/src/simd/num/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,4 @@ macro_rules! impl_trait {
450450
}
451451
}
452452

453-
impl_trait! { f32 { bits: u32, mask: i32 }, f64 { bits: u64, mask: i64 } }
453+
impl_trait! { f16 { bits: u16, mask: i16 }, f32 { bits: u32, mask: i32 }, f64 { bits: u64, mask: i64 } }

library/portable-simd/crates/core_simd/src/to_bytes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub trait ToBytes: Sealed {
4646
}
4747

4848
macro_rules! swap_bytes {
49+
{ f16, $x:expr } => { Simd::from_bits($x.to_bits().swap_bytes()) };
4950
{ f32, $x:expr } => { Simd::from_bits($x.to_bits().swap_bytes()) };
5051
{ f64, $x:expr } => { Simd::from_bits($x.to_bits().swap_bytes()) };
5152
{ $ty:ty, $x:expr } => { $x.swap_bytes() }
@@ -141,5 +142,6 @@ impl_to_bytes! { isize, 4 }
141142
#[cfg(target_pointer_width = "64")]
142143
impl_to_bytes! { isize, 8 }
143144

145+
impl_to_bytes! { f16, 2 }
144146
impl_to_bytes! { f32, 4 }
145147
impl_to_bytes! { f64, 8 }

0 commit comments

Comments
 (0)