clang 22.0.0git
shaintrin.h
Go to the documentation of this file.
1/*===---- shaintrin.h - SHA intrinsics -------------------------------------===
2 *
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 *
7 *===-----------------------------------------------------------------------===
8 */
9
10#ifndef __IMMINTRIN_H
11#error "Never use <shaintrin.h> directly; include <immintrin.h> instead."
12#endif
13
14#ifndef __SHAINTRIN_H
15#define __SHAINTRIN_H
16
17/* Define the default attributes for the functions in this file. */
18#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sha"), __min_vector_width__(128)))
19
20/// Performs four iterations of the inner loop of the SHA-1 message digest
21/// algorithm using the starting SHA-1 state (A, B, C, D) from the 128-bit
22/// vector of [4 x i32] in \a V1 and the next four 32-bit elements of the
23/// message from the 128-bit vector of [4 x i32] in \a V2. Note that the
24/// SHA-1 state variable E must have already been added to \a V2
25/// (\c _mm_sha1nexte_epu32() can perform this step). Returns the updated
26/// SHA-1 state (A, B, C, D) as a 128-bit vector of [4 x i32].
27///
28/// The SHA-1 algorithm has an inner loop of 80 iterations, twenty each
29/// with a different combining function and rounding constant. This
30/// intrinsic performs four iterations using a combining function and
31/// rounding constant selected by \a M[1:0].
32///
33/// \headerfile <immintrin.h>
34///
35/// \code
36/// __m128i _mm_sha1rnds4_epu32(__m128i V1, __m128i V2, const int M);
37/// \endcode
38///
39/// This intrinsic corresponds to the \c SHA1RNDS4 instruction.
40///
41/// \param V1
42/// A 128-bit vector of [4 x i32] containing the initial SHA-1 state.
43/// \param V2
44/// A 128-bit vector of [4 x i32] containing the next four elements of
45/// the message, plus SHA-1 state variable E.
46/// \param M
47/// An immediate value where bits [1:0] select among four possible
48/// combining functions and rounding constants (not specified here).
49/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-1 state.
50#define _mm_sha1rnds4_epu32(V1, V2, M) \
51 ((__m128i)__builtin_ia32_sha1rnds4((__v4si)(__m128i)(V1), \
52 (__v4si)(__m128i)(V2), (M)))
53
54/// Calculates the SHA-1 state variable E from the SHA-1 state variables in
55/// the 128-bit vector of [4 x i32] in \a __X, adds that to the next set of
56/// four message elements in the 128-bit vector of [4 x i32] in \a __Y, and
57/// returns the result.
58///
59/// \headerfile <immintrin.h>
60///
61/// This intrinsic corresponds to the \c SHA1NEXTE instruction.
62///
63/// \param __X
64/// A 128-bit vector of [4 x i32] containing the current SHA-1 state.
65/// \param __Y
66/// A 128-bit vector of [4 x i32] containing the next four elements of the
67/// message.
68/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-1
69/// values.
70static __inline__ __m128i __DEFAULT_FN_ATTRS
71_mm_sha1nexte_epu32(__m128i __X, __m128i __Y)
72{
73 return (__m128i)__builtin_ia32_sha1nexte((__v4si)__X, (__v4si)__Y);
74}
75
76/// Performs an intermediate calculation for deriving the next four SHA-1
77/// message elements using previous message elements from the 128-bit
78/// vectors of [4 x i32] in \a __X and \a __Y, and returns the result.
79///
80/// \headerfile <immintrin.h>
81///
82/// This intrinsic corresponds to the \c SHA1MSG1 instruction.
83///
84/// \param __X
85/// A 128-bit vector of [4 x i32] containing previous message elements.
86/// \param __Y
87/// A 128-bit vector of [4 x i32] containing previous message elements.
88/// \returns A 128-bit vector of [4 x i32] containing the derived SHA-1
89/// elements.
90static __inline__ __m128i __DEFAULT_FN_ATTRS
91_mm_sha1msg1_epu32(__m128i __X, __m128i __Y)
92{
93 return (__m128i)__builtin_ia32_sha1msg1((__v4si)__X, (__v4si)__Y);
94}
95
96/// Performs the final calculation for deriving the next four SHA-1 message
97/// elements using previous message elements from the 128-bit vectors of
98/// [4 x i32] in \a __X and \a __Y, and returns the result.
99///
100/// \headerfile <immintrin.h>
101///
102/// This intrinsic corresponds to the \c SHA1MSG2 instruction.
103///
104/// \param __X
105/// A 128-bit vector of [4 x i32] containing an intermediate result.
106/// \param __Y
107/// A 128-bit vector of [4 x i32] containing previous message values.
108/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-1
109/// values.
110static __inline__ __m128i __DEFAULT_FN_ATTRS
111_mm_sha1msg2_epu32(__m128i __X, __m128i __Y)
112{
113 return (__m128i)__builtin_ia32_sha1msg2((__v4si)__X, (__v4si)__Y);
114}
115
116/// Performs two rounds of SHA-256 operation using the following inputs: a
117/// starting SHA-256 state (C, D, G, H) from the 128-bit vector of
118/// [4 x i32] in \a __X; a starting SHA-256 state (A, B, E, F) from the
119/// 128-bit vector of [4 x i32] in \a __Y; and a pre-computed sum of the
120/// next two message elements (unsigned 32-bit integers) and corresponding
121/// rounding constants from the 128-bit vector of [4 x i32] in \a __Z.
122/// Returns the updated SHA-256 state (A, B, E, F) as a 128-bit vector of
123/// [4 x i32].
124///
125/// The SHA-256 algorithm has a core loop of 64 iterations. This intrinsic
126/// performs two of those iterations.
127///
128/// \headerfile <immintrin.h>
129///
130/// This intrinsic corresponds to the \c SHA256RNDS2 instruction.
131///
132/// \param __X
133/// A 128-bit vector of [4 x i32] containing part of the initial SHA-256
134/// state.
135/// \param __Y
136/// A 128-bit vector of [4 x i32] containing part of the initial SHA-256
137/// state.
138/// \param __Z
139/// A 128-bit vector of [4 x i32] containing additional input to the
140/// SHA-256 operation.
141/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-1 state.
142static __inline__ __m128i __DEFAULT_FN_ATTRS
143_mm_sha256rnds2_epu32(__m128i __X, __m128i __Y, __m128i __Z)
144{
145 return (__m128i)__builtin_ia32_sha256rnds2((__v4si)__X, (__v4si)__Y, (__v4si)__Z);
146}
147
148/// Performs an intermediate calculation for deriving the next four SHA-256
149/// message elements using previous message elements from the 128-bit
150/// vectors of [4 x i32] in \a __X and \a __Y, and returns the result.
151///
152/// \headerfile <immintrin.h>
153///
154/// This intrinsic corresponds to the \c SHA256MSG1 instruction.
155///
156/// \param __X
157/// A 128-bit vector of [4 x i32] containing previous message elements.
158/// \param __Y
159/// A 128-bit vector of [4 x i32] containing previous message elements.
160/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-256
161/// values.
162static __inline__ __m128i __DEFAULT_FN_ATTRS
163_mm_sha256msg1_epu32(__m128i __X, __m128i __Y)
164{
165 return (__m128i)__builtin_ia32_sha256msg1((__v4si)__X, (__v4si)__Y);
166}
167
168/// Performs the final calculation for deriving the next four SHA-256 message
169/// elements using previous message elements from the 128-bit vectors of
170/// [4 x i32] in \a __X and \a __Y, and returns the result.
171///
172/// \headerfile <immintrin.h>
173///
174/// This intrinsic corresponds to the \c SHA256MSG2 instruction.
175///
176/// \param __X
177/// A 128-bit vector of [4 x i32] containing an intermediate result.
178/// \param __Y
179/// A 128-bit vector of [4 x i32] containing previous message values.
180/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-256
181/// values.
182static __inline__ __m128i __DEFAULT_FN_ATTRS
183_mm_sha256msg2_epu32(__m128i __X, __m128i __Y)
184{
185 return (__m128i)__builtin_ia32_sha256msg2((__v4si)__X, (__v4si)__Y);
186}
187
188#undef __DEFAULT_FN_ATTRS
189
190#endif /* __SHAINTRIN_H */
#define __DEFAULT_FN_ATTRS
__inline unsigned int unsigned int __Y
Definition bmi2intrin.h:19
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha256rnds2_epu32(__m128i __X, __m128i __Y, __m128i __Z)
Performs two rounds of SHA-256 operation using the following inputs: a starting SHA-256 state (C,...
Definition shaintrin.h:143
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha1nexte_epu32(__m128i __X, __m128i __Y)
Calculates the SHA-1 state variable E from the SHA-1 state variables in the 128-bit vector of [4 x i3...
Definition shaintrin.h:71
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha1msg2_epu32(__m128i __X, __m128i __Y)
Performs the final calculation for deriving the next four SHA-1 message elements using previous messa...
Definition shaintrin.h:111
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha1msg1_epu32(__m128i __X, __m128i __Y)
Performs an intermediate calculation for deriving the next four SHA-1 message elements using previous...
Definition shaintrin.h:91
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha256msg1_epu32(__m128i __X, __m128i __Y)
Performs an intermediate calculation for deriving the next four SHA-256 message elements using previo...
Definition shaintrin.h:163
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_sha256msg2_epu32(__m128i __X, __m128i __Y)
Performs the final calculation for deriving the next four SHA-256 message elements using previous mes...
Definition shaintrin.h:183