master
 1/*===------------- amxfp16intrin.h - AMX_FP16 intrinsics -*- 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 <amxfp16intrin.h> directly; use <immintrin.h> instead."
12#endif /* __IMMINTRIN_H */
13
14#ifndef __AMX_FP16INTRIN_H
15#define __AMX_FP16INTRIN_H
16#ifdef __x86_64__
17
18/* Define the default attributes for the functions in this file. */
19#define __DEFAULT_FN_ATTRS                                                     \
20  __attribute__((__always_inline__, __nodebug__, __target__("amx-fp16")))
21
22/// Compute dot-product of FP16 (16-bit) floating-point pairs in tiles \a a
23///    and \a b, accumulating the intermediate single-precision (32-bit)
24///    floating-point elements with elements in \a dst, and store the 32-bit
25///    result back to tile \a dst.
26///
27/// \headerfile <immintrin.h>
28///
29/// \code
30/// void _tile_dpfp16ps (__tile dst, __tile a, __tile b)
31/// \endcode
32///
33/// \code{.operation}
34/// FOR m := 0 TO dst.rows - 1
35///	tmp := dst.row[m]
36///	FOR k := 0 TO (a.colsb / 4) - 1
37///		FOR n := 0 TO (dst.colsb / 4) - 1
38///			tmp.fp32[n] += FP32(a.row[m].fp16[2*k+0]) *
39///					FP32(b.row[k].fp16[2*n+0])
40///			tmp.fp32[n] += FP32(a.row[m].fp16[2*k+1]) *
41///					FP32(b.row[k].fp16[2*n+1])
42///		ENDFOR
43///	ENDFOR
44///	write_row_and_zero(dst, m, tmp, dst.colsb)
45/// ENDFOR
46/// zero_upper_rows(dst, dst.rows)
47/// zero_tileconfig_start()
48/// \endcode
49///
50/// This intrinsic corresponds to the \c TDPFP16PS instruction.
51///
52/// \param dst
53///    The destination tile. Max size is 1024 Bytes.
54/// \param a
55///    The 1st source tile. Max size is 1024 Bytes.
56/// \param b
57///    The 2nd source tile. Max size is 1024 Bytes.
58#define _tile_dpfp16ps(dst, a, b)                                \
59  __builtin_ia32_tdpfp16ps(dst, a, b)
60
61/// This is internal intrinsic. C/C++ user should avoid calling it directly.
62static __inline__ _tile1024i __DEFAULT_FN_ATTRS
63_tile_dpfp16ps_internal(unsigned short m, unsigned short n, unsigned short k,
64                        _tile1024i dst, _tile1024i src1, _tile1024i src2) {
65  return __builtin_ia32_tdpfp16ps_internal(m, n, k, dst, src1, src2);
66}
67
68/// Compute dot-product of FP16 (16-bit) floating-point pairs in tiles src0 and
69/// src1, accumulating the intermediate single-precision (32-bit) floating-point
70/// elements with elements in "dst", and store the 32-bit result back to tile
71/// "dst".
72///
73/// \headerfile <immintrin.h>
74///
75/// This intrinsic corresponds to the <c> TDPFP16PS </c> instruction.
76///
77/// \param dst
78///    The destination tile. Max size is 1024 Bytes.
79/// \param src0
80///    The 1st source tile. Max size is 1024 Bytes.
81/// \param src1
82///    The 2nd source tile. Max size is 1024 Bytes.
83__DEFAULT_FN_ATTRS
84static __inline__ void __tile_dpfp16ps(__tile1024i *dst, __tile1024i src0,
85                                       __tile1024i src1) {
86  dst->tile = _tile_dpfp16ps_internal(src0.row, src1.col, src0.col, dst->tile,
87                                      src0.tile, src1.tile);
88}
89
90#undef __DEFAULT_FN_ATTRS
91
92#endif /* __x86_64__ */
93#endif /* __AMX_FP16INTRIN_H */