From 30975615b7c206ee96eddbf84fc0f11ee896f849 Mon Sep 17 00:00:00 2001 From: Jubilee <46493976+workingjubilee@users.noreply.github.com> Date: Tue, 1 Mar 2022 16:10:49 -0800 Subject: [PATCH] rust-lang/portable-simd#250: Add bitmask i{N <8} -> u8 impls ...and copy the notes for why they're legal. --- crates/core_simd/src/intrinsics.rs | 8 ++++++++ crates/core_simd/src/masks/to_bitmask.rs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/crates/core_simd/src/intrinsics.rs b/crates/core_simd/src/intrinsics.rs index e150946c705c..47edff4a66af 100644 --- a/crates/core_simd/src/intrinsics.rs +++ b/crates/core_simd/src/intrinsics.rs @@ -130,6 +130,14 @@ extern "platform-intrinsic" { pub(crate) fn simd_reduce_xor(x: T) -> U; // truncate integer vector to bitmask + // `fn simd_bitmask(vector) -> unsigned integer` takes a vector of integers and + // returns either an unsigned integer or array of `u8`. + // Every element in the vector becomes a single bit in the returned bitmask. + // If the vector has less than 8 lanes, a u8 is returned with zeroed trailing bits. + // The bit order of the result depends on the byte endianness. LSB-first for little + // endian and MSB-first for big endian. + // + // UB if called on a vector with values other than 0 and -1. #[allow(unused)] pub(crate) fn simd_bitmask(x: T) -> U; diff --git a/crates/core_simd/src/masks/to_bitmask.rs b/crates/core_simd/src/masks/to_bitmask.rs index 1c2037764c1e..c263f6a4eec3 100644 --- a/crates/core_simd/src/masks/to_bitmask.rs +++ b/crates/core_simd/src/masks/to_bitmask.rs @@ -50,6 +50,9 @@ macro_rules! impl_integer_intrinsic { } impl_integer_intrinsic! { + unsafe impl ToBitMask for Mask<_, 1> + unsafe impl ToBitMask for Mask<_, 2> + unsafe impl ToBitMask for Mask<_, 4> unsafe impl ToBitMask for Mask<_, 8> unsafe impl ToBitMask for Mask<_, 16> unsafe impl ToBitMask for Mask<_, 32>