-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #98441 - calebzulawski:simd_as, r=oli-obk
Implement simd_as for pointers Expands `simd_as` (and `simd_cast`) to handle pointer-to-pointer, pointer-to-integer, and integer-to-pointer conversions. cc ``@programmerjake`` ``@thomcc``
- Loading branch information
Showing
4 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// run-pass | ||
|
||
#![feature(repr_simd, platform_intrinsics)] | ||
|
||
extern "platform-intrinsic" { | ||
fn simd_cast_ptr<T, U>(x: T) -> U; | ||
fn simd_expose_addr<T, U>(x: T) -> U; | ||
fn simd_from_exposed_addr<T, U>(x: T) -> U; | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(simd)] | ||
struct V<T>([T; 2]); | ||
|
||
fn main() { | ||
unsafe { | ||
let mut foo = 4i8; | ||
let ptr = &mut foo as *mut i8; | ||
|
||
let ptrs = V::<*mut i8>([ptr, core::ptr::null_mut()]); | ||
|
||
// change constness and type | ||
let const_ptrs: V<*const u8> = simd_cast_ptr(ptrs); | ||
|
||
let exposed_addr: V<usize> = simd_expose_addr(const_ptrs); | ||
|
||
let from_exposed_addr: V<*mut i8> = simd_from_exposed_addr(exposed_addr); | ||
|
||
assert!(const_ptrs.0 == [ptr as *const u8, core::ptr::null()]); | ||
assert!(exposed_addr.0 == [ptr as usize, 0]); | ||
assert!(from_exposed_addr.0 == ptrs.0); | ||
} | ||
} |