Debian Codegraph @

gcc/config/i386/avx512bf16vlintrin.h

raw
1 /* Copyright (C) 2019-2025 Free Software Foundation, Inc.
2
3 This file is part of GCC.
4
5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
8 any later version.
9
10 GCC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
18
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
23
24 #ifndef _IMMINTRIN_H_INCLUDED
25 #error "Never use <avx512bf16vlintrin.h> directly; include <immintrin.h> instead."
26 #endif
27
28 #ifndef _AVX512BF16VLINTRIN_H_INCLUDED
29 #define _AVX512BF16VLINTRIN_H_INCLUDED
30
31 #if !defined(__AVX512VL__) || !defined(__AVX512BF16__) || defined (__EVEX512__)
32 #pragma GCC push_options
33 #pragma GCC target("avx512bf16,avx512vl,no-evex512")
34 #define __DISABLE_AVX512BF16VL__
35 #endif /* __AVX512BF16__ */
36
37 /* Internal data types for implementing the intrinsics. */
38 typedef __bf16 __v16bf __attribute__ ((__vector_size__ (32)));
39 typedef __bf16 __v8bf __attribute__ ((__vector_size__ (16)));
40
41 /* The Intel API is flexible enough that we must allow aliasing with other
42 vector types, and their scalar components. */
43 typedef __bf16 __m256bh __attribute__ ((__vector_size__ (32), __may_alias__));
44 typedef __bf16 __m128bh __attribute__ ((__vector_size__ (16), __may_alias__));
45
46 typedef __bf16 __bfloat16;
47
48 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
49 _mm_avx512_castsi128_ps(__m128i __A)
50 {
51 return (__m128) __A;
52 }
53
54 extern __inline __m256 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
55 _mm256_avx512_castsi256_ps (__m256i __A)
56 {
57 return (__m256) __A;
58 }
59
60 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
61 _mm_avx512_slli_epi32 (__m128i __A, int __B)
62 {
63 return (__m128i)__builtin_ia32_pslldi128 ((__v4si)__A, __B);
64 }
65
66 extern __inline __m256i
67 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
68 _mm256_avx512_slli_epi32 (__m256i __A, int __B)
69 {
70 return (__m256i)__builtin_ia32_pslldi256 ((__v8si)__A, __B);
71 }
72
73 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
74 _mm_avx512_cvtepi16_epi32 (__m128i __X)
75 {
76 return (__m128i) __builtin_ia32_pmovsxwd128 ((__v8hi)__X);
77 }
78
79 extern __inline __m256i
80 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
81 _mm256_avx512_cvtepi16_epi32 (__m128i __X)
82 {
83 return (__m256i) __builtin_ia32_pmovsxwd256 ((__v8hi)__X);
84 }
85
86 #define _mm256_cvtneps_pbh(A) \
87 (__m128bh) __builtin_ia32_cvtneps2bf16_v8sf (A)
88 #define _mm_cvtneps_pbh(A) \
89 (__m128bh) __builtin_ia32_cvtneps2bf16_v4sf (A)
90
91 /* vcvtne2ps2bf16 */
92
93 extern __inline __m256bh
94 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
95 _mm256_cvtne2ps_pbh (__m256 __A, __m256 __B)
96 {
97 return (__m256bh)__builtin_ia32_cvtne2ps2bf16_v16bf(__A, __B);
98 }
99
100 extern __inline __m256bh
101 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
102 _mm256_mask_cvtne2ps_pbh (__m256bh __A, __mmask16 __B, __m256 __C, __m256 __D)
103 {
104 return (__m256bh)__builtin_ia32_cvtne2ps2bf16_v16bf_mask(__C, __D, __A, __B);
105 }
106
107 extern __inline __m256bh
108 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
109 _mm256_maskz_cvtne2ps_pbh (__mmask16 __A, __m256 __B, __m256 __C)
110 {
111 return (__m256bh)__builtin_ia32_cvtne2ps2bf16_v16bf_maskz(__B, __C, __A);
112 }
113
114 extern __inline __m128bh
115 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
116 _mm_cvtne2ps_pbh (__m128 __A, __m128 __B)
117 {
118 return (__m128bh)__builtin_ia32_cvtne2ps2bf16_v8bf(__A, __B);
119 }
120
121 extern __inline __m128bh
122 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
123 _mm_mask_cvtne2ps_pbh (__m128bh __A, __mmask8 __B, __m128 __C, __m128 __D)
124 {
125 return (__m128bh)__builtin_ia32_cvtne2ps2bf16_v8bf_mask(__C, __D, __A, __B);
126 }
127
128 extern __inline __m128bh
129 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
130 _mm_maskz_cvtne2ps_pbh (__mmask8 __A, __m128 __B, __m128 __C)
131 {
132 return (__m128bh)__builtin_ia32_cvtne2ps2bf16_v8bf_maskz(__B, __C, __A);
133 }
134
135 /* vcvtneps2bf16 */
136
137 extern __inline __m128bh
138 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
139 _mm256_mask_cvtneps_pbh (__m128bh __A, __mmask8 __B, __m256 __C)
140 {
141 return (__m128bh)__builtin_ia32_cvtneps2bf16_v8sf_mask(__C, __A, __B);
142 }
143
144 extern __inline __m128bh
145 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
146 _mm256_maskz_cvtneps_pbh (__mmask8 __A, __m256 __B)
147 {
148 return (__m128bh)__builtin_ia32_cvtneps2bf16_v8sf_maskz(__B, __A);
149 }
150
151 extern __inline __m128bh
152 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
153 _mm_mask_cvtneps_pbh (__m128bh __A, __mmask8 __B, __m128 __C)
154 {
155 return (__m128bh)__builtin_ia32_cvtneps2bf16_v4sf_mask(__C, __A, __B);
156 }
157
158 extern __inline __m128bh
159 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
160 _mm_maskz_cvtneps_pbh (__mmask8 __A, __m128 __B)
161 {
162 return (__m128bh)__builtin_ia32_cvtneps2bf16_v4sf_maskz(__B, __A);
163 }
164
165 /* vdpbf16ps */
166
167 extern __inline __m256
168 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
169 _mm256_dpbf16_ps (__m256 __A, __m256bh __B, __m256bh __C)
170 {
171 return (__m256)__builtin_ia32_dpbf16ps_v8sf(__A, __B, __C);
172 }
173
174 extern __inline __m256
175 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
176 _mm256_mask_dpbf16_ps (__m256 __A, __mmask8 __B, __m256bh __C, __m256bh __D)
177 {
178 return (__m256)__builtin_ia32_dpbf16ps_v8sf_mask(__A, __C, __D, __B);
179 }
180
181 extern __inline __m256
182 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
183 _mm256_maskz_dpbf16_ps (__mmask8 __A, __m256 __B, __m256bh __C, __m256bh __D)
184 {
185 return (__m256)__builtin_ia32_dpbf16ps_v8sf_maskz(__B, __C, __D, __A);
186 }
187
188 extern __inline __m128
189 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
190 _mm_dpbf16_ps (__m128 __A, __m128bh __B, __m128bh __C)
191 {
192 return (__m128)__builtin_ia32_dpbf16ps_v4sf(__A, __B, __C);
193 }
194
195 extern __inline __m128
196 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
197 _mm_mask_dpbf16_ps (__m128 __A, __mmask8 __B, __m128bh __C, __m128bh __D)
198 {
199 return (__m128)__builtin_ia32_dpbf16ps_v4sf_mask(__A, __C, __D, __B);
200 }
201
202 extern __inline __m128
203 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
204 _mm_maskz_dpbf16_ps (__mmask8 __A, __m128 __B, __m128bh __C, __m128bh __D)
205 {
206 return (__m128)__builtin_ia32_dpbf16ps_v4sf_maskz(__B, __C, __D, __A);
207 }
208
209 extern __inline __bf16
210 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
211 _mm_cvtness_sbh (float __A)
212 {
213 __v4sf __V = {__A, 0, 0, 0};
214 __v8bf __R = __builtin_ia32_cvtneps2bf16_v4sf_mask ((__v4sf)__V,
215 (__v8bf)_mm_avx512_undefined_si128 (), (__mmask8)-1);
216 return __R[0];
217 }
218
219 extern __inline __m128
220 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
221 _mm_cvtpbh_ps (__m128bh __A)
222 {
223 return (__m128)_mm_avx512_castsi128_ps ((__m128i)_mm_avx512_slli_epi32 (
224 (__m128i)_mm_avx512_cvtepi16_epi32 ((__m128i)__A), 16));
225 }
226
227 extern __inline __m256
228 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
229 _mm256_cvtpbh_ps (__m128bh __A)
230 {
231 return (__m256)_mm256_avx512_castsi256_ps ((__m256i)_mm256_avx512_slli_epi32 (
232 (__m256i)_mm256_avx512_cvtepi16_epi32 ((__m128i)__A), 16));
233 }
234
235 extern __inline __m128
236 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
237 _mm_maskz_cvtpbh_ps (__mmask8 __U, __m128bh __A)
238 {
239 return (__m128)_mm_avx512_castsi128_ps ((__m128i)_mm_avx512_slli_epi32 (
240 (__m128i)_mm_maskz_cvtepi16_epi32 (
241 (__mmask8)__U, (__m128i)__A), 16));
242 }
243
244 extern __inline __m256
245 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
246 _mm256_maskz_cvtpbh_ps (__mmask8 __U, __m128bh __A)
247 {
248 return (__m256)_mm256_avx512_castsi256_ps ((__m256i)_mm256_avx512_slli_epi32 (
249 (__m256i)_mm256_maskz_cvtepi16_epi32 (
250 (__mmask8)__U, (__m128i)__A), 16));
251 }
252
253 extern __inline __m128
254 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
255 _mm_mask_cvtpbh_ps (__m128 __S, __mmask8 __U, __m128bh __A)
256 {
257 return (__m128)_mm_avx512_castsi128_ps ((__m128i)_mm_mask_slli_epi32 (
258 (__m128i)__S, (__mmask8)__U, (__m128i)_mm_avx512_cvtepi16_epi32 (
259 (__m128i)__A), 16));
260 }
261
262 extern __inline __m256
263 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
264 _mm256_mask_cvtpbh_ps (__m256 __S, __mmask8 __U, __m128bh __A)
265 {
266 return (__m256)_mm256_avx512_castsi256_ps ((__m256i)_mm256_mask_slli_epi32 (
267 (__m256i)__S, (__mmask8)__U, (__m256i)_mm256_avx512_cvtepi16_epi32 (
268 (__m128i)__A), 16));
269 }
270
271 #ifdef __DISABLE_AVX512BF16VL__
272 #undef __DISABLE_AVX512BF16VL__
273 #pragma GCC pop_options
274 #endif /* __DISABLE_AVX512BF16VL__ */
275
276 #endif /* _AVX512BF16VLINTRIN_H_INCLUDED */