build-many-glibcs.py: Add openrisc hard float glibc variant
[glibc.git] / benchtests / Makefile
blob7e73b8504e3c4ded597d98b2afd6189c961d8f82
1 # Copyright (C) 2013-2024 Free Software Foundation, Inc.
2 # Copyright The GNU Toolchain Authors.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <https://www.gnu.org/licenses/>.
19 # Makefile for benchmark tests. The only useful target here is `bench`.
20 # Add benchmark functions in alphabetical order.
22 subdir := benchtests
24 include ../Makeconfig
26 bench-math := \
27 acos \
28 acosh \
29 asin \
30 asinh \
31 atan \
32 atan2 \
33 atanh \
34 cbrt \
35 ceil \
36 ceilf \
37 cos \
38 cosf \
39 cosh \
40 erf \
41 erfc \
42 exp \
43 exp10 \
44 exp10f \
45 exp2 \
46 exp2f \
47 expf \
48 expm1 \
49 floor \
50 floorf \
51 fmax \
52 fmaxf \
53 fmin \
54 fminf \
55 fmod \
56 fmodf \
57 hypot \
58 hypotf \
59 ilogb \
60 ilogbf \
61 isfinite \
62 isinf \
63 isnan \
64 j0 \
65 j1 \
66 lgamma \
67 llrint \
68 llrintf \
69 log \
70 log10 \
71 log1p \
72 log2 \
73 log2f \
74 logb \
75 logbf \
76 logf \
77 lrint \
78 lrintf \
79 modf \
80 nearbyint \
81 nearbyintf \
82 pow \
83 powf \
84 rint \
85 rintf \
86 roundeven \
87 roundevenf \
88 sin \
89 sincos \
90 sincosf \
91 sinf \
92 sinh \
93 sqrt \
94 tan \
95 tanh \
96 tgamma \
97 trunc \
98 truncf \
99 y0 \
100 y1 \
101 # bench-math
103 ifneq (,$(filter yes,$(float96-fcts)))
104 bench-math += \
105 cbrtl \
106 # bench-math
107 endif
109 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
110 bench-math += \
111 expf128 \
112 ilogbf128 \
113 powf128 \
114 sinf128 \
115 # bench-math
116 endif
118 bench-pthread := \
119 pthread-locks \
120 pthread-mutex-lock \
121 pthread-mutex-trylock \
122 pthread-spin-lock \
123 pthread-spin-trylock \
124 pthread_once \
125 thread_create \
126 # bench-pthread
128 LDLIBS-bench-pthread-mutex-lock += -lm
129 LDLIBS-bench-pthread-mutex-trylock += -lm
130 LDLIBS-bench-pthread-spin-lock += -lm
131 LDLIBS-bench-pthread-spin-trylock += -lm
133 bench-string := \
134 ffs \
135 ffsll \
136 # bench-string
138 # String function benchmarks.
139 string-benchset := \
140 bzero \
141 bzero-large \
142 bzero-walk \
143 memccpy \
144 memchr \
145 memcmp \
146 memcmpeq \
147 memcpy \
148 memcpy-large \
149 memcpy-random \
150 memcpy-walk \
151 memmem \
152 memmove \
153 memmove-large \
154 memmove-walk \
155 mempcpy \
156 memrchr \
157 memset \
158 memset-large \
159 memset-walk \
160 memset-zero \
161 memset-zero-large \
162 memset-zero-walk \
163 rawmemchr \
164 stpcpy \
165 stpcpy_chk \
166 stpncpy \
167 strcasecmp \
168 strcasestr \
169 strcat \
170 strchr \
171 strchrnul \
172 strcmp \
173 strcoll \
174 strcpy \
175 strcpy_chk \
176 strcspn \
177 strlen \
178 strncasecmp \
179 strncat \
180 strncmp \
181 strncpy \
182 strnlen \
183 strpbrk \
184 strrchr \
185 strsep \
186 strspn \
187 strstr \
188 strtok \
189 # string-benchset
191 # Build and run locale-dependent benchmarks only if we're building natively.
192 ifeq (no,$(cross-compiling))
193 wcsmbs-benchset := \
194 wcpcpy \
195 wcpncpy \
196 wcrtomb \
197 wcscat \
198 wcschr \
199 wcschrnul \
200 wcscmp \
201 wcscpy \
202 wcscspn \
203 wcslen \
204 wcsncat \
205 wcsncmp \
206 wcsncpy \
207 wcsnlen \
208 wcspbrk \
209 wcsrchr \
210 wcsspn \
211 wmemchr \
212 wmemcmp \
213 wmemset \
214 # wcsmbs-benchset
215 else
216 wcsmbs-benchset :=
217 endif
219 string-benchset-all := $(string-benchset) ${wcsmbs-benchset}
221 ifeq (no,$(cross-compiling))
222 # We have to generate locales
223 LOCALES := \
224 ar_SA.UTF-8 \
225 cs_CZ.UTF-8 \
226 da_DK.UTF-8 \
227 el_GR.UTF-8 \
228 en_GB.UTF-8 \
229 en_US.UTF-8 \
230 es_ES.UTF-8 \
231 fa_IR.UTF-8 \
232 fr_FR.UTF-8 \
233 he_IL.UTF-8 \
234 hi_IN.UTF-8 \
235 hu_HU.UTF-8 \
236 is_IS.UTF-8 \
237 it_IT.UTF-8 \
238 ja_JP.UTF-8 \
239 pl_PL.UTF-8 \
240 pt_PT.UTF-8 \
241 ru_RU.UTF-8 \
242 si_LK.UTF-8 \
243 sr_RS.UTF-8 \
244 sv_SE.UTF-8 \
245 tr_TR.UTF-8 \
246 vi_VN.UTF-8 \
247 zh_CN.UTF-8 \
248 # LOCALES
249 include ../gen-locales.mk
250 endif
252 hash-benchset := \
253 dl-elf-hash \
254 dl-new-hash \
255 nss-hash \
256 # hash-benchset
258 stdlib-benchset := \
259 arc4random \
260 random-lock \
261 strtod \
262 # stdlib-benchset
264 stdio-common-benchset := sprintf
266 math-benchset := math-inlines
268 ifeq (${BENCHSET},)
269 benchset := \
270 $(hash-benchset) \
271 $(math-benchset) \
272 $(stdio-common-benchset) \
273 $(stdlib-benchset) \
274 $(string-benchset-all) \
275 # benchset
276 else
277 benchset := $(foreach B,$(filter %-benchset,${BENCHSET}), ${${B}})
278 endif
280 CFLAGS-bench-ffs.c += -fno-builtin
281 CFLAGS-bench-ffsll.c += -fno-builtin
282 CFLAGS-bench-sqrt.c += -fno-builtin
283 CFLAGS-bench-fmin.c += -fno-builtin
284 CFLAGS-bench-fminf.c += -fno-builtin
285 CFLAGS-bench-fmax.c += -fno-builtin
286 CFLAGS-bench-fmaxf.c += -fno-builtin
287 CFLAGS-bench-trunc.c += -fno-builtin
288 CFLAGS-bench-truncf.c += -fno-builtin
289 CFLAGS-bench-roundeven.c += -fno-builtin
290 CFLAGS-bench-roundevenf.c += -fno-builtin
291 CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
292 CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
293 CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
295 ifeq (${BENCHSET},)
296 bench-malloc := \
297 malloc-simple \
298 malloc-thread \
299 # bench-malloc
300 else
301 bench-malloc := $(filter malloc-%,${BENCHSET})
302 endif
304 ifeq (${STATIC-BENCHTESTS},yes)
305 +link-benchtests = $(+link-static-tests)
306 link-libc-benchtests = $(link-libc-static)
307 libm-benchtests = $(common-objpfx)math/libm.a
308 thread-library-benchtests = $(static-thread-library)
309 else
310 link-libc-benchtests = $(link-libc)
311 +link-benchtests = $(+link-tests)
312 thread-library-benchtests = $(shared-thread-library)
313 libm-benchtests = $(libm)
314 endif
316 $(addprefix $(objpfx)bench-,$(bench-math)): $(libm-benchtests)
317 $(addprefix $(objpfx)bench-,$(math-benchset)): $(libm-benchtests)
318 $(addprefix $(objpfx)bench-,$(bench-pthread)): $(thread-library-benchtests)
319 $(addprefix $(objpfx)bench-,$(bench-malloc)): $(thread-library-benchtests)
320 $(addprefix $(objpfx)bench-,pthread-locks): $(libm-benchtests)
321 $(addprefix $(objpfx)bench-,pthread-mutex-locks): $(libm-benchtests)
325 # Rules to build and execute the benchmarks. Do not put any benchmark
326 # parameters beyond this point.
328 # We don't want the benchmark programs to run in parallel since that could
329 # affect their performance.
330 .NOTPARALLEL:
332 bench-extra-objs = json-lib.o
334 extra-objs += $(bench-extra-objs)
335 others-extras = $(bench-extra-objs)
337 # The default duration: 1 seconds.
338 ifndef BENCH_DURATION
339 BENCH_DURATION := 1
340 endif
342 CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
344 # Use clock_gettime to measure performance of functions. The default is
345 # to use the architecture-specific high precision timing instructions.
346 ifdef USE_CLOCK_GETTIME
347 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
348 else
349 # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
350 # of functions. All x86 processors since 2010 support RDTSCP instruction.
351 ifdef USE_RDTSCP
352 CPPFLAGS-nonlib += -DUSE_RDTSCP
353 endif
354 endif
356 DETAILED_OPT :=
358 ifdef DETAILED
359 DETAILED_OPT := -d
360 endif
362 bench-deps := bench-skeleton.c bench-timing.h Makefile
364 run-bench = $(test-wrapper-env) \
365 $(run-program-env) \
366 $($*-ENV) $(test-via-rtld-prefix) $${run}
368 timing-type := $(objpfx)bench-timing-type
369 extra-objs += bench-timing-type.o
371 include ../Rules
373 bench-math += $(bench-libmvec)
375 ifeq (${BENCHSET},)
376 bench := \
377 $(bench-math) \
378 $(bench-pthread) \
379 $(bench-string) \
380 # bench
381 else
382 bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}})
383 endif
385 # NB: Use "=" instead of ":=" since sysdeps Makefiles may add more
386 # benches.
387 binaries-bench = $(addprefix $(objpfx)bench-,$(bench))
388 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench)))
389 binaries-benchset = $(addprefix $(objpfx)bench-,$(benchset))
390 extra-objs += $(addsuffix .o,$(addprefix bench-,$(benchset)))
391 binaries-bench-malloc := $(addprefix $(objpfx)bench-,$(bench-malloc))
392 extra-objs += $(addsuffix .o,$(addprefix bench-,$(bench-malloc)))
394 # This makes sure CPPFLAGS-nonlib and CFLAGS-nonlib are passed
395 # for all these modules.
396 cpp-srcs-left := \
397 $(binaries-bench-malloc:=.c) \
398 $(binaries-bench:=.c) \
399 $(binaries-benchset:=.c) \
400 $(timing-type:=.c) \
401 # cpp-srcs-left
402 lib := nonlib
403 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
405 bench-clean:
406 rm -f $(binaries-bench) $(addsuffix .o,$(binaries-bench))
407 rm -f $(binaries-benchset) $(addsuffix .o,$(binaries-benchset))
408 rm -f $(binaries-bench-malloc) $(addsuffix .o,$(binaries-bench-malloc))
409 rm -f $(timing-type) $(addsuffix .o,$(timing-type))
410 rm -f $(addprefix $(objpfx),$(bench-extra-objs))
412 # Validate the passed in BENCHSET
413 ifneq ($(strip ${BENCHSET}),)
414 VALIDBENCHSETNAMES := \
415 bench-math \
416 bench-pthread \
417 bench-string \
418 hash-benchset \
419 malloc-simple \
420 malloc-thread \
421 math-benchset \
422 stdio-common-benchset \
423 stdlib-benchset \
424 string-benchset \
425 wcsmbs-benchset \
426 # VALIDBENCHSETNAMES
428 INVALIDBENCHSETNAMES := $(filter-out ${VALIDBENCHSETNAMES},${BENCHSET})
429 ifneq (${INVALIDBENCHSETNAMES},)
430 $(info The following values in BENCHSET are invalid: ${INVALIDBENCHSETNAMES})
431 $(info The valid ones are: ${VALIDBENCHSETNAMES})
432 $(error Invalid BENCHSET value)
433 endif
434 endif
436 bench: bench-build bench-set bench-func bench-malloc
438 # Target to only build the benchmark without running it. We generate locales
439 # only if we're building natively.
440 ifeq (no,$(cross-compiling))
441 bench-build: $(gen-locales) $(timing-type) $(binaries-bench) \
442 $(binaries-benchset) $(binaries-bench-malloc)
443 else
444 bench-build: $(timing-type) $(binaries-bench) $(binaries-benchset) \
445 $(binaries-bench-malloc)
446 endif
448 bench-set: $(binaries-benchset)
449 for run in $^; do \
450 echo "Running $${run}"; \
451 $(run-bench) > $${run}.out; \
452 done
454 bench-malloc: $(binaries-bench-malloc)
455 for run in $^; do \
456 echo "$${run}"; \
457 if [ `basename $${run}` = "bench-malloc-thread" ]; then \
458 for thr in 1 8 16 32; do \
459 echo "Running $${run} $${thr}"; \
460 $(run-bench) $${thr} > $${run}-$${thr}.out; \
461 done;\
462 else \
463 for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
464 echo "Running $${run} $${thr}"; \
465 $(run-bench) $${thr} > $${run}-$${thr}.out; \
466 done;\
467 fi;\
468 done
470 # Build and execute the benchmark functions. This target generates JSON
471 # formatted bench.out. Each of the programs produce independent JSON output,
472 # so one could even execute them individually and process it using any JSON
473 # capable language or tool.
474 bench-func: $(binaries-bench)
475 if [ -n '$^' ] ; then \
476 { timing_type=$$($(test-wrapper-env) \
477 $(run-program-env) \
478 $(test-via-rtld-prefix) \
479 $(timing-type)); \
480 echo "{\"timing_type\": \"$${timing_type}\","; \
481 echo " \"functions\": {"; \
482 for run in $^; do \
483 op=$$($(run-bench) $(DETAILED_OPT)); \
484 ret=$$?; \
485 case "$${ret}" in \
486 77) \
487 echo "UNSUPPORTED $${run}: $${op}" >&2; \
488 ;; \
489 0) \
490 echo "Running $${run}" >&2; \
491 if [ "$${run}" != "$<" ]; then \
492 echo ","; \
493 fi; \
494 echo "$${op}"; \
495 ;; \
496 *) \
497 echo "FAILED $${run}" >&2; \
498 ;; \
499 esac; \
500 done; \
501 echo; \
502 echo " }"; \
503 echo "}"; \
504 } > $(objpfx)bench.out-tmp; \
505 if [ -f $(objpfx)bench.out ]; then \
506 mv -f $(objpfx)bench.out $(objpfx)bench.out.old; \
507 fi; \
508 mv -f $(objpfx)bench.out-tmp $(objpfx)bench.out; \
509 $(PYTHON) scripts/validate_benchout.py $(objpfx)bench.out \
510 scripts/benchout.schema.json; \
513 ifeq ($(bind-now),yes)
514 link-bench-bind-now = -Wl,-z,now
515 endif
517 bench-link-targets = $(timing-type) $(binaries-bench) $(binaries-benchset) \
518 $(binaries-bench-malloc)
520 $(bench-link-targets): %: %.o $(objpfx)json-lib.o \
521 $(link-extra-libs-tests) \
522 $(sort $(filter $(common-objpfx)lib%,$(link-libc-benchtests))) \
523 $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
524 $(+link-benchtests)
526 $(bench-link-targets): LDFLAGS += $(link-bench-bind-now)
528 $(objpfx)bench-%.c: %-inputs $(bench-deps)
529 { if [ -n "$($*-INCLUDE)" ]; then \
530 cat $($*-INCLUDE); \
531 fi; \
532 $(PYTHON) scripts/bench.py $(patsubst %-inputs,%,$<); } > $@-tmp
533 mv -f $@-tmp $@