forked from kiss-community/repo
270 lines
9.5 KiB
Diff
270 lines
9.5 KiB
Diff
|
From 728d47506fe3a2599818060bd6e02e4bd3e338d5 Mon Sep 17 00:00:00 2001
|
||
|
From: Jubilee Young <workingjubilee@gmail.com>
|
||
|
Date: Sat, 15 May 2021 20:15:42 -0700
|
||
|
Subject: [PATCH] Update shuffle API for const generics
|
||
|
|
||
|
---
|
||
|
src/api/shuffle.rs | 46 +++++++++----------
|
||
|
src/codegen/llvm.rs | 109 ++++++++++++++++++++++++++------------------
|
||
|
src/lib.rs | 3 ++
|
||
|
3 files changed, 90 insertions(+), 68 deletions(-)
|
||
|
|
||
|
diff --git a/third_party/rust/packed_simd/src/api/shuffle.rs b/src/api/shuffle.rs
|
||
|
index da80b912..fda29ccd 100644
|
||
|
--- a/third_party/rust/packed_simd/src/api/shuffle.rs
|
||
|
+++ b/third_party/rust/packed_simd/src/api/shuffle.rs
|
||
|
@@ -75,20 +75,18 @@ macro_rules! shuffle {
|
||
|
($vec0:expr, $vec1:expr, [$l0:expr, $l1:expr]) => {{
|
||
|
#[allow(unused_unsafe)]
|
||
|
unsafe {
|
||
|
- $crate::Simd($crate::__shuffle_vector2(
|
||
|
+ $crate::Simd($crate::__shuffle_vector2::<{[$l0, $l1]}, _, _>(
|
||
|
$vec0.0,
|
||
|
$vec1.0,
|
||
|
- [$l0, $l1],
|
||
|
))
|
||
|
}
|
||
|
}};
|
||
|
($vec0:expr, $vec1:expr, [$l0:expr, $l1:expr, $l2:expr, $l3:expr]) => {{
|
||
|
#[allow(unused_unsafe)]
|
||
|
unsafe {
|
||
|
- $crate::Simd($crate::__shuffle_vector4(
|
||
|
+ $crate::Simd($crate::__shuffle_vector4::<{[$l0, $l1, $l2, $l3]}, _, _>(
|
||
|
$vec0.0,
|
||
|
$vec1.0,
|
||
|
- [$l0, $l1, $l2, $l3],
|
||
|
))
|
||
|
}
|
||
|
}};
|
||
|
@@ -97,10 +95,9 @@ macro_rules! shuffle {
|
||
|
$l4:expr, $l5:expr, $l6:expr, $l7:expr]) => {{
|
||
|
#[allow(unused_unsafe)]
|
||
|
unsafe {
|
||
|
- $crate::Simd($crate::__shuffle_vector8(
|
||
|
+ $crate::Simd($crate::__shuffle_vector8::<{[$l0, $l1, $l2, $l3, $l4, $l5, $l6, $l7]}, _, _>(
|
||
|
$vec0.0,
|
||
|
$vec1.0,
|
||
|
- [$l0, $l1, $l2, $l3, $l4, $l5, $l6, $l7],
|
||
|
))
|
||
|
}
|
||
|
}};
|
||
|
@@ -111,13 +108,14 @@ macro_rules! shuffle {
|
||
|
$l12:expr, $l13:expr, $l14:expr, $l15:expr]) => {{
|
||
|
#[allow(unused_unsafe)]
|
||
|
unsafe {
|
||
|
- $crate::Simd($crate::__shuffle_vector16(
|
||
|
- $vec0.0,
|
||
|
- $vec1.0,
|
||
|
+ $crate::Simd($crate::__shuffle_vector16::<{
|
||
|
[
|
||
|
$l0, $l1, $l2, $l3, $l4, $l5, $l6, $l7, $l8, $l9, $l10,
|
||
|
$l11, $l12, $l13, $l14, $l15,
|
||
|
- ],
|
||
|
+ ]
|
||
|
+ }, _, _>(
|
||
|
+ $vec0.0,
|
||
|
+ $vec1.0,
|
||
|
))
|
||
|
}
|
||
|
}};
|
||
|
@@ -132,15 +130,16 @@ macro_rules! shuffle {
|
||
|
$l28:expr, $l29:expr, $l30:expr, $l31:expr]) => {{
|
||
|
#[allow(unused_unsafe)]
|
||
|
unsafe {
|
||
|
- $crate::Simd($crate::__shuffle_vector32(
|
||
|
- $vec0.0,
|
||
|
- $vec1.0,
|
||
|
+ $crate::Simd($crate::__shuffle_vector32::<{
|
||
|
[
|
||
|
$l0, $l1, $l2, $l3, $l4, $l5, $l6, $l7, $l8, $l9, $l10,
|
||
|
$l11, $l12, $l13, $l14, $l15, $l16, $l17, $l18, $l19,
|
||
|
$l20, $l21, $l22, $l23, $l24, $l25, $l26, $l27, $l28,
|
||
|
$l29, $l30, $l31,
|
||
|
- ],
|
||
|
+ ]
|
||
|
+ }, _, _>(
|
||
|
+ $vec0.0,
|
||
|
+ $vec1.0,
|
||
|
))
|
||
|
}
|
||
|
}};
|
||
|
@@ -163,18 +162,17 @@ macro_rules! shuffle {
|
||
|
$l60:expr, $l61:expr, $l62:expr, $l63:expr]) => {{
|
||
|
#[allow(unused_unsafe)]
|
||
|
unsafe {
|
||
|
- $crate::Simd($crate::__shuffle_vector64(
|
||
|
+ $crate::Simd($crate::__shuffle_vector64::<{[
|
||
|
+ $l0, $l1, $l2, $l3, $l4, $l5, $l6, $l7, $l8, $l9, $l10,
|
||
|
+ $l11, $l12, $l13, $l14, $l15, $l16, $l17, $l18, $l19,
|
||
|
+ $l20, $l21, $l22, $l23, $l24, $l25, $l26, $l27, $l28,
|
||
|
+ $l29, $l30, $l31, $l32, $l33, $l34, $l35, $l36, $l37,
|
||
|
+ $l38, $l39, $l40, $l41, $l42, $l43, $l44, $l45, $l46,
|
||
|
+ $l47, $l48, $l49, $l50, $l51, $l52, $l53, $l54, $l55,
|
||
|
+ $l56, $l57, $l58, $l59, $l60, $l61, $l62, $l63,
|
||
|
+ ]}, _, _>(
|
||
|
$vec0.0,
|
||
|
$vec1.0,
|
||
|
- [
|
||
|
- $l0, $l1, $l2, $l3, $l4, $l5, $l6, $l7, $l8, $l9, $l10,
|
||
|
- $l11, $l12, $l13, $l14, $l15, $l16, $l17, $l18, $l19,
|
||
|
- $l20, $l21, $l22, $l23, $l24, $l25, $l26, $l27, $l28,
|
||
|
- $l29, $l30, $l31, $l32, $l33, $l34, $l35, $l36, $l37,
|
||
|
- $l38, $l39, $l40, $l41, $l42, $l43, $l44, $l45, $l46,
|
||
|
- $l47, $l48, $l49, $l50, $l51, $l52, $l53, $l54, $l55,
|
||
|
- $l56, $l57, $l58, $l59, $l60, $l61, $l62, $l63,
|
||
|
- ],
|
||
|
))
|
||
|
}
|
||
|
}};
|
||
|
diff --git a/third_party/rust/packed_simd/src/codegen/llvm.rs b/src/codegen/llvm.rs
|
||
|
index 93c6ce6b..52b11a95 100644
|
||
|
--- a/third_party/rust/packed_simd/src/codegen/llvm.rs
|
||
|
+++ b/third_party/rust/packed_simd/src/codegen/llvm.rs
|
||
|
@@ -7,52 +7,73 @@ use crate::sealed::Simd;
|
||
|
|
||
|
// Shuffle intrinsics: expanded in users' crates, therefore public.
|
||
|
extern "platform-intrinsic" {
|
||
|
- // FIXME: Passing this intrinsics an `idx` array with an index that is
|
||
|
- // out-of-bounds will produce a monomorphization-time error.
|
||
|
- // https://github.com/rust-lang-nursery/packed_simd/issues/21
|
||
|
- #[rustc_args_required_const(2)]
|
||
|
- pub fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U
|
||
|
- where
|
||
|
- T: Simd,
|
||
|
- <T as Simd>::Element: Shuffle<[u32; 2], Output = U>;
|
||
|
-
|
||
|
- #[rustc_args_required_const(2)]
|
||
|
- pub fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U
|
||
|
- where
|
||
|
- T: Simd,
|
||
|
- <T as Simd>::Element: Shuffle<[u32; 4], Output = U>;
|
||
|
-
|
||
|
- #[rustc_args_required_const(2)]
|
||
|
- pub fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U
|
||
|
- where
|
||
|
- T: Simd,
|
||
|
- <T as Simd>::Element: Shuffle<[u32; 8], Output = U>;
|
||
|
-
|
||
|
- #[rustc_args_required_const(2)]
|
||
|
- pub fn simd_shuffle16<T, U>(x: T, y: T, idx: [u32; 16]) -> U
|
||
|
- where
|
||
|
- T: Simd,
|
||
|
- <T as Simd>::Element: Shuffle<[u32; 16], Output = U>;
|
||
|
-
|
||
|
- #[rustc_args_required_const(2)]
|
||
|
- pub fn simd_shuffle32<T, U>(x: T, y: T, idx: [u32; 32]) -> U
|
||
|
- where
|
||
|
- T: Simd,
|
||
|
- <T as Simd>::Element: Shuffle<[u32; 32], Output = U>;
|
||
|
-
|
||
|
- #[rustc_args_required_const(2)]
|
||
|
- pub fn simd_shuffle64<T, U>(x: T, y: T, idx: [u32; 64]) -> U
|
||
|
- where
|
||
|
- T: Simd,
|
||
|
- <T as Simd>::Element: Shuffle<[u32; 64], Output = U>;
|
||
|
+ pub fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
|
||
|
+ pub fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
|
||
|
+ pub fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
|
||
|
+ pub fn simd_shuffle16<T, U>(x: T, y: T, idx: [u32; 16]) -> U;
|
||
|
+ pub fn simd_shuffle32<T, U>(x: T, y: T, idx: [u32; 32]) -> U;
|
||
|
+ pub fn simd_shuffle64<T, U>(x: T, y: T, idx: [u32; 64]) -> U;
|
||
|
}
|
||
|
|
||
|
-pub use self::simd_shuffle16 as __shuffle_vector16;
|
||
|
-pub use self::simd_shuffle2 as __shuffle_vector2;
|
||
|
-pub use self::simd_shuffle32 as __shuffle_vector32;
|
||
|
-pub use self::simd_shuffle4 as __shuffle_vector4;
|
||
|
-pub use self::simd_shuffle64 as __shuffle_vector64;
|
||
|
-pub use self::simd_shuffle8 as __shuffle_vector8;
|
||
|
+#[allow(clippy::missing_safety_doc)]
|
||
|
+#[inline]
|
||
|
+pub unsafe fn __shuffle_vector2<const IDX: [u32; 2], T, U>(x: T, y: T) -> U
|
||
|
+where
|
||
|
+ T: Simd,
|
||
|
+ <T as Simd>::Element: Shuffle<[u32; 2], Output = U>,
|
||
|
+{
|
||
|
+ simd_shuffle2(x, y, IDX)
|
||
|
+}
|
||
|
+
|
||
|
+#[allow(clippy::missing_safety_doc)]
|
||
|
+#[inline]
|
||
|
+pub unsafe fn __shuffle_vector4<const IDX: [u32; 4], T, U>(x: T, y: T) -> U
|
||
|
+where
|
||
|
+ T: Simd,
|
||
|
+ <T as Simd>::Element: Shuffle<[u32; 4], Output = U>,
|
||
|
+{
|
||
|
+ simd_shuffle4(x, y, IDX)
|
||
|
+}
|
||
|
+
|
||
|
+#[allow(clippy::missing_safety_doc)]
|
||
|
+#[inline]
|
||
|
+pub unsafe fn __shuffle_vector8<const IDX: [u32; 8], T, U>(x: T, y: T) -> U
|
||
|
+where
|
||
|
+ T: Simd,
|
||
|
+ <T as Simd>::Element: Shuffle<[u32; 8], Output = U>,
|
||
|
+{
|
||
|
+ simd_shuffle8(x, y, IDX)
|
||
|
+}
|
||
|
+
|
||
|
+#[allow(clippy::missing_safety_doc)]
|
||
|
+#[inline]
|
||
|
+pub unsafe fn __shuffle_vector16<const IDX: [u32; 16], T, U>(x: T, y: T) -> U
|
||
|
+where
|
||
|
+ T: Simd,
|
||
|
+ <T as Simd>::Element: Shuffle<[u32; 16], Output = U>,
|
||
|
+{
|
||
|
+ simd_shuffle16(x, y, IDX)
|
||
|
+}
|
||
|
+
|
||
|
+#[allow(clippy::missing_safety_doc)]
|
||
|
+#[inline]
|
||
|
+pub unsafe fn __shuffle_vector32<const IDX: [u32; 32], T, U>(x: T, y: T) -> U
|
||
|
+where
|
||
|
+ T: Simd,
|
||
|
+ <T as Simd>::Element: Shuffle<[u32; 32], Output = U>,
|
||
|
+{
|
||
|
+ simd_shuffle32(x, y, IDX)
|
||
|
+}
|
||
|
+
|
||
|
+#[allow(clippy::missing_safety_doc)]
|
||
|
+#[inline]
|
||
|
+pub unsafe fn __shuffle_vector64<const IDX: [u32; 64], T, U>(x: T, y: T) -> U
|
||
|
+where
|
||
|
+ T: Simd,
|
||
|
+ <T as Simd>::Element: Shuffle<[u32; 64], Output = U>,
|
||
|
+{
|
||
|
+ simd_shuffle64(x, y, IDX)
|
||
|
+}
|
||
|
|
||
|
extern "platform-intrinsic" {
|
||
|
crate fn simd_eq<T, U>(x: T, y: T) -> U;
|
||
|
diff --git a/third_party/rust/packed_simd/src/lib.rs
|
||
|
b/third_party/rust/packed_simd/src/lib.rs
|
||
|
index 9c9b060..cccdb85 100644
|
||
|
--- a/third_party/rust/packed_simd/src/lib.rs
|
||
|
+++ b/third_party/rust/packed_simd/src/lib.rs
|
||
|
@@ -200,6 +200,7 @@
|
||
|
//! preserving, etc.
|
||
|
|
||
|
#![feature(
|
||
|
+ const_generics,
|
||
|
repr_simd,
|
||
|
rustc_attrs,
|
||
|
platform_intrinsics,
|
||
|
@@ -216,6 +217,7 @@
|
||
|
// FIXME: these types are unsound in C FFI already
|
||
|
// See https://github.com/rust-lang/rust/issues/53346
|
||
|
improper_ctypes_definitions,
|
||
|
+ incomplete_features,
|
||
|
clippy::cast_possible_truncation,
|
||
|
clippy::cast_lossless,
|
||
|
clippy::cast_possible_wrap,
|
||
|
@@ -226,6 +228,7 @@
|
||
|
// See https://github.com/rust-lang/rust-clippy/issues/3410
|
||
|
clippy::use_self,
|
||
|
clippy::wrong_self_convention,
|
||
|
+ clippy::from_over_into,
|
||
|
)]
|
||
|
#![cfg_attr(test, feature(hashmap_internals))]
|
||
|
#![deny(rust_2018_idioms, clippy::missing_inline_in_public_items)]
|