diff options
| author | Caleb Zulawski <caleb.zulawski@gmail.com> | 2022-11-09 22:10:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-09 22:10:23 -0500 |
| commit | ecc28752e871af8886a49fdefdf4733a2dae8aac (patch) | |
| tree | 137e0638e25518974e00dac3bfa6baa4712b8cec | |
| parent | de30820035cb42d05f49575811a9f33661985e67 (diff) | |
| parent | 572122a95da6f8aaf513f53c426732f4c0a91325 (diff) | |
| download | rust-ecc28752e871af8886a49fdefdf4733a2dae8aac.tar.gz rust-ecc28752e871af8886a49fdefdf4733a2dae8aac.zip | |
Merge pull request #313 from rust-lang/pointer-tests
Add missing pointer tests and rename pointer cast fns to match scalars
| -rw-r--r-- | crates/core_simd/src/elements/const_ptr.rs | 6 | ||||
| -rw-r--r-- | crates/core_simd/src/elements/mut_ptr.rs | 6 | ||||
| -rw-r--r-- | crates/core_simd/tests/pointers.rs | 52 |
3 files changed, 60 insertions, 4 deletions
diff --git a/crates/core_simd/src/elements/const_ptr.rs b/crates/core_simd/src/elements/const_ptr.rs index f7227a56d58..0ef9802b5e2 100644 --- a/crates/core_simd/src/elements/const_ptr.rs +++ b/crates/core_simd/src/elements/const_ptr.rs @@ -19,7 +19,9 @@ pub trait SimdConstPtr: Copy + Sealed { fn is_null(self) -> Self::Mask; /// Changes constness without changing the type. - fn as_mut(self) -> Self::MutPtr; + /// + /// Equivalent to calling [`pointer::cast_mut`] on each lane. + fn cast_mut(self) -> Self::MutPtr; /// Gets the "address" portion of the pointer. /// @@ -85,7 +87,7 @@ where } #[inline] - fn as_mut(self) -> Self::MutPtr { + fn cast_mut(self) -> Self::MutPtr { self.cast_ptr() } diff --git a/crates/core_simd/src/elements/mut_ptr.rs b/crates/core_simd/src/elements/mut_ptr.rs index e2fd438ef8f..d87986b4a09 100644 --- a/crates/core_simd/src/elements/mut_ptr.rs +++ b/crates/core_simd/src/elements/mut_ptr.rs @@ -19,7 +19,9 @@ pub trait SimdMutPtr: Copy + Sealed { fn is_null(self) -> Self::Mask; /// Changes constness without changing the type. - fn as_const(self) -> Self::ConstPtr; + /// + /// Equivalent to calling [`pointer::cast_const`] on each lane. + fn cast_const(self) -> Self::ConstPtr; /// Gets the "address" portion of the pointer. /// @@ -80,7 +82,7 @@ where } #[inline] - fn as_const(self) -> Self::ConstPtr { + fn cast_const(self) -> Self::ConstPtr { self.cast_ptr() } diff --git a/crates/core_simd/tests/pointers.rs b/crates/core_simd/tests/pointers.rs index 8eb0bd84042..2b0008624ad 100644 --- a/crates/core_simd/tests/pointers.rs +++ b/crates/core_simd/tests/pointers.rs @@ -21,6 +21,22 @@ macro_rules! common_tests { ); } + fn with_addr<const LANES: usize>() { + test_helpers::test_binary_elementwise( + &Simd::<*$constness u32, LANES>::with_addr, + &<*$constness u32>::with_addr, + &|_, _| true, + ); + } + + fn expose_addr<const LANES: usize>() { + test_helpers::test_unary_elementwise( + &Simd::<*$constness u32, LANES>::expose_addr, + &<*$constness u32>::expose_addr, + &|_| true, + ); + } + fn wrapping_offset<const LANES: usize>() { test_helpers::test_binary_elementwise( &Simd::<*$constness u32, LANES>::wrapping_offset, @@ -51,9 +67,45 @@ macro_rules! common_tests { mod const_ptr { use super::*; common_tests! { const } + + test_helpers::test_lanes! { + fn cast_mut<const LANES: usize>() { + test_helpers::test_unary_elementwise( + &Simd::<*const u32, LANES>::cast_mut, + &<*const u32>::cast_mut, + &|_| true, + ); + } + + fn from_exposed_addr<const LANES: usize>() { + test_helpers::test_unary_elementwise( + &Simd::<*const u32, LANES>::from_exposed_addr, + &core::ptr::from_exposed_addr::<u32>, + &|_| true, + ); + } + } } mod mut_ptr { use super::*; common_tests! { mut } + + test_helpers::test_lanes! { + fn cast_const<const LANES: usize>() { + test_helpers::test_unary_elementwise( + &Simd::<*mut u32, LANES>::cast_const, + &<*mut u32>::cast_const, + &|_| true, + ); + } + + fn from_exposed_addr<const LANES: usize>() { + test_helpers::test_unary_elementwise( + &Simd::<*mut u32, LANES>::from_exposed_addr, + &core::ptr::from_exposed_addr_mut::<u32>, + &|_| true, + ); + } + } } |
