Skip to content

Commit ecc2875

Browse files
Merge pull request #313 from rust-lang/pointer-tests
Add missing pointer tests and rename pointer cast fns to match scalars
2 parents de30820 + 572122a commit ecc2875

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

crates/core_simd/src/elements/const_ptr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub trait SimdConstPtr: Copy + Sealed {
1919
fn is_null(self) -> Self::Mask;
2020

2121
/// Changes constness without changing the type.
22-
fn as_mut(self) -> Self::MutPtr;
22+
///
23+
/// Equivalent to calling [`pointer::cast_mut`] on each lane.
24+
fn cast_mut(self) -> Self::MutPtr;
2325

2426
/// Gets the "address" portion of the pointer.
2527
///
@@ -85,7 +87,7 @@ where
8587
}
8688

8789
#[inline]
88-
fn as_mut(self) -> Self::MutPtr {
90+
fn cast_mut(self) -> Self::MutPtr {
8991
self.cast_ptr()
9092
}
9193

crates/core_simd/src/elements/mut_ptr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub trait SimdMutPtr: Copy + Sealed {
1919
fn is_null(self) -> Self::Mask;
2020

2121
/// Changes constness without changing the type.
22-
fn as_const(self) -> Self::ConstPtr;
22+
///
23+
/// Equivalent to calling [`pointer::cast_const`] on each lane.
24+
fn cast_const(self) -> Self::ConstPtr;
2325

2426
/// Gets the "address" portion of the pointer.
2527
///
@@ -80,7 +82,7 @@ where
8082
}
8183

8284
#[inline]
83-
fn as_const(self) -> Self::ConstPtr {
85+
fn cast_const(self) -> Self::ConstPtr {
8486
self.cast_ptr()
8587
}
8688

crates/core_simd/tests/pointers.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ macro_rules! common_tests {
2121
);
2222
}
2323

24+
fn with_addr<const LANES: usize>() {
25+
test_helpers::test_binary_elementwise(
26+
&Simd::<*$constness u32, LANES>::with_addr,
27+
&<*$constness u32>::with_addr,
28+
&|_, _| true,
29+
);
30+
}
31+
32+
fn expose_addr<const LANES: usize>() {
33+
test_helpers::test_unary_elementwise(
34+
&Simd::<*$constness u32, LANES>::expose_addr,
35+
&<*$constness u32>::expose_addr,
36+
&|_| true,
37+
);
38+
}
39+
2440
fn wrapping_offset<const LANES: usize>() {
2541
test_helpers::test_binary_elementwise(
2642
&Simd::<*$constness u32, LANES>::wrapping_offset,
@@ -51,9 +67,45 @@ macro_rules! common_tests {
5167
mod const_ptr {
5268
use super::*;
5369
common_tests! { const }
70+
71+
test_helpers::test_lanes! {
72+
fn cast_mut<const LANES: usize>() {
73+
test_helpers::test_unary_elementwise(
74+
&Simd::<*const u32, LANES>::cast_mut,
75+
&<*const u32>::cast_mut,
76+
&|_| true,
77+
);
78+
}
79+
80+
fn from_exposed_addr<const LANES: usize>() {
81+
test_helpers::test_unary_elementwise(
82+
&Simd::<*const u32, LANES>::from_exposed_addr,
83+
&core::ptr::from_exposed_addr::<u32>,
84+
&|_| true,
85+
);
86+
}
87+
}
5488
}
5589

5690
mod mut_ptr {
5791
use super::*;
5892
common_tests! { mut }
93+
94+
test_helpers::test_lanes! {
95+
fn cast_const<const LANES: usize>() {
96+
test_helpers::test_unary_elementwise(
97+
&Simd::<*mut u32, LANES>::cast_const,
98+
&<*mut u32>::cast_const,
99+
&|_| true,
100+
);
101+
}
102+
103+
fn from_exposed_addr<const LANES: usize>() {
104+
test_helpers::test_unary_elementwise(
105+
&Simd::<*mut u32, LANES>::from_exposed_addr,
106+
&core::ptr::from_exposed_addr_mut::<u32>,
107+
&|_| true,
108+
);
109+
}
110+
}
59111
}

0 commit comments

Comments
 (0)