Fix pointer mutability casts and safety lints
This commit is contained in:
parent
e5db1ecc82
commit
0fcc4069c1
@ -1,23 +1,45 @@
|
|||||||
use crate::simd::SimdElement;
|
use crate::simd::SimdElement;
|
||||||
|
|
||||||
/// Supporting trait for `Simd::cast`. Typically doesn't need to be used directly.
|
/// Supporting trait for `Simd::cast`. Typically doesn't need to be used directly.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// Implementing this trait asserts that the type is a valid vector element for the `simd_cast` or
|
||||||
|
/// `simd_as` intrinsics.
|
||||||
pub unsafe trait SimdCast: SimdElement {}
|
pub unsafe trait SimdCast: SimdElement {}
|
||||||
|
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for i8 {}
|
unsafe impl SimdCast for i8 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for i16 {}
|
unsafe impl SimdCast for i16 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for i32 {}
|
unsafe impl SimdCast for i32 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for i64 {}
|
unsafe impl SimdCast for i64 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for isize {}
|
unsafe impl SimdCast for isize {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for u8 {}
|
unsafe impl SimdCast for u8 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for u16 {}
|
unsafe impl SimdCast for u16 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for u32 {}
|
unsafe impl SimdCast for u32 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for u64 {}
|
unsafe impl SimdCast for u64 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for usize {}
|
unsafe impl SimdCast for usize {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for f32 {}
|
unsafe impl SimdCast for f32 {}
|
||||||
|
// Safety: primitive number types can be cast to other primitive number types
|
||||||
unsafe impl SimdCast for f64 {}
|
unsafe impl SimdCast for f64 {}
|
||||||
|
|
||||||
/// Supporting trait for `Simd::cast_ptr`. Typically doesn't need to be used directly.
|
/// Supporting trait for `Simd::cast_ptr`. Typically doesn't need to be used directly.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// Implementing this trait asserts that the type is a valid vector element for the `simd_cast_ptr`
|
||||||
|
/// intrinsic.
|
||||||
pub unsafe trait SimdCastPtr: SimdElement {}
|
pub unsafe trait SimdCastPtr: SimdElement {}
|
||||||
|
|
||||||
|
// Safety: pointers can be cast to other pointer types
|
||||||
unsafe impl<T> SimdCastPtr for *const T {}
|
unsafe impl<T> SimdCastPtr for *const T {}
|
||||||
|
// Safety: pointers can be cast to other pointer types
|
||||||
unsafe impl<T> SimdCastPtr for *mut T {}
|
unsafe impl<T> SimdCastPtr for *mut T {}
|
||||||
|
@ -86,7 +86,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut(self) -> Self::MutPtr {
|
fn as_mut(self) -> Self::MutPtr {
|
||||||
unsafe { intrinsics::simd_cast_ptr(self) }
|
self.cast_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -111,11 +111,13 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn expose_addr(self) -> Self::Usize {
|
fn expose_addr(self) -> Self::Usize {
|
||||||
|
// Safety: `self` is a pointer vector
|
||||||
unsafe { intrinsics::simd_expose_addr(self) }
|
unsafe { intrinsics::simd_expose_addr(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_exposed_addr(addr: Self::Usize) -> Self {
|
fn from_exposed_addr(addr: Self::Usize) -> Self {
|
||||||
|
// Safety: `self` is a pointer vector
|
||||||
unsafe { intrinsics::simd_from_exposed_addr(addr) }
|
unsafe { intrinsics::simd_from_exposed_addr(addr) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +81,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_const(self) -> Self::ConstPtr {
|
fn as_const(self) -> Self::ConstPtr {
|
||||||
unimplemented!()
|
self.cast_ptr()
|
||||||
//self.cast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -107,11 +106,13 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn expose_addr(self) -> Self::Usize {
|
fn expose_addr(self) -> Self::Usize {
|
||||||
|
// Safety: `self` is a pointer vector
|
||||||
unsafe { intrinsics::simd_expose_addr(self) }
|
unsafe { intrinsics::simd_expose_addr(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_exposed_addr(addr: Self::Usize) -> Self {
|
fn from_exposed_addr(addr: Self::Usize) -> Self {
|
||||||
|
// Safety: `self` is a pointer vector
|
||||||
unsafe { intrinsics::simd_from_exposed_addr(addr) }
|
unsafe { intrinsics::simd_from_exposed_addr(addr) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user