Skip to content

Commit 8a58f3c

Browse files
committed
Implement SimdFloat for f16
1 parent 8ce88bc commit 8a58f3c

File tree

16 files changed

+71
-6
lines changed

16 files changed

+71
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Currently, vectors may have up to 64 elements, but aliases are provided only up
4444
Depending on the size of the primitive type, the number of lanes the vector will have varies. For example, 128-bit vectors have four `f32` lanes and two `f64` lanes.
4545

4646
The supported element types are as follows:
47-
* **Floating Point:** `f32`, `f64`
47+
* **Floating Point:** `f16`, `f32`, `f64`
4848
* **Signed Integers:** `i8`, `i16`, `i32`, `i64`, `isize` (`i128` excluded)
4949
* **Unsigned Integers:** `u8`, `u16`, `u32`, `u64`, `usize` (`u128` excluded)
5050
* **Pointers:** `*const T` and `*mut T` (zero-sized metadata only)

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

crates/core_simd/src/cast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ 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+
unsafe impl Sealed for f16 {}
48+
impl SimdCast for f16 {}
49+
// Safety: primitive number types can be cast to other primitive number types
4750
unsafe impl Sealed for f32 {}
4851
impl SimdCast for f32 {}
4952
// Safety: primitive number types can be cast to other primitive number types

crates/core_simd/src/iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ macro_rules! impl_traits {
4040
}
4141
}
4242

43+
impl_traits! { f16 }
4344
impl_traits! { f32 }
4445
impl_traits! { f64 }
4546
impl_traits! { u8 }

crates/core_simd/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
staged_api,
1111
prelude_import,
1212
ptr_metadata,
13-
rustc_attrs
13+
rustc_attrs,
14+
f16
1415
)]
1516
#![cfg_attr(
1617
all(
@@ -35,6 +36,18 @@
3536
all(target_arch = "x86_64", target_feature = "avx512f"),
3637
feature(stdarch_x86_avx512)
3738
)]
39+
#![cfg_attr(
40+
any(target_arch = "x86", target_arch = "x86_64"),
41+
feature(stdarch_x86_avx512_f16)
42+
)]
43+
#![cfg_attr(
44+
any(
45+
target_arch = "aarch64",
46+
target_arch = "arm64ec",
47+
all(target_arch = "arm", target_feature = "v7"),
48+
),
49+
feature(stdarch_neon_f16)
50+
)]
3851
#![warn(missing_docs, clippy::missing_inline_in_public_items)] // basically all items, really
3952
#![deny(
4053
unsafe_op_in_unsafe_fn,

crates/core_simd/src/ops.rs

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

crates/core_simd/src/ops/unary.rs

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

2121
neg! {
22+
impl<const N: usize> Neg for Simd<f16, N>
23+
2224
impl<const N: usize> Neg for Simd<f32, N>
2325

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

crates/core_simd/src/simd/cmp/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ macro_rules! impl_number {
4242
}
4343
}
4444

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

4747
macro_rules! impl_mask {
4848
{ $($integer:ty),* } => {

crates/core_simd/src/simd/cmp/ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ macro_rules! impl_float {
144144
}
145145
}
146146

147-
impl_float! { f32, f64 }
147+
impl_float! { f16, f32, f64 }
148148

149149
macro_rules! impl_mask {
150150
{ $($integer:ty),* } => {

crates/core_simd/src/simd/num/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,4 @@ macro_rules! impl_trait {
444444
}
445445
}
446446

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

0 commit comments

Comments
 (0)