From dd01ccae422e882ad58aa579185bd03aaad29dc2 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Wed, 15 Dec 2021 23:16:38 -0700 Subject: [PATCH] nightly_portable_simd --- Cargo.toml | 3 +++ src/lib.rs | 10 ++++++---- src/pod.rs | 8 ++++++++ src/zeroable.rs | 8 ++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 521807a..b0fbc08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,9 @@ wasm_simd = [] # Until >= 1.54.0 is MSRV this is an off-by-default feature. # Do not use if you can avoid it, because this is unsound. unsound_ptr_pod_impl = [] +# NOT SEMVER SUPPORTED! TEMPORARY ONLY! +nightly_portable_simd = [] + [dependencies] # use the upper line for testing against bytemuck_derive changes, if any #bytemuck_derive = { version = "1.0.1-alpha.0", path = "derive", optional = true } diff --git a/src/lib.rs b/src/lib.rs index c39e91f..355caa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![warn(missing_docs)] +#![cfg_attr(feature = "nightly_portable_simd", feature(portable_simd))] //! This crate gives small utilities for casting between plain data types. //! @@ -59,7 +60,8 @@ macro_rules! impl_unsafe_marker_for_array { } } -/// A macro to transmute between two types without requiring knowing size statically. +/// A macro to transmute between two types without requiring knowing size +/// statically. macro_rules! transmute { ($val:expr) => { transmute_copy(&ManuallyDrop::new($val)) @@ -117,9 +119,9 @@ fn something_went_wrong(_src: &str, _err: PodCastError) -> ! { panic!("{src}>{err:?}", src = _src, err = _err); // Note: On the spirv targets from [rust-gpu](https://github.com/EmbarkStudios/rust-gpu) // panic formatting cannot be used. We we just give a generic error message - // The chance that the panicking version of these functions will ever get called - // on spir-v targets with invalid inputs is small, but giving a simple error - // message is better than no error message at all. + // The chance that the panicking version of these functions will ever get + // called on spir-v targets with invalid inputs is small, but giving a + // simple error message is better than no error message at all. #[cfg(target_arch = "spirv")] panic!("Called a panicing helper from bytemuck which paniced"); } diff --git a/src/pod.rs b/src/pod.rs index aef4af6..e2542c7 100644 --- a/src/pod.rs +++ b/src/pod.rs @@ -108,3 +108,11 @@ unsafe impl Pod for x86_64::__m256i {} unsafe impl Pod for x86_64::__m256 {} #[cfg(target_arch = "x86_64")] unsafe impl Pod for x86_64::__m256d {} + +#[cfg(feature = "nightly_portable_simd")] +unsafe impl Pod for core::simd::Simd +where + T: core::simd::SimdElement + Pod, + core::simd::LaneCount: core::simd::SupportedLaneCount, +{ +} diff --git a/src/zeroable.rs b/src/zeroable.rs index ae9e6ef..2870b32 100644 --- a/src/zeroable.rs +++ b/src/zeroable.rs @@ -147,3 +147,11 @@ unsafe impl Zeroable for x86_64::__m256i {} unsafe impl Zeroable for x86_64::__m256 {} #[cfg(target_arch = "x86_64")] unsafe impl Zeroable for x86_64::__m256d {} + +#[cfg(feature = "nightly_portable_simd")] +unsafe impl Zeroable for core::simd::Simd +where + T: core::simd::SimdElement + Zeroable, + core::simd::LaneCount: core::simd::SupportedLaneCount, +{ +}