Skip to main content

core\stdarch\crates\core_arch\src\aarch64/
rand.rs

1//! AArch64 Random Number intrinsics
2//!
3//! [ACLE documentation](https://arm-software.github.io/acle/main/acle.html#random-number-generation-intrinsics)
4
5#[cfg(test)]
6use stdarch_test::assert_instr;
7
8unsafe extern "unadjusted" {
9    #[link_name = "llvm.aarch64.rndr"]
10    fn rndr_() -> Tuple;
11
12    #[link_name = "llvm.aarch64.rndrrs"]
13    fn rndrrs_() -> Tuple;
14}
15
16#[repr(C)]
17struct Tuple {
18    bits: u64,
19    status: bool,
20}
21
22/// Stores a 64-bit random number into the object pointed to by the argument and returns
23/// zero. If the implementation could not generate a random number within a reasonable
24/// period of time the object pointed to by the input is set to zero and a non-zero value
25/// is returned.
26#[inline]
27#[target_feature(enable = "rand")]
28#[cfg_attr(test, assert_instr(mrs))]
29#[unstable(feature = "stdarch_aarch64_rand", issue = "153514")]
30pub unsafe fn __rndr(value: *mut u64) -> i32 {
31    let Tuple { bits, status } = rndr_();
32    unsafe { *value = bits };
33    status as i32
34}
35
36/// Reseeds the random number generator. After that stores a 64-bit random number into
37/// the object pointed to by the argument and returns zero. If the implementation could
38/// not generate a random number within a reasonable period of time the object pointed
39/// to by the input is set to zero and a non-zero value is returned.
40#[inline]
41#[target_feature(enable = "rand")]
42#[cfg_attr(test, assert_instr(mrs))]
43#[unstable(feature = "stdarch_aarch64_rand", issue = "153514")]
44pub unsafe fn __rndrrs(value: *mut u64) -> i32 {
45    let Tuple { bits, status } = rndrrs_();
46    unsafe { *value = bits };
47    status as i32
48}