1# Copyright (C) 1996-2022 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# <https://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 \
26		   fpu_control.h complex.h bits/cmathcalls.h fenv.h \
27		   bits/fenv.h bits/mathdef.h tgmath.h \
28		   bits/math-vector.h finclude/math-vector-fortran.h \
29		   bits/libm-simd-decl-stubs.h bits/iscanonical.h \
30		   bits/flt-eval-method.h bits/fp-fast.h bits/fp-logb.h \
31		   bits/long-double.h bits/mathcalls-helper-functions.h \
32		   bits/floatn.h bits/floatn-common.h bits/mathcalls-narrow.h
33
34# FPU support code.
35aux		:= setfpucw fpu_control
36
37# Build the -lm library.
38
39extra-libs	:= libm
40extra-libs-others = $(extra-libs)
41
42libm-support = s_lib_version s_matherr s_signgam			\
43	       fclrexcpt fgetexcptflg fraiseexcpt fsetexcptflg		\
44	       ftestexcept fegetround fesetround fegetenv feholdexcpt	\
45	       fesetenv feupdateenv fedisblxcpt feenablxcpt	\
46	       fegetexcept fesetexcept fetestexceptflag fegetmode	\
47	       fesetmode
48
49# Wrappers for these functions generated per type using a file named
50# <func>_template.c and the appropriate math-type-macros-<TYPE>.h.
51gen-libm-calls = cargF conjF cimagF crealF cabsF e_scalbF s_cacosF	  \
52	         s_cacoshF s_ccosF s_ccoshF s_casinF s_csinF s_casinhF	  \
53		 k_casinhF s_csinhF k_casinhF s_csinhF s_catanhF s_catanF \
54		 s_ctanF s_ctanhF s_cexpF s_clogF s_cprojF s_csqrtF	  \
55		 s_cpowF s_clog10F s_fdimF s_nextdownF s_fmaxF s_fminF	  \
56		 s_nanF s_iseqsigF s_canonicalizeF s_significandF	  \
57		 w_ilogbF w_llogbF					  \
58		 w_log1pF w_scalblnF s_fmaxmagF s_fminmagF w_acosF	  \
59		 w_acoshF w_asinF w_atan2F w_atanhF w_coshF w_exp10F	  \
60		 w_exp2F w_fmodF w_hypotF w_j0F w_j1F w_jnF w_logF	  \
61		 w_log10F w_log2F w_powF w_remainderF w_scalbF		  \
62		 w_sinhF w_sqrtF					  \
63		 w_tgammaF w_lgammaF w_lgammaF_r w_expF e_exp2F		  \
64		 s_fmaximumF s_fmaximum_magF s_fmaximum_numF		  \
65		 s_fmaximum_mag_numF s_fminimumF s_fminimum_magF	  \
66		 s_fminimum_numF s_fminimum_mag_numF
67
68libm-calls =								  \
69	e_acosF e_acoshF e_asinF e_atan2F e_atanhF e_coshF e_expF e_fmodF \
70	e_hypotF e_j0F e_j1F e_jnF e_lgammaF_r e_logF e_log10F e_powF	  \
71	e_remainderF e_sinhF e_sqrtF e_gammaF_r				  \
72	e_ilogbF							  \
73	k_tanF s_asinhF s_atanF s_cbrtF					  \
74	s_ceilF s_cosF s_erfF s_expm1F s_fabsF				  \
75	s_floorF s_log1pF s_logbF				  \
76	s_nextafterF s_nexttowardF s_rintF s_scalblnF			  \
77	s_sinF s_tanF s_tanhF						  \
78	s_fpclassifyF s_truncF						  \
79	s_remquoF e_log2F s_roundF s_nearbyintF s_sincosF		  \
80	s_fmaF s_lrintF s_llrintF s_lroundF s_llroundF e_exp10F		  \
81	s_issignalingF $(calls:s_%=m_%) x2y2m1F				  \
82	gamma_productF lgamma_negF lgamma_productF			  \
83	s_nextupF s_totalorderF s_totalordermagF s_getpayloadF		  \
84	s_setpayloadF s_setpayloadsigF s_roundevenF s_fromfpF s_ufromfpF  \
85	s_fromfpxF s_ufromfpxF $(gen-libm-calls)
86
87libm-compat-calls =							\
88	w_acosF_compat w_acoshF_compat w_asinF_compat w_atan2F_compat	\
89	w_atanhF_compat w_coshF_compat w_exp2F_compat w_exp10F_compat	\
90	w_fmodF_compat w_hypotF_compat w_j0F_compat w_j1F_compat	\
91	w_jnF_compat w_log2F_compat w_log10F_compat w_logF_compat	\
92	w_powF_compat w_remainderF_compat w_scalbF_compat		\
93	w_sinhF_compat w_sqrtF_compat w_tgammaF_compat			\
94	w_lgammaF_r_compat w_lgammaF_compat2 w_expF_compat		\
95	w_lgamma_compatF k_standardF
96
97libm-narrow-fns = add div fma mul sqrt sub
98libm-narrow-types-basic = s_fF s_f32xFf64
99libm-narrow-types-ldouble-yes = s_fFl s_dFl
100libm-narrow-types-float128-yes = s_f32Ff128 s_f64Ff128 s_f64xFf128
101libm-narrow-types-float128-alias-yes = s_f64xFf128
102libm-narrow-types = $(libm-narrow-types-basic) \
103		    $(libm-narrow-types-ldouble-$(long-double-fcts)) \
104		    $(libm-narrow-types-float128-$(float128-fcts)) \
105		    $(libm-narrow-types-float128-alias-$(float128-alias-fcts))
106
107# Type specific routine support.
108#
109# The following three variables control what is included for each type:
110#
111# type-floatN-suffix = The suffix of the type
112# type-floatN-routines = Type specific support objects
113# type-floatN-yes = If the type is supported, evaluates to floatN
114#
115# Finally, note that types is an intentionally recursive variable.
116# We only know the full set of supported types for the target machine
117# after the Rules makefile has been parsed.
118types-basic = $(type-ldouble-$(long-double-fcts)) double float
119
120# Like types, but includes types whose functions alias those for
121# another type.
122test-types-basic = ldouble double float
123
124# long double support
125type-ldouble-suffix := l
126type-ldouble-routines := t_sincosl k_sinl k_cosl k_sincosl s_iscanonicall \
127			 e_rem_pio2l
128type-ldouble-yes := ldouble
129
130# double support
131type-double-suffix :=
132type-double-routines := branred k_rem_pio2 	\
133		       sincostab math_err e_exp_data e_log_data	\
134		       e_log2_data e_pow_log_data
135
136# float support
137type-float-suffix := f
138type-float-routines := math_errf e_exp2f_data e_logf_data	\
139		       e_log2f_data e_powf_log2_data s_sincosf_data
140
141# _Float128 support
142type-float128-suffix := f128
143type-float128-routines := t_sincosf128 k_sinf128 k_cosf128 k_sincosf128 \
144			  e_rem_pio2f128
145type-float128-yes := float128
146
147# _Float64x may be supported, only as an alias type.
148type-float64x-yes := float64x
149
150# IBM long double support in additional to IEEE 128 long double support
151type-ibm128-suffix := l
152type-ibm128-yes := ibm128
153
154types = $(types-basic) $(type-float128-$(float128-fcts))
155test-types = $(test-types-basic) $(type-float128-$(float128-fcts)) \
156	     float32 float64 $(type-float128-$(float128-alias-fcts)) \
157	     float32x $(type-float64x-$(float64x-alias-fcts)) \
158	     $(type-ibm128-$(ibm128-fcts))
159
160# Pairs of types for which narrowing functions should be tested (this
161# variable has more entries than libm-narrow-types because it includes
162# pairs for which the functions sometimes or always alias functions
163# for other types). This definition embeds the assumption that if
164# _Float64x is supported, so is _Float128, and vice versa (they may or
165# may not have the same format).
166test-type-pairs = float-double float-ldouble double-ldouble \
167		  float32-float64 float32-float32x float32x-float64 \
168		  $(test-type-pairs-f64xf128-$(float128-fcts)) \
169		  $(test-type-pairs-f64xf128-$(float128-alias-fcts))
170test-type-pairs-f64xf128-yes = float32-float64x float32-float128 \
171			       float64-float64x float64-float128 \
172			       float32x-float64x float32x-float128 \
173			       float64x-float128
174
175# For each of the basic types (float, double, long double), replace the
176# occurrences of 'F' in arg 1 with the appropriate suffix for the type.
177type-basic-foreach = $(foreach t, $(types-basic), \
178		       $(subst F,$(type-$(t)-suffix),$(1)))
179
180# Apply suffix to each type in arg 1
181type-foreach = $(foreach t,$(types),$(subst F,$(type-$(t)-suffix),$(1)))
182
183libm-routines = $(strip $(libm-support)					\
184			$(call type-basic-foreach,			\
185			       $(libm-compat-calls))			\
186			$(call type-foreach, $(libm-calls))		\
187			$(foreach t, $(types), $(type-$(t)-routines))) 	\
188			$(foreach f,$(libm-narrow-fns),			\
189				    $(subst F,$(f),$(libm-narrow-types)))
190
191# These functions are in libc instead of libm because __printf_fp
192# calls them, so any program using printf will need them linked in,
193# and we don't want to have to link every program with -lm.
194# In libm-calls (above), list m_foo in place of s_foo for any
195# routine that should be compiled separately for its libc and libm versions.
196calls = s_isinfF s_isnanF s_finiteF s_copysignF s_modfF s_scalbnF s_frexpF \
197	s_signbitF $(gen-calls)
198gen-calls = s_ldexpF
199generated += $(foreach s,.c .S,$(call type-foreach, $(calls:s_%=m_%$(s))))
200routines = $(call type-foreach, $(calls))
201# The $(calls) that are shared between libm and libc are not included in static
202# libm so the symbols end up in exactly one place.
203libm-shared-only-routines = $(call type-foreach, $(calls:s_%=m_%))
204
205ifeq ($(build-mathvec),yes)
206# We need to install libm.so and libm.a as linker scripts
207# for transparent use of vector math library.
208install-lib-ldscripts := libm.so libm.a
209install-others = $(inst_libdir)/libm.so $(inst_libdir)/libm.a
210$(inst_libdir)/libm.so: $(common-objpfx)format.lds \
211			$(libm) \
212			$(libmvec) \
213			$(+force)
214	(echo '/* GNU ld script'; echo '*/';\
215	 cat $<; \
216	 echo 'GROUP ( $(slibdir)/libm.so$(libm.so-version) ' \
217	      'AS_NEEDED ( $(slibdir)/libmvec.so$(libmvec.so-version) ) )' \
218	) > $@.new
219	mv -f $@.new $@
220
221$(inst_libdir)/libm-$(version).a: $(objpfx)libm.a \
222				  $(+force)
223	$(do-install)
224
225$(inst_libdir)/libm.a: $(common-objpfx)format.lds \
226		       $(inst_libdir)/libm-$(version).a \
227		       $(objpfx)../mathvec/libmvec.a \
228		       $(+force)
229	(echo '/* GNU ld script'; echo '*/';\
230	 cat $<; \
231	 echo 'GROUP ( $(libdir)/libm-$(version).a $(libdir)/libmvec.a )' \
232	) > $@.new
233	mv -f $@.new $@
234endif
235
236# Rules for the test suite.
237tests = test-matherr-3 test-fenv basic-test \
238	test-misc test-fpucw test-fpucw-ieee tst-definitions test-tgmath \
239	test-tgmath-ret bug-nextafter bug-nexttoward bug-tgmath1 \
240	test-tgmath-int test-tgmath2 test-powl tst-CMPLX tst-CMPLX2 test-snan \
241	test-fenv-tls test-fenv-preserve test-fenv-return \
242	test-nearbyint-except test-fenv-clear \
243	test-nearbyint-except-2 test-signgam-uchar test-signgam-uchar-init \
244	test-signgam-uint test-signgam-uint-init test-signgam-ullong \
245	test-signgam-ullong-init test-nan-overflow test-nan-payload \
246	test-fexcept test-fexcept-traps test-fesetexcept \
247	test-fesetexcept-traps test-fetestexceptflag test-femode \
248	test-femode-traps test-iszero-excess-precision \
249	test-iseqsig-excess-precision test-flt-eval-method \
250	test-fp-ilogb-constants test-fp-llogb-constants \
251	test-fe-snans-always-signal test-narrow-macros \
252	test-nan-const $(tests-static)
253tests-static = test-fpucw-static test-fpucw-ieee-static \
254	       test-signgam-uchar-static test-signgam-uchar-init-static \
255	       test-signgam-uint-static test-signgam-uint-init-static \
256	       test-signgam-ullong-static test-signgam-ullong-init-static
257
258# The tested symbols matherr, _LIB_VERSION have been removed in glibc 2.27.
259ifeq ($(have-GLIBC_2.26)$(build-shared),yesyes)
260tests += test-matherr test-matherr-2
261endif
262
263# These tests use internal (unexported) GMP functions and are linked
264# statically to obtain access to these functions.
265tests-static += atest-exp atest-sincos atest-exp2
266
267ifneq (,$(CXX))
268tests += test-math-isinff test-math-iszero test-math-issignaling \
269	 test-math-iscanonical test-math-cxx11 test-math-iseqsig
270endif
271
272libm-vec-tests = $(addprefix test-,$(libmvec-tests))
273libm-test-support = $(foreach t,$(test-types),libm-test-support-$(t))
274test-extras += $(libm-test-support)
275extra-test-objs += $(addsuffix .o, $(libm-test-support))
276libm-vec-test-wrappers = $(addsuffix -wrappers, $(libm-vec-tests))
277test-extras += $(libm-vec-test-wrappers)
278extra-test-objs += $(addsuffix .o, $(libm-vec-test-wrappers))
279
280ulps-file = $(firstword $(wildcard $(sysdirs:%=%/libm-test-ulps)))
281
282$(objpfx)libm-test-ulps.h: $(ulps-file) gen-libm-test.py
283	$(make-target-directory)
284	$(PYTHON) gen-libm-test.py -u $< -H $@
285
286libm-test-funcs-auto = acos acosh asin asinh atan atan2 atanh cabs cacos \
287		       cacosh carg casin casinh catan catanh cbrt ccos ccosh \
288		       cexp clog clog10 cos cosh cpow csin csinh csqrt ctan \
289		       ctanh erf erfc exp exp10 exp2 expm1 fma hypot j0 j1 jn \
290		       lgamma log log10 log1p log2 pow sin sincos sinh sqrt \
291		       tan tanh tgamma y0 y1 yn
292libm-test-funcs-noauto = canonicalize ceil cimag conj copysign cproj creal \
293			 fabs fdim floor fmax fmaximum fmaximum_mag \
294			 fmaximum_mag_num fmaximum_num fmaxmag fmin fminimum \
295			 fminimum_mag fminimum_mag_num fminimum_num fminmag \
296			 fmod fpclassify frexp fromfp fromfpx getpayload \
297			 ilogb iscanonical iseqsig isfinite isgreater \
298			 isgreaterequal isinf isless islessequal \
299			 islessgreater isnan isnormal issignaling issubnormal \
300			 isunordered iszero llogb llrint llround logb lrint \
301			 lround modf nearbyint nextafter nextdown nexttoward \
302			 nextup remainder remquo rint round roundeven scalb \
303			 scalbln scalbn setpayload setpayloadsig signbit \
304			 significand totalorder totalordermag trunc ufromfp \
305			 ufromfpx compat_totalorder compat_totalordermag
306libm-test-funcs-compat = compat_totalorder compat_totalordermag
307libm-test-funcs-narrow = add div fma mul sqrt sub
308libm-test-funcs-all = $(libm-test-funcs-auto) $(libm-test-funcs-noauto)
309libm-test-c-auto = $(foreach f,$(libm-test-funcs-auto),libm-test-$(f).c)
310libm-test-c-noauto = $(foreach f,$(libm-test-funcs-noauto),libm-test-$(f).c)
311libm-test-c-narrow = $(foreach f,$(libm-test-funcs-narrow),\
312				 libm-test-narrow-$(f).c)
313generated += libm-test-ulps.h $(libm-test-c-auto) $(libm-test-c-noauto) \
314	     $(libm-test-c-narrow)
315
316libm-tests-base-normal = $(foreach t,$(test-types),test-$(t))
317libm-tests-base-narrow = $(foreach t,$(test-type-pairs),test-$(t))
318libm-tests-base = $(libm-tests-base-normal) $(libm-vec-tests)
319libm-tests-normal = $(foreach t,$(libm-tests-base-normal),\
320				$(foreach f,$(libm-test-funcs-all),\
321					    $(t)-$(f)))
322libm-tests-narrow = $(foreach t,$(libm-tests-base-narrow),\
323				$(foreach f,$(libm-test-funcs-narrow),\
324					    $(t)-$(f)))
325libm-tests-vector = $(foreach t,$(libmvec-tests),\
326				$(foreach f,$($(t)-funcs),test-$(t)-$(f)))
327libm-tests = $(libm-tests-normal) $(libm-tests-narrow) $(libm-tests-vector)
328libm-tests-compat = $(foreach t,$(libm-tests-base-normal) \
329				$(libm-tests-base-finite),\
330				$(foreach f,$(libm-test-funcs-compat),\
331					    $(t)-$(f)))
332libm-tests-for-type = $(foreach f,$(libm-test-funcs-all),\
333				  test-$(1)-$(f) test-i$(1)-$(f)) \
334		      $(filter test-$(1)-%,$(libm-tests-vector) \
335					   $(libm-tests-narrow))
336
337libm-tests.o = $(addsuffix .o,$(libm-tests))
338
339tests += $(libm-tests)
340generated += $(addsuffix .c,$(libm-tests)) \
341	     $(foreach t,$(test-types),libm-test-support-$(t).c)
342
343libm-test-c-auto-obj = $(addprefix $(objpfx),$(libm-test-c-auto))
344libm-test-c-noauto-obj = $(addprefix $(objpfx),$(libm-test-c-noauto))
345libm-test-c-narrow-obj = $(addprefix $(objpfx),$(libm-test-c-narrow))
346
347$(libm-test-c-noauto-obj): $(objpfx)libm-test%.c: libm-test%.inc \
348						  gen-libm-test.py
349	$(make-target-directory)
350	$(PYTHON) gen-libm-test.py -c $< -a /dev/null -C $@
351
352$(libm-test-c-auto-obj): $(objpfx)libm-test%.c: libm-test%.inc \
353						gen-libm-test.py \
354						auto-libm-test-out%
355	$(make-target-directory)
356	$(PYTHON) gen-libm-test.py -c $< -a auto-libm-test-out$* -C $@
357
358$(libm-test-c-narrow-obj): $(objpfx)libm-test%.c: libm-test%.inc \
359						  gen-libm-test.py \
360						  auto-libm-test-out%
361	$(make-target-directory)
362	$(PYTHON) gen-libm-test.py -c $< -a auto-libm-test-out$* -C $@
363
364# Tests for totalorder compat symbols reuse the table of tests as
365# processed by gen-libm-test.py, so add dependencies on the generated
366# .c files.
367$(foreach t,$(libm-tests-base),\
368	    $(objpfx)$(t)-compat_totalorder.o): $(objpfx)libm-test-totalorder.c
369
370$(foreach t,$(libm-tests-base),\
371	    $(objpfx)$(t)-compat_totalordermag.o): $(objpfx)libm-test-totalordermag.c
372
373# _Float128x omitted as not supported by gen-tgmath-tests.py.
374tgmath3-narrow-types = f d f16 f32 f64 f128 f32x f64x
375tgmath3-narrow-macros = $(foreach t,$(tgmath3-narrow-types), \
376				    $(foreach f,$(libm-narrow-fns),$(t)$(f)))
377tgmath3-macros = atan2 cbrt ceil copysign erf erfc exp10 exp2 expm1 fdim \
378		 floor fma fmax fmin fmod frexp hypot ilogb ldexp lgamma \
379		 llrint llround log10 log1p log2 logb lrint lround nearbyint \
380		 nextafter nexttoward remainder remquo rint round scalbn \
381		 scalbln tgamma trunc acos asin atan acosh asinh atanh cos \
382		 sin tan cosh sinh tanh exp log pow sqrt fabs carg cimag conj \
383		 cproj creal roundeven nextup nextdown fminmag fmaxmag \
384		 fmaximum fmaximum_mag fmaximum_num fmaximum_mag_num \
385		 fminimum fminimum_mag fminimum_num fminimum_mag_num llogb \
386		 fromfp fromfpx ufromfp ufromfpx scalb $(tgmath3-narrow-macros)
387tgmath3-macro-tests = $(addprefix test-tgmath3-,$(tgmath3-macros))
388tests += $(tgmath3-macro-tests)
389generated += $(addsuffix .c,$(tgmath3-macro-tests))
390
391$(tgmath3-macro-tests:%=$(objpfx)%.o): CFLAGS += -fno-builtin
392
393$(foreach m,$(tgmath3-macros),\
394	    $(objpfx)test-tgmath3-$(m).c): $(objpfx)test-tgmath3-%.c: \
395					   gen-tgmath-tests.py
396	$(PYTHON) gen-tgmath-tests.py $* > $@
397
398# Verify that the list of supported macros is in sync between the
399# Makefile and gen-tgmath-tests.py.
400tests-special += $(objpfx)test-tgmath3-macro-list.out
401$(objpfx)test-tgmath3-macro-list.out: gen-tgmath-tests.py
402	$(PYTHON) $< check-list $(tgmath3-macros) > $@; \
403	$(evaluate-test)
404
405libm-test-fast-math-cflags = -fno-builtin -D__FAST_MATH__ -DTEST_FAST_MATH
406libm-test-vec-cflags = $(libm-test-fast-math-cflags) -fno-inline \
407		       -ffloat-store -D_OPENMP=201307 -Wno-unknown-pragmas
408
409CFLAGS-test-double-vlen4-wrappers.c += $(double-vlen4-arch-ext-cflags)
410
411CFLAGS-test-double-vlen8-wrappers.c += $(double-vlen8-arch-ext-cflags)
412
413CFLAGS-test-float-vlen8-wrappers.c += $(float-vlen8-arch-ext-cflags)
414
415CFLAGS-test-float-vlen16-wrappers.c += $(float-vlen16-arch-ext-cflags)
416
417# The no-inline tests use -fsignaling-nans, and thereby use the
418# versions of classification macros that support sNaNs.  The inline
419# function tests use the versions of classification macros that may
420# raise spurious exceptions for sNaNs, but also do not test for
421# exceptions.  Thus both versions of the classification macros are
422# validated.
423libm-test-no-inline-cflags = -fno-inline -ffloat-store -fno-builtin \
424			     -fsignaling-nans
425CFLAGS-test-tgmath.c += -fno-builtin
426# The following testcase uses very long lines (>3 million), so it may take a
427# while to compile it. See: http://llvm.org/bugs/show_bug.cgi?id=14106 and
428# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54402
429CFLAGS-test-tgmath2.c += -fno-builtin
430CFLAGS-test-tgmath-ret.c += -fno-builtin
431CFLAGS-test-powl.c += -fno-builtin
432
433CFLAGS-test-snan.c += -fsignaling-nans
434
435CFLAGS-test-signgam-uchar.c += -std=c99
436CFLAGS-test-signgam-uchar-init.c += -std=c99
437CFLAGS-test-signgam-uchar-static.c += -std=c99
438CFLAGS-test-signgam-uchar-init-static.c += -std=c99
439CFLAGS-test-signgam-uint.c += -std=c99
440CFLAGS-test-signgam-uint-init.c += -std=c99
441CFLAGS-test-signgam-uint-static.c += -std=c99
442CFLAGS-test-signgam-uint-init-static.c += -std=c99
443CFLAGS-test-signgam-ullong.c += -std=c99
444CFLAGS-test-signgam-ullong-init.c += -std=c99
445CFLAGS-test-signgam-ullong-static.c += -std=c99
446CFLAGS-test-signgam-ullong-init-static.c += -std=c99
447
448CFLAGS-test-math-cxx11.cc += -std=c++11
449
450CFLAGS-test-math-isinff.cc += -std=gnu++11
451CFLAGS-test-math-iszero.cc += -std=gnu++11
452CFLAGS-test-math-issignaling.cc += -std=gnu++11
453CFLAGS-test-math-iscanonical.cc += -std=gnu++11
454
455CFLAGS-test-iszero-excess-precision.c += -fexcess-precision=standard
456CFLAGS-test-iseqsig-excess-precision.c += -fexcess-precision=standard
457CFLAGS-test-flt-eval-method.c += -fexcess-precision=standard
458
459CFLAGS-test-fe-snans-always-signal.c += -fsignaling-nans
460
461CFLAGS-test-nan-const.c += -fno-builtin
462
463include ../Rules
464
465gen-all-calls = $(gen-libm-calls) $(gen-calls)
466
467generated += $(addsuffix .c,$(call type-foreach,$(gen-all-calls))) \
468	     gen-libm-templates.stmp
469
470# Create wrappers in the math build directory.
471$(objpfx)gen-libm-templates.stmp: Makefile
472	$(make-target-directory)
473	for gcall in $(gen-all-calls); do                                 \
474	  func=$${gcall%F*}$${gcall#*F};                                  \
475	  for type in $(foreach t,$(types),$(t)__$(type-$(t)-suffix)); do \
476	    suff=$${type#*__};                                            \
477	    type=$${type%__*};                                            \
478	    file=$(objpfx)$${gcall%F*}$${suff}$${gcall#*F}.c;             \
479	    (                                                             \
480	      echo "#include <math-type-macros-$${type}.h>";              \
481	      echo "#include <$${func}_template.c>";                      \
482	    ) > $${file};                                                 \
483	  done;                                                           \
484	done;                                                             \
485	echo > $(@)
486
487# Add dependency to ensure the generator runs prior.
488$(foreach t, $(call type-foreach, $(gen-all-calls)), \
489             $(objpfx)$(t).c): $(objpfx)gen-libm-templates.stmp
490
491# This must come after the inclusion of sysdeps Makefiles via Rules.
492
493$(foreach t,$(libm-tests-normal),$(objpfx)$(t).c): $(objpfx)test-%.c:
494	type_func=$*; \
495	type=$${type_func%%-*}; \
496	func=$${type_func#*-}; \
497	( \
498	  echo "#include <test-$$type.h>"; \
499	  echo "#include <test-math-exceptions.h>"; \
500	  echo "#include <test-math-errno.h>"; \
501	  echo "#include <test-math-scalar.h>"; \
502	  echo "#include <libm-test-$$func.c>"; \
503	) > $@
504
505$(foreach t,$(libm-tests-narrow),$(objpfx)$(t).c): $(objpfx)test-%.c:
506	type_pair_func=$*; \
507	type_pair=$${type_pair_func%-*}; \
508	func=$${type_pair_func##*-}; \
509	ret_type=$${type_pair%%-*}; \
510	arg_type=$${type_pair#*-}; \
511	( \
512	  echo "#include <test-$$ret_type.h>"; \
513	  echo "#include <test-arg-$$arg_type.h>"; \
514	  echo "#include <test-math-exceptions.h>"; \
515	  echo "#include <test-math-errno.h>"; \
516	  echo "#include <test-math-narrow.h>"; \
517	  echo "#include <libm-test-narrow-$$func.c>"; \
518	) > $@
519
520$(foreach t,$(libm-tests-vector),$(objpfx)$(t).c): $(objpfx)test-%.c:
521	type_func=$*; \
522	type=$${type_func%-*}; \
523	func=$${type_func##*-}; \
524	func_args=$$(grep ALL_RM_TEST libm-test-$$func.inc \
525		     | sed 's/.*RUN_TEST_LOOP_//;s/_.*//'); \
526	( \
527	  echo "#include <test-$$type.h>"; \
528	  echo "WRAPPER_DECL_$$func_args (WRAPPER_NAME (FUNC ($$func)))"; \
529	  echo "#include <libm-test-$$func.c>"; \
530	) > $@
531
532$(foreach t,$(test-types),\
533	    $(objpfx)libm-test-support-$(t).c): $(objpfx)libm-test-support-%.c:
534	( \
535	  echo "#include <test-$*.h>"; \
536	  echo "#include <libm-test-support.c>"; \
537	) > $@
538
539$(addprefix $(objpfx), $(libm-tests.o)): $(objpfx)libm-test-ulps.h
540
541define o-iterator-doit
542$(foreach f,$(libm-test-funcs-all),\
543	    $(objpfx)$(o)-$(f).o): $(objpfx)$(o)%.o: $(objpfx)libm-test%.c
544endef
545object-suffixes-left := $(libm-tests-base)
546include $(o-iterator)
547
548define o-iterator-doit
549$(foreach f,$(libm-test-funcs-narrow),\
550	    $(objpfx)$(o)-$(f).o): $(objpfx)$(o)%.o: \
551				   $(objpfx)libm-test-narrow%.c
552endef
553object-suffixes-left := $(libm-tests-base-narrow)
554include $(o-iterator)
555
556define o-iterator-doit
557$(foreach f,$(libm-test-funcs-all),\
558	    $(objpfx)$(o)-$(f).o): CFLAGS += $(libm-test-no-inline-cflags)
559endef
560object-suffixes-left := $(libm-tests-base-normal)
561include $(o-iterator)
562
563define o-iterator-doit
564$(foreach f,$(libm-test-funcs-narrow),\
565	    $(objpfx)$(o)-$(f).o): CFLAGS += $(libm-test-no-inline-cflags)
566endef
567object-suffixes-left := $(libm-tests-base-narrow)
568include $(o-iterator)
569
570define o-iterator-doit
571$(foreach f,$($(o)-funcs),\
572	    $(objpfx)test-$(o)-$(f).o): CFLAGS += $(libm-test-vec-cflags)
573endef
574object-suffixes-left := $(libmvec-tests)
575include $(o-iterator)
576
577define o-iterator-doit
578$(addprefix $(objpfx),\
579	    $(call libm-tests-for-type,$(o))): $(objpfx)libm-test-support-$(o).o
580endef
581object-suffixes-left := $(test-types)
582include $(o-iterator)
583
584define o-iterator-doit
585$(objpfx)libm-test-support-$(o).o: CFLAGS += $(libm-test-no-inline-cflags)
586endef
587object-suffixes-left := $(test-types)
588include $(o-iterator)
589
590# Run the math programs to automatically generate ULPs files.
591.PHONY: regen-ulps
592
593run-regen-ulps = $(test-wrapper-env) \
594	    $(run-program-env) \
595	    $($*-ENV) $(rtld-prefix) $(objpfx)$${run}
596
597regen-ulps: $(addprefix $(objpfx),$(libm-tests))
598	rm -f $(objpfx)ULPs; rm -f $(objpfx)NewUlps; \
599	cp $(ulps-file) $(objpfx)libm-test-ulps; \
600	for run in $(libm-tests); do \
601	  echo "Regenerating ULPs for $${run}"; \
602	  $(run-regen-ulps) -u -o $(objpfx); \
603	  cat $(objpfx)ULPs >> $(objpfx)libm-test-ulps; \
604	  rm $(objpfx)ULPs; \
605	done; \
606	$(PYTHON) gen-libm-test.py -n $(objpfx)NewUlps \
607				   -u $(objpfx)libm-test-ulps; \
608	echo "Automatic regeneration of ULPs complete."; \
609	echo "Difference between the current baseline and the new baseline is:";\
610	diff -urN $(ulps-file) $(objpfx)NewUlps; \
611	echo "Copy $(objpfx)NewUlps to $(ulps-file) (relative to source)."
612
613# The generated sysd-rules file defines rules like this for sources
614# coming from sysdeps/ directories.  These rules find the generic sources.
615define o-iterator-doit
616$(objpfx)m_%$o: s_%.c $(before-compile); $$(compile-command.c)
617endef
618object-suffixes-left := $(all-object-suffixes)
619include $(o-iterator)
620
621# Likewise, for those generated files shared with libc.
622define o-iterator-doit
623$(objpfx)m_%$o: $(objpfx)s_%.c $(before-compile); $$(compile-command.c)
624endef
625object-suffixes-left := $(all-object-suffixes)
626include $(o-iterator)
627
628ifneq ($(long-double-fcts),yes)
629# The `double' and `long double' types are the same on this machine.
630# We won't compile the `long double' code at all.  Tell the `double' code
631# to define aliases for the `FUNCl' names.
632math-CPPFLAGS += -DNO_LONG_DOUBLE
633# GCC 10 diagnoses aliases with types conflicting with built-in
634# functions.
635CFLAGS-w_acos.c += -fno-builtin-acosl
636CFLAGS-w_acosh.c += -fno-builtin-acoshl
637CFLAGS-w_asin.c += -fno-builtin-asinl
638CFLAGS-s_asinh.c += -fno-builtin-asinhl
639CFLAGS-s_atan.c += -fno-builtin-atanl
640CFLAGS-w_atan2.c += -fno-builtin-atan2l
641CFLAGS-w_atanh.c += -fno-builtin-atanhl
642CFLAGS-s_cabs.c += -fno-builtin-cabsl
643CFLAGS-s_cacos.c += -fno-builtin-cacosl
644CFLAGS-s_cacosh.c += -fno-builtin-cacoshl
645CFLAGS-s_canonicalize.c += -fno-builtin-canonicalizel
646CFLAGS-s_carg.c += -fno-builtin-cargl
647CFLAGS-s_casin.c += -fno-builtin-casinl
648CFLAGS-s_casinh.c += -fno-builtin-casinhl
649CFLAGS-s_catan.c += -fno-builtin-catanl
650CFLAGS-s_catanh.c += -fno-builtin-catanhl
651CFLAGS-s_cbrt.c += -fno-builtin-cbrtl
652CFLAGS-s_ccos.c += -fno-builtin-ccosl
653CFLAGS-s_ccosh.c += -fno-builtin-ccoshl
654CFLAGS-s_ceil.c += -fno-builtin-ceill
655CFLAGS-s_cexp.c += -fno-builtin-cexpl
656CFLAGS-s_cimag.c += -fno-builtin-cimagl
657CFLAGS-s_clog.c += -fno-builtin-clogl
658CFLAGS-s_clog10.c += -fno-builtin-clog10l
659CFLAGS-s_conj.c += -fno-builtin-conjl
660CFLAGS-s_copysign.c += -fno-builtin-copysignl
661CFLAGS-s_cos.c += -fno-builtin-cosl
662CFLAGS-w_cosh.c += -fno-builtin-coshl
663CFLAGS-s_cpow.c += -fno-builtin-cpowl
664CFLAGS-s_cproj.c += -fno-builtin-cprojl
665CFLAGS-s_creal.c += -fno-builtin-creall
666CFLAGS-s_csin.c += -fno-builtin-csinl
667CFLAGS-s_csinh.c += -fno-builtin-csinhl
668CFLAGS-s_csqrt.c += -fno-builtin-csqrtl
669CFLAGS-s_ctan.c += -fno-builtin-ctanl
670CFLAGS-s_ctanh.c += -fno-builtin-ctanhl
671CFLAGS-s_dadd.c += -fno-builtin-daddl
672CFLAGS-s_ddiv.c += -fno-builtin-ddivl
673CFLAGS-s_dfma.c += -fno-builtin-dfmal
674CFLAGS-s_dmul.c += -fno-builtin-dmull
675CFLAGS-s_dsqrt.c += -fno-builtin-dsqrtl
676CFLAGS-s_dsub.c += -fno-builtin-dsubl
677CFLAGS-s_erf.c += -fno-builtin-erfl
678CFLAGS-s_erfc.c += -fno-builtin-erfcl
679CFLAGS-e_exp.c += -fno-builtin-expl
680CFLAGS-w_exp10.c += -fno-builtin-exp10l
681CFLAGS-e_exp2.c += -fno-builtin-exp2l
682CFLAGS-s_expm1.c += -fno-builtin-expm1l
683CFLAGS-s_fabs.c += -fno-builtin-fabsl
684CFLAGS-s_fadd.c += -fno-builtin-faddl
685CFLAGS-s_fdim.c += -fno-builtin-fdiml
686CFLAGS-s_fdiv.c += -fno-builtin-fdivl
687CFLAGS-s_ffma.c += -fno-builtin-ffmal
688CFLAGS-s_finite.c += -fno-builtin-finitel
689CFLAGS-s_floor.c += -fno-builtin-floorl
690CFLAGS-s_fma.c += -fno-builtin-fmal
691CFLAGS-s_fmax.c += -fno-builtin-fmaxl
692CFLAGS-s_fmaximum.c += -fno-builtin-fmaximuml
693CFLAGS-s_fmaximum_mag.c += -fno-builtin-fmaximum_magl
694CFLAGS-s_fmaximum_mag_num.c += -fno-builtin-fmaximum_mag_numl
695CFLAGS-s_fmaximum_num.c += -fno-builtin-fmaximum_numl
696CFLAGS-s_fmaxmag.c += -fno-builtin-fmaxmagl
697CFLAGS-s_fmin.c += -fno-builtin-fminl
698CFLAGS-s_fminimum.c += -fno-builtin-fminimuml
699CFLAGS-s_fminimum_mag.c += -fno-builtin-fminimum_magl
700CFLAGS-s_fminimum_mag_num.c += -fno-builtin-fminimum_mag_numl
701CFLAGS-s_fminimum_num.c += -fno-builtin-fminimum_numl
702CFLAGS-s_fminmag.c += -fno-builtin-fminmagl
703CFLAGS-w_fmod.c += -fno-builtin-fmodl
704CFLAGS-s_fmul.c += -fno-builtin-fmull
705CFLAGS-s_frexp.c += -fno-builtin-frexpl
706CFLAGS-s_fromfp.c += -fno-builtin-fromfpl
707CFLAGS-s_fromfpx.c += -fno-builtin-fromfpxl
708CFLAGS-s_fsqrt.c += -fno-builtin-fsqrtl
709CFLAGS-s_fsub.c += -fno-builtin-fsubl
710CFLAGS-s_gamma.c += -fno-builtin-gammal
711CFLAGS-s_getpayload.c += -fno-builtin-getpayloadl
712CFLAGS-w_hypot.c += -fno-builtin-hypotl
713CFLAGS-w_ilogb.c += -fno-builtin-ilogbl
714CFLAGS-s_isinf.c += -fno-builtin-isinfl
715CFLAGS-s_isnan.c += -fno-builtin-isnanl
716CFLAGS-w_j0.c += -fno-builtin-j0l
717CFLAGS-w_j1.c += -fno-builtin-j1l
718CFLAGS-w_jn.c += -fno-builtin-jnl
719CFLAGS-s_ldexp.c += -fno-builtin-ldexpl
720CFLAGS-w_lgamma.c += -fno-builtin-lgammal
721CFLAGS-w_lgamma_r.c += -fno-builtin-lgammal_r
722CFLAGS-w_llogb.c += -fno-builtin-llogbl
723CFLAGS-s_llrint.c += -fno-builtin-llrintl
724CFLAGS-s_llround.c += -fno-builtin-llroundl
725CFLAGS-e_log.c += -fno-builtin-logl
726CFLAGS-w_log10.c += -fno-builtin-log10l
727CFLAGS-w_log1p.c += -fno-builtin-log1pl
728CFLAGS-e_log2.c += -fno-builtin-log2l
729CFLAGS-s_logb.c += -fno-builtin-logbl
730CFLAGS-s_lrint.c += -fno-builtin-lrintl
731CFLAGS-s_lround.c += -fno-builtin-lroundl
732CFLAGS-s_modf.c += -fno-builtin-modfl
733CFLAGS-s_nan.c += -fno-builtin-nanl
734CFLAGS-s_nearbyint.c += -fno-builtin-nearbyintl
735CFLAGS-s_nextafter.c += -fno-builtin-nextafterl
736CFLAGS-s_nextdown.c += -fno-builtin-nextdownl
737CFLAGS-s_nexttoward.c += -fno-builtin-nexttoward -fno-builtin-nexttowardl
738CFLAGS-s_nexttowardf.c += -fno-builtin-nexttowardf
739CFLAGS-s_nextup.c += -fno-builtin-nextupl
740CFLAGS-e_pow.c += -fno-builtin-powl
741CFLAGS-w_remainder.c += -fno-builtin-remainderl -fno-builtin-dreml
742CFLAGS-s_remquo.c += -fno-builtin-remquol
743CFLAGS-s_rint.c += -fno-builtin-rintl
744CFLAGS-s_round.c += -fno-builtin-roundl
745CFLAGS-s_roundeven.c += -fno-builtin-roundevenl
746CFLAGS-w_scalb.c += -fno-builtin-scalbl
747CFLAGS-w_scalbln.c += -fno-builtin-scalblnl
748CFLAGS-s_scalbn.c += -fno-builtin-scalbnl
749CFLAGS-s_setpayload.c += -fno-builtin-setpayloadl
750CFLAGS-s_setpayloadsig.c += -fno-builtin-setpayloadsigl
751CFLAGS-s_significand.c += -fno-builtin-significandl
752CFLAGS-s_sin.c += -fno-builtin-sinl
753CFLAGS-s_sincos.c += -fno-builtin-sincosl
754CFLAGS-w_sinh.c += -fno-builtin-sinhl
755CFLAGS-w_sqrt.c += -fno-builtin-sqrtl
756CFLAGS-s_tan.c += -fno-builtin-tanl
757CFLAGS-s_tanh.c += -fno-builtin-tanhl
758CFLAGS-w_tgamma.c += -fno-builtin-tgammal
759CFLAGS-s_totalorder.c += -fno-builtin-totalorderl
760CFLAGS-s_totalordermag.c += -fno-builtin-totalordermagl
761CFLAGS-s_trunc.c += -fno-builtin-truncl
762CFLAGS-s_ufromfp.c += -fno-builtin-ufromfpl
763CFLAGS-s_ufromfpx.c += -fno-builtin-ufromfpxl
764CFLAGS-s_y0.c += -fno-builtin-y0l
765CFLAGS-s_y1.c += -fno-builtin-y1l
766CFLAGS-s_yn.c += -fno-builtin-ynl
767endif
768
769# These files quiet sNaNs in a way that is optimized away without
770# -fsignaling-nans.
771CFLAGS-s_modf.c += -fsignaling-nans
772CFLAGS-s_modff.c += -fsignaling-nans
773CFLAGS-s_modfl.c += -fsignaling-nans
774CFLAGS-s_modff128.c += -fsignaling-nans
775
776$(addprefix $(objpfx),\
777	    $(filter-out $(tests-static) $(libm-tests-vector),\
778			 $(tests) $(tests-internal))): $(libm)
779$(addprefix $(objpfx),$(tests-static)): $(objpfx)libm.a
780define o-iterator-doit
781$(foreach f,$($(o)-funcs),\
782	    $(objpfx)test-$(o)-$(f)): $(objpfx)test-$(o)-wrappers.o \
783				      $(libm) $(libmvec)
784endef
785object-suffixes-left := $(libmvec-tests)
786include $(o-iterator)
787
788$(objpfx)test-fenv-tls: $(shared-thread-library)
789