mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Merge pull request #2050 from folkertdev/aarch64-rand
add ACLE random number generation intrinsics
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
#[unstable(feature = "stdarch_aarch64_mte", issue = "129010")]
|
||||
pub use self::mte::*;
|
||||
|
||||
mod rand;
|
||||
#[unstable(feature = "stdarch_aarch64_rand", issue = "153514")]
|
||||
pub use self::rand::*;
|
||||
|
||||
mod neon;
|
||||
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
|
||||
pub use self::neon::*;
|
||||
|
||||
@@ -3,35 +3,17 @@
|
||||
//! [ACLE documentation](https://arm-software.github.io/acle/main/acle.html#markdown-toc-mte-intrinsics)
|
||||
|
||||
unsafe extern "unadjusted" {
|
||||
#[cfg_attr(
|
||||
any(target_arch = "aarch64", target_arch = "arm64ec"),
|
||||
link_name = "llvm.aarch64.irg"
|
||||
)]
|
||||
#[link_name = "llvm.aarch64.irg"]
|
||||
fn irg_(ptr: *const (), exclude: i64) -> *const ();
|
||||
#[cfg_attr(
|
||||
any(target_arch = "aarch64", target_arch = "arm64ec"),
|
||||
link_name = "llvm.aarch64.gmi"
|
||||
)]
|
||||
#[link_name = "llvm.aarch64.gmi"]
|
||||
fn gmi_(ptr: *const (), exclude: i64) -> i64;
|
||||
#[cfg_attr(
|
||||
any(target_arch = "aarch64", target_arch = "arm64ec"),
|
||||
link_name = "llvm.aarch64.ldg"
|
||||
)]
|
||||
#[link_name = "llvm.aarch64.ldg"]
|
||||
fn ldg_(ptr: *const (), tag_ptr: *const ()) -> *const ();
|
||||
#[cfg_attr(
|
||||
any(target_arch = "aarch64", target_arch = "arm64ec"),
|
||||
link_name = "llvm.aarch64.stg"
|
||||
)]
|
||||
#[link_name = "llvm.aarch64.stg"]
|
||||
fn stg_(tagged_ptr: *const (), addr_to_tag: *const ());
|
||||
#[cfg_attr(
|
||||
any(target_arch = "aarch64", target_arch = "arm64ec"),
|
||||
link_name = "llvm.aarch64.addg"
|
||||
)]
|
||||
#[link_name = "llvm.aarch64.addg"]
|
||||
fn addg_(ptr: *const (), value: i64) -> *const ();
|
||||
#[cfg_attr(
|
||||
any(target_arch = "aarch64", target_arch = "arm64ec"),
|
||||
link_name = "llvm.aarch64.subp"
|
||||
)]
|
||||
#[link_name = "llvm.aarch64.subp"]
|
||||
fn subp_(ptr_a: *const (), ptr_b: *const ()) -> i64;
|
||||
}
|
||||
|
||||
@@ -127,42 +109,46 @@ mod test {
|
||||
use super::*;
|
||||
use stdarch_test::assert_instr;
|
||||
|
||||
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(irg))] // FIXME: MSVC `dumpbin` doesn't support MTE
|
||||
// Instruction tests are separate because the functions use generics.
|
||||
//
|
||||
// FIXME: As of 2026 MSVC `dumpbin` doesn't support MTE.
|
||||
|
||||
#[cfg_attr(not(target_env = "msvc"), assert_instr(irg))]
|
||||
#[allow(dead_code)]
|
||||
#[target_feature(enable = "mte")]
|
||||
unsafe fn test_arm_mte_create_random_tag(src: *const (), mask: u64) -> *const () {
|
||||
__arm_mte_create_random_tag(src, mask)
|
||||
}
|
||||
|
||||
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(addg))]
|
||||
#[cfg_attr(not(target_env = "msvc"), assert_instr(addg))]
|
||||
#[allow(dead_code)]
|
||||
#[target_feature(enable = "mte")]
|
||||
unsafe fn test_arm_mte_increment_tag(src: *const ()) -> *const () {
|
||||
__arm_mte_increment_tag::<1, _>(src)
|
||||
}
|
||||
|
||||
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(gmi))]
|
||||
#[cfg_attr(not(target_env = "msvc"), assert_instr(gmi))]
|
||||
#[allow(dead_code)]
|
||||
#[target_feature(enable = "mte")]
|
||||
unsafe fn test_arm_mte_exclude_tag(src: *const (), excluded: u64) -> u64 {
|
||||
__arm_mte_exclude_tag(src, excluded)
|
||||
}
|
||||
|
||||
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(stg))]
|
||||
#[cfg_attr(not(target_env = "msvc"), assert_instr(stg))]
|
||||
#[allow(dead_code)]
|
||||
#[target_feature(enable = "mte")]
|
||||
unsafe fn test_arm_mte_set_tag(src: *const ()) {
|
||||
__arm_mte_set_tag(src)
|
||||
}
|
||||
|
||||
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(ldg))]
|
||||
#[cfg_attr(not(target_env = "msvc"), assert_instr(ldg))]
|
||||
#[allow(dead_code)]
|
||||
#[target_feature(enable = "mte")]
|
||||
unsafe fn test_arm_mte_get_tag(src: *const ()) -> *const () {
|
||||
__arm_mte_get_tag(src)
|
||||
}
|
||||
|
||||
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(subp))]
|
||||
#[cfg_attr(not(target_env = "msvc"), assert_instr(subp))]
|
||||
#[allow(dead_code)]
|
||||
#[target_feature(enable = "mte")]
|
||||
unsafe fn test_arm_mte_ptrdiff(a: *const (), b: *const ()) -> i64 {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//! AArch64 Random Number intrinsics
|
||||
//!
|
||||
//! [ACLE documentation](https://arm-software.github.io/acle/main/acle.html#random-number-generation-intrinsics)
|
||||
|
||||
#[cfg(test)]
|
||||
use stdarch_test::assert_instr;
|
||||
|
||||
unsafe extern "unadjusted" {
|
||||
#[link_name = "llvm.aarch64.rndr"]
|
||||
fn rndr_() -> Tuple;
|
||||
|
||||
#[link_name = "llvm.aarch64.rndrrs"]
|
||||
fn rndrrs_() -> Tuple;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Tuple {
|
||||
bits: u64,
|
||||
status: bool,
|
||||
}
|
||||
|
||||
/// Stores a 64-bit random number into the object pointed to by the argument and returns
|
||||
/// zero. If the implementation could not generate a random number within a reasonable
|
||||
/// period of time the object pointed to by the input is set to zero and a non-zero value
|
||||
/// is returned.
|
||||
#[inline]
|
||||
#[target_feature(enable = "rand")]
|
||||
#[cfg_attr(test, assert_instr(mrs))]
|
||||
#[unstable(feature = "stdarch_aarch64_rand", issue = "153514")]
|
||||
pub unsafe fn __rndr(value: *mut u64) -> i32 {
|
||||
let Tuple { bits, status } = rndr_();
|
||||
unsafe { *value = bits };
|
||||
status as i32
|
||||
}
|
||||
|
||||
/// Reseeds the random number generator. After that stores a 64-bit random number into
|
||||
/// the object pointed to by the argument and returns zero. If the implementation could
|
||||
/// not generate a random number within a reasonable period of time the object pointed
|
||||
/// to by the input is set to zero and a non-zero value is returned.
|
||||
#[inline]
|
||||
#[target_feature(enable = "rand")]
|
||||
#[cfg_attr(test, assert_instr(mrs))]
|
||||
#[unstable(feature = "stdarch_aarch64_rand", issue = "153514")]
|
||||
pub unsafe fn __rndrrs(value: *mut u64) -> i32 {
|
||||
let Tuple { bits, status } = rndrrs_();
|
||||
unsafe { *value = bits };
|
||||
status as i32
|
||||
}
|
||||
@@ -445,6 +445,7 @@ fn verify_all_signatures() {
|
||||
&& !rust.file.ends_with("v7.rs\"")
|
||||
&& !rust.file.ends_with("v8.rs\"")
|
||||
&& !rust.file.ends_with("mte.rs\"")
|
||||
&& !rust.file.ends_with("rand.rs\"")
|
||||
&& !rust.file.ends_with("ex.rs\"")
|
||||
&& !skip_intrinsic_verify.contains(&rust.name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user