xref: /netbsd-src/external/lgpl3/mpc/dist/src/logging.c (revision 367b82799ab709709d3c3b541df56a2a14644d3e)
1 /* logging.c -- "Dummy" functions logging calls to real mpc functions.
2 
3 Copyright (C) 2011, 2022 INRIA
4 
5 This file is part of GNU MPC.
6 
7 GNU MPC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/ .
19 */
20 
21 #include <stdio.h>
22 
23 #define __MPC_LIBRARY_BUILD
24    /* to indicate we are inside the library build; needed here since mpc-log.h
25       includes mpc.h and not mpc-impl.h */
26 #include "mpc-log.h"
27 
28 #include "config.h"
29 #ifdef HAVE_DLFCN_H
30 #include <dlfcn.h>
31 #endif
32 
33 typedef int (*c_c_func_ptr) (mpc_ptr, mpc_srcptr, mpc_rnd_t);
34 typedef int (*c_cc_func_ptr) (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
35 typedef int (*c_ccc_func_ptr) (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
36 typedef int (*cc_c_func_ptr) (mpc_ptr, mpc_ptr, mpc_srcptr, mpc_rnd_t, mpc_rnd_t);
37 
38 #define MPC_LOGGING_OUT_PREC(z) \
39    do { \
40       fprintf (stderr, " %li %li", (long) mpfr_get_prec (mpc_realref (z)),  \
41                                 (long) mpfr_get_prec (mpc_imagref (z))); \
42    } while (0);
43 
44 #define MPC_LOGGING_OUT_C(z) \
45    do { \
46       MPC_LOGGING_OUT_PREC (z); \
47       fprintf (stderr, " "); \
48       mpc_out_str (stderr, 16, 0, z, MPC_RNDNN); \
49    } while (0);
50 
51 #define MPC_LOGGING_FUNC_TYPE(funcname, type) \
52    do { \
53       fprintf (stderr, "mpc_"#funcname" "#type); \
54    } while (0);
55 
56 #define MPC_LOGGING_C_C(funcname) \
57 __MPC_DECLSPEC int mpc_log_##funcname (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) \
58 { \
59    static c_c_func_ptr func = NULL; \
60    if (func == NULL) \
61       func = (c_c_func_ptr) (intptr_t) dlsym (NULL, "mpc_"#funcname); \
62    MPC_LOGGING_FUNC_TYPE (funcname, c_c); \
63    MPC_LOGGING_OUT_PREC (rop); \
64    MPC_LOGGING_OUT_C (op); \
65    fprintf (stderr, "\n"); \
66    return func (rop, op, rnd); \
67 }
68 
69 #define MPC_LOGGING_C_CC(funcname) \
70 __MPC_DECLSPEC int mpc_log_##funcname (mpc_ptr rop, mpc_srcptr op1, mpc_srcptr op2, mpc_rnd_t rnd) \
71 { \
72    static c_cc_func_ptr func = NULL; \
73    if (func == NULL) \
74       func = (c_cc_func_ptr) (intptr_t) dlsym (NULL, "mpc_"#funcname); \
75    MPC_LOGGING_FUNC_TYPE (funcname, c_cc); \
76    MPC_LOGGING_OUT_PREC (rop); \
77    MPC_LOGGING_OUT_C (op1); \
78    MPC_LOGGING_OUT_C (op2); \
79    fprintf (stderr, "\n"); \
80    return func (rop, op1, op2, rnd); \
81 }
82 
83 #define MPC_LOGGING_C_CCC(funcname) \
84 __MPC_DECLSPEC int mpc_log_##funcname (mpc_ptr rop, mpc_srcptr op1, mpc_srcptr op2, mpc_srcptr op3, mpc_rnd_t rnd) \
85 { \
86    static c_ccc_func_ptr func = NULL; \
87    if (func == NULL) \
88       func = (c_ccc_func_ptr) (intptr_t) dlsym (NULL, "mpc_"#funcname); \
89    MPC_LOGGING_FUNC_TYPE (funcname, c_ccc); \
90    MPC_LOGGING_OUT_PREC (rop); \
91    MPC_LOGGING_OUT_C (op1); \
92    MPC_LOGGING_OUT_C (op2); \
93    MPC_LOGGING_OUT_C (op3); \
94    fprintf (stderr, "\n"); \
95    return func (rop, op1, op2, op3, rnd); \
96 }
97 
98 #define MPC_LOGGING_CC_C(funcname) \
99 __MPC_DECLSPEC int mpc_log_##funcname (mpc_ptr rop1, mpc_ptr rop2, mpc_srcptr op, mpc_rnd_t rnd1, mpc_rnd_t rnd2) \
100 { \
101    static cc_c_func_ptr func = NULL; \
102    if (func == NULL) \
103       func = (cc_c_func_ptr) (intptr_t) dlsym (NULL, "mpc_"#funcname); \
104    MPC_LOGGING_FUNC_TYPE (funcname, cc_c); \
105    MPC_LOGGING_OUT_PREC (rop1); \
106    MPC_LOGGING_OUT_PREC (rop2); \
107    MPC_LOGGING_OUT_C (op); \
108    fprintf (stderr, "\n"); \
109    return func (rop1, rop2, op, rnd1, rnd2); \
110 }
111 
112 MPC_LOGGING_C_C (sqr)
113 MPC_LOGGING_C_C (conj)
114 MPC_LOGGING_C_C (neg)
115 MPC_LOGGING_C_C (sqrt)
116 MPC_LOGGING_C_C (proj)
117 MPC_LOGGING_C_C (exp)
118 MPC_LOGGING_C_C (log)
119 MPC_LOGGING_C_C (sin)
120 MPC_LOGGING_C_C (cos)
121 MPC_LOGGING_C_C (tan)
122 MPC_LOGGING_C_C (sinh)
123 MPC_LOGGING_C_C (cosh)
124 MPC_LOGGING_C_C (tanh)
125 MPC_LOGGING_C_C (asin)
126 MPC_LOGGING_C_C (acos)
127 MPC_LOGGING_C_C (atan)
128 MPC_LOGGING_C_C (asinh)
129 MPC_LOGGING_C_C (acosh)
130 MPC_LOGGING_C_C (atanh)
131 
132 MPC_LOGGING_C_CC (add)
133 MPC_LOGGING_C_CC (sub)
134 MPC_LOGGING_C_CC (mul)
135 MPC_LOGGING_C_CC (div)
136 MPC_LOGGING_C_CC (pow)
137 
138 MPC_LOGGING_C_CCC (fma)
139 
140 MPC_LOGGING_CC_C (sin_cos)
141