From 9b81537c5fc4db6f529f388b0af8cf1fe97b6764 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 18 Jun 2024 22:24:29 -0500 Subject: [PATCH] Support `Zeroable` and `Pod` for `f16` and `f128` (#251) These are gated under a new feature flag `nightly_float`. Fixes: --- Cargo.toml | 2 ++ src/lib.rs | 1 + src/pod.rs | 4 ++++ src/zeroable.rs | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 05a2715..bfa5d8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,8 @@ unsound_ptr_pod_impl = [] # NOT SEMVER SUPPORTED! TEMPORARY ONLY! nightly_portable_simd = [] nightly_stdsimd = [] +# Enable `f16` and `f128` +nightly_float = [] # Improved documentation using the nightly toolchain nightly_docs = [] diff --git a/src/lib.rs b/src/lib.rs index daa8177..1526587 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ #![allow(clippy::type_complexity)] #![cfg_attr(feature = "nightly_docs", feature(doc_cfg))] #![cfg_attr(feature = "nightly_portable_simd", feature(portable_simd))] +#![cfg_attr(feature = "nightly_float", feature(f16, f128))] #![cfg_attr( all( feature = "nightly_stdsimd", diff --git a/src/pod.rs b/src/pod.rs index 724c0a0..92747a1 100644 --- a/src/pod.rs +++ b/src/pod.rs @@ -49,8 +49,12 @@ unsafe impl Pod for usize {} unsafe impl Pod for isize {} unsafe impl Pod for u128 {} unsafe impl Pod for i128 {} +#[cfg(feature = "nightly_float")] +unsafe impl Pod for f16 {} unsafe impl Pod for f32 {} unsafe impl Pod for f64 {} +#[cfg(feature = "nightly_float")] +unsafe impl Pod for f128 {} unsafe impl Pod for Wrapping {} #[cfg(feature = "unsound_ptr_pod_impl")] diff --git a/src/zeroable.rs b/src/zeroable.rs index f7d7ed8..60dfc8d 100644 --- a/src/zeroable.rs +++ b/src/zeroable.rs @@ -48,8 +48,12 @@ unsafe impl Zeroable for usize {} unsafe impl Zeroable for isize {} unsafe impl Zeroable for u128 {} unsafe impl Zeroable for i128 {} +#[cfg(feature = "nightly_float")] +unsafe impl Zeroable for f16 {} unsafe impl Zeroable for f32 {} unsafe impl Zeroable for f64 {} +#[cfg(feature = "nightly_float")] +unsafe impl Zeroable for f128 {} unsafe impl Zeroable for Wrapping {} unsafe impl Zeroable for core::cmp::Reverse {}