Skip to content

Commit 0557e34

Browse files
Add f16 vector support (#513)
* Add `f16` vector support * run `cargo update` * disable `f16` tests on wasm32 with simd128 llvm hangs in that case, see llvm/llvm-project#189251 * Add reference to LLVM issue causing f16 wasm ICE --------- Co-authored-by: Caleb Zulawski <caleb.zulawski@gmail.com>
1 parent 8ada24a commit 0557e34

18 files changed

Lines changed: 261 additions & 144 deletions

File tree

Cargo.lock

Lines changed: 204 additions & 134 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ opt-level = 2
1111

1212
[profile.test.package.test_helpers]
1313
opt-level = 2
14+
15+
[workspace.dependencies.proptest]
16+
version = "1.11"
17+
default-features = false
18+
features = ["alloc", "f16"]

crates/core_simd/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ wasm-bindgen = "0.2"
1818
wasm-bindgen-test = "0.3"
1919

2020
[dev-dependencies.proptest]
21-
version = "1.0"
22-
default-features = false
23-
features = ["alloc"]
21+
workspace = true
2422

2523
# Enable the `wasm_js` feature so that getrandom works on wasm32-unknown-unknown.
2624
[dev-dependencies.getrandom]

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/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_std]
22
#![feature(
33
convert_float_to_int,
4+
f16,
45
core_intrinsics,
56
decl_macro,
67
repr_simd,

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),* } => {

0 commit comments

Comments
 (0)