clang 24.0.0git
acev1intrin.h
Go to the documentation of this file.
1/*===-------------- acev1intrin.h - ACEV1 intrinsics -*- C/C++ -*------------===
2 *
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
6 *
7 *===------------------------------------------------------------------------===
8 */
9
10#ifndef __IMMINTRIN_H
11#error "Never use <acev1intrin.h> directly; include <immintrin.h> instead."
12#endif /* __IMMINTRIN_H */
13
14#ifndef __ACEV1INTRIN_H
15#define __ACEV1INTRIN_H
16#if defined(__x86_64__) && defined(__SSE2__)
17
18/* Define the default attributes for the functions in this file. */
19#define __DEFAULT_FN_ATTRS_ACE \
20 __attribute__((__always_inline__, __nodebug__, __target__("acev1")))
21
22// clang-format off
23
24/// Load tile configuration from a 64-byte memory location. For ACE
25/// (Palette 2), the palette_id byte must be 2. Unlike AMX (Palette 1),
26/// ACE tiles have fixed dimensions of 16 rows x 64 bytes, so per-tile
27/// row/column configuration bytes are ignored. If palette_id is zero,
28/// tiles return to init state and are zeroed. Invalid configurations
29/// result in #GP fault.
30///
31/// \headerfile <immintrin.h>
32///
33/// This intrinsic corresponds to the <c> LDTILECFG </c> instruction.
34///
35/// \param __config
36/// A pointer to 64-byte tile configuration (use __ace_tile_config).
37static __inline__ void __DEFAULT_FN_ATTRS_ACE
38_tile_ace_loadconfig(const void *__config) {
39 __builtin_ia32_tile_loadconfig(__config);
40}
41
42/// Store the current tile configuration to a 64-byte memory location.
43/// For ACE (Palette 2), the stored palette_id will be 2 and per-tile
44/// configuration bytes reflect the fixed 16x64 dimensions. If tiles
45/// are not configured, all zeroes are stored.
46///
47/// \headerfile <immintrin.h>
48///
49/// This intrinsic corresponds to the <c> STTILECFG </c> instruction.
50///
51/// \param __config
52/// A pointer to 64-byte tile configuration buffer.
53static __inline__ void __DEFAULT_FN_ATTRS_ACE
54_tile_ace_storeconfig(void *__config) {
55 __builtin_ia32_tile_storeconfig(__config);
56}
57
58/// Release the tile configuration to return to init state, releasing
59/// all tile storage. After this, tiles must be reconfigured with
60/// _tile_ace_loadconfig before use.
61///
62/// \headerfile <immintrin.h>
63///
64/// This intrinsic corresponds to the <c> TILERELEASE </c> instruction.
65static __inline__ void __DEFAULT_FN_ATTRS_ACE
66_tile_ace_release(void) {
67 __builtin_ia32_tilerelease();
68}
69
70/// Zero the ACE tile specified by "tile". Sets all 1024 bytes
71/// (16 rows x 64 bytes) of the tile register to zero.
72///
73/// \headerfile <immintrin.h>
74///
75/// This intrinsic corresponds to the <c> TILEZERO </c> instruction.
76///
77/// \param tile
78/// Destination tile register ID (0-7).
79#define _tile_ace_zero(tile) __builtin_ia32_acev1_tilezero((tile))
80
81/// Move a 64-byte ZMM vector to a tile column. The 16 doublewords from
82/// the ZMM are written as a vertical column in the tile at the specified
83/// index.
84///
85/// \headerfile <immintrin.h>
86///
87/// This intrinsic corresponds to the <c> TILEMOVCOL </c> instruction.
88///
89/// \param dst
90/// Destination tile register ID (0-7).
91/// \param src
92/// Source ZMM vector (__m512i) containing 16 doublewords.
93/// \param idx
94/// Column index (0-15). Immediate or register form selected automatically.
95#define _tile_insertcol(dst, src, idx) \
96 __builtin_ia32_tilemovcolinsert((dst), (__v16si)(src), (idx))
97
98/// Move a 64-byte ZMM vector to a tile row. The ZMM contents are written
99/// as a horizontal row in the tile at the specified index.
100///
101/// \headerfile <immintrin.h>
102///
103/// This intrinsic corresponds to the <c> TILEMOVROW </c> instruction.
104///
105/// \param dst
106/// Destination tile register ID (0-7).
107/// \param src
108/// Source ZMM vector (__m512i) containing 16 doublewords.
109/// \param idx
110/// Row index (0-15). Immediate or register form selected automatically.
111#define _tile_insertrow(dst, src, idx) \
112 __builtin_ia32_tilemovrowinsert((dst), (__v16si)(src), (idx))
113
114/// Initialize the Block Scale Register (BSR), setting all 128 scale bytes to
115/// 0x7F (the E8M0 encoding of 1.0), the same state LDTILECFG leaves it in.
116/// The BSR holds the scale factors used by the mixed-precision outer product
117/// instructions (TOP4MX* variants).
118///
119/// \headerfile <immintrin.h>
120///
121/// This intrinsic corresponds to the <c> BSRINIT </c> instruction.
122static __inline__ void __DEFAULT_FN_ATTRS_ACE
123_bsr0_init(void) {
124 __builtin_ia32_bsr0init();
125}
126
127/// Load the full BSR (128 scale bytes) from two ZMM registers. The high half
128/// (A scales) comes from __src1 and the low half (B scales) from __src2.
129///
130/// \headerfile <immintrin.h>
131///
132/// This intrinsic corresponds to the <c> BSRMOVF </c> instruction.
133///
134/// \param __src1
135/// ZMM with the 64 A-operand scale bytes for the BSR high half.
136/// \param __src2
137/// ZMM with the 64 B-operand scale bytes for the BSR low half.
138static __inline__ void __DEFAULT_FN_ATTRS_ACE
139_bsr0_insertfull(__m512i __src1, __m512i __src2) {
140 __builtin_ia32_bsr0movf((__v64qi)__src1, (__v64qi)__src2);
141}
142
143/// Load the high half of BSR (64 A-operand scale bytes) from a ZMM register.
144///
145/// \headerfile <immintrin.h>
146///
147/// This intrinsic corresponds to the <c> BSRMOVH </c> instruction.
148///
149/// \param __src
150/// ZMM with 64 scale bytes to write to the BSR high half.
151static __inline__ void __DEFAULT_FN_ATTRS_ACE
152_bsr0_inserth(__m512i __src) {
153 __builtin_ia32_bsr0movhinsert((__v64qi)__src);
154}
155
156/// Read the high half of BSR (64 A-operand scale bytes) to a ZMM register.
157///
158/// \headerfile <immintrin.h>
159///
160/// This intrinsic corresponds to the <c> BSRMOVH </c> instruction.
161///
162/// \returns
163/// ZMM containing the 64 scale bytes from the BSR high half.
164static __inline__ __m512i __DEFAULT_FN_ATTRS_ACE
165_bsr0_extracth(void) {
166 return (__m512i)__builtin_ia32_bsr0movhextract();
167}
168
169/// Load the low half of BSR (64 B-operand scale bytes) from a ZMM register.
170///
171/// \headerfile <immintrin.h>
172///
173/// This intrinsic corresponds to the <c> BSRMOVL </c> instruction.
174///
175/// \param __src
176/// ZMM with 64 scale bytes to write to the BSR low half.
177static __inline__ void __DEFAULT_FN_ATTRS_ACE
178_bsr0_insertl(__m512i __src) {
179 __builtin_ia32_bsr0movlinsert((__v64qi)__src);
180}
181
182/// Read the low half of BSR (64 B-operand scale bytes) to a ZMM register.
183///
184/// \headerfile <immintrin.h>
185///
186/// This intrinsic corresponds to the <c> BSRMOVL </c> instruction.
187///
188/// \returns
189/// ZMM containing the 64 scale bytes from the BSR low half.
190static __inline__ __m512i __DEFAULT_FN_ATTRS_ACE
191_bsr0_extractl(void) {
192 return (__m512i)__builtin_ia32_bsr0movlextract();
193}
194
195/// Compute 2-way outer product of BF16 pairs, accumulating to FP32.
196/// Each BF16 pair from src1 and src2 produces two FP32 products that
197/// are accumulated into the destination tile.
198///
199/// \headerfile <immintrin.h>
200///
201/// This intrinsic corresponds to the <c> TOP2BF16PS </c> instruction.
202///
203/// \param dst
204/// Destination/accumulator tile register ID (0-7).
205/// \param src1
206/// First source ZMM vector (__m512bh) containing 32 BF16 values.
207/// \param src2
208/// Second source ZMM vector (__m512bh) containing 32 BF16 values.
209#define _tile_op2bf16_ps(dst, src1, src2) \
210 __builtin_ia32_top2bf16ps((dst), (__v32bf)(src1), (__v32bf)(src2))
211
212/// Compute 4-way outer product of unsigned x unsigned bytes to INT32.
213/// Each group of 4 unsigned byte pairs from src1 and src2 produces
214/// 4 products accumulated into the destination tile as 32-bit integers.
215///
216/// \headerfile <immintrin.h>
217///
218/// This intrinsic corresponds to the <c> TOP4BUUD </c> instruction.
219///
220/// \param dst
221/// Destination/accumulator tile register ID (0-7).
222/// \param src1
223/// First source ZMM vector (__m512i) containing 64 unsigned bytes.
224/// \param src2
225/// Second source ZMM vector (__m512i) containing 64 unsigned bytes.
226#define _tile_op4buud_epi32(dst, src1, src2) \
227 __builtin_ia32_top4buud((dst), (__v64qi)(src1), (__v64qi)(src2))
228
229/// Compute 4-way outer product of unsigned x signed bytes to INT32.
230/// Each group of 4 byte pairs (unsigned from src1, signed from src2)
231/// produces 4 products accumulated into the destination tile.
232///
233/// \headerfile <immintrin.h>
234///
235/// This intrinsic corresponds to the <c> TOP4BUSD </c> instruction.
236///
237/// \param dst
238/// Destination/accumulator tile register ID (0-7).
239/// \param src1
240/// First source ZMM vector (__m512i) containing 64 unsigned bytes.
241/// \param src2
242/// Second source ZMM vector (__m512i) containing 64 signed bytes.
243#define _tile_op4busd_epi32(dst, src1, src2) \
244 __builtin_ia32_top4busd((dst), (__v64qi)(src1), (__v64qi)(src2))
245
246/// Compute 4-way outer product of signed x signed bytes to INT32.
247/// Each group of 4 signed byte pairs produces 4 products accumulated
248/// into the destination tile as 32-bit integers.
249///
250/// \headerfile <immintrin.h>
251///
252/// This intrinsic corresponds to the <c> TOP4BSSD </c> instruction.
253///
254/// \param dst
255/// Destination/accumulator tile register ID (0-7).
256/// \param src1
257/// First source ZMM vector (__m512i) containing 64 signed bytes.
258/// \param src2
259/// Second source ZMM vector (__m512i) containing 64 signed bytes.
260#define _tile_op4bssd_epi32(dst, src1, src2) \
261 __builtin_ia32_top4bssd((dst), (__v64qi)(src1), (__v64qi)(src2))
262
263/// Compute 4-way outer product of signed x unsigned bytes to INT32.
264/// Each group of 4 byte pairs (signed from src1, unsigned from src2)
265/// produces 4 products accumulated into the destination tile.
266///
267/// \headerfile <immintrin.h>
268///
269/// This intrinsic corresponds to the <c> TOP4BSUD </c> instruction.
270///
271/// \param dst
272/// Destination/accumulator tile register ID (0-7).
273/// \param src1
274/// First source ZMM vector (__m512i) containing 64 signed bytes.
275/// \param src2
276/// Second source ZMM vector (__m512i) containing 64 unsigned bytes.
277#define _tile_op4bsud_epi32(dst, src1, src2) \
278 __builtin_ia32_top4bsud((dst), (__v64qi)(src1), (__v64qi)(src2))
279
280/// Select the A-input scale group within the BSR for the mixed precision
281/// outer product intrinsics. Combine with \c _MM_ACE_SCALE_B using a bitwise
282/// OR to form the scale group selector.
283///
284/// \headerfile <immintrin.h>
285///
286/// \param g
287/// A-input scale group number (0-3).
288/// \returns
289/// The A-input field of the scale group selector.
290#define _MM_ACE_SCALE_A(g) ((g) << 0)
291
292/// Select the B-input scale group within the BSR for the mixed precision
293/// outer product intrinsics. Combine with \c _MM_ACE_SCALE_A using a bitwise
294/// OR to form the scale group selector.
295///
296/// \headerfile <immintrin.h>
297///
298/// \param g
299/// B-input scale group number (0-3).
300/// \returns
301/// The B-input field of the scale group selector.
302#define _MM_ACE_SCALE_B(g) ((g) << 3)
303
304/// Rank-4 MX FP8 outer product. A = FP8 E4M3, B = FP8 E4M3. OCP MX block
305/// scaling via the BSR, with FP32 accumulation into the destination tile.
306///
307/// \headerfile <immintrin.h>
308///
309/// This intrinsic corresponds to the <c> TOP4MXHF8PS </c> instruction.
310///
311/// \param dst
312/// Destination/accumulator tile register ID (0-7).
313/// \param src1
314/// The A input: ZMM vector (__m512i) of FP8 E4M3 (HF8) values.
315/// \param src2
316/// The B input: ZMM vector (__m512i) of FP8 E4M3 (HF8) values.
317/// \param imm
318/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
319/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
320#define _tile_op4mxhf8_ps(dst, src1, src2, imm) \
321 __builtin_ia32_top4mxhf8ps((dst), (__v64qi)(src1), (__v64qi)(src2), (imm))
322
323/// Rank-4 MX FP8 outer product. A = FP8 E5M2, B = FP8 E4M3. OCP MX block
324/// scaling via the BSR, with FP32 accumulation into the destination tile.
325///
326/// \headerfile <immintrin.h>
327///
328/// This intrinsic corresponds to the <c> TOP4MXBHF8PS </c> instruction.
329///
330/// \param dst
331/// Destination/accumulator tile register ID (0-7).
332/// \param src1
333/// The A input: ZMM vector (__m512i) of FP8 E5M2 (BF8) values.
334/// \param src2
335/// The B input: ZMM vector (__m512i) of FP8 E4M3 (HF8) values.
336/// \param imm
337/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
338/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
339#define _tile_op4mxbhf8_ps(dst, src1, src2, imm) \
340 __builtin_ia32_top4mxbhf8ps((dst), (__v64qi)(src1), (__v64qi)(src2), (imm))
341
342/// Rank-4 MX FP8 outer product. A = FP8 E4M3, B = FP8 E5M2. OCP MX block
343/// scaling via the BSR, with FP32 accumulation into the destination tile.
344///
345/// \headerfile <immintrin.h>
346///
347/// This intrinsic corresponds to the <c> TOP4MXHBF8PS </c> instruction.
348///
349/// \param dst
350/// Destination/accumulator tile register ID (0-7).
351/// \param src1
352/// The A input: ZMM vector (__m512i) of FP8 E4M3 (HF8) values.
353/// \param src2
354/// The B input: ZMM vector (__m512i) of FP8 E5M2 (BF8) values.
355/// \param imm
356/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
357/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
358#define _tile_op4mxhbf8_ps(dst, src1, src2, imm) \
359 __builtin_ia32_top4mxhbf8ps((dst), (__v64qi)(src1), (__v64qi)(src2), (imm))
360
361/// Rank-4 MX FP8 outer product. A = FP8 E5M2, B = FP8 E5M2. OCP MX block
362/// scaling via the BSR, with FP32 accumulation into the destination tile.
363///
364/// \headerfile <immintrin.h>
365///
366/// This intrinsic corresponds to the <c> TOP4MXBF8PS </c> instruction.
367///
368/// \param dst
369/// Destination/accumulator tile register ID (0-7).
370/// \param src1
371/// The A input: ZMM vector (__m512i) of FP8 E5M2 (BF8) values.
372/// \param src2
373/// The B input: ZMM vector (__m512i) of FP8 E5M2 (BF8) values.
374/// \param imm
375/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
376/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
377#define _tile_op4mxbf8_ps(dst, src1, src2, imm) \
378 __builtin_ia32_top4mxbf8ps((dst), (__v64qi)(src1), (__v64qi)(src2), (imm))
379
380/// Rank-4 MX INT8 outer product. A = MX INT8 signed, B = MX INT8 signed.
381/// OCP MX block scaling via the BSR, with FP32 accumulation into the
382/// destination tile.
383///
384/// \headerfile <immintrin.h>
385///
386/// This intrinsic corresponds to the <c> TOP4MXBSSPS </c> instruction.
387///
388/// \param dst
389/// Destination/accumulator tile register ID (0-7).
390/// \param src1
391/// The A input: ZMM vector (__m512i) of MX INT8 signed values.
392/// \param src2
393/// The B input: ZMM vector (__m512i) of MX INT8 signed values.
394/// \param imm
395/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
396/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
397#define _tile_op4mxbss_ps(dst, src1, src2, imm) \
398 __builtin_ia32_top4mxbssps((dst), (__v64qi)(src1), (__v64qi)(src2), (imm))
399
400/// Read a row from a tile register and convert its int32 elements to FP32.
401///
402/// \headerfile <immintrin.h>
403///
404/// This intrinsic corresponds to the <c> TCVTROWD2PS </c> instruction.
405///
406/// \param tsrc
407/// Source tile register ID (0-7).
408/// \param row
409/// Row index selecting the tile row to read.
410/// \returns
411/// ZMM vector (__m512) holding the converted FP32 elements.
412#define _tile_ace_cvtrow_epi32_ps(tsrc, row) \
413 __builtin_ia32_acev1_tcvtrowd2ps((tsrc), (row))
414
415/// Read a row from a tile register and convert its FP32 elements to BF16,
416/// placing the results in the high half of each destination dword.
417///
418/// \headerfile <immintrin.h>
419///
420/// This intrinsic corresponds to the <c> TCVTROWPS2BF16H </c> instruction.
421///
422/// \param tsrc
423/// Source tile register ID (0-7).
424/// \param row
425/// Row index selecting the tile row to read.
426/// \returns
427/// ZMM vector (__m512bh) holding the converted BF16 elements.
428#define _tile_ace_cvtrowh_ps_pbh(tsrc, row) \
429 __builtin_ia32_acev1_tcvtrowps2bf16h((tsrc), (row))
430
431/// Read a row from a tile register and convert its FP32 elements to BF16,
432/// placing the results in the low half of each destination dword.
433///
434/// \headerfile <immintrin.h>
435///
436/// This intrinsic corresponds to the <c> TCVTROWPS2BF16L </c> instruction.
437///
438/// \param tsrc
439/// Source tile register ID (0-7).
440/// \param row
441/// Row index selecting the tile row to read.
442/// \returns
443/// ZMM vector (__m512bh) holding the converted BF16 elements.
444#define _tile_ace_cvtrowl_ps_pbh(tsrc, row) \
445 __builtin_ia32_acev1_tcvtrowps2bf16l((tsrc), (row))
446
447/// Read a row from a tile register and convert its FP32 elements to FP16,
448/// placing the results in the high half of each destination dword.
449///
450/// \headerfile <immintrin.h>
451///
452/// This intrinsic corresponds to the <c> TCVTROWPS2PHH </c> instruction.
453///
454/// \param tsrc
455/// Source tile register ID (0-7).
456/// \param row
457/// Row index selecting the tile row to read.
458/// \returns
459/// ZMM vector (__m512h) holding the converted FP16 elements.
460#define _tile_ace_cvtrowh_ps_ph(tsrc, row) \
461 __builtin_ia32_acev1_tcvtrowps2phh((tsrc), (row))
462
463/// Read a row from a tile register and convert its FP32 elements to FP16,
464/// placing the results in the low half of each destination dword.
465///
466/// \headerfile <immintrin.h>
467///
468/// This intrinsic corresponds to the <c> TCVTROWPS2PHL </c> instruction.
469///
470/// \param tsrc
471/// Source tile register ID (0-7).
472/// \param row
473/// Row index selecting the tile row to read.
474/// \returns
475/// ZMM vector (__m512h) holding the converted FP16 elements.
476#define _tile_ace_cvtrowl_ps_ph(tsrc, row) \
477 __builtin_ia32_acev1_tcvtrowps2phl((tsrc), (row))
478
479/// Extract one row of a tile register into a ZMM destination.
480///
481/// \headerfile <immintrin.h>
482///
483/// This intrinsic corresponds to the <c> TILEMOVROW </c> instruction.
484///
485/// \param tsrc
486/// Source tile register ID (0-7).
487/// \param row
488/// Row index selecting the tile row to read.
489/// \returns
490/// ZMM vector (__m512i) holding the extracted row.
491#define _tile_ace_extractrow(tsrc, row) \
492 ((__m512i)__builtin_ia32_acev1_tilemovrowextract((tsrc), (row)))
493
494/// ACE tile type with fixed dimensions (16 rows x 64 bytes = 1024 bytes).
495/// ACE Palette 2 uses fixed tile dimensions, unlike AMX Palette 1.
496typedef int __acetile __attribute__((__vector_size__(1024), __aligned__(64)));
497
498/// ACE Palette 2 tile configuration structure (64 bytes).
499/// For ACE, only byte 0 (palette_id = 2) is significant; bytes 1-63
500/// must be zero. Unlike AMX Palette 1, tile dimensions are fixed.
501typedef struct __attribute__((__packed__, __aligned__(64))) {
502 unsigned char palette_id;
503 unsigned char reserved[63];
504} __ace_tile_config;
505
506/// Initialize an ACE tile configuration structure for Palette 2.
507/// Sets palette_id to 2 and clears all reserved bytes to zero.
508/// Use with _tile_ace_loadconfig to configure tiles for ACE operations.
509static __inline__ void __DEFAULT_FN_ATTRS_ACE
510__ace_init_config(__ace_tile_config *cfg) {
511 __builtin_memset(cfg, 0, sizeof(*cfg));
512 cfg->palette_id = 2;
513}
514
515/// Zero an ACE tile variable. Sets all 1024 bytes to zero.
516///
517/// \headerfile <immintrin.h>
518///
519/// This intrinsic corresponds to the <c> TILEZERO </c> instruction.
520///
521/// \param dst
522/// Pointer to __acetile variable to be zeroed.
523__DEFAULT_FN_ATTRS_ACE
524static __inline__ void __tile_ace_zero(__acetile *dst) {
525 *dst = __builtin_ia32_acev1_tilezero_internal(16, 64);
526}
527
528/// Compute 4-way outer product of unsigned x unsigned bytes to INT32.
529/// Multiplies 64 unsigned bytes from each ZMM source, producing a
530/// 16x16 grid of 32-bit sums accumulated into the ACE tile.
531///
532/// \headerfile <immintrin.h>
533///
534/// This intrinsic corresponds to the <c> TOP4BUUD </c> instruction.
535///
536/// \param dst
537/// Pointer to destination/accumulator __acetile.
538/// \param src1
539/// First source ZMM vector containing 64 unsigned bytes.
540/// \param src2
541/// Second source ZMM vector containing 64 unsigned bytes.
542__DEFAULT_FN_ATTRS_ACE
543static __inline__ void __tile_ace_top4buud(__acetile *dst, __m512i src1,
544 __m512i src2) {
545 *dst = __builtin_ia32_top4buud_internal(16, 64, *dst, (__v64qi)src1,
546 (__v64qi)src2);
547}
548
549/// Compute 4-way outer product of unsigned x signed bytes to INT32.
550/// Multiplies 64 bytes from each ZMM source (unsigned from src1,
551/// signed from src2), producing a 16x16 grid of 32-bit sums.
552///
553/// \headerfile <immintrin.h>
554///
555/// This intrinsic corresponds to the <c> TOP4BUSD </c> instruction.
556///
557/// \param dst
558/// Pointer to destination/accumulator __acetile.
559/// \param src1
560/// First source ZMM vector containing 64 unsigned bytes.
561/// \param src2
562/// Second source ZMM vector containing 64 signed bytes.
563__DEFAULT_FN_ATTRS_ACE
564static __inline__ void __tile_ace_top4busd(__acetile *dst, __m512i src1,
565 __m512i src2) {
566 *dst = __builtin_ia32_top4busd_internal(16, 64, *dst, (__v64qi)src1,
567 (__v64qi)src2);
568}
569
570/// Compute 4-way outer product of signed x signed bytes to INT32.
571/// Multiplies 64 signed bytes from each ZMM source, producing a
572/// 16x16 grid of 32-bit sums accumulated into the ACE tile.
573///
574/// \headerfile <immintrin.h>
575///
576/// This intrinsic corresponds to the <c> TOP4BSSD </c> instruction.
577///
578/// \param dst
579/// Pointer to destination/accumulator __acetile.
580/// \param src1
581/// First source ZMM vector containing 64 signed bytes.
582/// \param src2
583/// Second source ZMM vector containing 64 signed bytes.
584__DEFAULT_FN_ATTRS_ACE
585static __inline__ void __tile_ace_top4bssd(__acetile *dst, __m512i src1,
586 __m512i src2) {
587 *dst = __builtin_ia32_top4bssd_internal(16, 64, *dst, (__v64qi)src1,
588 (__v64qi)src2);
589}
590
591/// Compute 4-way outer product of signed x unsigned bytes to INT32.
592/// Multiplies 64 bytes from each ZMM source (signed from src1,
593/// unsigned from src2), producing a 16x16 grid of 32-bit sums.
594///
595/// \headerfile <immintrin.h>
596///
597/// This intrinsic corresponds to the <c> TOP4BSUD </c> instruction.
598///
599/// \param dst
600/// Pointer to destination/accumulator __acetile.
601/// \param src1
602/// First source ZMM vector containing 64 signed bytes.
603/// \param src2
604/// Second source ZMM vector containing 64 unsigned bytes.
605__DEFAULT_FN_ATTRS_ACE
606static __inline__ void __tile_ace_top4bsud(__acetile *dst, __m512i src1,
607 __m512i src2) {
608 *dst = __builtin_ia32_top4bsud_internal(16, 64, *dst, (__v64qi)src1,
609 (__v64qi)src2);
610}
611
612/// Compute 2-way outer product of BF16 to FP32.
613/// Multiplies 32 BF16 values from each source, producing a 16x16 grid
614/// of FP32 sums accumulated into the ACE tile.
615///
616/// \headerfile <immintrin.h>
617///
618/// This intrinsic corresponds to the <c> TOP2BF16PS </c> instruction.
619///
620/// \param dst
621/// Pointer to destination/accumulator __acetile.
622/// \param src1
623/// First source ZMM vector (__m512bh) containing 32 BF16 values.
624/// \param src2
625/// Second source ZMM vector (__m512bh) containing 32 BF16 values.
626__DEFAULT_FN_ATTRS_ACE
627static __inline__ void __tile_ace_top2bf16ps(__acetile *dst, __m512bh src1,
628 __m512bh src2) {
629 *dst = __builtin_ia32_top2bf16ps_internal(16, 64, *dst, (__v32bf)src1,
630 (__v32bf)src2);
631}
632
633/// Rank-4 MX FP8 outer product. A = FP8 E4M3, B = FP8 E4M3. OCP MX block
634/// scaling via the BSR, with FP32 accumulation into the destination tile.
635///
636/// \headerfile <immintrin.h>
637///
638/// This intrinsic corresponds to the <c> TOP4MXHF8PS </c> instruction.
639///
640/// \param dst
641/// Pointer to destination/accumulator __acetile.
642/// \param src1
643/// The A input: ZMM vector of FP8 E4M3 (HF8) values.
644/// \param src2
645/// The B input: ZMM vector of FP8 E4M3 (HF8) values.
646/// \param imm
647/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
648/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
649#define __tile_ace_top4mxhf8ps(dst, src1, src2, imm) \
650 (*(dst) = __builtin_ia32_top4mxhf8ps_internal( \
651 16, 64, (imm), *(dst), (__v64qi)(src1), (__v64qi)(src2)))
652
653/// Rank-4 MX FP8 outer product. A = FP8 E5M2, B = FP8 E4M3. OCP MX block
654/// scaling via the BSR, with FP32 accumulation into the destination tile.
655///
656/// \headerfile <immintrin.h>
657///
658/// This intrinsic corresponds to the <c> TOP4MXBHF8PS </c> instruction.
659///
660/// \param dst
661/// Pointer to destination/accumulator __acetile.
662/// \param src1
663/// The A input: ZMM vector of FP8 E5M2 (BF8) values.
664/// \param src2
665/// The B input: ZMM vector of FP8 E4M3 (HF8) values.
666/// \param imm
667/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
668/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
669#define __tile_ace_top4mxbhf8ps(dst, src1, src2, imm) \
670 (*(dst) = __builtin_ia32_top4mxbhf8ps_internal( \
671 16, 64, (imm), *(dst), (__v64qi)(src1), (__v64qi)(src2)))
672
673/// Rank-4 MX FP8 outer product. A = FP8 E4M3, B = FP8 E5M2. OCP MX block
674/// scaling via the BSR, with FP32 accumulation into the destination tile.
675///
676/// \headerfile <immintrin.h>
677///
678/// This intrinsic corresponds to the <c> TOP4MXHBF8PS </c> instruction.
679///
680/// \param dst
681/// Pointer to destination/accumulator __acetile.
682/// \param src1
683/// The A input: ZMM vector of FP8 E4M3 (HF8) values.
684/// \param src2
685/// The B input: ZMM vector of FP8 E5M2 (BF8) values.
686/// \param imm
687/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
688/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
689#define __tile_ace_top4mxhbf8ps(dst, src1, src2, imm) \
690 (*(dst) = __builtin_ia32_top4mxhbf8ps_internal( \
691 16, 64, (imm), *(dst), (__v64qi)(src1), (__v64qi)(src2)))
692
693/// Rank-4 MX FP8 outer product. A = FP8 E5M2, B = FP8 E5M2. OCP MX block
694/// scaling via the BSR, with FP32 accumulation into the destination tile.
695///
696/// \headerfile <immintrin.h>
697///
698/// This intrinsic corresponds to the <c> TOP4MXBF8PS </c> instruction.
699///
700/// \param dst
701/// Pointer to destination/accumulator __acetile.
702/// \param src1
703/// The A input: ZMM vector of FP8 E5M2 (BF8) values.
704/// \param src2
705/// The B input: ZMM vector of FP8 E5M2 (BF8) values.
706/// \param imm
707/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
708/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
709#define __tile_ace_top4mxbf8ps(dst, src1, src2, imm) \
710 (*(dst) = __builtin_ia32_top4mxbf8ps_internal( \
711 16, 64, (imm), *(dst), (__v64qi)(src1), (__v64qi)(src2)))
712
713/// Rank-4 MX INT8 outer product. A = MX INT8 signed, B = MX INT8 signed.
714/// OCP MX block scaling via the BSR, with FP32 accumulation into the
715/// destination tile.
716///
717/// \headerfile <immintrin.h>
718///
719/// This intrinsic corresponds to the <c> TOP4MXBSSPS </c> instruction.
720///
721/// \param dst
722/// Pointer to destination/accumulator __acetile.
723/// \param src1
724/// The A input: ZMM vector of MX INT8 signed values.
725/// \param src2
726/// The B input: ZMM vector of MX INT8 signed values.
727/// \param imm
728/// Scale group selector, formed from \c _MM_ACE_SCALE_A and
729/// \c _MM_ACE_SCALE_B; all other bits are reserved and must be zero.
730#define __tile_ace_top4mxbssps(dst, src1, src2, imm) \
731 (*(dst) = __builtin_ia32_top4mxbssps_internal( \
732 16, 64, (imm), *(dst), (__v64qi)(src1), (__v64qi)(src2)))
733
734/// Write a ZMM vector as a column in an ACE tile.
735/// The 16 doublewords from src are written vertically at column idx.
736///
737/// \headerfile <immintrin.h>
738///
739/// This intrinsic corresponds to the <c> TILEMOVCOL </c> instruction.
740///
741/// \param dst
742/// Pointer to destination __acetile.
743/// \param src
744/// Source ZMM vector (__m512i) with 16 doublewords.
745/// \param idx
746/// Column index (0-15).
747__DEFAULT_FN_ATTRS_ACE
748static __inline__ void __tile_ace_setcol(__acetile *dst, __m512i src,
749 unsigned int idx) {
750 *dst = __builtin_ia32_tilemovcolinsert_internal(16, 64, *dst, (__v16si)src,
751 idx);
752}
753
754/// Write a ZMM vector as a row in an ACE tile.
755/// The 64 bytes from src are written horizontally at row idx.
756///
757/// \headerfile <immintrin.h>
758///
759/// This intrinsic corresponds to the <c> TILEMOVROW </c> instruction.
760///
761/// \param dst
762/// Pointer to destination __acetile.
763/// \param src
764/// Source ZMM vector (__m512i) with 64 bytes.
765/// \param idx
766/// Row index (0-15).
767__DEFAULT_FN_ATTRS_ACE
768static __inline__ void __tile_ace_setrow(__acetile *dst, __m512i src,
769 unsigned int idx) {
770 *dst = __builtin_ia32_tilemovrowinsert_internal(16, 64, *dst, (__v16si)src,
771 idx);
772}
773
774/// Read a row from an ACE tile to a ZMM vector.
775/// Returns the 64 bytes at row idx as a ZMM vector.
776///
777/// \headerfile <immintrin.h>
778///
779/// This intrinsic corresponds to the <c> TILEMOVROW </c> instruction.
780///
781/// \param src
782/// Pointer to source __acetile.
783/// \param idx
784/// Row index (0-15).
785/// \returns
786/// ZMM vector (__m512i) containing the 64-byte row.
787__DEFAULT_FN_ATTRS_ACE
788static __inline__ __m512i __tile_ace_getrow(__acetile *src, unsigned int idx) {
789 return (__m512i)__builtin_ia32_acev1_tilemovrowextract_internal(
790 16, 64, *src, idx);
791}
792
793/// Read a row from an ACE tile and convert INT32 elements to FP32.
794/// Each of the 16 INT32 elements in the row is converted to FP32.
795/// Rounding uses RTNE (round to nearest even).
796///
797/// \headerfile <immintrin.h>
798///
799/// This intrinsic corresponds to the <c> TCVTROWD2PS </c> instruction.
800///
801/// \param src
802/// Pointer to source __acetile containing INT32 elements.
803/// \param idx
804/// Row index (0-15).
805/// \returns
806/// ZMM vector (__m512) containing 16 FP32 values.
807__DEFAULT_FN_ATTRS_ACE
808static __inline__ __m512 __tile_ace_cvtrowd2ps(__acetile *src,
809 unsigned int idx) {
810 return __builtin_ia32_acev1_tcvtrowd2ps_internal(16, 64, *src, idx);
811}
812
813/// Read a row from an ACE tile and convert FP32 elements to BF16 (high).
814/// Each FP32 element is converted to BF16 and placed in the high 16 bits
815/// of each destination dword; low 16 bits are zeroed.
816///
817/// \headerfile <immintrin.h>
818///
819/// This intrinsic corresponds to the <c> TCVTROWPS2BF16H </c> instruction.
820///
821/// \param src
822/// Pointer to source __acetile containing FP32 elements.
823/// \param idx
824/// Row index (0-15).
825/// \returns
826/// ZMM vector (__m512bh) with BF16 values in high half of each dword.
827__DEFAULT_FN_ATTRS_ACE
828static __inline__ __m512bh __tile_ace_cvtrowps2bf16h(__acetile *src,
829 unsigned int idx) {
830 return __builtin_ia32_acev1_tcvtrowps2bf16h_internal(16, 64, *src, idx);
831}
832
833/// Read a row from an ACE tile and convert FP32 elements to BF16 (low).
834/// Each FP32 element is converted to BF16 and placed in the low 16 bits
835/// of each destination dword; high 16 bits are zeroed.
836///
837/// \headerfile <immintrin.h>
838///
839/// This intrinsic corresponds to the <c> TCVTROWPS2BF16L </c> instruction.
840///
841/// \param src
842/// Pointer to source __acetile containing FP32 elements.
843/// \param idx
844/// Row index (0-15).
845/// \returns
846/// ZMM vector (__m512bh) with BF16 values in low half of each dword.
847__DEFAULT_FN_ATTRS_ACE
848static __inline__ __m512bh __tile_ace_cvtrowps2bf16l(__acetile *src,
849 unsigned int idx) {
850 return __builtin_ia32_acev1_tcvtrowps2bf16l_internal(16, 64, *src, idx);
851}
852
853/// Read a row from an ACE tile and convert FP32 elements to FP16 (high).
854/// Each FP32 element is converted to FP16 and placed in the high 16 bits
855/// of each destination dword; low 16 bits are zeroed.
856///
857/// \headerfile <immintrin.h>
858///
859/// This intrinsic corresponds to the <c> TCVTROWPS2PHH </c> instruction.
860///
861/// \param src
862/// Pointer to source __acetile containing FP32 elements.
863/// \param idx
864/// Row index (0-15).
865/// \returns
866/// ZMM vector (__m512h) with FP16 values in high half of each dword.
867__DEFAULT_FN_ATTRS_ACE
868static __inline__ __m512h __tile_ace_cvtrowps2phh(__acetile *src,
869 unsigned int idx) {
870 return __builtin_ia32_acev1_tcvtrowps2phh_internal(16, 64, *src, idx);
871}
872
873/// Read a row from an ACE tile and convert FP32 elements to FP16 (low).
874/// Each FP32 element is converted to FP16 and placed in the low 16 bits
875/// of each destination dword; high 16 bits are zeroed.
876///
877/// \headerfile <immintrin.h>
878///
879/// This intrinsic corresponds to the <c> TCVTROWPS2PHL </c> instruction.
880///
881/// \param src
882/// Pointer to source __acetile containing FP32 elements.
883/// \param idx
884/// Row index (0-15).
885/// \returns
886/// ZMM vector (__m512h) with FP16 values in low half of each dword.
887__DEFAULT_FN_ATTRS_ACE
888static __inline__ __m512h __tile_ace_cvtrowps2phl(__acetile *src,
889 unsigned int idx) {
890 return __builtin_ia32_acev1_tcvtrowps2phl_internal(16, 64, *src, idx);
891}
892
893// clang-format on
894
895#undef __DEFAULT_FN_ATTRS_ACE
896
897#endif /* __x86_64__ && __SSE2__ */
898#endif /* __ACEV1INTRIN_H */
_Float16 __2f16 __attribute__((ext_vector_type(2)))
Zeroes the upper 128 bits (bits 255:128) of all YMM registers.
static __inline__ void const void * __src