Skip to content

Commit 7e96f5d

Browse files
committed
Use safe casts
1 parent d3cfd7c commit 7e96f5d

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

crates/core_simd/src/elements/const_ptr.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::sealed::Sealed;
2-
use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
2+
use crate::simd::{LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
33

44
/// Operations on SIMD vectors of constant pointers.
55
pub trait SimdConstPtr: Copy + Sealed {
@@ -43,17 +43,14 @@ where
4343
}
4444

4545
fn as_mut(self) -> Self::MutPtr {
46-
// Converting between pointers is safe
47-
unsafe { intrinsics::simd_as(self) }
46+
self.cast()
4847
}
4948

5049
fn to_bits(self) -> Self::Bits {
51-
// Casting pointers to usize is safe
52-
unsafe { intrinsics::simd_as(self) }
50+
self.cast()
5351
}
5452

5553
fn from_bits(bits: Self::Bits) -> Self {
56-
// Casting usize to pointers is safe
57-
unsafe { intrinsics::simd_as(bits) }
54+
bits.cast()
5855
}
5956
}

crates/core_simd/src/elements/mut_ptr.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::sealed::Sealed;
2-
use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
2+
use crate::simd::{LaneCount, Mask, Simd, SimdPartialEq, SupportedLaneCount};
33

44
/// Operations on SIMD vectors of mutable pointers.
55
pub trait SimdMutPtr: Copy + Sealed {
@@ -41,17 +41,14 @@ where
4141
}
4242

4343
fn as_const(self) -> Self::ConstPtr {
44-
// Converting between pointers is safe
45-
unsafe { intrinsics::simd_as(self) }
44+
self.cast()
4645
}
4746

4847
fn to_bits(self) -> Self::Bits {
49-
// Casting pointers to usize is safe
50-
unsafe { intrinsics::simd_as(self) }
48+
self.cast()
5149
}
5250

5351
fn from_bits(bits: Self::Bits) -> Self {
54-
// Casting usize to pointers is safe
55-
unsafe { intrinsics::simd_as(bits) }
52+
bits.cast()
5653
}
5754
}

0 commit comments

Comments
 (0)