blob: 7d573a0074ff79c84c7fa2c95a148ad7f714515c [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001# Copyright (C) 1996-2016 Free Software Foundation, Inc.
2# This file is part of the GNU C Library.
3
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.
8
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.
13
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/>.
17
18# Makefile for the math library.
19
20subdir := math
21
22include ../Makeconfig
23
24# Installed header files.
25headers := math.h bits/mathcalls.h bits/mathinline.h bits/huge_val.h \
26 bits/huge_valf.h bits/huge_vall.h bits/inf.h bits/nan.h \
27 fpu_control.h complex.h bits/cmathcalls.h fenv.h \
28 bits/fenv.h bits/fenvinline.h bits/mathdef.h tgmath.h \
29 bits/math-finite.h bits/math-vector.h \
30 bits/libm-simd-decl-stubs.h
31
32# FPU support code.
33aux := setfpucw fpu_control
34
35# Build the -lm library.
36
37extra-libs := libm
38extra-libs-others = $(extra-libs)
39
40libm-support = s_lib_version s_matherr s_signgam \
41 fclrexcpt fgetexcptflg fraiseexcpt fsetexcptflg \
42 ftestexcept fegetround fesetround fegetenv feholdexcpt \
43 fesetenv feupdateenv t_exp fedisblxcpt feenablxcpt \
44 fegetexcept
45libm-calls = e_acos e_acosh e_asin e_atan2 e_atanh e_cosh e_exp e_fmod \
46 e_hypot e_j0 e_j1 e_jn e_lgamma_r e_log e_log10 e_pow \
47 e_rem_pio2 e_remainder e_scalb e_sinh e_sqrt e_gamma_r \
48 e_ilogb \
49 k_cos k_rem_pio2 k_sin k_tan s_asinh s_atan s_cbrt \
50 s_ceil s_cos s_erf s_expm1 s_fabs \
51 s_floor s_log1p w_log1p s_logb \
52 s_nextafter s_nexttoward s_rint s_scalbln w_scalbln \
53 s_significand s_sin s_tan s_tanh w_acos w_acosh w_asin \
54 w_atan2 w_atanh w_cosh w_exp w_exp2 w_exp10 w_fmod \
55 w_tgamma w_hypot w_j0 w_j1 w_jn w_lgamma w_lgamma_r \
56 w_log w_log10 w_pow w_remainder w_scalb w_sinh w_sqrt \
57 w_ilogb \
58 s_fpclassify s_fmax s_fmin s_fdim s_nan s_trunc \
59 s_remquo e_log2 e_exp2 s_round s_nearbyint s_sincos \
60 conj cimag creal cabs carg s_cexp s_csinh s_ccosh s_clog \
61 s_catan s_casin s_ccos s_csin s_ctan s_ctanh s_cacos \
62 s_casinh s_cacosh s_catanh s_csqrt s_cpow s_cproj s_clog10 \
63 s_fma s_lrint s_llrint s_lround s_llround e_exp10 w_log2 \
64 s_issignaling $(calls:s_%=m_%) x2y2m1 k_casinh \
65 gamma_product k_standard lgamma_neg lgamma_product \
66 w_lgamma_compat
67
68dbl-only-routines := branred doasin dosincos halfulp mpa mpatan2 \
69 mpatan mpexp mplog mpsqrt mptan sincos32 slowexp \
70 slowpow sincostab
71libm-routines = $(strip $(libm-support) $(libm-calls) \
72 $(patsubst %_rf,%f_r,$(libm-calls:=f)) \
73 $(long-m-$(long-double-fcts))) \
74 $(dbl-only-routines)
75long-m-routines = $(patsubst %_rl,%l_r,$(libm-calls:=l))
76long-m-support = t_sincosl k_sincosl
77long-m-yes = $(long-m-routines) $(long-m-support)
78
79# These functions are in libc instead of libm because __printf_fp
80# calls them, so any program using printf will need them linked in,
81# and we don't want to have to link every program with -lm.
82# In libm-calls (above), list m_foo in place of s_foo for any
83# routine that should be compiled separately for its libc and libm versions.
84calls = s_isinf s_isnan s_finite s_copysign s_modf s_scalbn s_frexp s_ldexp \
85 s_signbit
86generated += $(foreach s,.c .S l.c l.S f.c f.S,$(calls:s_%=m_%$s))
87routines = $(calls) $(calls:=f) $(long-c-$(long-double-fcts))
88long-c-yes = $(calls:=l)
89
90ifeq ($(build-mathvec),yes)
91# We need to install libm.so as linker script
92# for more comfortable use of vector math library.
93install-lib-ldscripts := libm.so
94install_subdir: $(inst_libdir)/libm.so
95$(inst_libdir)/libm.so: $(common-objpfx)format.lds \
96 $(libm) \
97 $(libmvec) \
98 $(+force)
99 (echo '/* GNU ld script'; echo '*/';\
100 cat $<; \
101 echo 'GROUP ( $(slibdir)/libm.so$(libm.so-version) ' \
102 'AS_NEEDED ( $(libdir)/libmvec_nonshared.a $(slibdir)/libmvec.so$(libmvec.so-version) ) )' \
103 ) > $@
104endif
105
106# Rules for the test suite.
107tests = test-matherr test-fenv atest-exp atest-sincos atest-exp2 basic-test \
108 test-misc test-fpucw test-fpucw-ieee tst-definitions test-tgmath \
109 test-tgmath-ret bug-nextafter bug-nexttoward bug-tgmath1 \
110 test-tgmath-int test-tgmath2 test-powl tst-CMPLX tst-CMPLX2 test-snan \
111 test-fenv-tls test-fenv-preserve test-fenv-return test-fenvinline \
112 test-nearbyint-except test-fenv-clear test-signgam-finite \
113 test-signgam-finite-c99 test-signgam-finite-c11 \
114 test-nearbyint-except-2 test-signgam-uchar test-signgam-uchar-init \
115 test-signgam-uint test-signgam-uint-init test-signgam-ullong \
116 test-signgam-ullong-init test-nan-overflow test-nan-payload \
117 test-math-isinff \
118 $(tests-static)
119tests-static = test-fpucw-static test-fpucw-ieee-static \
120 test-signgam-uchar-static test-signgam-uchar-init-static \
121 test-signgam-uint-static test-signgam-uint-init-static \
122 test-signgam-ullong-static test-signgam-ullong-init-static
123# We do the `long double' tests only if this data type is available and
124# distinct from `double'.
125test-longdouble-yes = test-ldouble test-ildoubl test-ldouble-finite
126
127ifneq (no,$(PERL))
128libm-vec-tests = $(addprefix test-,$(libmvec-tests))
129libm-tests = test-float test-double $(test-longdouble-$(long-double-fcts)) \
130 test-ifloat test-idouble test-float-finite test-double-finite \
131 $(libm-vec-tests)
132libm-tests.o = $(addsuffix .o,$(libm-tests))
133
134tests += $(libm-tests)
135libm-tests-generated = libm-test-ulps.h libm-have-vector-test.h libm-test.c
136generated += $(libm-tests-generated) libm-test.stmp
137
138# This is needed for dependencies
139before-compile += $(objpfx)libm-test.c
140
141ulps-file = $(firstword $(wildcard $(sysdirs:%=%/libm-test-ulps)))
142
143$(addprefix $(objpfx), $(libm-tests-generated)): $(objpfx)libm-test.stmp
144
145$(objpfx)libm-test.stmp: $(ulps-file) libm-test.inc gen-libm-test.pl \
146 gen-libm-have-vector-test.sh auto-libm-test-out
147 $(make-target-directory)
148 $(PERL) gen-libm-test.pl -u $< -o "$(objpfx)"
149 $(SHELL) gen-libm-have-vector-test.sh > $(objpfx)libm-have-vector-test.h
150 @echo > $@
151
152$(objpfx)test-float.o: $(objpfx)libm-test.stmp
153$(objpfx)test-ifloat.o: $(objpfx)libm-test.stmp
154$(objpfx)test-float-finite.o: $(objpfx)libm-test.stmp
155$(objpfx)test-double.o: $(objpfx)libm-test.stmp
156$(objpfx)test-idouble.o: $(objpfx)libm-test.stmp
157$(objpfx)test-double-finite.o: $(objpfx)libm-test.stmp
158$(objpfx)test-ldouble.o: $(objpfx)libm-test.stmp
159$(objpfx)test-ildoubl.o: $(objpfx)libm-test.stmp
160$(objpfx)test-ldouble-finite.o: $(objpfx)libm-test.stmp
161endif
162
163libm-test-fast-math-cflags = -fno-builtin -D__FAST_MATH__ -DTEST_FAST_MATH
164libm-test-vec-cflags = $(libm-test-fast-math-cflags) -fno-inline \
165 -ffloat-store -D_OPENMP=201307 -Wno-unknown-pragmas
166
167CFLAGS-test-double-vlen2.c = $(libm-test-vec-cflags)
168
169CFLAGS-test-double-vlen4.c = $(libm-test-vec-cflags)
170CFLAGS-test-double-vlen4-wrappers.c = $(double-vlen4-arch-ext-cflags)
171
172CFLAGS-test-double-vlen8.c = $(libm-test-vec-cflags)
173CFLAGS-test-double-vlen8-wrappers.c = $(double-vlen8-arch-ext-cflags)
174
175CFLAGS-test-float-vlen4.c = $(libm-test-vec-cflags)
176
177CFLAGS-test-float-vlen8.c = $(libm-test-vec-cflags)
178CFLAGS-test-float-vlen8-wrappers.c = $(float-vlen8-arch-ext-cflags)
179
180CFLAGS-test-float-vlen16.c = $(libm-test-vec-cflags)
181CFLAGS-test-float-vlen16-wrappers.c = $(float-vlen16-arch-ext-cflags)
182
183libm-test-no-inline-cflags = -fno-inline -ffloat-store -fno-builtin
184libm-test-finite-cflags = $(libm-test-no-inline-cflags) \
185 -U__FINITE_MATH_ONLY__ -D__FINITE_MATH_ONLY__=1
186CFLAGS-test-float.c = $(libm-test-no-inline-cflags)
187CFLAGS-test-float-finite.c = $(libm-test-finite-cflags)
188CFLAGS-test-double.c = $(libm-test-no-inline-cflags)
189CFLAGS-test-double-finite.c = $(libm-test-finite-cflags)
190CFLAGS-test-ldouble.c = $(libm-test-no-inline-cflags)
191CFLAGS-test-ldouble-finite.c = $(libm-test-finite-cflags)
192CFLAGS-test-tgmath.c = -fno-builtin
193# The following testcase uses very long lines (>3 million), so it may take a
194# while to compile it. See: http://llvm.org/bugs/show_bug.cgi?id=14106 and
195# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54402
196CFLAGS-test-tgmath2.c = -fno-builtin
197CFLAGS-test-tgmath-ret.c = -fno-builtin
198CFLAGS-test-powl.c = -fno-builtin
199
200CFLAGS-test-snan.c = -fsignaling-nans
201CPPFLAGS-test-ifloat.c = -U__LIBC_INTERNAL_MATH_INLINES \
202 $(libm-test-fast-math-cflags)
203CPPFLAGS-test-idouble.c = -U__LIBC_INTERNAL_MATH_INLINES \
204 $(libm-test-fast-math-cflags)
205CPPFLAGS-test-ildoubl.c = -U__LIBC_INTERNAL_MATH_INLINES \
206 $(libm-test-fast-math-cflags)
207
208CFLAGS-test-signgam-finite.c = -ffinite-math-only
209CFLAGS-test-signgam-finite-c99.c = -ffinite-math-only -std=c99
210CFLAGS-test-signgam-finite-c11.c = -ffinite-math-only -std=c11
211CFLAGS-test-signgam-uchar.c = -std=c99
212CFLAGS-test-signgam-uchar-init.c = -std=c99
213CFLAGS-test-signgam-uchar-static.c = -std=c99
214CFLAGS-test-signgam-uchar-init-static.c = -std=c99
215CFLAGS-test-signgam-uint.c = -std=c99
216CFLAGS-test-signgam-uint-init.c = -std=c99
217CFLAGS-test-signgam-uint-static.c = -std=c99
218CFLAGS-test-signgam-uint-init-static.c = -std=c99
219CFLAGS-test-signgam-ullong.c = -std=c99
220CFLAGS-test-signgam-ullong-init.c = -std=c99
221CFLAGS-test-signgam-ullong-static.c = -std=c99
222CFLAGS-test-signgam-ullong-init-static.c = -std=c99
223
224CFLAGS-test-math-isinff.cc = -std=gnu++11
225
226# The -lieee module sets the _LIB_VERSION_ switch to IEEE mode
227# for error handling in the -lm functions.
228install-lib += libieee.a
229non-lib.a += libieee.a
230extra-objs += libieee.a ieee-math.o
231
232include ../Rules
233
234ifneq (no,$(PERL))
235# This must come after the inclusion of sysdeps Makefiles via Rules.
236$(addprefix $(objpfx), $(addsuffix .o, $(libm-vec-tests))): $(objpfx)libm-test.stmp
237
238# Run the math programs to automatically generate ULPs files.
239.PHONY: regen-ulps
240
241run-regen-ulps = $(test-wrapper-env) \
242 $(run-program-env) \
243 $($*-ENV) $(rtld-prefix) $${run}
244
245regen-ulps: $(addprefix $(objpfx),$(libm-tests))
246 rm -f $(objpfx)ULPs; rm -f $(objpfx)NewUlps; \
247 cp $(ulps-file) $(objpfx)libm-test-ulps; \
248 for run in $^; do \
249 echo "Regenerating ULPs for $${run}"; \
250 $(run-regen-ulps) -u -o $(objpfx); \
251 cat $(objpfx)ULPs >> $(objpfx)libm-test-ulps; \
252 rm $(objpfx)ULPs; \
253 done; \
254 $(PERL) gen-libm-test.pl -o $(objpfx) -n -u $(objpfx)libm-test-ulps; \
255 echo "Automatic regeneration of ULPs complete."; \
256 echo "Difference between the current baseline and the new baseline is:";\
257 diff -urN $(ulps-file) $(objpfx)NewUlps; \
258 echo "Copy $(objpfx)NewUlps to $(ulps-file) (relative to source)."
259else
260regen-ulps:
261 @echo "Automatic regeneration of ULPs requires perl."; \
262 exit 1;
263endif
264
265# The generated sysd-rules file defines rules like this for sources
266# coming from sysdeps/ directories. These rules find the generic sources.
267define o-iterator-doit
268$(objpfx)m_%$o: s_%.c $(before-compile); $$(compile-command.c)
269endef
270object-suffixes-left := $(all-object-suffixes)
271include $(o-iterator)
272
273
274# This file defines the default _LIB_VERSION variable that controls
275# the error return conventions for the math functions.
276CPPFLAGS-s_lib_version.c := -D_POSIX_MODE
277
278# We don't want the fdlibm code to use the inline math functions,
279# only the fdlibm code.
280math-CPPFLAGS += -D__NO_MATH_INLINES -D__LIBC_INTERNAL_MATH_INLINES
281
282ifneq ($(long-double-fcts),yes)
283# The `double' and `long double' types are the same on this machine.
284# We won't compile the `long double' code at all. Tell the `double' code
285# to define aliases for the `FUNCl' names. To avoid type conflicts in
286# defining those aliases, tell <math.h> to declare the `FUNCl' names with
287# `double' instead of `long double'.
288math-CPPFLAGS += -DNO_LONG_DOUBLE -D_Mlong_double_=double
289endif
290
291# The -lieee library is actually an object file.
292# The module just defines the _LIB_VERSION_ variable.
293# It's not a library to make sure it is linked in instead of s_lib_version.o.
294$(objpfx)libieee.a: $(objpfx)ieee-math.o
295 rm -f $@
296 $(patsubst %/,cd % &&,$(objpfx)) \
297 $(LN_S) $(<F) $(@F)
298
299$(addprefix $(objpfx),$(filter-out $(tests-static) $(libm-vec-tests),$(tests))): $(libm)
300$(addprefix $(objpfx),$(tests-static)): $(objpfx)libm.a
301$(addprefix $(objpfx), $(libm-vec-tests)): $(objpfx)%: $(objpfx)%-wrappers.o $(libm) \
302 $(libmvec)
303
304gmp-objs = $(patsubst %,$(common-objpfx)stdlib/%.o,\
305 add_n sub_n cmp addmul_1 mul_1 mul_n divmod_1 \
306 lshift rshift mp_clz_tab udiv_qrnnd inlines \
307 $(gmp-sysdep_routines))
308$(objpfx)atest-exp: $(gmp-objs)
309$(objpfx)atest-sincos: $(gmp-objs)
310$(objpfx)atest-exp2: $(gmp-objs)
311$(objpfx)test-fenv-tls: $(shared-thread-library)