Define NOT_IN_libc when compiling benchmark programs
[glibc.git] / benchtests / Makefile
blob5d3de5db0b48ca848bd8c8306bb7c299db08f4bf
1 # Copyright (C) 2013 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <http://www.gnu.org/licenses/>.
19 # Makefile for benchmark tests. The only useful target here is `bench`.
21 # Adding a new function `foo`:
22 # ---------------------------
24 # - Append the function name to the bench variable
26 # - Define foo-ITER with the number of iterations you want to run. Keep it
27 # high enough that the overhead of clock_gettime is only a small fraction of
28 # the total run time of the test. A good idea would be to keep the run time
29 # of each test at around 10 seconds for x86_64. That is just a guideline,
30 # since some scenarios may require higher run times.
32 # - Define foo-ARGLIST as a colon separated list of types of the input
33 # arguments. Use `void` if function does not take any inputs. Put in quotes
34 # if the input argument is a pointer, e.g.:
36 # malloc-ARGLIST: "void *"
38 # - Define foo-RET as the type the function returns. Skip if the function
39 # returns void. One could even skip foo-ARGLIST if the function does not
40 # take any inputs AND the function returns void.
43 # - Make a file called `foo-inputs` with one input value per line, an input
44 # being a comma separated list of arguments to be passed into the function.
45 # See pow-inputs for an example.
47 subdir := benchtests
48 bench := exp pow rint sin atan slowexp slowpow slowsin slowatan
50 # exp function fast path
51 exp-ITER = 5e8
52 exp-ARGLIST = double
53 exp-RET = double
54 LDFLAGS-bench-exp = -lm
56 # pow function fast path
57 pow-ITER = 2e8
58 pow-ARGLIST = double:double
59 pow-RET = double
60 LDFLAGS-bench-pow = -lm
62 rint-ITER = 250000000
63 rint-ARGLIST = double
64 rint-RET = double
65 LDFLAGS-bench-rint = -lm
67 # exp function slowest path
68 slowexp-ITER = 3e5
69 slowexp-ARGLIST = double
70 slowexp-RET = double
71 slowexp-INCLUDE = slowexp.c
72 LDFLAGS-bench-slowexp = -lm
74 # sin function fast path
75 sin-ITER = 3e9
76 sin-ARGLIST = double
77 sin-RET = double
78 LDFLAGS-bench-sin = -lm
80 # atan function fast path
81 atan-ITER = 6e9
82 atan-ARGLIST = double
83 atan-RET = double
84 LDFLAGS-bench-atan = -lm
86 # pow function slowest path
87 slowpow-ITER = 1e5
88 slowpow-ARGLIST = double:double
89 slowpow-RET = double
90 slowpow-INCLUDE = slowpow.c
91 LDFLAGS-bench-slowpow = -lm
93 # sin function slowest path
94 slowsin-ITER = 3e7
95 slowsin-ARGLIST = double
96 slowsin-RET = double
97 slowsin-INCLUDE = slowsin.c
98 LDFLAGS-bench-slowsin = -lm
100 # atan function slowest path
101 slowatan-ITER = 3e8
102 slowatan-ARGLIST = double
103 slowatan-RET = double
104 slowatan-INCLUDE = slowatan.c
105 LDFLAGS-bench-slowatan = -lm
109 # Rules to build and execute the benchmarks. Do not put any benchmark
110 # parameters beyond this point.
112 include ../Makeconfig
113 include ../Rules
115 binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
117 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
118 # for all these modules.
119 cpp-srcs-left := $(binaries-bench:=.c)
120 lib := nonlib
121 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
123 bench-deps := bench-skeleton.c Makefile
125 run-bench = $(test-wrapper-env) \
126 GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
127 $($*-ENV) $(rtld-prefix) $${run}
129 bench-clean:
130 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
132 bench: $(binaries-bench)
133 { for run in $^; do \
134 echo "Running $${run}" >&2; \
135 $(run-bench); \
136 done; } > $(objpfx)bench.out-tmp; \
137 if [ -f $(objpfx)bench.out ]; then \
138 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
139 fi; \
140 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out
142 $(binaries-bench): %: %.o \
143 $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
144 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
145 $(+link)
147 $(objpfx)bench-%.c: %-inputs $(bench-deps)
148 { if [ -n "$($*-INCLUDE)" ]; then \
149 cat $($*-INCLUDE); \
150 fi; \
151 $(..)scripts/bench.pl $(patsubst %-inputs,%,$<) \
152 $($*-ITER) $($*-ARGLIST) $($*-RET); } > $@-tmp
153 mv -f $@-tmp $@