Path: blob/main/contrib/llvm-project/clang/lib/Headers/avx512bf16intrin.h
35233 views
/*===------------ avx512bf16intrin.h - AVX512_BF16 intrinsics --------------===1*2* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3* See https://llvm.org/LICENSE.txt for license information.4* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5*6*===-----------------------------------------------------------------------===7*/8#ifndef __IMMINTRIN_H9#error "Never use <avx512bf16intrin.h> directly; include <immintrin.h> instead."10#endif1112#ifdef __SSE2__1314#ifndef __AVX512BF16INTRIN_H15#define __AVX512BF16INTRIN_H1617typedef __bf16 __v32bf __attribute__((__vector_size__(64), __aligned__(64)));18typedef __bf16 __m512bh __attribute__((__vector_size__(64), __aligned__(64)));19typedef __bf16 __bfloat16 __attribute__((deprecated("use __bf16 instead")));2021#define __DEFAULT_FN_ATTRS512 \22__attribute__((__always_inline__, __nodebug__, __target__("avx512bf16,evex512"), \23__min_vector_width__(512)))24#define __DEFAULT_FN_ATTRS \25__attribute__((__always_inline__, __nodebug__, \26__target__("avx512bf16,no-evex512")))2728/// Convert One BF16 Data to One Single Float Data.29///30/// \headerfile <x86intrin.h>31///32/// This intrinsic does not correspond to a specific instruction.33///34/// \param __A35/// A bfloat data.36/// \returns A float data whose sign field and exponent field keep unchanged,37/// and fraction field is extended to 23 bits.38static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtsbh_ss(__bf16 __A) {39return __builtin_ia32_cvtsbf162ss_32(__A);40}4142/// Convert Two Packed Single Data to One Packed BF16 Data.43///44/// \headerfile <x86intrin.h>45///46/// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.47///48/// \param __A49/// A 512-bit vector of [16 x float].50/// \param __B51/// A 512-bit vector of [16 x float].52/// \returns A 512-bit vector of [32 x bfloat] whose lower 256 bits come from53/// conversion of __B, and higher 256 bits come from conversion of __A.54static __inline__ __m512bh __DEFAULT_FN_ATTRS51255_mm512_cvtne2ps_pbh(__m512 __A, __m512 __B) {56return (__m512bh)__builtin_ia32_cvtne2ps2bf16_512((__v16sf) __A,57(__v16sf) __B);58}5960/// Convert Two Packed Single Data to One Packed BF16 Data.61///62/// \headerfile <x86intrin.h>63///64/// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.65///66/// \param __A67/// A 512-bit vector of [16 x float].68/// \param __B69/// A 512-bit vector of [16 x float].70/// \param __W71/// A 512-bit vector of [32 x bfloat].72/// \param __U73/// A 32-bit mask value specifying what is chosen for each element.74/// A 1 means conversion of __A or __B. A 0 means element from __W.75/// \returns A 512-bit vector of [32 x bfloat] whose lower 256 bits come from76/// conversion of __B, and higher 256 bits come from conversion of __A.77static __inline__ __m512bh __DEFAULT_FN_ATTRS51278_mm512_mask_cvtne2ps_pbh(__m512bh __W, __mmask32 __U, __m512 __A, __m512 __B) {79return (__m512bh)__builtin_ia32_selectpbf_512((__mmask32)__U,80(__v32bf)_mm512_cvtne2ps_pbh(__A, __B),81(__v32bf)__W);82}8384/// Convert Two Packed Single Data to One Packed BF16 Data.85///86/// \headerfile <x86intrin.h>87///88/// This intrinsic corresponds to the <c> VCVTNE2PS2BF16 </c> instructions.89///90/// \param __A91/// A 512-bit vector of [16 x float].92/// \param __B93/// A 512-bit vector of [16 x float].94/// \param __U95/// A 32-bit mask value specifying what is chosen for each element.96/// A 1 means conversion of __A or __B. A 0 means element is zero.97/// \returns A 512-bit vector of [32 x bfloat] whose lower 256 bits come from98/// conversion of __B, and higher 256 bits come from conversion of __A.99static __inline__ __m512bh __DEFAULT_FN_ATTRS512100_mm512_maskz_cvtne2ps_pbh(__mmask32 __U, __m512 __A, __m512 __B) {101return (__m512bh)__builtin_ia32_selectpbf_512((__mmask32)__U,102(__v32bf)_mm512_cvtne2ps_pbh(__A, __B),103(__v32bf)_mm512_setzero_si512());104}105106/// Convert Packed Single Data to Packed BF16 Data.107///108/// \headerfile <x86intrin.h>109///110/// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.111///112/// \param __A113/// A 512-bit vector of [16 x float].114/// \returns A 256-bit vector of [16 x bfloat] come from conversion of __A.115static __inline__ __m256bh __DEFAULT_FN_ATTRS512116_mm512_cvtneps_pbh(__m512 __A) {117return (__m256bh)__builtin_ia32_cvtneps2bf16_512_mask((__v16sf)__A,118(__v16bf)_mm256_undefined_si256(),119(__mmask16)-1);120}121122/// Convert Packed Single Data to Packed BF16 Data.123///124/// \headerfile <x86intrin.h>125///126/// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.127///128/// \param __A129/// A 512-bit vector of [16 x float].130/// \param __W131/// A 256-bit vector of [16 x bfloat].132/// \param __U133/// A 16-bit mask value specifying what is chosen for each element.134/// A 1 means conversion of __A. A 0 means element from __W.135/// \returns A 256-bit vector of [16 x bfloat] come from conversion of __A.136static __inline__ __m256bh __DEFAULT_FN_ATTRS512137_mm512_mask_cvtneps_pbh(__m256bh __W, __mmask16 __U, __m512 __A) {138return (__m256bh)__builtin_ia32_cvtneps2bf16_512_mask((__v16sf)__A,139(__v16bf)__W,140(__mmask16)__U);141}142143/// Convert Packed Single Data to Packed BF16 Data.144///145/// \headerfile <x86intrin.h>146///147/// This intrinsic corresponds to the <c> VCVTNEPS2BF16 </c> instructions.148///149/// \param __A150/// A 512-bit vector of [16 x float].151/// \param __U152/// A 16-bit mask value specifying what is chosen for each element.153/// A 1 means conversion of __A. A 0 means element is zero.154/// \returns A 256-bit vector of [16 x bfloat] come from conversion of __A.155static __inline__ __m256bh __DEFAULT_FN_ATTRS512156_mm512_maskz_cvtneps_pbh(__mmask16 __U, __m512 __A) {157return (__m256bh)__builtin_ia32_cvtneps2bf16_512_mask((__v16sf)__A,158(__v16bf)_mm256_setzero_si256(),159(__mmask16)__U);160}161162/// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.163///164/// \headerfile <x86intrin.h>165///166/// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.167///168/// \param __A169/// A 512-bit vector of [32 x bfloat].170/// \param __B171/// A 512-bit vector of [32 x bfloat].172/// \param __D173/// A 512-bit vector of [16 x float].174/// \returns A 512-bit vector of [16 x float] comes from Dot Product of175/// __A, __B and __D176static __inline__ __m512 __DEFAULT_FN_ATTRS512177_mm512_dpbf16_ps(__m512 __D, __m512bh __A, __m512bh __B) {178return (__m512)__builtin_ia32_dpbf16ps_512((__v16sf) __D,179(__v32bf) __A,180(__v32bf) __B);181}182183/// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.184///185/// \headerfile <x86intrin.h>186///187/// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.188///189/// \param __A190/// A 512-bit vector of [32 x bfloat].191/// \param __B192/// A 512-bit vector of [32 x bfloat].193/// \param __D194/// A 512-bit vector of [16 x float].195/// \param __U196/// A 16-bit mask value specifying what is chosen for each element.197/// A 1 means __A and __B's dot product accumulated with __D. A 0 means __D.198/// \returns A 512-bit vector of [16 x float] comes from Dot Product of199/// __A, __B and __D200static __inline__ __m512 __DEFAULT_FN_ATTRS512201_mm512_mask_dpbf16_ps(__m512 __D, __mmask16 __U, __m512bh __A, __m512bh __B) {202return (__m512)__builtin_ia32_selectps_512((__mmask16)__U,203(__v16sf)_mm512_dpbf16_ps(__D, __A, __B),204(__v16sf)__D);205}206207/// Dot Product of BF16 Pairs Accumulated into Packed Single Precision.208///209/// \headerfile <x86intrin.h>210///211/// This intrinsic corresponds to the <c> VDPBF16PS </c> instructions.212///213/// \param __A214/// A 512-bit vector of [32 x bfloat].215/// \param __B216/// A 512-bit vector of [32 x bfloat].217/// \param __D218/// A 512-bit vector of [16 x float].219/// \param __U220/// A 16-bit mask value specifying what is chosen for each element.221/// A 1 means __A and __B's dot product accumulated with __D. A 0 means 0.222/// \returns A 512-bit vector of [16 x float] comes from Dot Product of223/// __A, __B and __D224static __inline__ __m512 __DEFAULT_FN_ATTRS512225_mm512_maskz_dpbf16_ps(__mmask16 __U, __m512 __D, __m512bh __A, __m512bh __B) {226return (__m512)__builtin_ia32_selectps_512((__mmask16)__U,227(__v16sf)_mm512_dpbf16_ps(__D, __A, __B),228(__v16sf)_mm512_setzero_si512());229}230231/// Convert Packed BF16 Data to Packed float Data.232///233/// \headerfile <x86intrin.h>234///235/// \param __A236/// A 256-bit vector of [16 x bfloat].237/// \returns A 512-bit vector of [16 x float] come from conversion of __A238static __inline__ __m512 __DEFAULT_FN_ATTRS512 _mm512_cvtpbh_ps(__m256bh __A) {239return _mm512_castsi512_ps((__m512i)_mm512_slli_epi32(240(__m512i)_mm512_cvtepi16_epi32((__m256i)__A), 16));241}242243/// Convert Packed BF16 Data to Packed float Data using zeroing mask.244///245/// \headerfile <x86intrin.h>246///247/// \param __U248/// A 16-bit mask. Elements are zeroed out when the corresponding mask249/// bit is not set.250/// \param __A251/// A 256-bit vector of [16 x bfloat].252/// \returns A 512-bit vector of [16 x float] come from conversion of __A253static __inline__ __m512 __DEFAULT_FN_ATTRS512254_mm512_maskz_cvtpbh_ps(__mmask16 __U, __m256bh __A) {255return _mm512_castsi512_ps((__m512i)_mm512_slli_epi32(256(__m512i)_mm512_maskz_cvtepi16_epi32((__mmask16)__U, (__m256i)__A), 16));257}258259/// Convert Packed BF16 Data to Packed float Data using merging mask.260///261/// \headerfile <x86intrin.h>262///263/// \param __S264/// A 512-bit vector of [16 x float]. Elements are copied from __S when265/// the corresponding mask bit is not set.266/// \param __U267/// A 16-bit mask.268/// \param __A269/// A 256-bit vector of [16 x bfloat].270/// \returns A 512-bit vector of [16 x float] come from conversion of __A271static __inline__ __m512 __DEFAULT_FN_ATTRS512272_mm512_mask_cvtpbh_ps(__m512 __S, __mmask16 __U, __m256bh __A) {273return _mm512_castsi512_ps((__m512i)_mm512_mask_slli_epi32(274(__m512i)__S, (__mmask16)__U,275(__m512i)_mm512_cvtepi16_epi32((__m256i)__A), 16));276}277278#undef __DEFAULT_FN_ATTRS279#undef __DEFAULT_FN_ATTRS512280281#endif282#endif283284285