diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | configure.ac | 28 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/logging.c | 104 | ||||
-rw-r--r-- | src/mpc-log.h | 48 |
6 files changed, 187 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index ac6a49f..27d260c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,5 +3,6 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = src tests doc -include_HEADERS = src/mpc.h +EXTRA_HEADERS = src/mpc-log.h +include_HEADERS = src/mpc.h @MPC_LOG_H@ EXTRA_DIST = Makefile.vc tests/tgeneric.c @@ -22,3 +22,8 @@ Code clean-up: - from Andreas Enge 12 January 2011 factor out code such as test_failed in ttan.c, error message in bug20090105 of tcos.c etc. into one macro in mpc-tests.h +- from Andreas Enge 12 January 2011 + in tests, replace CCC by C_CC - one output, two inputs, to be able to + write generic reuse tests and data files for the case CC_C presented by + sin_cos + diff --git a/configure.ac b/configure.ac index 565916d..fa49e9e 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,17 @@ AC_ARG_WITH([gmp], AC_MSG_FAILURE([Do not use --with-gmp and --with-gmp-include/--with-gmp-lib options simultaneously.]) fi ]) +AC_ARG_ENABLE([logging], + [AC_HELP_STRING([--enable-logging], + [enable logging of function calls to stderr (default = no)])], + [case $enableval in + yes) ;; + no) ;; + *) AC_MSG_ERROR([Bad value for --enable-logging: Use yes or no]) ;; + esac + ] + ) + dnl Setup CC and CFLAGS @@ -163,13 +174,28 @@ error # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([complex.h locale.h inttypes.h limits.h unistd.h sys/time.h]) +AC_CHECK_HEADERS([complex.h locale.h inttypes.h stdint.h limits.h unistd.h sys/time.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_SIZE_T AC_HEADER_TIME +# Check for logging feature +AS_IF([test "x$enable_logging" = "xyes"], + [AC_CHECK_HEADERS([dlfcn.h]) + AC_CHECK_LIB([dl],[dlsym], + [ + AC_DEFINE(HAVE_LIBDL, 1, [Library dl present]) + LIBS="-ldl $LIBS" + AC_TYPE_INTPTR_T + AC_LIBOBJ([logging]) + AC_SUBST([MPC_LOG_H],[src/mpc-log.h]) + ], + [AC_MSG_ERROR([Library dl not found, logging impossible])]) + ] + ) + # Checks if compiler accepts warning flags. MPC_PROG_CC_WARNINGCFLAGS([WARNINGCFLAGS]) diff --git a/src/Makefile.am b/src/Makefile.am index 80e17ab..b9cb03b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,3 +14,4 @@ libmpc_la_SOURCES = mpc-impl.h abs.c acos.c acosh.c add.c add_fr.c \ sub.c sub_fr.c sub_ui.c swap.c tan.c tanh.c uceil_log2.c ui_div.c \ ui_ui_sub.c +libmpc_la_LIBADD = @LTLIBOBJS@ diff --git a/src/logging.c b/src/logging.c new file mode 100644 index 0000000..fb91290 --- /dev/null +++ b/src/logging.c @@ -0,0 +1,104 @@ +/* logging.c -- "Dummy" functions logging calls to real mpc functions. + +Copyright (C) 2011 Andreas Enge + +This file is part of the MPC Library. + +The MPC Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPC Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPC Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. */ + +#include "config.h" +#include <stdio.h> + +#ifdef HAVE_INTTYPES_H +#include <inttypes.h> +#endif +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif + +#include "mpc-log.h" +#include "mpc-impl.h" + +#include <dlfcn.h> + +typedef int (*c_cc_func_ptr) (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t); +typedef int (*c_c_func_ptr) (mpc_ptr, mpc_srcptr, mpc_rnd_t); + +#define MPC_LOGGING_OUT_PREC(z) \ + do { \ + fprintf (stderr, " %li %li", (long) mpfr_get_prec (mpc_realref (z)), \ + (long) mpfr_get_prec (mpc_imagref (z))); \ + } while (0); + +#define MPC_LOGGING_OUT_C(z) \ + do { \ + MPC_LOGGING_OUT_PREC (z); \ + fprintf (stderr, " "); \ + mpc_out_str (stderr, 16, 0, z, MPC_RNDNN); \ + } while (0); + +#define MPC_LOGGING_C_CC(funcname) \ +__MPC_DECLSPEC int mpc_log_##funcname (mpc_ptr rop, mpc_srcptr op1, mpc_srcptr op2, mpc_rnd_t rnd) \ +{ \ + static c_cc_func_ptr func = NULL; \ + if (func == NULL) \ + func = (c_cc_func_ptr) (intptr_t) dlsym (NULL, "mpc_"#funcname); \ + fprintf (stderr, #funcname" c_cc"); \ + MPC_LOGGING_OUT_PREC (rop); \ + MPC_LOGGING_OUT_C (op1); \ + MPC_LOGGING_OUT_C (op2); \ + fprintf (stderr, "\n"); \ + return func (rop, op1, op2, rnd); \ +} + +#define MPC_LOGGING_C_C(funcname) \ +__MPC_DECLSPEC int mpc_log_##funcname (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) \ +{ \ + static c_c_func_ptr func = NULL; \ + if (func == NULL) \ + func = (c_c_func_ptr) (intptr_t) dlsym (NULL, "mpc_"#funcname); \ + fprintf (stderr, #funcname" c_c"); \ + MPC_LOGGING_OUT_PREC (rop); \ + MPC_LOGGING_OUT_C (op); \ + fprintf (stderr, "\n"); \ + return func (rop, op, rnd); \ +} + +MPC_LOGGING_C_CC (add) +MPC_LOGGING_C_CC (sub) +MPC_LOGGING_C_CC (mul) +MPC_LOGGING_C_CC (div) +MPC_LOGGING_C_CC (pow) + +MPC_LOGGING_C_C (sqr) +MPC_LOGGING_C_C (conj) +MPC_LOGGING_C_C (neg) +MPC_LOGGING_C_C (sqrt) +MPC_LOGGING_C_C (proj) +MPC_LOGGING_C_C (exp) +MPC_LOGGING_C_C (log) +MPC_LOGGING_C_C (sin) +MPC_LOGGING_C_C (cos) +MPC_LOGGING_C_C (tan) +MPC_LOGGING_C_C (sinh) +MPC_LOGGING_C_C (cosh) +MPC_LOGGING_C_C (tanh) +MPC_LOGGING_C_C (asin) +MPC_LOGGING_C_C (acos) +MPC_LOGGING_C_C (atan) +MPC_LOGGING_C_C (asinh) +MPC_LOGGING_C_C (acosh) +MPC_LOGGING_C_C (atanh) diff --git a/src/mpc-log.h b/src/mpc-log.h new file mode 100644 index 0000000..55e6f21 --- /dev/null +++ b/src/mpc-log.h @@ -0,0 +1,48 @@ +/* mpc-log.h -- Include file to enable function call logging; replaces mpc.h. + +Copyright (C) 2011 Andreas Enge + +This file is part of the MPC Library. + +The MPC Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPC Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPC Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. */ + +#define mpc_add mpc_log_add +#define mpc_sub mpc_log_sub +#define mpc_mul mpc_log_mul +#define mpc_div mpc_log_div +#define mpc_pow mpc_log_pow + +#define mpc_sqr mpc_log_sqr +#define mpc_conj mpc_log_conj +#define mpc_neg mpc_log_neg +#define mpc_sqrt mpc_log_sqrt +#define mpc_proj mpc_log_proj +#define mpc_exp mpc_log_exp +#define mpc_log mpc_log_log +#define mpc_sin mpc_log_sin +#define mpc_cos mpc_log_cos +#define mpc_tan mpc_log_tan +#define mpc_sinh mpc_log_sinh +#define mpc_cosh mpc_log_cosh +#define mpc_tanh mpc_log_tanh +#define mpc_asin mpc_log_asin +#define mpc_acos mpc_log_acos +#define mpc_atan mpc_log_atan +#define mpc_asinh mpc_log_asinh +#define mpc_acosh mpc_log_acosh +#define mpc_atanh mpc_log_atanh + +#include "mpc.h" |