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