Update libc.pot for 2.35 release.
[glibc.git] / benchtests / Makefile
blob4c6af01c5f70a58d8d398eb56b33d12b340943a8
1 # Copyright (C) 2013-2022 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 # <https://www.gnu.org/licenses/>.
18 # Makefile for benchmark tests. The only useful target here is `bench`.
19 # Add benchmark functions in alphabetical order.
21 subdir := benchtests
23 include ../Makeconfig
25 bench-math := \
26 acos \
27 acosh \
28 asin \
29 asinh \
30 atan \
31 atan2 \
32 atanh \
33 cbrt \
34 cos \
35 cosf \
36 cosh \
37 erf \
38 erfc \
39 exp \
40 exp10 \
41 exp10f \
42 exp2 \
43 exp2f \
44 expf \
45 expm1 \
46 fmax \
47 fmaxf \
48 fmin \
49 fminf \
50 hypot \
51 hypotf \
52 ilogb \
53 ilogbf \
54 isfinite \
55 isinf \
56 isnan \
57 j0 \
58 j1 \
59 lgamma \
60 log \
61 log10 \
62 log1p \
63 log2 \
64 log2f \
65 logb \
66 logbf \
67 logf \
68 modf \
69 pow \
70 powf \
71 rint \
72 roundeven \
73 roundevenf \
74 sin \
75 sincos \
76 sincosf \
77 sinf \
78 sinh \
79 sqrt \
80 tan \
81 tanh \
82 tgamma \
83 trunc \
84 truncf \
85 y0 \
86 y1 \
88 ifneq (,$(filter yes,$(float96-fcts)))
89 bench-math += cbrtl
90 endif
92 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
93 bench-math += expf128 powf128 sinf128 ilogbf128
94 endif
96 bench-pthread := pthread_once thread_create pthread-locks
98 bench-string := ffs ffsll
100 ifeq (${BENCHSET},)
101 bench := $(bench-math) $(bench-pthread) $(bench-string)
102 else
103 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
104 endif
106 # String function benchmarks.
107 string-benchset := memccpy memchr memcmp memcmpeq memcpy memmem memmove \
108 mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
109 strcat strchr strchrnul strcmp strcpy strcspn strlen \
110 strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
111 strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
112 strcoll memcpy-large memcpy-random memmove-large memset-large \
113 memcpy-walk memset-walk memmove-walk
115 # Build and run locale-dependent benchmarks only if we're building natively.
116 ifeq (no,$(cross-compiling))
117 wcsmbs-benchset := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
118 wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
119 wmemchr wmemset wmemcmp
120 else
121 wcsmbs-benchset :=
122 endif
124 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
126 ifeq (no,$(cross-compiling))
127 # We have to generate locales
128 LOCALES := en_US.UTF-8 tr_TR.UTF-8 cs_CZ.UTF-8 fa_IR.UTF-8 fr_FR.UTF-8 \
129 ja_JP.UTF-8 si_LK.UTF-8 en_GB.UTF-8 vi_VN.UTF-8 ar_SA.UTF-8 \
130 da_DK.UTF-8 pl_PL.UTF-8 pt_PT.UTF-8 el_GR.UTF-8 ru_RU.UTF-8 \
131 he_IL.UTF-8 is_IS.UTF-8 es_ES.UTF-8 hi_IN.UTF-8 sv_SE.UTF-8 \
132 hu_HU.UTF-8 it_IT.UTF-8 sr_RS.UTF-8 zh_CN.UTF-8
133 include ../gen-locales.mk
134 endif
136 stdlib-benchset := strtod
138 stdio-common-benchset := sprintf
140 math-benchset := math-inlines
142 ifeq (${BENCHSET},)
143 benchset := $(string-benchset-all) $(stdlib-benchset) $(stdio-common-benchset) \
144 $(math-benchset)
145 else
146 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
147 endif
149 CFLAGS-bench-ffs.c += -fno-builtin
150 CFLAGS-bench-ffsll.c += -fno-builtin
151 CFLAGS-bench-sqrt.c += -fno-builtin
152 CFLAGS-bench-fmin.c += -fno-builtin
153 CFLAGS-bench-fminf.c += -fno-builtin
154 CFLAGS-bench-fmax.c += -fno-builtin
155 CFLAGS-bench-fmaxf.c += -fno-builtin
156 CFLAGS-bench-trunc.c += -fno-builtin
157 CFLAGS-bench-truncf.c += -fno-builtin
158 CFLAGS-bench-roundeven.c += -fno-builtin
159 CFLAGS-bench-roundevenf.c += -fno-builtin
160 CFLAGS-bench-isnan.c += -fsignaling-nans
161 CFLAGS-bench-isinf.c += -fsignaling-nans
162 CFLAGS-bench-isfinite.c += -fsignaling-nans
164 ifeq (${BENCHSET},)
165 bench-malloc := malloc-thread malloc-simple
166 else
167 bench-malloc := $(filter malloc-%,${BENCHSET})
168 endif
170 ifeq (${STATIC-BENCHTESTS},yes)
171 +link-benchtests = $(+link-static-tests)
172 link-libc-benchtests = $(link-libc-static)
173 libm-benchtests = $(common-objpfx)math/libm.a
174 thread-library-benchtests = $(static-thread-library)
175 else
176 link-libc-benchtests = $(link-libc)
177 +link-benchtests = $(+link-tests)
178 thread-library-benchtests = $(shared-thread-library)
179 libm-benchtests = $(libm)
180 endif
182 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
183 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
184 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
185 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
186 $(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
190 # Rules to build and execute the benchmarks. Do not put any benchmark
191 # parameters beyond this point.
193 # We don't want the benchmark programs to run in parallel since that could
194 # affect their performance.
195 .NOTPARALLEL:
197 bench-extra-objs = json-lib.o
199 extra-objs += $(bench-extra-objs)
200 others-extras = $(bench-extra-objs)
202 include ../Rules
204 binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
205 binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
206 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
208 # The default duration: 1 seconds.
209 ifndef BENCH_DURATION
210 BENCH_DURATION := 1
211 endif
213 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
215 # Use clock_gettime to measure performance of functions. The default is
216 # to use the architecture-specific high precision timing instructions.
217 ifdef USE_CLOCK_GETTIME
218 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
219 else
220 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
221 # of functions. All x86 processors since 2010 support RDTSCP instruction.
222 ifdef USE_RDTSCP
223 CPPFLAGS-nonlib += -DUSE_RDTSCP
224 endif
225 endif
227 DETAILED_OPT :=
229 ifdef DETAILED
230 DETAILED_OPT := -d
231 endif
233 bench-deps := bench-skeleton.c bench-timing.h Makefile
235 run-bench = $(test-wrapper-env) \
236 $(run-program-env) \
237 $($*-ENV) $(test-via-rtld-prefix) $${run}
239 timing-type := $(objpfx)bench-timing-type
241 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
242 # for all these modules.
243 cpp-srcs-left := $(binaries-benchset:=.c) $(binaries-bench:=.c) \
244 $(binaries-bench-malloc:=.c) $(timing-type:=.c)
245 lib := nonlib
246 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
248 bench-clean:
249 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
250 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
251 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
252 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
253 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
255 # Validate the passed in BENCHSET
256 ifneq ($(strip ${BENCHSET}),)
257 VALIDBENCHSETNAMES := bench-pthread bench-math bench-string string-benchset \
258 wcsmbs-benchset stdlib-benchset stdio-common-benchset math-benchset \
259 malloc-thread malloc-simple
260 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
261 ifneq (${INVALIDBENCHSETNAMES},)
262 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
263 $(info The valid ones are: ${VALIDBENCHSETNAMES})
264 $(error Invalid BENCHSET value)
265 endif
266 endif
268 bench: bench-build bench-set bench-func bench-malloc
270 # Target to only build the benchmark without running it. We generate locales
271 # only if we're building natively.
272 ifeq (no,$(cross-compiling))
273 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
274 $(binaries-benchset) $(binaries-bench-malloc)
275 else
276 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
277 $(binaries-bench-malloc)
278 endif
280 bench-set: $(binaries-benchset)
281 for run in $^; do \
282 echo "Running $${run}"; \
283 $(run-bench) > $${run}.out; \
284 done
286 bench-malloc: $(binaries-bench-malloc)
287 for run in $^; do \
288 echo "$${run}"; \
289 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
290 for thr in 1 8 16 32; do \
291 echo "Running $${run} $${thr}"; \
292 $(run-bench) $${thr} > $${run}-$${thr}.out; \
293 done;\
294 else \
295 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
296 echo "Running $${run} $${thr}"; \
297 $(run-bench) $${thr} > $${run}-$${thr}.out; \
298 done;\
299 fi;\
300 done
302 # Build and execute the benchmark functions. This target generates JSON
303 # formatted bench.out. Each of the programs produce independent JSON output,
304 # so one could even execute them individually and process it using any JSON
305 # capable language or tool.
306 bench-func: $(binaries-bench)
307 if [ -n '$^' ] ; then \
308 { timing_type=$$($(test-wrapper-env) \
309 $(run-program-env) \
310 $(test-via-rtld-prefix) \
311 $(timing-type)); \
312 echo "{\"timing_type\": \"$${timing_type}\","; \
313 echo " \"functions\": {"; \
314 for run in $^; do \
315 if ! [ "x$${run}" = "x$<" ]; then \
316 echo ","; \
317 fi; \
318 echo "Running $${run}" >&2; \
319 $(run-bench) $(DETAILED_OPT); \
320 done; \
321 echo; \
322 echo " }"; \
323 echo "}"; \
324 } > $(objpfx)bench.out-tmp; \
325 if [ -f $(objpfx)bench.out ]; then \
326 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
327 fi; \
328 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
329 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
330 scripts/benchout.schema.json; \
333 ifeq ($(bind-now),yes)
334 link-bench-bind-now = -Wl,-z,now
335 endif
337 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
338 $(binaries-bench-malloc)
340 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
341 $(link-extra-libs-tests) \
342 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
343 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
344 $(+link-benchtests)
346 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
348 $(objpfx)bench-%.c: %-inputs $(bench-deps)
349 { if [ -n "$($*-INCLUDE)" ]; then \
350 cat $($*-INCLUDE); \
351 fi; \
352 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
353 mv -f $@-tmp $@