1*5273c5e4Smrg /* benchtime.h -- compute the timings for the benchmark.
2*5273c5e4Smrg 
3*5273c5e4Smrg Copyright (C) 2014 INRIA - CNRS
4*5273c5e4Smrg 
5*5273c5e4Smrg This file is part of GNU MPC.
6*5273c5e4Smrg 
7*5273c5e4Smrg GNU MPC is free software; you can redistribute it and/or modify it under
8*5273c5e4Smrg the terms of the GNU Lesser General Public License as published by the
9*5273c5e4Smrg Free Software Foundation; either version 3 of the License, or (at your
10*5273c5e4Smrg option) any later version.
11*5273c5e4Smrg 
12*5273c5e4Smrg GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13*5273c5e4Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14*5273c5e4Smrg FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15*5273c5e4Smrg more details.
16*5273c5e4Smrg 
17*5273c5e4Smrg You should have received a copy of the GNU Lesser General Public License
18*5273c5e4Smrg along with this program. If not, see http://www.gnu.org/licenses/ .
19*5273c5e4Smrg */
20*5273c5e4Smrg 
21*5273c5e4Smrg 
22*5273c5e4Smrg /* compute the time to run accurately niter calls of the function for any number of inputs */
23*5273c5e4Smrg #define DECLARE_ACCURATE_TIME_NOP(func, funccall)      \
24*5273c5e4Smrg unsigned long int ACCURATE_TIME_NOP##func( unsigned long int niter, int n, mpc_t* z, mpc_t* x, mpc_t* y, int nop);\
25*5273c5e4Smrg unsigned long int ACCURATE_TIME_NOP##func( unsigned long int niter, int n, mpc_t* z, mpc_t* x, \
26*5273c5e4Smrg __attribute__ ((__unused__)) mpc_t* y, \
27*5273c5e4Smrg __attribute__ ((__unused__)) int nop)\
28*5273c5e4Smrg {                                             \
29*5273c5e4Smrg   unsigned long int i;  int kn;           \
30*5273c5e4Smrg   unsigned long int t0 = get_cputime ();      \
31*5273c5e4Smrg   for (i = niter, kn=0; i > 0; i--)           \
32*5273c5e4Smrg     {                                         \
33*5273c5e4Smrg 	  funccall;	                              \
34*5273c5e4Smrg 	  kn++; if (kn==n) kn = 0; 			      \
35*5273c5e4Smrg     }                                         \
36*5273c5e4Smrg   return get_cputime () - t0;                 \
37*5273c5e4Smrg }
38*5273c5e4Smrg 
39*5273c5e4Smrg /* address of the function to time accurately niter calls of func */
40*5273c5e4Smrg #define ADDR_ACCURATE_TIME_NOP(func) ACCURATE_TIME_NOP##func
41*5273c5e4Smrg 
42*5273c5e4Smrg /* address of the function to time one call of func */
43*5273c5e4Smrg #define ADDR_TIME_NOP(func) TIME_NOP##func
44*5273c5e4Smrg 
45*5273c5e4Smrg 
46*5273c5e4Smrg /* compute the time to run only one call of the function with two inputs  */
47*5273c5e4Smrg #define DECLARE_TIME_NOP(func, funcall, nop)				  \
48*5273c5e4Smrg  DECLARE_ACCURATE_TIME_NOP(func, funcall)					  \
49*5273c5e4Smrg  double TIME_NOP##func(int n, mpc_t* z, mpc_t* x, mpc_t* y);  \
50*5273c5e4Smrg  double TIME_NOP##func(int n, mpc_t* z, mpc_t* x, mpc_t* y)   \
51*5273c5e4Smrg  {					                                          \
52*5273c5e4Smrg   double t; unsigned long int nbcall, mytime;                 \
53*5273c5e4Smrg     for (nbcall = 1, mytime=0; mytime<25000; ) 	  \
54*5273c5e4Smrg       {									                      \
55*5273c5e4Smrg           nbcall <<= 1; \
56*5273c5e4Smrg 	   mytime = ACCURATE_TIME_NOP##func(nbcall, n, z, x, y, nop);  \
57*5273c5e4Smrg       }									                      \
58*5273c5e4Smrg       t = (double) mytime/ nbcall ;					          \
59*5273c5e4Smrg    return t;							                      \
60*5273c5e4Smrg  }
61*5273c5e4Smrg 
62*5273c5e4Smrg /* compute the time to run accurately niter calls of the function */
63*5273c5e4Smrg /* functions with 2 operands */
64*5273c5e4Smrg #define DECLARE_TIME_2OP(func)   DECLARE_TIME_NOP(func, func(z[kn],x[kn],y[kn], MPC_RNDNN), 2 )
65*5273c5e4Smrg /* functions with 1 operand */
66*5273c5e4Smrg #define DECLARE_TIME_1OP(func)   DECLARE_TIME_NOP(func, func(z[kn],x[kn], MPC_RNDNN), 1 )
67