1 /*===--------- avx512vlbf16intrin.h - AVX512_BF16 intrinsics ---------------===
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
7 *===-----------------------------------------------------------------------===
10 #error "Never use <avx512vlbf16intrin.h> directly; include <immintrin.h> instead."
13 #ifndef __AVX512VLBF16INTRIN_H
14 #define __AVX512VLBF16INTRIN_H
16 typedef short __m128bh __attribute__((__vector_size__(16), __aligned__(16)));
18 #define __DEFAULT_FN_ATTRS128 \
19 __attribute__((__always_inline__, __nodebug__, \
20 __target__("avx512vl, avx512bf16"), __min_vector_width__(128)))
21 #define __DEFAULT_FN_ATTRS256 \
22 __attribute__((__always_inline__, __nodebug__, \
23 __target__("avx512vl, avx512bf16"), __min_vector_width__(256)))
25 /// Convert Two Packed Single Data to One Packed BF16 Data.
27 /// \headerfile <x86intrin.h>
29 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
32 /// A 128-bit vector of [4 x float].
34 /// A 128-bit vector of [4 x float].
35 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
36 /// conversion of __B, and higher 64 bits come from conversion of __A.
37 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
38 _mm_cvtne2ps_pbh(__m128 __A, __m128 __B) {
39 return (__m128bh)__builtin_ia32_cvtne2ps2bf16_128((__v4sf) __A,
43 /// Convert Two Packed Single Data to One Packed BF16 Data.
45 /// \headerfile <x86intrin.h>
47 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
50 /// A 128-bit vector of [4 x float].
52 /// A 128-bit vector of [4 x float].
54 /// A 128-bit vector of [8 x bfloat].
56 /// A 8-bit mask value specifying what is chosen for each element.
57 /// A 1 means conversion of __A or __B. A 0 means element from __W.
58 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
59 /// conversion of __B, and higher 64 bits come from conversion of __A.
60 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
61 _mm_mask_cvtne2ps_pbh(__m128bh __W, __mmask8 __U, __m128 __A, __m128 __B) {
62 return (__m128bh)__builtin_ia32_selectw_128((__mmask8)__U,
63 (__v8hi)_mm_cvtne2ps_pbh(__A, __B),
67 /// Convert Two Packed Single Data to One Packed BF16 Data.
69 /// \headerfile <x86intrin.h>
71 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
74 /// A 128-bit vector of [4 x float].
76 /// A 128-bit vector of [4 x float].
78 /// A 8-bit mask value specifying what is chosen for each element.
79 /// A 1 means conversion of __A or __B. A 0 means element is zero.
80 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
81 /// conversion of __B, and higher 64 bits come from conversion of __A.
82 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
83 _mm_maskz_cvtne2ps_pbh(__mmask8 __U, __m128 __A, __m128 __B) {
84 return (__m128bh)__builtin_ia32_selectw_128((__mmask8)__U,
85 (__v8hi)_mm_cvtne2ps_pbh(__A, __B),
86 (__v8hi)_mm_setzero_si128());
89 /// Convert Two Packed Single Data to One Packed BF16 Data.
91 /// \headerfile <x86intrin.h>
93 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
96 /// A 256-bit vector of [8 x float].
98 /// A 256-bit vector of [8 x float].
99 /// \returns A 256-bit vector of [16 x bfloat] whose lower 128 bits come from
100 /// conversion of __B, and higher 128 bits come from conversion of __A.
101 static __inline__ __m256bh __DEFAULT_FN_ATTRS256
102 _mm256_cvtne2ps_pbh(__m256 __A, __m256 __B) {
103 return (__m256bh)__builtin_ia32_cvtne2ps2bf16_256((__v8sf) __A,
107 /// Convert Two Packed Single Data to One Packed BF16 Data.
109 /// \headerfile <x86intrin.h>
111 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
114 /// A 256-bit vector of [8 x float].
116 /// A 256-bit vector of [8 x float].
118 /// A 256-bit vector of [16 x bfloat].
120 /// A 16-bit mask value specifying what is chosen for each element.
121 /// A 1 means conversion of __A or __B. A 0 means element from __W.
122 /// \returns A 256-bit vector of [16 x bfloat] whose lower 128 bits come from
123 /// conversion of __B, and higher 128 bits come from conversion of __A.
124 static __inline__ __m256bh __DEFAULT_FN_ATTRS256
125 _mm256_mask_cvtne2ps_pbh(__m256bh __W, __mmask16 __U, __m256 __A, __m256 __B) {
126 return (__m256bh)__builtin_ia32_selectw_256((__mmask16)__U,
127 (__v16hi)_mm256_cvtne2ps_pbh(__A, __B),
131 /// Convert Two Packed Single Data to One Packed BF16 Data.
133 /// \headerfile <x86intrin.h>
135 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
138 /// A 256-bit vector of [8 x float].
140 /// A 256-bit vector of [8 x float].
142 /// A 16-bit mask value specifying what is chosen for each element.
143 /// A 1 means conversion of __A or __B. A 0 means element is zero.
144 /// \returns A 256-bit vector of [16 x bfloat] whose lower 128 bits come from
145 /// conversion of __B, and higher 128 bits come from conversion of __A.
146 static __inline__ __m256bh __DEFAULT_FN_ATTRS256
147 _mm256_maskz_cvtne2ps_pbh(__mmask16 __U, __m256 __A, __m256 __B) {
148 return (__m256bh)__builtin_ia32_selectw_256((__mmask16)__U,
149 (__v16hi)_mm256_cvtne2ps_pbh(__A, __B),
150 (__v16hi)_mm256_setzero_si256());
153 /// Convert Packed Single Data to Packed BF16 Data.
155 /// \headerfile <x86intrin.h>
157 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
160 /// A 128-bit vector of [4 x float].
161 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
162 /// conversion of __A, and higher 64 bits are 0.
163 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
164 _mm_cvtneps_pbh(__m128 __A) {
165 return (__m128bh)__builtin_ia32_cvtneps2bf16_128_mask((__v4sf) __A,
166 (__v8hi)_mm_undefined_si128(),
170 /// Convert Packed Single Data to Packed BF16 Data.
172 /// \headerfile <x86intrin.h>
174 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
177 /// A 128-bit vector of [4 x float].
179 /// A 128-bit vector of [8 x bfloat].
181 /// A 4-bit mask value specifying what is chosen for each element.
182 /// A 1 means conversion of __A. A 0 means element from __W.
183 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
184 /// conversion of __A, and higher 64 bits are 0.
185 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
186 _mm_mask_cvtneps_pbh(__m128bh __W, __mmask8 __U, __m128 __A) {
187 return (__m128bh)__builtin_ia32_cvtneps2bf16_128_mask((__v4sf) __A,
192 /// Convert Packed Single Data to Packed BF16 Data.
194 /// \headerfile <x86intrin.h>
196 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
199 /// A 128-bit vector of [4 x float].
201 /// A 4-bit mask value specifying what is chosen for each element.
202 /// A 1 means conversion of __A. A 0 means element is zero.
203 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
204 /// conversion of __A, and higher 64 bits are 0.
205 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
206 _mm_maskz_cvtneps_pbh(__mmask8 __U, __m128 __A) {
207 return (__m128bh)__builtin_ia32_cvtneps2bf16_128_mask((__v4sf) __A,
208 (__v8hi)_mm_setzero_si128(),
212 /// Convert Packed Single Data to Packed BF16 Data.
214 /// \headerfile <x86intrin.h>
216 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
219 /// A 256-bit vector of [8 x float].
220 /// \returns A 128-bit vector of [8 x bfloat] comes from conversion of __A.
221 static __inline__ __m128bh __DEFAULT_FN_ATTRS256
222 _mm256_cvtneps_pbh(__m256 __A) {
223 return (__m128bh)__builtin_ia32_cvtneps2bf16_256_mask((__v8sf)__A,
224 (__v8hi)_mm_undefined_si128(),
228 /// Convert Packed Single Data to Packed BF16 Data.
230 /// \headerfile <x86intrin.h>
232 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
235 /// A 256-bit vector of [8 x float].
237 /// A 256-bit vector of [8 x bfloat].
239 /// A 8-bit mask value specifying what is chosen for each element.
240 /// A 1 means conversion of __A. A 0 means element from __W.
241 /// \returns A 128-bit vector of [8 x bfloat] comes from conversion of __A.
242 static __inline__ __m128bh __DEFAULT_FN_ATTRS256
243 _mm256_mask_cvtneps_pbh(__m128bh __W, __mmask8 __U, __m256 __A) {
244 return (__m128bh)__builtin_ia32_cvtneps2bf16_256_mask((__v8sf)__A,
249 /// Convert Packed Single Data to Packed BF16 Data.
251 /// \headerfile <x86intrin.h>
253 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
256 /// A 256-bit vector of [8 x float].
258 /// A 8-bit mask value specifying what is chosen for each element.
259 /// A 1 means conversion of __A. A 0 means element is zero.
260 /// \returns A 128-bit vector of [8 x bfloat] comes from conversion of __A.
261 static __inline__ __m128bh __DEFAULT_FN_ATTRS256
262 _mm256_maskz_cvtneps_pbh(__mmask8 __U, __m256 __A) {
263 return (__m128bh)__builtin_ia32_cvtneps2bf16_256_mask((__v8sf)__A,
264 (__v8hi)_mm_setzero_si128(),
268 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
270 /// \headerfile <x86intrin.h>
272 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
275 /// A 128-bit vector of [8 x bfloat].
277 /// A 128-bit vector of [8 x bfloat].
279 /// A 128-bit vector of [4 x float].
280 /// \returns A 128-bit vector of [4 x float] comes from Dot Product of
282 static __inline__ __m128 __DEFAULT_FN_ATTRS128
283 _mm_dpbf16_ps(__m128 __D, __m128bh __A, __m128bh __B) {
284 return (__m128)__builtin_ia32_dpbf16ps_128((__v4sf)__D,
289 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
291 /// \headerfile <x86intrin.h>
293 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
296 /// A 128-bit vector of [8 x bfloat].
298 /// A 128-bit vector of [8 x bfloat].
300 /// A 128-bit vector of [4 x float].
302 /// A 8-bit mask value specifying what is chosen for each element.
303 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means __D.
304 /// \returns A 128-bit vector of [4 x float] comes from Dot Product of
306 static __inline__ __m128 __DEFAULT_FN_ATTRS128
307 _mm_mask_dpbf16_ps(__m128 __D, __mmask8 __U, __m128bh __A, __m128bh __B) {
308 return (__m128)__builtin_ia32_selectps_128((__mmask8)__U,
309 (__v4sf)_mm_dpbf16_ps(__D, __A, __B),
313 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
315 /// \headerfile <x86intrin.h>
317 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
320 /// A 128-bit vector of [8 x bfloat].
322 /// A 128-bit vector of [8 x bfloat].
324 /// A 128-bit vector of [4 x float].
326 /// A 8-bit mask value specifying what is chosen for each element.
327 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means 0.
328 /// \returns A 128-bit vector of [4 x float] comes from Dot Product of
330 static __inline__ __m128 __DEFAULT_FN_ATTRS128
331 _mm_maskz_dpbf16_ps(__mmask8 __U, __m128 __D, __m128bh __A, __m128bh __B) {
332 return (__m128)__builtin_ia32_selectps_128((__mmask8)__U,
333 (__v4sf)_mm_dpbf16_ps(__D, __A, __B),
334 (__v4sf)_mm_setzero_si128());
337 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
339 /// \headerfile <x86intrin.h>
341 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
344 /// A 256-bit vector of [16 x bfloat].
346 /// A 256-bit vector of [16 x bfloat].
348 /// A 256-bit vector of [8 x float].
349 /// \returns A 256-bit vector of [8 x float] comes from Dot Product of
351 static __inline__ __m256 __DEFAULT_FN_ATTRS256
352 _mm256_dpbf16_ps(__m256 __D, __m256bh __A, __m256bh __B) {
353 return (__m256)__builtin_ia32_dpbf16ps_256((__v8sf)__D,
358 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
360 /// \headerfile <x86intrin.h>
362 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
365 /// A 256-bit vector of [16 x bfloat].
367 /// A 256-bit vector of [16 x bfloat].
369 /// A 256-bit vector of [8 x float].
371 /// A 16-bit mask value specifying what is chosen for each element.
372 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means __D.
373 /// \returns A 256-bit vector of [8 x float] comes from Dot Product of
375 static __inline__ __m256 __DEFAULT_FN_ATTRS256
376 _mm256_mask_dpbf16_ps(__m256 __D, __mmask8 __U, __m256bh __A, __m256bh __B) {
377 return (__m256)__builtin_ia32_selectps_256((__mmask8)__U,
378 (__v8sf)_mm256_dpbf16_ps(__D, __A, __B),
382 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
384 /// \headerfile <x86intrin.h>
386 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
389 /// A 256-bit vector of [16 x bfloat].
391 /// A 256-bit vector of [16 x bfloat].
393 /// A 256-bit vector of [8 x float].
395 /// A 8-bit mask value specifying what is chosen for each element.
396 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means 0.
397 /// \returns A 256-bit vector of [8 x float] comes from Dot Product of
399 static __inline__ __m256 __DEFAULT_FN_ATTRS256
400 _mm256_maskz_dpbf16_ps(__mmask8 __U, __m256 __D, __m256bh __A, __m256bh __B) {
401 return (__m256)__builtin_ia32_selectps_256((__mmask8)__U,
402 (__v8sf)_mm256_dpbf16_ps(__D, __A, __B),
403 (__v8sf)_mm256_setzero_si256());
406 /// Convert One Single float Data to One BF16 Data.
408 /// \headerfile <x86intrin.h>
410 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
414 /// \returns A bf16 data whose sign field and exponent field keep unchanged,
415 /// and fraction field is truncated to 7 bits.
416 static __inline__ __bfloat16 __DEFAULT_FN_ATTRS128 _mm_cvtness_sbh(float __A) {
417 __v4sf __V = {__A, 0, 0, 0};
418 __v8hi __R = __builtin_ia32_cvtneps2bf16_128_mask(
419 (__v4sf)__V, (__v8hi)_mm_undefined_si128(), (__mmask8)-1);
423 /// Convert Packed BF16 Data to Packed float Data.
425 /// \headerfile <x86intrin.h>
428 /// A 128-bit vector of [4 x bfloat].
429 /// \returns A 128-bit vector of [4 x float] come from conversion of __A
430 static __inline__ __m128 __DEFAULT_FN_ATTRS128 _mm_cvtpbh_ps(__m128bh __A) {
431 return _mm_castsi128_ps(
432 (__m128i)_mm_slli_epi32((__m128i)_mm_cvtepi16_epi32((__m128i)__A), 16));
435 /// Convert Packed BF16 Data to Packed float Data.
437 /// \headerfile <x86intrin.h>
440 /// A 128-bit vector of [8 x bfloat].
441 /// \returns A 256-bit vector of [8 x float] come from conversion of __A
442 static __inline__ __m256 __DEFAULT_FN_ATTRS256 _mm256_cvtpbh_ps(__m128bh __A) {
443 return _mm256_castsi256_ps((__m256i)_mm256_slli_epi32(
444 (__m256i)_mm256_cvtepi16_epi32((__m128i)__A), 16));
447 /// Convert Packed BF16 Data to Packed float Data using zeroing mask.
449 /// \headerfile <x86intrin.h>
452 /// A 4-bit mask. Elements are zeroed out when the corresponding mask
455 /// A 128-bit vector of [4 x bfloat].
456 /// \returns A 128-bit vector of [4 x float] come from conversion of __A
457 static __inline__ __m128 __DEFAULT_FN_ATTRS128
458 _mm_maskz_cvtpbh_ps(__mmask8 __U, __m128bh __A) {
459 return _mm_castsi128_ps((__m128i)_mm_slli_epi32(
460 (__m128i)_mm_maskz_cvtepi16_epi32((__mmask8)__U, (__m128i)__A), 16));
463 /// Convert Packed BF16 Data to Packed float Data using zeroing mask.
465 /// \headerfile <x86intrin.h>
468 /// A 8-bit mask. Elements are zeroed out when the corresponding mask
471 /// A 128-bit vector of [8 x bfloat].
472 /// \returns A 256-bit vector of [8 x float] come from conversion of __A
473 static __inline__ __m256 __DEFAULT_FN_ATTRS256
474 _mm256_maskz_cvtpbh_ps(__mmask8 __U, __m128bh __A) {
475 return _mm256_castsi256_ps((__m256i)_mm256_slli_epi32(
476 (__m256i)_mm256_maskz_cvtepi16_epi32((__mmask8)__U, (__m128i)__A), 16));
479 /// Convert Packed BF16 Data to Packed float Data using merging mask.
481 /// \headerfile <x86intrin.h>
484 /// A 128-bit vector of [4 x float]. Elements are copied from __S when
485 /// the corresponding mask bit is not set.
487 /// A 4-bit mask. Elements are zeroed out when the corresponding mask
490 /// A 128-bit vector of [4 x bfloat].
491 /// \returns A 128-bit vector of [4 x float] come from conversion of __A
492 static __inline__ __m128 __DEFAULT_FN_ATTRS128
493 _mm_mask_cvtpbh_ps(__m128 __S, __mmask8 __U, __m128bh __A) {
494 return _mm_castsi128_ps((__m128i)_mm_mask_slli_epi32(
495 (__m128i)__S, (__mmask8)__U, (__m128i)_mm_cvtepi16_epi32((__m128i)__A),
499 /// Convert Packed BF16 Data to Packed float Data using merging mask.
501 /// \headerfile <x86intrin.h>
504 /// A 256-bit vector of [8 x float]. Elements are copied from __S when
505 /// the corresponding mask bit is not set.
507 /// A 8-bit mask. Elements are zeroed out when the corresponding mask
510 /// A 128-bit vector of [8 x bfloat].
511 /// \returns A 256-bit vector of [8 x float] come from conversion of __A
512 static __inline__ __m256 __DEFAULT_FN_ATTRS256
513 _mm256_mask_cvtpbh_ps(__m256 __S, __mmask8 __U, __m128bh __A) {
514 return _mm256_castsi256_ps((__m256i)_mm256_mask_slli_epi32(
515 (__m256i)__S, (__mmask8)__U, (__m256i)_mm256_cvtepi16_epi32((__m128i)__A),
519 #undef __DEFAULT_FN_ATTRS128
520 #undef __DEFAULT_FN_ATTRS256