safe_arch/x86_x64/
rdrand.rs

1#![cfg(target_feature = "rdrand")]
2
3use super::*;
4
5/// Try to obtain a random `u16` from the hardware RNG.
6///
7/// * **Intrinsic:** [`_rdrand16_step`]
8/// * **Assembly:** `rdrand r16`
9#[must_use]
10#[inline(always)]
11#[cfg_attr(docsrs, doc(cfg(target_feature = "rdrand")))]
12pub fn rdrand_u16(out: &mut u16) -> i32 {
13  unsafe { _rdrand16_step(out) }
14}
15
16/// Try to obtain a random `u32` from the hardware RNG.
17///
18/// * **Intrinsic:** [`_rdrand32_step`]
19/// * **Assembly:** `rdrand r32`
20#[must_use]
21#[inline(always)]
22#[cfg_attr(docsrs, doc(cfg(target_feature = "rdrand")))]
23pub fn rdrand_u32(out: &mut u32) -> i32 {
24  unsafe { _rdrand32_step(out) }
25}
26
27/// Try to obtain a random `u64` from the hardware RNG.
28///
29/// * **Intrinsic:** [`_rdrand64_step`]
30/// * **Assembly:** `rdrand r64`
31#[must_use]
32#[inline(always)]
33#[cfg(target_arch = "x86_64")]
34#[cfg_attr(docsrs, doc(cfg(target_feature = "rdrand")))]
35pub fn rdrand_u64(out: &mut u64) -> i32 {
36  unsafe { _rdrand64_step(out) }
37}
38