1 #ifndef MATMUL_FACADE_H_
2 #define MATMUL_FACADE_H_
3 
4 #include <stdarg.h>  // for va_list
5 #include <stddef.h>  // for size_t
6 #include <stdint.h>  // for uint32_t
7 #include "params.h"  // for param_list
8 
9 /* This file is included by all matmul implementations so as to enable
10  * the macros MATMUL_NAME and MATMUL_T.
11  *
12  * It does not make sense to have it included from the higher-level code
13  * (in fact, it will error out).
14  */
15 #include "matmul.h"
16 
17 /* Include all matmul implementations here */
18 
19 #if !defined(MM_MPFQ_LAYER)
20 #error "Please compile this file with the MM_MPFQ_LAYER macro defined"
21 #endif
22 
23 /* Now some cpp glue which sets up the different options */
24 #define MATMUL_NAME_INNER(abase, impl, func) matmul_ ## abase ## _ ## impl ## _ ## func
25 #define MATMUL_NAME_INNER0(abase, impl, func) MATMUL_NAME_INNER(abase, impl, func)
26 #define MATMUL_NAME(func) MATMUL_NAME_INNER0(MM_MPFQ_LAYER, MM_IMPL, func)
27 
28 #define MATMUL_T(func) matmul_ ## func ## _t
29 
30 #define REBIND_F(mm, func) \
31         mm->bind->func = (MATMUL_T(func)) & MATMUL_NAME(func)
32 
33 #define SET_IMPL_INNER(mm, mpfq_, impl_) do {  \
34     mm->bind->impl = # impl_ ;                  \
35 } while (0)
36 
37 #define SET_IMPL_INNER0(mm, mpfq_, impl_) SET_IMPL_INNER(mm, mpfq_, impl_)
38 
39 #define SET_IMPL(mm) SET_IMPL_INNER0(mm, MM_MPFQ_LAYER, MM_IMPL)
40 
41 #define REBIND_ALL(mm) do {				\
42         REBIND_F(mm, build_cache);		        \
43         REBIND_F(mm, reload_cache);			\
44         REBIND_F(mm, save_cache);		        \
45         REBIND_F(mm, mul);			        \
46         REBIND_F(mm, report);				\
47         REBIND_F(mm, clear);				\
48         REBIND_F(mm, init);				\
49         REBIND_F(mm, auxv);				\
50         REBIND_F(mm, aux);			       	\
51         SET_IMPL(mm);                                   \
52     } while (0)
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /* those are defined on a per-impl basis, in the impl specific source
59  * files (most often it's called matmul-MM_IMPL.c , or .cpp) */
60 extern matmul_ptr MATMUL_NAME(init)(void *, param_list pl, int);
61 extern void MATMUL_NAME(build_cache)(matmul_ptr, uint32_t *, size_t);
62 extern int MATMUL_NAME(reload_cache)(matmul_ptr);
63 extern void MATMUL_NAME(save_cache)(matmul_ptr);
64 extern void MATMUL_NAME(mul)(matmul_ptr, void *, const void *, int);
65 extern void MATMUL_NAME(report)(matmul_ptr, double scale);
66 extern void MATMUL_NAME(clear)(matmul_ptr mm);
67 extern void MATMUL_NAME(auxv)(matmul_ptr mm, int op, va_list ap);
68 extern void MATMUL_NAME(aux)(matmul_ptr mm, int op, ...);
69 
70 /* this one is defined collectively for all impls in matmul_facade.c */
71 extern void MATMUL_NAME(rebind)(matmul_ptr mm);
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif	/* MATMUL_FACADE_H_ */
78