xref: /freebsd-src/contrib/llvm-project/clang/lib/Headers/amxcomplexintrin.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric /*===--------- amxcomplexintrin.h - AMXCOMPLEX intrinsics -*- C++ -*---------===
2*06c3fb27SDimitry Andric  *
3*06c3fb27SDimitry Andric  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*06c3fb27SDimitry Andric  * See https://llvm.org/LICENSE.txt for license information.
5*06c3fb27SDimitry Andric  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*06c3fb27SDimitry Andric  *
7*06c3fb27SDimitry Andric  *===------------------------------------------------------------------------===
8*06c3fb27SDimitry Andric  */
9*06c3fb27SDimitry Andric 
10*06c3fb27SDimitry Andric #ifndef __IMMINTRIN_H
11*06c3fb27SDimitry Andric #error "Never use <amxcomplexintrin.h> directly; include <immintrin.h> instead."
12*06c3fb27SDimitry Andric #endif // __IMMINTRIN_H
13*06c3fb27SDimitry Andric 
14*06c3fb27SDimitry Andric #ifndef __AMX_COMPLEXINTRIN_H
15*06c3fb27SDimitry Andric #define __AMX_COMPLEXINTRIN_H
16*06c3fb27SDimitry Andric #ifdef __x86_64__
17*06c3fb27SDimitry Andric 
18*06c3fb27SDimitry Andric #define __DEFAULT_FN_ATTRS_COMPLEX                                             \
19*06c3fb27SDimitry Andric   __attribute__((__always_inline__, __nodebug__, __target__("amx-complex")))
20*06c3fb27SDimitry Andric 
21*06c3fb27SDimitry Andric /// Perform matrix multiplication of two tiles containing complex elements and
22*06c3fb27SDimitry Andric ///    accumulate the results into a packed single precision tile. Each dword
23*06c3fb27SDimitry Andric ///    element in input tiles \a a and \a b is interpreted as a complex number
24*06c3fb27SDimitry Andric ///    with FP16 real part and FP16 imaginary part.
25*06c3fb27SDimitry Andric /// Calculates the imaginary part of the result. For each possible combination
26*06c3fb27SDimitry Andric ///    of (row of \a a, column of \a b), it performs a set of multiplication
27*06c3fb27SDimitry Andric ///    and accumulations on all corresponding complex numbers (one from \a a
28*06c3fb27SDimitry Andric ///    and one from \a b). The imaginary part of the \a a element is multiplied
29*06c3fb27SDimitry Andric ///    with the real part of the corresponding \a b element, and the real part
30*06c3fb27SDimitry Andric ///    of the \a a element is multiplied with the imaginary part of the
31*06c3fb27SDimitry Andric ///    corresponding \a b elements. The two accumulated results are added, and
32*06c3fb27SDimitry Andric ///    then accumulated into the corresponding row and column of \a dst.
33*06c3fb27SDimitry Andric ///
34*06c3fb27SDimitry Andric /// \headerfile <x86intrin.h>
35*06c3fb27SDimitry Andric ///
36*06c3fb27SDimitry Andric /// \code
37*06c3fb27SDimitry Andric /// void _tile_cmmimfp16ps(__tile dst, __tile a, __tile b);
38*06c3fb27SDimitry Andric /// \endcode
39*06c3fb27SDimitry Andric ///
40*06c3fb27SDimitry Andric /// \code{.operation}
41*06c3fb27SDimitry Andric /// FOR m := 0 TO dst.rows - 1
42*06c3fb27SDimitry Andric ///	tmp := dst.row[m]
43*06c3fb27SDimitry Andric ///	FOR k := 0 TO (a.colsb / 4) - 1
44*06c3fb27SDimitry Andric ///		FOR n := 0 TO (dst.colsb / 4) - 1
45*06c3fb27SDimitry Andric ///			tmp.fp32[n] += FP32(a.row[m].fp16[2*k+0]) * FP32(b.row[k].fp16[2*n+1])
46*06c3fb27SDimitry Andric ///			tmp.fp32[n] += FP32(a.row[m].fp16[2*k+1]) * FP32(b.row[k].fp16[2*n+0])
47*06c3fb27SDimitry Andric ///		ENDFOR
48*06c3fb27SDimitry Andric ///	ENDFOR
49*06c3fb27SDimitry Andric ///	write_row_and_zero(dst, m, tmp, dst.colsb)
50*06c3fb27SDimitry Andric /// ENDFOR
51*06c3fb27SDimitry Andric /// zero_upper_rows(dst, dst.rows)
52*06c3fb27SDimitry Andric /// zero_tileconfig_start()
53*06c3fb27SDimitry Andric /// \endcode
54*06c3fb27SDimitry Andric ///
55*06c3fb27SDimitry Andric /// This intrinsic corresponds to the \c TCMMIMFP16PS instruction.
56*06c3fb27SDimitry Andric ///
57*06c3fb27SDimitry Andric /// \param dst
58*06c3fb27SDimitry Andric ///    The destination tile. Max size is 1024 Bytes.
59*06c3fb27SDimitry Andric /// \param a
60*06c3fb27SDimitry Andric ///    The 1st source tile. Max size is 1024 Bytes.
61*06c3fb27SDimitry Andric /// \param b
62*06c3fb27SDimitry Andric ///    The 2nd source tile. Max size is 1024 Bytes.
63*06c3fb27SDimitry Andric #define _tile_cmmimfp16ps(dst, a, b) __builtin_ia32_tcmmimfp16ps(dst, a, b)
64*06c3fb27SDimitry Andric 
65*06c3fb27SDimitry Andric /// Perform matrix multiplication of two tiles containing complex elements and
66*06c3fb27SDimitry Andric ///    accumulate the results into a packed single precision tile. Each dword
67*06c3fb27SDimitry Andric ///    element in input tiles \a a and \a b is interpreted as a complex number
68*06c3fb27SDimitry Andric ///    with FP16 real part and FP16 imaginary part.
69*06c3fb27SDimitry Andric /// Calculates the real part of the result. For each possible combination
70*06c3fb27SDimitry Andric ///    of (row of \a a, column of \a b), it performs a set of multiplication
71*06c3fb27SDimitry Andric ///    and accumulations on all corresponding complex numbers (one from \a a
72*06c3fb27SDimitry Andric ///    and one from \a b). The real part of the \a a element is multiplied
73*06c3fb27SDimitry Andric ///    with the real part of the corresponding \a b element, and the negated
74*06c3fb27SDimitry Andric ///    imaginary part of the \a a element is multiplied with the imaginary
75*06c3fb27SDimitry Andric ///    part of the corresponding \a b elements. The two accumulated results
76*06c3fb27SDimitry Andric ///    are added, and then accumulated into the corresponding row and column
77*06c3fb27SDimitry Andric ///    of \a dst.
78*06c3fb27SDimitry Andric ///
79*06c3fb27SDimitry Andric /// \headerfile <x86intrin.h>
80*06c3fb27SDimitry Andric ///
81*06c3fb27SDimitry Andric /// \code
82*06c3fb27SDimitry Andric /// void _tile_cmmrlfp16ps(__tile dst, __tile a, __tile b);
83*06c3fb27SDimitry Andric /// \endcode
84*06c3fb27SDimitry Andric ///
85*06c3fb27SDimitry Andric /// \code{.operation}
86*06c3fb27SDimitry Andric /// FOR m := 0 TO dst.rows - 1
87*06c3fb27SDimitry Andric ///	tmp := dst.row[m]
88*06c3fb27SDimitry Andric ///	FOR k := 0 TO (a.colsb / 4) - 1
89*06c3fb27SDimitry Andric ///		FOR n := 0 TO (dst.colsb / 4) - 1
90*06c3fb27SDimitry Andric ///			tmp.fp32[n] += FP32(a.row[m].fp16[2*k+0]) * FP32(b.row[k].fp16[2*n+0])
91*06c3fb27SDimitry Andric ///			tmp.fp32[n] += FP32(-a.row[m].fp16[2*k+1]) * FP32(b.row[k].fp16[2*n+1])
92*06c3fb27SDimitry Andric ///		ENDFOR
93*06c3fb27SDimitry Andric ///	ENDFOR
94*06c3fb27SDimitry Andric ///	write_row_and_zero(dst, m, tmp, dst.colsb)
95*06c3fb27SDimitry Andric /// ENDFOR
96*06c3fb27SDimitry Andric /// zero_upper_rows(dst, dst.rows)
97*06c3fb27SDimitry Andric /// zero_tileconfig_start()
98*06c3fb27SDimitry Andric /// \endcode
99*06c3fb27SDimitry Andric ///
100*06c3fb27SDimitry Andric /// This intrinsic corresponds to the \c TCMMIMFP16PS instruction.
101*06c3fb27SDimitry Andric ///
102*06c3fb27SDimitry Andric /// \param dst
103*06c3fb27SDimitry Andric ///    The destination tile. Max size is 1024 Bytes.
104*06c3fb27SDimitry Andric /// \param a
105*06c3fb27SDimitry Andric ///    The 1st source tile. Max size is 1024 Bytes.
106*06c3fb27SDimitry Andric /// \param b
107*06c3fb27SDimitry Andric ///    The 2nd source tile. Max size is 1024 Bytes.
108*06c3fb27SDimitry Andric #define _tile_cmmrlfp16ps(dst, a, b) __builtin_ia32_tcmmrlfp16ps(dst, a, b)
109*06c3fb27SDimitry Andric 
110*06c3fb27SDimitry Andric static __inline__ _tile1024i __DEFAULT_FN_ATTRS_COMPLEX
_tile_cmmimfp16ps_internal(unsigned short m,unsigned short n,unsigned short k,_tile1024i dst,_tile1024i src1,_tile1024i src2)111*06c3fb27SDimitry Andric _tile_cmmimfp16ps_internal(unsigned short m, unsigned short n, unsigned short k,
112*06c3fb27SDimitry Andric                            _tile1024i dst, _tile1024i src1, _tile1024i src2) {
113*06c3fb27SDimitry Andric   return __builtin_ia32_tcmmimfp16ps_internal(m, n, k, dst, src1, src2);
114*06c3fb27SDimitry Andric }
115*06c3fb27SDimitry Andric 
116*06c3fb27SDimitry Andric static __inline__ _tile1024i __DEFAULT_FN_ATTRS_COMPLEX
_tile_cmmrlfp16ps_internal(unsigned short m,unsigned short n,unsigned short k,_tile1024i dst,_tile1024i src1,_tile1024i src2)117*06c3fb27SDimitry Andric _tile_cmmrlfp16ps_internal(unsigned short m, unsigned short n, unsigned short k,
118*06c3fb27SDimitry Andric                            _tile1024i dst, _tile1024i src1, _tile1024i src2) {
119*06c3fb27SDimitry Andric   return __builtin_ia32_tcmmrlfp16ps_internal(m, n, k, dst, src1, src2);
120*06c3fb27SDimitry Andric }
121*06c3fb27SDimitry Andric 
122*06c3fb27SDimitry Andric /// Perform matrix multiplication of two tiles containing complex elements and
123*06c3fb27SDimitry Andric /// accumulate the results into a packed single precision tile. Each dword
124*06c3fb27SDimitry Andric /// element in input tiles src0 and src1 is interpreted as a complex number with
125*06c3fb27SDimitry Andric /// FP16 real part and FP16 imaginary part.
126*06c3fb27SDimitry Andric /// This function calculates the imaginary part of the result.
127*06c3fb27SDimitry Andric ///
128*06c3fb27SDimitry Andric /// \headerfile <immintrin.h>
129*06c3fb27SDimitry Andric ///
130*06c3fb27SDimitry Andric /// This intrinsic corresponds to the <c> TCMMIMFP16PS </c> instruction.
131*06c3fb27SDimitry Andric ///
132*06c3fb27SDimitry Andric /// \param dst
133*06c3fb27SDimitry Andric ///    The destination tile. Max size is 1024 Bytes.
134*06c3fb27SDimitry Andric /// \param src0
135*06c3fb27SDimitry Andric ///    The 1st source tile. Max size is 1024 Bytes.
136*06c3fb27SDimitry Andric /// \param src1
137*06c3fb27SDimitry Andric ///    The 2nd source tile. Max size is 1024 Bytes.
138*06c3fb27SDimitry Andric __DEFAULT_FN_ATTRS_COMPLEX
__tile_cmmimfp16ps(__tile1024i * dst,__tile1024i src0,__tile1024i src1)139*06c3fb27SDimitry Andric static void __tile_cmmimfp16ps(__tile1024i *dst, __tile1024i src0,
140*06c3fb27SDimitry Andric                                __tile1024i src1) {
141*06c3fb27SDimitry Andric   dst->tile = _tile_cmmimfp16ps_internal(src0.row, src1.col, src0.col,
142*06c3fb27SDimitry Andric                                          dst->tile, src0.tile, src1.tile);
143*06c3fb27SDimitry Andric }
144*06c3fb27SDimitry Andric 
145*06c3fb27SDimitry Andric /// Perform matrix multiplication of two tiles containing complex elements and
146*06c3fb27SDimitry Andric /// accumulate the results into a packed single precision tile. Each dword
147*06c3fb27SDimitry Andric /// element in input tiles src0 and src1 is interpreted as a complex number with
148*06c3fb27SDimitry Andric /// FP16 real part and FP16 imaginary part.
149*06c3fb27SDimitry Andric /// This function calculates the real part of the result.
150*06c3fb27SDimitry Andric ///
151*06c3fb27SDimitry Andric /// \headerfile <immintrin.h>
152*06c3fb27SDimitry Andric ///
153*06c3fb27SDimitry Andric /// This intrinsic corresponds to the <c> TCMMRLFP16PS </c> instruction.
154*06c3fb27SDimitry Andric ///
155*06c3fb27SDimitry Andric /// \param dst
156*06c3fb27SDimitry Andric ///    The destination tile. Max size is 1024 Bytes.
157*06c3fb27SDimitry Andric /// \param src0
158*06c3fb27SDimitry Andric ///    The 1st source tile. Max size is 1024 Bytes.
159*06c3fb27SDimitry Andric /// \param src1
160*06c3fb27SDimitry Andric ///    The 2nd source tile. Max size is 1024 Bytes.
161*06c3fb27SDimitry Andric __DEFAULT_FN_ATTRS_COMPLEX
__tile_cmmrlfp16ps(__tile1024i * dst,__tile1024i src0,__tile1024i src1)162*06c3fb27SDimitry Andric static void __tile_cmmrlfp16ps(__tile1024i *dst, __tile1024i src0,
163*06c3fb27SDimitry Andric                                __tile1024i src1) {
164*06c3fb27SDimitry Andric   dst->tile = _tile_cmmrlfp16ps_internal(src0.row, src1.col, src0.col,
165*06c3fb27SDimitry Andric                                          dst->tile, src0.tile, src1.tile);
166*06c3fb27SDimitry Andric }
167*06c3fb27SDimitry Andric 
168*06c3fb27SDimitry Andric #endif // __x86_64__
169*06c3fb27SDimitry Andric #endif // __AMX_COMPLEXINTRIN_H
170