xref: /aosp_15_r20/prebuilts/clang-tools/linux-x86/clang-headers/rdseedintrin.h (revision bed243d3d9cd544cfb038bfa7be843dedc6e6bf7)
1*bed243d3SAndroid Build Coastguard Worker /*===---- rdseedintrin.h - RDSEED intrinsics -------------------------------===
2*bed243d3SAndroid Build Coastguard Worker  *
3*bed243d3SAndroid Build Coastguard Worker  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bed243d3SAndroid Build Coastguard Worker  * See https://llvm.org/LICENSE.txt for license information.
5*bed243d3SAndroid Build Coastguard Worker  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bed243d3SAndroid Build Coastguard Worker  *
7*bed243d3SAndroid Build Coastguard Worker  *===-----------------------------------------------------------------------===
8*bed243d3SAndroid Build Coastguard Worker  */
9*bed243d3SAndroid Build Coastguard Worker 
10*bed243d3SAndroid Build Coastguard Worker #ifndef __IMMINTRIN_H
11*bed243d3SAndroid Build Coastguard Worker #error "Never use <rdseedintrin.h> directly; include <immintrin.h> instead."
12*bed243d3SAndroid Build Coastguard Worker #endif
13*bed243d3SAndroid Build Coastguard Worker 
14*bed243d3SAndroid Build Coastguard Worker #ifndef __RDSEEDINTRIN_H
15*bed243d3SAndroid Build Coastguard Worker #define __RDSEEDINTRIN_H
16*bed243d3SAndroid Build Coastguard Worker 
17*bed243d3SAndroid Build Coastguard Worker /* Define the default attributes for the functions in this file. */
18*bed243d3SAndroid Build Coastguard Worker #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("rdseed")))
19*bed243d3SAndroid Build Coastguard Worker 
20*bed243d3SAndroid Build Coastguard Worker /// Stores a hardware-generated 16-bit random value in the memory at \a __p.
21*bed243d3SAndroid Build Coastguard Worker ///
22*bed243d3SAndroid Build Coastguard Worker ///    The random number generator complies with NIST SP800-90B and SP800-90C.
23*bed243d3SAndroid Build Coastguard Worker ///
24*bed243d3SAndroid Build Coastguard Worker /// \code{.operation}
25*bed243d3SAndroid Build Coastguard Worker /// IF HW_NRND_GEN.ready == 1
26*bed243d3SAndroid Build Coastguard Worker ///   Store16(__p, HW_NRND_GEN.data)
27*bed243d3SAndroid Build Coastguard Worker ///   result := 1
28*bed243d3SAndroid Build Coastguard Worker /// ELSE
29*bed243d3SAndroid Build Coastguard Worker ///   Store16(__p, 0)
30*bed243d3SAndroid Build Coastguard Worker ///   result := 0
31*bed243d3SAndroid Build Coastguard Worker /// END
32*bed243d3SAndroid Build Coastguard Worker /// \endcode
33*bed243d3SAndroid Build Coastguard Worker ///
34*bed243d3SAndroid Build Coastguard Worker /// \headerfile <immintrin.h>
35*bed243d3SAndroid Build Coastguard Worker ///
36*bed243d3SAndroid Build Coastguard Worker /// This intrinsic corresponds to the \c RDSEED instruction.
37*bed243d3SAndroid Build Coastguard Worker ///
38*bed243d3SAndroid Build Coastguard Worker /// \param __p
39*bed243d3SAndroid Build Coastguard Worker ///    Pointer to memory for storing the 16-bit random number.
40*bed243d3SAndroid Build Coastguard Worker /// \returns 1 if a random number was generated, 0 if not.
41*bed243d3SAndroid Build Coastguard Worker static __inline__ int __DEFAULT_FN_ATTRS
_rdseed16_step(unsigned short * __p)42*bed243d3SAndroid Build Coastguard Worker _rdseed16_step(unsigned short *__p)
43*bed243d3SAndroid Build Coastguard Worker {
44*bed243d3SAndroid Build Coastguard Worker   return (int) __builtin_ia32_rdseed16_step(__p);
45*bed243d3SAndroid Build Coastguard Worker }
46*bed243d3SAndroid Build Coastguard Worker 
47*bed243d3SAndroid Build Coastguard Worker /// Stores a hardware-generated 32-bit random value in the memory at \a __p.
48*bed243d3SAndroid Build Coastguard Worker ///
49*bed243d3SAndroid Build Coastguard Worker ///    The random number generator complies with NIST SP800-90B and SP800-90C.
50*bed243d3SAndroid Build Coastguard Worker ///
51*bed243d3SAndroid Build Coastguard Worker /// \code{.operation}
52*bed243d3SAndroid Build Coastguard Worker /// IF HW_NRND_GEN.ready == 1
53*bed243d3SAndroid Build Coastguard Worker ///   Store32(__p, HW_NRND_GEN.data)
54*bed243d3SAndroid Build Coastguard Worker ///   result := 1
55*bed243d3SAndroid Build Coastguard Worker /// ELSE
56*bed243d3SAndroid Build Coastguard Worker ///   Store32(__p, 0)
57*bed243d3SAndroid Build Coastguard Worker ///   result := 0
58*bed243d3SAndroid Build Coastguard Worker /// END
59*bed243d3SAndroid Build Coastguard Worker /// \endcode
60*bed243d3SAndroid Build Coastguard Worker ///
61*bed243d3SAndroid Build Coastguard Worker /// \headerfile <immintrin.h>
62*bed243d3SAndroid Build Coastguard Worker ///
63*bed243d3SAndroid Build Coastguard Worker /// This intrinsic corresponds to the \c RDSEED instruction.
64*bed243d3SAndroid Build Coastguard Worker ///
65*bed243d3SAndroid Build Coastguard Worker /// \param __p
66*bed243d3SAndroid Build Coastguard Worker ///    Pointer to memory for storing the 32-bit random number.
67*bed243d3SAndroid Build Coastguard Worker /// \returns 1 if a random number was generated, 0 if not.
68*bed243d3SAndroid Build Coastguard Worker static __inline__ int __DEFAULT_FN_ATTRS
_rdseed32_step(unsigned int * __p)69*bed243d3SAndroid Build Coastguard Worker _rdseed32_step(unsigned int *__p)
70*bed243d3SAndroid Build Coastguard Worker {
71*bed243d3SAndroid Build Coastguard Worker   return (int) __builtin_ia32_rdseed32_step(__p);
72*bed243d3SAndroid Build Coastguard Worker }
73*bed243d3SAndroid Build Coastguard Worker 
74*bed243d3SAndroid Build Coastguard Worker #ifdef __x86_64__
75*bed243d3SAndroid Build Coastguard Worker /// Stores a hardware-generated 64-bit random value in the memory at \a __p.
76*bed243d3SAndroid Build Coastguard Worker ///
77*bed243d3SAndroid Build Coastguard Worker ///    The random number generator complies with NIST SP800-90B and SP800-90C.
78*bed243d3SAndroid Build Coastguard Worker ///
79*bed243d3SAndroid Build Coastguard Worker /// \code{.operation}
80*bed243d3SAndroid Build Coastguard Worker /// IF HW_NRND_GEN.ready == 1
81*bed243d3SAndroid Build Coastguard Worker ///   Store64(__p, HW_NRND_GEN.data)
82*bed243d3SAndroid Build Coastguard Worker ///   result := 1
83*bed243d3SAndroid Build Coastguard Worker /// ELSE
84*bed243d3SAndroid Build Coastguard Worker ///   Store64(__p, 0)
85*bed243d3SAndroid Build Coastguard Worker ///   result := 0
86*bed243d3SAndroid Build Coastguard Worker /// END
87*bed243d3SAndroid Build Coastguard Worker /// \endcode
88*bed243d3SAndroid Build Coastguard Worker ///
89*bed243d3SAndroid Build Coastguard Worker /// \headerfile <immintrin.h>
90*bed243d3SAndroid Build Coastguard Worker ///
91*bed243d3SAndroid Build Coastguard Worker /// This intrinsic corresponds to the \c RDSEED instruction.
92*bed243d3SAndroid Build Coastguard Worker ///
93*bed243d3SAndroid Build Coastguard Worker /// \param __p
94*bed243d3SAndroid Build Coastguard Worker ///    Pointer to memory for storing the 64-bit random number.
95*bed243d3SAndroid Build Coastguard Worker /// \returns 1 if a random number was generated, 0 if not.
96*bed243d3SAndroid Build Coastguard Worker static __inline__ int __DEFAULT_FN_ATTRS
_rdseed64_step(unsigned long long * __p)97*bed243d3SAndroid Build Coastguard Worker _rdseed64_step(unsigned long long *__p)
98*bed243d3SAndroid Build Coastguard Worker {
99*bed243d3SAndroid Build Coastguard Worker   return (int) __builtin_ia32_rdseed64_step(__p);
100*bed243d3SAndroid Build Coastguard Worker }
101*bed243d3SAndroid Build Coastguard Worker #endif
102*bed243d3SAndroid Build Coastguard Worker 
103*bed243d3SAndroid Build Coastguard Worker #undef __DEFAULT_FN_ATTRS
104*bed243d3SAndroid Build Coastguard Worker 
105*bed243d3SAndroid Build Coastguard Worker #endif /* __RDSEEDINTRIN_H */
106