1243791Sdim/*===---- __wmmintrin_aes.h - AES intrinsics -------------------------------===
2243791Sdim *
3353358Sdim * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim * See https://llvm.org/LICENSE.txt for license information.
5353358Sdim * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6243791Sdim *
7243791Sdim *===-----------------------------------------------------------------------===
8243791Sdim */
9243791Sdim
10341825Sdim#ifndef __WMMINTRIN_H
11341825Sdim#error "Never use <__wmmintrin_aes.h> directly; include <wmmintrin.h> instead."
12341825Sdim#endif
13243791Sdim
14341825Sdim#ifndef __WMMINTRIN_AES_H
15341825Sdim#define __WMMINTRIN_AES_H
16341825Sdim
17288943Sdim/* Define the default attributes for the functions in this file. */
18341825Sdim#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("aes"), __min_vector_width__(128)))
19288943Sdim
20341825Sdim/// Performs a single round of AES encryption using the Equivalent
21309124Sdim///    Inverse Cipher, transforming the state value from the first source
22309124Sdim///    operand using a 128-bit round key value contained in the second source
23309124Sdim///    operand, and writes the result to the destination.
24309124Sdim///
25309124Sdim/// \headerfile <x86intrin.h>
26309124Sdim///
27314564Sdim/// This intrinsic corresponds to the <c> VAESENC </c> instruction.
28309124Sdim///
29309124Sdim/// \param __V
30309124Sdim///    A 128-bit integer vector containing the state value.
31309124Sdim/// \param __R
32309124Sdim///    A 128-bit integer vector containing the round key value.
33309124Sdim/// \returns A 128-bit integer vector containing the encrypted value.
34288943Sdimstatic __inline__ __m128i __DEFAULT_FN_ATTRS
35243791Sdim_mm_aesenc_si128(__m128i __V, __m128i __R)
36243791Sdim{
37309124Sdim  return (__m128i)__builtin_ia32_aesenc128((__v2di)__V, (__v2di)__R);
38243791Sdim}
39243791Sdim
40341825Sdim/// Performs the final round of AES encryption using the Equivalent
41309124Sdim///    Inverse Cipher, transforming the state value from the first source
42309124Sdim///    operand using a 128-bit round key value contained in the second source
43309124Sdim///    operand, and writes the result to the destination.
44309124Sdim///
45309124Sdim/// \headerfile <x86intrin.h>
46309124Sdim///
47314564Sdim/// This intrinsic corresponds to the <c> VAESENCLAST </c> instruction.
48309124Sdim///
49309124Sdim/// \param __V
50309124Sdim///    A 128-bit integer vector containing the state value.
51309124Sdim/// \param __R
52309124Sdim///    A 128-bit integer vector containing the round key value.
53309124Sdim/// \returns A 128-bit integer vector containing the encrypted value.
54288943Sdimstatic __inline__ __m128i __DEFAULT_FN_ATTRS
55243791Sdim_mm_aesenclast_si128(__m128i __V, __m128i __R)
56243791Sdim{
57309124Sdim  return (__m128i)__builtin_ia32_aesenclast128((__v2di)__V, (__v2di)__R);
58243791Sdim}
59243791Sdim
60341825Sdim/// Performs a single round of AES decryption using the Equivalent
61309124Sdim///    Inverse Cipher, transforming the state value from the first source
62309124Sdim///    operand using a 128-bit round key value contained in the second source
63309124Sdim///    operand, and writes the result to the destination.
64309124Sdim///
65309124Sdim/// \headerfile <x86intrin.h>
66309124Sdim///
67314564Sdim/// This intrinsic corresponds to the <c> VAESDEC </c> instruction.
68309124Sdim///
69309124Sdim/// \param __V
70309124Sdim///    A 128-bit integer vector containing the state value.
71309124Sdim/// \param __R
72309124Sdim///    A 128-bit integer vector containing the round key value.
73309124Sdim/// \returns A 128-bit integer vector containing the decrypted value.
74288943Sdimstatic __inline__ __m128i __DEFAULT_FN_ATTRS
75243791Sdim_mm_aesdec_si128(__m128i __V, __m128i __R)
76243791Sdim{
77309124Sdim  return (__m128i)__builtin_ia32_aesdec128((__v2di)__V, (__v2di)__R);
78243791Sdim}
79243791Sdim
80341825Sdim/// Performs the final round of AES decryption using the Equivalent
81309124Sdim///    Inverse Cipher, transforming the state value from the first source
82309124Sdim///    operand using a 128-bit round key value contained in the second source
83309124Sdim///    operand, and writes the result to the destination.
84309124Sdim///
85309124Sdim/// \headerfile <x86intrin.h>
86309124Sdim///
87314564Sdim/// This intrinsic corresponds to the <c> VAESDECLAST </c> instruction.
88309124Sdim///
89309124Sdim/// \param __V
90309124Sdim///    A 128-bit integer vector containing the state value.
91309124Sdim/// \param __R
92309124Sdim///    A 128-bit integer vector containing the round key value.
93309124Sdim/// \returns A 128-bit integer vector containing the decrypted value.
94288943Sdimstatic __inline__ __m128i __DEFAULT_FN_ATTRS
95243791Sdim_mm_aesdeclast_si128(__m128i __V, __m128i __R)
96243791Sdim{
97309124Sdim  return (__m128i)__builtin_ia32_aesdeclast128((__v2di)__V, (__v2di)__R);
98243791Sdim}
99243791Sdim
100341825Sdim/// Applies the AES InvMixColumns() transformation to an expanded key
101309124Sdim///    contained in the source operand, and writes the result to the
102309124Sdim///    destination.
103309124Sdim///
104309124Sdim/// \headerfile <x86intrin.h>
105309124Sdim///
106314564Sdim/// This intrinsic corresponds to the <c> VAESIMC </c> instruction.
107309124Sdim///
108309124Sdim/// \param __V
109309124Sdim///    A 128-bit integer vector containing the expanded key.
110309124Sdim/// \returns A 128-bit integer vector containing the transformed value.
111288943Sdimstatic __inline__ __m128i __DEFAULT_FN_ATTRS
112243791Sdim_mm_aesimc_si128(__m128i __V)
113243791Sdim{
114309124Sdim  return (__m128i)__builtin_ia32_aesimc128((__v2di)__V);
115243791Sdim}
116243791Sdim
117341825Sdim/// Generates a round key for AES encryption, operating on 128-bit data
118309124Sdim///    specified in the first source operand and using an 8-bit round constant
119309124Sdim///    specified by the second source operand, and writes the result to the
120309124Sdim///    destination.
121309124Sdim///
122309124Sdim/// \headerfile <x86intrin.h>
123309124Sdim///
124309124Sdim/// \code
125309124Sdim/// __m128i _mm_aeskeygenassist_si128(__m128i C, const int R);
126309124Sdim/// \endcode
127309124Sdim///
128314564Sdim/// This intrinsic corresponds to the <c> AESKEYGENASSIST </c> instruction.
129309124Sdim///
130309124Sdim/// \param C
131309124Sdim///    A 128-bit integer vector that is used to generate the AES encryption key.
132309124Sdim/// \param R
133309124Sdim///    An 8-bit round constant used to generate the AES encryption key.
134309124Sdim/// \returns A 128-bit round key for AES encryption.
135243791Sdim#define _mm_aeskeygenassist_si128(C, R) \
136296417Sdim  (__m128i)__builtin_ia32_aeskeygenassist128((__v2di)(__m128i)(C), (int)(R))
137243791Sdim
138288943Sdim#undef __DEFAULT_FN_ATTRS
139288943Sdim
140341825Sdim#endif  /* __WMMINTRIN_AES_H */
141