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."
15 #ifndef __AVX512VLBF16INTRIN_H
16 #define __AVX512VLBF16INTRIN_H
18 #define __DEFAULT_FN_ATTRS128 \
19 __attribute__((__always_inline__, __nodebug__, \
20 __target__("avx512vl,avx512bf16,no-evex512"), \
21 __min_vector_width__(128)))
22 #define __DEFAULT_FN_ATTRS256 \
23 __attribute__((__always_inline__, __nodebug__, \
24 __target__("avx512vl,avx512bf16,no-evex512"), \
25 __min_vector_width__(256)))
27 /// Convert Two Packed Single Data to One Packed BF16 Data.
29 /// \headerfile <x86intrin.h>
31 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
34 /// A 128-bit vector of [4 x float].
36 /// A 128-bit vector of [4 x float].
37 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
38 /// conversion of __B, and higher 64 bits come from conversion of __A.
39 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
40 _mm_cvtne2ps_pbh(__m128 __A
, __m128 __B
) {
41 return (__m128bh
)__builtin_ia32_cvtne2ps2bf16_128((__v4sf
) __A
,
45 /// Convert Two Packed Single Data to One Packed BF16 Data.
47 /// \headerfile <x86intrin.h>
49 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
52 /// A 128-bit vector of [4 x float].
54 /// A 128-bit vector of [4 x float].
56 /// A 128-bit vector of [8 x bfloat].
58 /// A 8-bit mask value specifying what is chosen for each element.
59 /// A 1 means conversion of __A or __B. A 0 means element from __W.
60 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
61 /// conversion of __B, and higher 64 bits come from conversion of __A.
62 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
63 _mm_mask_cvtne2ps_pbh(__m128bh __W
, __mmask8 __U
, __m128 __A
, __m128 __B
) {
64 return (__m128bh
)__builtin_ia32_selectpbf_128((__mmask8
)__U
,
65 (__v8bf
)_mm_cvtne2ps_pbh(__A
, __B
),
69 /// Convert Two Packed Single Data to One Packed BF16 Data.
71 /// \headerfile <x86intrin.h>
73 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
76 /// A 128-bit vector of [4 x float].
78 /// A 128-bit vector of [4 x float].
80 /// A 8-bit mask value specifying what is chosen for each element.
81 /// A 1 means conversion of __A or __B. A 0 means element is zero.
82 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
83 /// conversion of __B, and higher 64 bits come from conversion of __A.
84 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
85 _mm_maskz_cvtne2ps_pbh(__mmask8 __U
, __m128 __A
, __m128 __B
) {
86 return (__m128bh
)__builtin_ia32_selectpbf_128((__mmask8
)__U
,
87 (__v8bf
)_mm_cvtne2ps_pbh(__A
, __B
),
88 (__v8bf
)_mm_setzero_si128());
91 /// Convert Two Packed Single Data to One Packed BF16 Data.
93 /// \headerfile <x86intrin.h>
95 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
98 /// A 256-bit vector of [8 x float].
100 /// A 256-bit vector of [8 x float].
101 /// \returns A 256-bit vector of [16 x bfloat] whose lower 128 bits come from
102 /// conversion of __B, and higher 128 bits come from conversion of __A.
103 static __inline__ __m256bh __DEFAULT_FN_ATTRS256
104 _mm256_cvtne2ps_pbh(__m256 __A
, __m256 __B
) {
105 return (__m256bh
)__builtin_ia32_cvtne2ps2bf16_256((__v8sf
) __A
,
109 /// Convert Two Packed Single Data to One Packed BF16 Data.
111 /// \headerfile <x86intrin.h>
113 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
116 /// A 256-bit vector of [8 x float].
118 /// A 256-bit vector of [8 x float].
120 /// A 256-bit vector of [16 x bfloat].
122 /// A 16-bit mask value specifying what is chosen for each element.
123 /// A 1 means conversion of __A or __B. A 0 means element from __W.
124 /// \returns A 256-bit vector of [16 x bfloat] whose lower 128 bits come from
125 /// conversion of __B, and higher 128 bits come from conversion of __A.
126 static __inline__ __m256bh __DEFAULT_FN_ATTRS256
127 _mm256_mask_cvtne2ps_pbh(__m256bh __W
, __mmask16 __U
, __m256 __A
, __m256 __B
) {
128 return (__m256bh
)__builtin_ia32_selectpbf_256((__mmask16
)__U
,
129 (__v16bf
)_mm256_cvtne2ps_pbh(__A
, __B
),
133 /// Convert Two Packed Single Data to One Packed BF16 Data.
135 /// \headerfile <x86intrin.h>
137 /// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.
140 /// A 256-bit vector of [8 x float].
142 /// A 256-bit vector of [8 x float].
144 /// A 16-bit mask value specifying what is chosen for each element.
145 /// A 1 means conversion of __A or __B. A 0 means element is zero.
146 /// \returns A 256-bit vector of [16 x bfloat] whose lower 128 bits come from
147 /// conversion of __B, and higher 128 bits come from conversion of __A.
148 static __inline__ __m256bh __DEFAULT_FN_ATTRS256
149 _mm256_maskz_cvtne2ps_pbh(__mmask16 __U
, __m256 __A
, __m256 __B
) {
150 return (__m256bh
)__builtin_ia32_selectpbf_256((__mmask16
)__U
,
151 (__v16bf
)_mm256_cvtne2ps_pbh(__A
, __B
),
152 (__v16bf
)_mm256_setzero_si256());
155 /// Convert Packed Single Data to Packed BF16 Data.
157 /// \headerfile <x86intrin.h>
159 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
162 /// A 128-bit vector of [4 x float].
163 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
164 /// conversion of __A, and higher 64 bits are 0.
165 #define _mm_cvtneps_pbh(A) \
166 ((__m128bh)__builtin_ia32_vcvtneps2bf16128((__v4sf)(A)))
168 /// Convert Packed Single Data to Packed BF16 Data.
170 /// \headerfile <x86intrin.h>
172 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
175 /// A 128-bit vector of [4 x float].
177 /// A 128-bit vector of [8 x bfloat].
179 /// A 4-bit mask value specifying what is chosen for each element.
180 /// A 1 means conversion of __A. A 0 means element from __W.
181 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
182 /// conversion of __A, and higher 64 bits are 0.
183 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
184 _mm_mask_cvtneps_pbh(__m128bh __W
, __mmask8 __U
, __m128 __A
) {
185 return (__m128bh
)__builtin_ia32_cvtneps2bf16_128_mask((__v4sf
) __A
,
190 /// Convert Packed Single Data to Packed BF16 Data.
192 /// \headerfile <x86intrin.h>
194 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
197 /// A 128-bit vector of [4 x float].
199 /// A 4-bit mask value specifying what is chosen for each element.
200 /// A 1 means conversion of __A. A 0 means element is zero.
201 /// \returns A 128-bit vector of [8 x bfloat] whose lower 64 bits come from
202 /// conversion of __A, and higher 64 bits are 0.
203 static __inline__ __m128bh __DEFAULT_FN_ATTRS128
204 _mm_maskz_cvtneps_pbh(__mmask8 __U
, __m128 __A
) {
205 return (__m128bh
)__builtin_ia32_cvtneps2bf16_128_mask((__v4sf
) __A
,
206 (__v8bf
)_mm_setzero_si128(),
210 /// Convert Packed Single Data to Packed BF16 Data.
212 /// \headerfile <x86intrin.h>
214 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
217 /// A 256-bit vector of [8 x float].
218 /// \returns A 128-bit vector of [8 x bfloat] comes from conversion of __A.
219 #define _mm256_cvtneps_pbh(A) \
220 ((__m128bh)__builtin_ia32_vcvtneps2bf16256((__v8sf)(A)))
222 /// Convert Packed Single Data to Packed BF16 Data.
224 /// \headerfile <x86intrin.h>
226 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
229 /// A 256-bit vector of [8 x float].
231 /// A 256-bit vector of [8 x bfloat].
233 /// A 8-bit mask value specifying what is chosen for each element.
234 /// A 1 means conversion of __A. A 0 means element from __W.
235 /// \returns A 128-bit vector of [8 x bfloat] comes from conversion of __A.
236 static __inline__ __m128bh __DEFAULT_FN_ATTRS256
237 _mm256_mask_cvtneps_pbh(__m128bh __W
, __mmask8 __U
, __m256 __A
) {
238 return (__m128bh
)__builtin_ia32_cvtneps2bf16_256_mask((__v8sf
)__A
,
243 /// Convert Packed Single Data to Packed BF16 Data.
245 /// \headerfile <x86intrin.h>
247 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
250 /// A 256-bit vector of [8 x float].
252 /// A 8-bit mask value specifying what is chosen for each element.
253 /// A 1 means conversion of __A. A 0 means element is zero.
254 /// \returns A 128-bit vector of [8 x bfloat] comes from conversion of __A.
255 static __inline__ __m128bh __DEFAULT_FN_ATTRS256
256 _mm256_maskz_cvtneps_pbh(__mmask8 __U
, __m256 __A
) {
257 return (__m128bh
)__builtin_ia32_cvtneps2bf16_256_mask((__v8sf
)__A
,
258 (__v8bf
)_mm_setzero_si128(),
262 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
264 /// \headerfile <x86intrin.h>
266 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
269 /// A 128-bit vector of [8 x bfloat].
271 /// A 128-bit vector of [8 x bfloat].
273 /// A 128-bit vector of [4 x float].
274 /// \returns A 128-bit vector of [4 x float] comes from Dot Product of
276 static __inline__ __m128 __DEFAULT_FN_ATTRS128
277 _mm_dpbf16_ps(__m128 __D
, __m128bh __A
, __m128bh __B
) {
278 return (__m128
)__builtin_ia32_dpbf16ps_128((__v4sf
)__D
,
283 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
285 /// \headerfile <x86intrin.h>
287 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
290 /// A 128-bit vector of [8 x bfloat].
292 /// A 128-bit vector of [8 x bfloat].
294 /// A 128-bit vector of [4 x float].
296 /// A 8-bit mask value specifying what is chosen for each element.
297 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means __D.
298 /// \returns A 128-bit vector of [4 x float] comes from Dot Product of
300 static __inline__ __m128 __DEFAULT_FN_ATTRS128
301 _mm_mask_dpbf16_ps(__m128 __D
, __mmask8 __U
, __m128bh __A
, __m128bh __B
) {
302 return (__m128
)__builtin_ia32_selectps_128((__mmask8
)__U
,
303 (__v4sf
)_mm_dpbf16_ps(__D
, __A
, __B
),
307 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
309 /// \headerfile <x86intrin.h>
311 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
314 /// A 128-bit vector of [8 x bfloat].
316 /// A 128-bit vector of [8 x bfloat].
318 /// A 128-bit vector of [4 x float].
320 /// A 8-bit mask value specifying what is chosen for each element.
321 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means 0.
322 /// \returns A 128-bit vector of [4 x float] comes from Dot Product of
324 static __inline__ __m128 __DEFAULT_FN_ATTRS128
325 _mm_maskz_dpbf16_ps(__mmask8 __U
, __m128 __D
, __m128bh __A
, __m128bh __B
) {
326 return (__m128
)__builtin_ia32_selectps_128((__mmask8
)__U
,
327 (__v4sf
)_mm_dpbf16_ps(__D
, __A
, __B
),
328 (__v4sf
)_mm_setzero_si128());
331 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
333 /// \headerfile <x86intrin.h>
335 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
338 /// A 256-bit vector of [16 x bfloat].
340 /// A 256-bit vector of [16 x bfloat].
342 /// A 256-bit vector of [8 x float].
343 /// \returns A 256-bit vector of [8 x float] comes from Dot Product of
345 static __inline__ __m256 __DEFAULT_FN_ATTRS256
346 _mm256_dpbf16_ps(__m256 __D
, __m256bh __A
, __m256bh __B
) {
347 return (__m256
)__builtin_ia32_dpbf16ps_256((__v8sf
)__D
,
352 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
354 /// \headerfile <x86intrin.h>
356 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
359 /// A 256-bit vector of [16 x bfloat].
361 /// A 256-bit vector of [16 x bfloat].
363 /// A 256-bit vector of [8 x float].
365 /// A 16-bit mask value specifying what is chosen for each element.
366 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means __D.
367 /// \returns A 256-bit vector of [8 x float] comes from Dot Product of
369 static __inline__ __m256 __DEFAULT_FN_ATTRS256
370 _mm256_mask_dpbf16_ps(__m256 __D
, __mmask8 __U
, __m256bh __A
, __m256bh __B
) {
371 return (__m256
)__builtin_ia32_selectps_256((__mmask8
)__U
,
372 (__v8sf
)_mm256_dpbf16_ps(__D
, __A
, __B
),
376 /// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.
378 /// \headerfile <x86intrin.h>
380 /// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.
383 /// A 256-bit vector of [16 x bfloat].
385 /// A 256-bit vector of [16 x bfloat].
387 /// A 256-bit vector of [8 x float].
389 /// A 8-bit mask value specifying what is chosen for each element.
390 /// A 1 means __A and __B's dot product accumulated with __D. A 0 means 0.
391 /// \returns A 256-bit vector of [8 x float] comes from Dot Product of
393 static __inline__ __m256 __DEFAULT_FN_ATTRS256
394 _mm256_maskz_dpbf16_ps(__mmask8 __U
, __m256 __D
, __m256bh __A
, __m256bh __B
) {
395 return (__m256
)__builtin_ia32_selectps_256((__mmask8
)__U
,
396 (__v8sf
)_mm256_dpbf16_ps(__D
, __A
, __B
),
397 (__v8sf
)_mm256_setzero_si256());
400 /// Convert One Single float Data to One BF16 Data.
402 /// \headerfile <x86intrin.h>
404 /// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.
408 /// \returns A bf16 data whose sign field and exponent field keep unchanged,
409 /// and fraction field is truncated to 7 bits.
410 static __inline__ __bf16 __DEFAULT_FN_ATTRS128
_mm_cvtness_sbh(float __A
) {
411 __v4sf __V
= {__A
, 0, 0, 0};
412 __v8bf __R
= __builtin_ia32_cvtneps2bf16_128_mask(
413 (__v4sf
)__V
, (__v8bf
)_mm_undefined_si128(), (__mmask8
)-1);
414 return (__bf16
)__R
[0];
417 /// Convert Packed BF16 Data to Packed float Data.
419 /// \headerfile <x86intrin.h>
422 /// A 128-bit vector of [4 x bfloat].
423 /// \returns A 128-bit vector of [4 x float] come from conversion of __A
424 static __inline__ __m128 __DEFAULT_FN_ATTRS128
_mm_cvtpbh_ps(__m128bh __A
) {
425 return _mm_castsi128_ps(
426 (__m128i
)_mm_slli_epi32((__m128i
)_mm_cvtepi16_epi32((__m128i
)__A
), 16));
429 /// Convert Packed BF16 Data to Packed float Data.
431 /// \headerfile <x86intrin.h>
434 /// A 128-bit vector of [8 x bfloat].
435 /// \returns A 256-bit vector of [8 x float] come from conversion of __A
436 static __inline__ __m256 __DEFAULT_FN_ATTRS256
_mm256_cvtpbh_ps(__m128bh __A
) {
437 return _mm256_castsi256_ps((__m256i
)_mm256_slli_epi32(
438 (__m256i
)_mm256_cvtepi16_epi32((__m128i
)__A
), 16));
441 /// Convert Packed BF16 Data to Packed float Data using zeroing mask.
443 /// \headerfile <x86intrin.h>
446 /// A 4-bit mask. Elements are zeroed out when the corresponding mask
449 /// A 128-bit vector of [4 x bfloat].
450 /// \returns A 128-bit vector of [4 x float] come from conversion of __A
451 static __inline__ __m128 __DEFAULT_FN_ATTRS128
452 _mm_maskz_cvtpbh_ps(__mmask8 __U
, __m128bh __A
) {
453 return _mm_castsi128_ps((__m128i
)_mm_slli_epi32(
454 (__m128i
)_mm_maskz_cvtepi16_epi32((__mmask8
)__U
, (__m128i
)__A
), 16));
457 /// Convert Packed BF16 Data to Packed float Data using zeroing mask.
459 /// \headerfile <x86intrin.h>
462 /// A 8-bit mask. Elements are zeroed out when the corresponding mask
465 /// A 128-bit vector of [8 x bfloat].
466 /// \returns A 256-bit vector of [8 x float] come from conversion of __A
467 static __inline__ __m256 __DEFAULT_FN_ATTRS256
468 _mm256_maskz_cvtpbh_ps(__mmask8 __U
, __m128bh __A
) {
469 return _mm256_castsi256_ps((__m256i
)_mm256_slli_epi32(
470 (__m256i
)_mm256_maskz_cvtepi16_epi32((__mmask8
)__U
, (__m128i
)__A
), 16));
473 /// Convert Packed BF16 Data to Packed float Data using merging mask.
475 /// \headerfile <x86intrin.h>
478 /// A 128-bit vector of [4 x float]. Elements are copied from __S when
479 /// the corresponding mask bit is not set.
481 /// A 4-bit mask. Elements are zeroed out when the corresponding mask
484 /// A 128-bit vector of [4 x bfloat].
485 /// \returns A 128-bit vector of [4 x float] come from conversion of __A
486 static __inline__ __m128 __DEFAULT_FN_ATTRS128
487 _mm_mask_cvtpbh_ps(__m128 __S
, __mmask8 __U
, __m128bh __A
) {
488 return _mm_castsi128_ps((__m128i
)_mm_mask_slli_epi32(
489 (__m128i
)__S
, (__mmask8
)__U
, (__m128i
)_mm_cvtepi16_epi32((__m128i
)__A
),
493 /// Convert Packed BF16 Data to Packed float Data using merging mask.
495 /// \headerfile <x86intrin.h>
498 /// A 256-bit vector of [8 x float]. Elements are copied from __S when
499 /// the corresponding mask bit is not set.
501 /// A 8-bit mask. Elements are zeroed out when the corresponding mask
504 /// A 128-bit vector of [8 x bfloat].
505 /// \returns A 256-bit vector of [8 x float] come from conversion of __A
506 static __inline__ __m256 __DEFAULT_FN_ATTRS256
507 _mm256_mask_cvtpbh_ps(__m256 __S
, __mmask8 __U
, __m128bh __A
) {
508 return _mm256_castsi256_ps((__m256i
)_mm256_mask_slli_epi32(
509 (__m256i
)__S
, (__mmask8
)__U
, (__m256i
)_mm256_cvtepi16_epi32((__m128i
)__A
),
513 #undef __DEFAULT_FN_ATTRS128
514 #undef __DEFAULT_FN_ATTRS256