clang 23.0.0git
avxvnniintrin.h
Go to the documentation of this file.
1/*===--------------- avxvnniintrin.h - VNNI intrinsics --------------------===
2 *
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 *
22 *===-----------------------------------------------------------------------===
23 */
24#ifndef __IMMINTRIN_H
25#error "Never use <avxvnniintrin.h> directly; include <immintrin.h> instead."
26#endif
27
28#ifndef __AVXVNNIINTRIN_H
29#define __AVXVNNIINTRIN_H
30
31/* Below intrinsics defined in avx512vlvnniintrin.h can be used for AVXVNNI */
32/// \fn __m256i _mm256_dpbusd_epi32(__m256i __S, __m256i __A, __m256i __B)
33/// \fn __m256i _mm256_dpbusds_epi32(__m256i __S, __m256i __A, __m256i __B)
34/// \fn __m256i _mm256_dpwssd_epi32(__m256i __S, __m256i __A, __m256i __B)
35/// \fn __m256i _mm256_dpwssds_epi32(__m256i __S, __m256i __A, __m256i __B)
36/// \fn __m128i _mm_dpbusd_epi32(__m128i __S, __m128i __A, __m128i __B)
37/// \fn __m128i _mm_dpbusds_epi32(__m128i __S, __m128i __A, __m128i __B)
38/// \fn __m128i _mm_dpwssd_epi32(__m128i __S, __m128i __A, __m128i __B)
39/// \fn __m128i _mm_dpwssds_epi32(__m128i __S, __m128i __A, __m128i __B)
40
41/* Intrinsics with _avx_ prefix are for compatibility with msvc. */
42/* Define the default attributes for the functions in this file. */
43#if defined(__cplusplus) && (__cplusplus >= 201103L)
44#define __DEFAULT_FN_ATTRS256 \
45 __attribute__((__always_inline__, __nodebug__, __target__("avxvnni"), \
46 __min_vector_width__(256))) constexpr
47#define __DEFAULT_FN_ATTRS128 \
48 __attribute__((__always_inline__, __nodebug__, __target__("avxvnni"), \
49 __min_vector_width__(128))) constexpr
50#else
51#define __DEFAULT_FN_ATTRS256 \
52 __attribute__((__always_inline__, __nodebug__, __target__("avxvnni"), \
53 __min_vector_width__(256)))
54#define __DEFAULT_FN_ATTRS128 \
55 __attribute__((__always_inline__, __nodebug__, __target__("avxvnni"), \
56 __min_vector_width__(128)))
57#endif
58
59/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
60/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
61/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
62/// in \a __S, and store the packed 32-bit results in DST.
63///
64/// This intrinsic corresponds to the <c> VPDPBUSD </c> instructions.
65///
66/// \code{.operation}
67/// FOR j := 0 to 7
68/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
69/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
70/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
71/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
72/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4
73/// ENDFOR
74/// DST[MAX:256] := 0
75/// \endcode
76static __inline__ __m256i __DEFAULT_FN_ATTRS256
77_mm256_dpbusd_avx_epi32(__m256i __S, __m256i __A, __m256i __B) {
78 return (__m256i)__builtin_ia32_vpdpbusd256((__v8si)__S, (__v32qu)__A,
79 (__v32qi)__B);
80}
81
82/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
83/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
84/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
85/// in \a __S using signed saturation, and store the packed 32-bit results in DST.
86///
87/// This intrinsic corresponds to the <c> VPDPBUSDS </c> instructions.
88///
89/// \code{.operation}
90/// FOR j := 0 to 7
91/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
92/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
93/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
94/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
95/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4)
96/// ENDFOR
97/// DST[MAX:256] := 0
98/// \endcode
99static __inline__ __m256i __DEFAULT_FN_ATTRS256
100_mm256_dpbusds_avx_epi32(__m256i __S, __m256i __A, __m256i __B) {
101 return (__m256i)__builtin_ia32_vpdpbusds256((__v8si)__S, (__v32qu)__A,
102 (__v32qi)__B);
103}
104
105/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
106/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
107/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S,
108/// and store the packed 32-bit results in DST.
109///
110/// This intrinsic corresponds to the <c> VPDPWSSD </c> instructions.
111///
112/// \code{.operation}
113/// FOR j := 0 to 7
114/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
115/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
116/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2
117/// ENDFOR
118/// DST[MAX:256] := 0
119/// \endcode
120static __inline__ __m256i __DEFAULT_FN_ATTRS256
121_mm256_dpwssd_avx_epi32(__m256i __S, __m256i __A, __m256i __B) {
122 return (__m256i)__builtin_ia32_vpdpwssd256((__v8si)__S, (__v16hi)__A,
123 (__v16hi)__B);
124}
125
126/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
127/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
128/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S
129/// using signed saturation, and store the packed 32-bit results in DST.
130///
131/// This intrinsic corresponds to the <c> VPDPWSSDS </c> instructions.
132///
133/// \code{.operation}
134/// FOR j := 0 to 7
135/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
136/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
137/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2)
138/// ENDFOR
139/// DST[MAX:256] := 0
140/// \endcode
141static __inline__ __m256i __DEFAULT_FN_ATTRS256
142_mm256_dpwssds_avx_epi32(__m256i __S, __m256i __A, __m256i __B) {
143 return (__m256i)__builtin_ia32_vpdpwssds256((__v8si)__S, (__v16hi)__A,
144 (__v16hi)__B);
145}
146
147/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
148/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
149/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
150/// in \a __S, and store the packed 32-bit results in DST.
151///
152/// This intrinsic corresponds to the <c> VPDPBUSD </c> instructions.
153///
154/// \code{.operation}
155/// FOR j := 0 to 3
156/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
157/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
158/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
159/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
160/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4
161/// ENDFOR
162/// DST[MAX:128] := 0
163/// \endcode
164static __inline__ __m128i __DEFAULT_FN_ATTRS128
165_mm_dpbusd_avx_epi32(__m128i __S, __m128i __A, __m128i __B) {
166 return (__m128i)__builtin_ia32_vpdpbusd128((__v4si)__S, (__v16qu)__A,
167 (__v16qi)__B);
168}
169
170/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
171/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
172/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
173/// in \a __S using signed saturation, and store the packed 32-bit results in DST.
174///
175/// This intrinsic corresponds to the <c> VPDPBUSDS </c> instructions.
176///
177/// \code{.operation}
178/// FOR j := 0 to 3
179/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
180/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
181/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
182/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
183/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4)
184/// ENDFOR
185/// DST[MAX:128] := 0
186/// \endcode
187static __inline__ __m128i __DEFAULT_FN_ATTRS128
188_mm_dpbusds_avx_epi32(__m128i __S, __m128i __A, __m128i __B) {
189 return (__m128i)__builtin_ia32_vpdpbusds128((__v4si)__S, (__v16qu)__A,
190 (__v16qi)__B);
191}
192
193/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
194/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
195/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S,
196/// and store the packed 32-bit results in DST.
197///
198/// This intrinsic corresponds to the <c> VPDPWSSD </c> instructions.
199///
200/// \code{.operation}
201/// FOR j := 0 to 3
202/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
203/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
204/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2
205/// ENDFOR
206/// DST[MAX:128] := 0
207/// \endcode
208static __inline__ __m128i __DEFAULT_FN_ATTRS128
209_mm_dpwssd_avx_epi32(__m128i __S, __m128i __A, __m128i __B) {
210 return (__m128i)__builtin_ia32_vpdpwssd128((__v4si)__S, (__v8hi)__A,
211 (__v8hi)__B);
212}
213
214/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
215/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
216/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S
217/// using signed saturation, and store the packed 32-bit results in DST.
218///
219/// This intrinsic corresponds to the <c> VPDPWSSDS </c> instructions.
220///
221/// \code{.operation}
222/// FOR j := 0 to 3
223/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
224/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
225/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2)
226/// ENDFOR
227/// DST[MAX:128] := 0
228/// \endcode
229static __inline__ __m128i __DEFAULT_FN_ATTRS128
230_mm_dpwssds_avx_epi32(__m128i __S, __m128i __A, __m128i __B) {
231 return (__m128i)__builtin_ia32_vpdpwssds128((__v4si)__S, (__v8hi)__A,
232 (__v8hi)__B);
233}
234
235#undef __DEFAULT_FN_ATTRS128
236#undef __DEFAULT_FN_ATTRS256
237
238#endif // __AVXVNNIINTRIN_H
#define __DEFAULT_FN_ATTRS128
#define __DEFAULT_FN_ATTRS256
static __inline__ __m256i __DEFAULT_FN_ATTRS256 _mm256_dpwssds_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
Multiply groups of 2 adjacent pairs of signed 16-bit integers in __A with corresponding 16-bit intege...
static __inline__ __m256i __DEFAULT_FN_ATTRS256 _mm256_dpbusds_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in __A with corresponding signed 8-bit...
static __inline__ __m256i __DEFAULT_FN_ATTRS256 _mm256_dpwssd_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
Multiply groups of 2 adjacent pairs of signed 16-bit integers in __A with corresponding 16-bit intege...
static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_dpwssd_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
Multiply groups of 2 adjacent pairs of signed 16-bit integers in __A with corresponding 16-bit intege...
static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_dpbusds_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in __A with corresponding signed 8-bit...
static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_dpwssds_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
Multiply groups of 2 adjacent pairs of signed 16-bit integers in __A with corresponding 16-bit intege...
static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_dpbusd_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in __A with corresponding signed 8-bit...
static __inline__ __m256i __DEFAULT_FN_ATTRS256 _mm256_dpbusd_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in __A with corresponding signed 8-bit...