]>
Commit | Line | Data |
---|---|---|
f7a9f785 | 1 | # Copyright (C) 1996-2016 Free Software Foundation, Inc. |
28f540f4 RM |
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 | |
41bdb6e2 AJ |
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. | |
28f540f4 RM |
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 | |
41bdb6e2 | 12 | # Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 | 14 | # You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | # License along with the GNU C Library; if not, see |
16 | # <http://www.gnu.org/licenses/>. | |
0c5ecdc4 UD |
17 | |
18 | # Makefile for the math library. | |
28f540f4 | 19 | |
f7eac6eb RM |
20 | subdir := math |
21 | ||
a5f891ac JM |
22 | include ../Makeconfig |
23 | ||
f7eac6eb | 24 | # Installed header files. |
5107cf1d | 25 | headers := math.h bits/mathcalls.h bits/mathinline.h bits/huge_val.h \ |
a86573f4 RH |
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 \ | |
0ac5ae23 | 28 | bits/fenv.h bits/fenvinline.h bits/mathdef.h tgmath.h \ |
202d48da AS |
29 | bits/math-finite.h bits/math-vector.h \ |
30 | bits/libm-simd-decl-stubs.h | |
f7eac6eb | 31 | |
5fbef188 | 32 | # FPU support code. |
c94a8080 | 33 | aux := setfpucw fpu_control |
28f540f4 | 34 | |
f7eac6eb | 35 | # Build the -lm library. |
28f540f4 | 36 | |
f7eac6eb | 37 | extra-libs := libm |
ec4b0518 | 38 | extra-libs-others = $(extra-libs) |
58e07151 | 39 | |
f56f9124 | 40 | libm-support = s_lib_version s_matherr s_signgam \ |
63551311 UD |
41 | fclrexcpt fgetexcptflg fraiseexcpt fsetexcptflg \ |
42 | ftestexcept fegetround fesetround fegetenv feholdexcpt \ | |
05ef7ce9 | 43 | fesetenv feupdateenv t_exp fedisblxcpt feenablxcpt \ |
5146356f | 44 | fegetexcept fesetexcept |
b9e05ed0 PM |
45 | |
46 | libm-calls = \ | |
47 | e_acosF e_acoshF e_asinF e_atan2F e_atanhF e_coshF e_expF e_fmodF \ | |
48 | e_hypotF e_j0F e_j1F e_jnF e_lgammaF_r e_logF e_log10F e_powF \ | |
49 | e_rem_pio2F e_remainderF e_scalbF e_sinhF e_sqrtF e_gammaF_r \ | |
50 | e_ilogbF \ | |
51 | k_cosF k_rem_pio2F k_sinF k_tanF s_asinhF s_atanF s_cbrtF \ | |
52 | s_ceilF s_cosF s_erfF s_expm1F s_fabsF \ | |
53 | s_floorF s_log1pF w_log1pF s_logbF \ | |
54 | s_nextafterF s_nexttowardF s_rintF s_scalblnF w_scalblnF \ | |
55 | s_significandF s_sinF s_tanF s_tanhF w_acosF w_acoshF w_asinF \ | |
56 | w_atan2F w_atanhF w_coshF w_expF w_exp2F w_exp10F w_fmodF \ | |
57 | w_tgammaF w_hypotF w_j0F w_j1F w_jnF w_lgammaF w_lgammaF_r \ | |
58 | w_logF w_log10F w_powF w_remainderF w_scalbF w_sinhF w_sqrtF \ | |
59 | w_ilogbF \ | |
60 | s_fpclassifyF s_fmaxF s_fminF s_fdimF s_nanF s_truncF \ | |
61 | s_remquoF e_log2F e_exp2F s_roundF s_nearbyintF s_sincosF \ | |
62 | conjF cimagF crealF cabsF cargF s_cexpF s_csinhF s_ccoshF s_clogF \ | |
63 | s_catanF s_casinF s_ccosF s_csinF s_ctanF s_ctanhF s_cacosF \ | |
64 | s_casinhF s_cacoshF s_catanhF s_csqrtF s_cpowF s_cprojF s_clog10F \ | |
65 | s_fmaF s_lrintF s_llrintF s_lroundF s_llroundF e_exp10F w_log2F \ | |
66 | s_issignalingF $(calls:s_%=m_%) x2y2m1F k_casinhF \ | |
67 | gamma_productF lgamma_negF lgamma_productF \ | |
68 | s_nextupF s_nextdownF | |
69 | ||
70 | libm-compat-calls-ldouble-yes = w_lgamma_compatl k_standardl | |
71 | libm-compat-calls = w_lgamma_compatf w_lgamma_compat k_standard k_standardf \ | |
72 | $(libm-compat-calls-ldouble-$(long-double-fcts)) | |
73 | ||
74 | ||
75 | # Type specific routine support. | |
76 | # | |
77 | # The following three variables control what is included for each type: | |
78 | # | |
79 | # type-floatN-suffix = The suffix of the type | |
80 | # type-floatN-routines = Type specific support objects | |
81 | # type-floatN-yes = If the type is supported, evaluates to floatN | |
82 | # | |
83 | # Finally, note that types is an intentionally recursive variable. | |
84 | # We only know the full set of supported types for the target machine | |
85 | # after the Rules makefile has been parsed. | |
86 | types = $(type-ldouble-$(long-double-fcts)) double float | |
87 | ||
88 | # long double support | |
89 | type-ldouble-suffix := l | |
90 | type-ldouble-routines := t_sincosl k_sincosl | |
91 | type-ldouble-yes := ldouble | |
92 | ||
93 | # double support | |
94 | type-double-suffix := | |
95 | type-double-routines := branred doasin dosincos halfulp mpa mpatan2 \ | |
96 | mpatan mpexp mplog mpsqrt mptan sincos32 slowexp \ | |
97 | slowpow sincostab | |
98 | ||
99 | # float support | |
100 | type-float-suffix := f | |
101 | type-float-routines := | |
102 | ||
103 | ||
104 | # Apply suffix to each type in arg 1 | |
105 | type-foreach = $(foreach t,$(types),$(subst F,$(type-$(t)-suffix),$(1))) | |
106 | ||
107 | libm-routines = $(strip $(libm-support) $(libm-compat-calls) \ | |
108 | $(call type-foreach, $(libm-calls)) \ | |
109 | $(foreach t, $(types), $(type-$(t)-routines))) \ | |
58e07151 | 110 | |
f7eac6eb RM |
111 | # These functions are in libc instead of libm because __printf_fp |
112 | # calls them, so any program using printf will need them linked in, | |
113 | # and we don't want to have to link every program with -lm. | |
92712dee RM |
114 | # In libm-calls (above), list m_foo in place of s_foo for any |
115 | # routine that should be compiled separately for its libc and libm versions. | |
b9e05ed0 PM |
116 | calls = s_isinfF s_isnanF s_finiteF s_copysignF s_modfF s_scalbnF s_frexpF \ |
117 | s_ldexpF s_signbitF | |
118 | generated += $(foreach s,.c .S,$(call type-foreach, $(calls:s_%=m_%$(s)))) | |
119 | routines = $(call type-foreach, $(calls)) | |
8847214f | 120 | |
5695d46f AS |
121 | ifeq ($(build-mathvec),yes) |
122 | # We need to install libm.so as linker script | |
123 | # for more comfortable use of vector math library. | |
124 | install-lib-ldscripts := libm.so | |
125 | install_subdir: $(inst_libdir)/libm.so | |
126 | $(inst_libdir)/libm.so: $(common-objpfx)format.lds \ | |
127 | $(libm) \ | |
128 | $(libmvec) \ | |
129 | $(+force) | |
130 | (echo '/* GNU ld script'; echo '*/';\ | |
131 | cat $<; \ | |
132 | echo 'GROUP ( $(slibdir)/libm.so$(libm.so-version) ' \ | |
b3f60407 | 133 | 'AS_NEEDED ( $(libdir)/libmvec_nonshared.a $(slibdir)/libmvec.so$(libmvec.so-version) ) )' \ |
f9378ac3 DAS |
134 | ) > $@.new |
135 | mv -f $@.new $@ | |
5695d46f AS |
136 | endif |
137 | ||
c57abfa7 | 138 | # Rules for the test suite. |
9861985f | 139 | tests = test-matherr test-fenv atest-exp atest-sincos atest-exp2 basic-test \ |
95e7cf29 MR |
140 | test-misc test-fpucw test-fpucw-ieee tst-definitions test-tgmath \ |
141 | test-tgmath-ret bug-nextafter bug-nexttoward bug-tgmath1 \ | |
142 | test-tgmath-int test-tgmath2 test-powl tst-CMPLX tst-CMPLX2 test-snan \ | |
85b29045 | 143 | test-fenv-tls test-fenv-preserve test-fenv-return test-fenvinline \ |
939fdd1c | 144 | test-nearbyint-except test-fenv-clear test-signgam-finite \ |
71d1b016 | 145 | test-signgam-finite-c99 test-signgam-finite-c11 \ |
d709042a JM |
146 | test-nearbyint-except-2 test-signgam-uchar test-signgam-uchar-init \ |
147 | test-signgam-uint test-signgam-uint-init test-signgam-ullong \ | |
8f5e8b01 | 148 | test-signgam-ullong-init test-nan-overflow test-nan-payload \ |
5146356f JM |
149 | test-fexcept test-fexcept-traps test-fesetexcept \ |
150 | test-fesetexcept-traps $(tests-static) | |
d709042a JM |
151 | tests-static = test-fpucw-static test-fpucw-ieee-static \ |
152 | test-signgam-uchar-static test-signgam-uchar-init-static \ | |
153 | test-signgam-uint-static test-signgam-uint-init-static \ | |
154 | test-signgam-ullong-static test-signgam-ullong-init-static | |
c57abfa7 | 155 | |
0800411f RM |
156 | ifneq (,$(CXX)) |
157 | tests += test-math-isinff | |
158 | endif | |
159 | ||
8847214f | 160 | ifneq (no,$(PERL)) |
24a2718f | 161 | libm-vec-tests = $(addprefix test-,$(libmvec-tests)) |
b9e05ed0 PM |
162 | |
163 | libm-tests = $(foreach t,$(types),test-$(t) test-$(t)-finite test-i$(t)) \ | |
164 | $(libm-vec-tests) | |
165 | ||
8847214f UD |
166 | libm-tests.o = $(addsuffix .o,$(libm-tests)) |
167 | ||
168 | tests += $(libm-tests) | |
b4bcb3ae AS |
169 | libm-vec-test-wrappers = $(addsuffix -wrappers, $(libm-vec-tests)) |
170 | test-extras += $(libm-vec-test-wrappers) | |
171 | extra-test-objs += $(addsuffix .o, $(libm-vec-test-wrappers)) | |
58c50f06 | 172 | libm-tests-generated = libm-test-ulps.h libm-have-vector-test.h libm-test.c |
882ed1be | 173 | generated += $(libm-tests-generated) libm-test.stmp |
8847214f | 174 | |
882ed1be UD |
175 | # This is needed for dependencies |
176 | before-compile += $(objpfx)libm-test.c | |
8847214f | 177 | |
e0a3ed4f | 178 | ulps-file = $(firstword $(wildcard $(sysdirs:%=%/libm-test-ulps))) |
882ed1be UD |
179 | |
180 | $(addprefix $(objpfx), $(libm-tests-generated)): $(objpfx)libm-test.stmp | |
8847214f | 181 | |
ffb536d0 | 182 | $(objpfx)libm-test.stmp: $(ulps-file) libm-test.inc gen-libm-test.pl \ |
58c50f06 | 183 | gen-libm-have-vector-test.sh auto-libm-test-out |
882ed1be UD |
184 | $(make-target-directory) |
185 | $(PERL) gen-libm-test.pl -u $< -o "$(objpfx)" | |
58c50f06 | 186 | $(SHELL) gen-libm-have-vector-test.sh > $(objpfx)libm-have-vector-test.h |
8847214f | 187 | @echo > $@ |
8847214f UD |
188 | endif |
189 | ||
24a2718f AS |
190 | libm-test-fast-math-cflags = -fno-builtin -D__FAST_MATH__ -DTEST_FAST_MATH |
191 | libm-test-vec-cflags = $(libm-test-fast-math-cflags) -fno-inline \ | |
192 | -ffloat-store -D_OPENMP=201307 -Wno-unknown-pragmas | |
193 | ||
194 | CFLAGS-test-double-vlen2.c = $(libm-test-vec-cflags) | |
24a2718f AS |
195 | |
196 | CFLAGS-test-double-vlen4.c = $(libm-test-vec-cflags) | |
197 | CFLAGS-test-double-vlen4-wrappers.c = $(double-vlen4-arch-ext-cflags) | |
198 | ||
199 | CFLAGS-test-double-vlen8.c = $(libm-test-vec-cflags) | |
200 | CFLAGS-test-double-vlen8-wrappers.c = $(double-vlen8-arch-ext-cflags) | |
201 | ||
2a523216 | 202 | CFLAGS-test-float-vlen4.c = $(libm-test-vec-cflags) |
2a523216 AS |
203 | |
204 | CFLAGS-test-float-vlen8.c = $(libm-test-vec-cflags) | |
205 | CFLAGS-test-float-vlen8-wrappers.c = $(float-vlen8-arch-ext-cflags) | |
206 | ||
207 | CFLAGS-test-float-vlen16.c = $(libm-test-vec-cflags) | |
208 | CFLAGS-test-float-vlen16-wrappers.c = $(float-vlen16-arch-ext-cflags) | |
209 | ||
26211284 JM |
210 | # The no-inline tests use -fsignaling-nans, and thereby use the |
211 | # versions of classification macros that support sNaNs. The inline | |
212 | # function tests use the versions of classification macros that may | |
213 | # raise spurious exceptions for sNaNs, but also do not test for | |
214 | # exceptions. Thus both versions of the classification macros are | |
215 | # validated. | |
216 | libm-test-no-inline-cflags = -fno-inline -ffloat-store -fno-builtin \ | |
217 | -fsignaling-nans | |
5a28590a JM |
218 | libm-test-finite-cflags = $(libm-test-no-inline-cflags) \ |
219 | -U__FINITE_MATH_ONLY__ -D__FINITE_MATH_ONLY__=1 | |
220 | CFLAGS-test-float.c = $(libm-test-no-inline-cflags) | |
221 | CFLAGS-test-float-finite.c = $(libm-test-finite-cflags) | |
222 | CFLAGS-test-double.c = $(libm-test-no-inline-cflags) | |
223 | CFLAGS-test-double-finite.c = $(libm-test-finite-cflags) | |
224 | CFLAGS-test-ldouble.c = $(libm-test-no-inline-cflags) | |
225 | CFLAGS-test-ldouble-finite.c = $(libm-test-finite-cflags) | |
4f2689f4 | 226 | CFLAGS-test-tgmath.c = -fno-builtin |
d077f65f MT |
227 | # The following testcase uses very long lines (>3 million), so it may take a |
228 | # while to compile it. See: http://llvm.org/bugs/show_bug.cgi?id=14106 and | |
229 | # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54402 | |
8790af5f | 230 | CFLAGS-test-tgmath2.c = -fno-builtin |
301a6724 | 231 | CFLAGS-test-tgmath-ret.c = -fno-builtin |
8db73634 | 232 | CFLAGS-test-powl.c = -fno-builtin |
8df4e219 WD |
233 | |
234 | CFLAGS-test-snan.c = -fsignaling-nans | |
24a2718f AS |
235 | CPPFLAGS-test-ifloat.c = -U__LIBC_INTERNAL_MATH_INLINES \ |
236 | $(libm-test-fast-math-cflags) | |
237 | CPPFLAGS-test-idouble.c = -U__LIBC_INTERNAL_MATH_INLINES \ | |
238 | $(libm-test-fast-math-cflags) | |
b9e05ed0 | 239 | CPPFLAGS-test-ildouble.c = -U__LIBC_INTERNAL_MATH_INLINES \ |
24a2718f | 240 | $(libm-test-fast-math-cflags) |
c57abfa7 | 241 | |
939fdd1c JM |
242 | CFLAGS-test-signgam-finite.c = -ffinite-math-only |
243 | CFLAGS-test-signgam-finite-c99.c = -ffinite-math-only -std=c99 | |
244 | CFLAGS-test-signgam-finite-c11.c = -ffinite-math-only -std=c11 | |
d709042a JM |
245 | CFLAGS-test-signgam-uchar.c = -std=c99 |
246 | CFLAGS-test-signgam-uchar-init.c = -std=c99 | |
247 | CFLAGS-test-signgam-uchar-static.c = -std=c99 | |
248 | CFLAGS-test-signgam-uchar-init-static.c = -std=c99 | |
249 | CFLAGS-test-signgam-uint.c = -std=c99 | |
250 | CFLAGS-test-signgam-uint-init.c = -std=c99 | |
251 | CFLAGS-test-signgam-uint-static.c = -std=c99 | |
252 | CFLAGS-test-signgam-uint-init-static.c = -std=c99 | |
253 | CFLAGS-test-signgam-ullong.c = -std=c99 | |
254 | CFLAGS-test-signgam-ullong-init.c = -std=c99 | |
255 | CFLAGS-test-signgam-ullong-static.c = -std=c99 | |
256 | CFLAGS-test-signgam-ullong-init-static.c = -std=c99 | |
939fdd1c | 257 | |
3c47c83a CD |
258 | CFLAGS-test-math-isinff.cc = -std=gnu++11 |
259 | ||
26da047f RM |
260 | # The -lieee module sets the _LIB_VERSION_ switch to IEEE mode |
261 | # for error handling in the -lm functions. | |
262 | install-lib += libieee.a | |
263 | non-lib.a += libieee.a | |
264 | extra-objs += libieee.a ieee-math.o | |
265 | ||
28f540f4 RM |
266 | include ../Rules |
267 | ||
26510bdd | 268 | ifneq (no,$(PERL)) |
b2faf4ea | 269 | # This must come after the inclusion of sysdeps Makefiles via Rules. |
b9e05ed0 | 270 | $(addprefix $(objpfx), $(libm-tests.o)): $(objpfx)libm-test.stmp |
b2faf4ea | 271 | |
26510bdd CD |
272 | # Run the math programs to automatically generate ULPs files. |
273 | .PHONY: regen-ulps | |
274 | ||
275 | run-regen-ulps = $(test-wrapper-env) \ | |
8540f6d2 | 276 | $(run-program-env) \ |
01dc6df9 | 277 | $($*-ENV) $(rtld-prefix) $${run} |
26510bdd CD |
278 | |
279 | regen-ulps: $(addprefix $(objpfx),$(libm-tests)) | |
280 | rm -f $(objpfx)ULPs; rm -f $(objpfx)NewUlps; \ | |
281 | cp $(ulps-file) $(objpfx)libm-test-ulps; \ | |
282 | for run in $^; do \ | |
283 | echo "Regenerating ULPs for $${run}"; \ | |
284 | $(run-regen-ulps) -u -o $(objpfx); \ | |
285 | cat $(objpfx)ULPs >> $(objpfx)libm-test-ulps; \ | |
286 | rm $(objpfx)ULPs; \ | |
287 | done; \ | |
288 | $(PERL) gen-libm-test.pl -o $(objpfx) -n -u $(objpfx)libm-test-ulps; \ | |
289 | echo "Automatic regeneration of ULPs complete."; \ | |
290 | echo "Difference between the current baseline and the new baseline is:";\ | |
291 | diff -urN $(ulps-file) $(objpfx)NewUlps; \ | |
292 | echo "Copy $(objpfx)NewUlps to $(ulps-file) (relative to source)." | |
293 | else | |
294 | regen-ulps: | |
295 | @echo "Automatic regeneration of ULPs requires perl."; \ | |
296 | exit 1; | |
297 | endif | |
f7eac6eb | 298 | |
2f663a98 RM |
299 | # The generated sysd-rules file defines rules like this for sources |
300 | # coming from sysdeps/ directories. These rules find the generic sources. | |
301 | define o-iterator-doit | |
302 | $(objpfx)m_%$o: s_%.c $(before-compile); $$(compile-command.c) | |
303 | endef | |
304 | object-suffixes-left := $(all-object-suffixes) | |
305 | include $(o-iterator) | |
306 | ||
307 | ||
f7eac6eb RM |
308 | # This file defines the default _LIB_VERSION variable that controls |
309 | # the error return conventions for the math functions. | |
310 | CPPFLAGS-s_lib_version.c := -D_POSIX_MODE | |
311 | ||
a641835a RM |
312 | # We don't want the fdlibm code to use the inline math functions, |
313 | # only the fdlibm code. | |
4b9afc43 | 314 | math-CPPFLAGS += -D__NO_MATH_INLINES -D__LIBC_INTERNAL_MATH_INLINES |
a641835a | 315 | |
58e07151 RM |
316 | ifneq ($(long-double-fcts),yes) |
317 | # The `double' and `long double' types are the same on this machine. | |
318 | # We won't compile the `long double' code at all. Tell the `double' code | |
f5cb4a5c RM |
319 | # to define aliases for the `FUNCl' names. To avoid type conflicts in |
320 | # defining those aliases, tell <math.h> to declare the `FUNCl' names with | |
321 | # `double' instead of `long double'. | |
4b9afc43 | 322 | math-CPPFLAGS += -DNO_LONG_DOUBLE -D_Mlong_double_=double |
58e07151 RM |
323 | endif |
324 | ||
a6a4395d JM |
325 | # These files quiet sNaNs in a way that is optimized away without |
326 | # -fsignaling-nans. | |
327 | CFLAGS-s_modf.c += -fsignaling-nans | |
328 | CFLAGS-s_modff.c += -fsignaling-nans | |
329 | CFLAGS-s_modfl.c += -fsignaling-nans | |
330 | ||
26da047f RM |
331 | # The -lieee library is actually an object file. |
332 | # The module just defines the _LIB_VERSION_ variable. | |
333 | # It's not a library to make sure it is linked in instead of s_lib_version.o. | |
334 | $(objpfx)libieee.a: $(objpfx)ieee-math.o | |
335 | rm -f $@ | |
e7c5513d UD |
336 | $(patsubst %/,cd % &&,$(objpfx)) \ |
337 | $(LN_S) $(<F) $(@F) | |
3e5f5557 | 338 | |
b4bcb3ae AS |
339 | $(addprefix $(objpfx),\ |
340 | $(filter-out $(tests-static) $(libm-vec-tests),$(tests))): $(libm) | |
95e7cf29 | 341 | $(addprefix $(objpfx),$(tests-static)): $(objpfx)libm.a |
b4bcb3ae AS |
342 | $(addprefix $(objpfx), $(libm-vec-tests)): $(objpfx)%: $(objpfx)%-wrappers.o \ |
343 | $(libm) $(libmvec) | |
9498096c | 344 | |
2119dcfa | 345 | gmp-objs = $(patsubst %,$(common-objpfx)stdlib/%.o,\ |
6075607b | 346 | add_n sub_n cmp addmul_1 mul_1 mul_n divmod_1 \ |
32fcb36d DM |
347 | lshift rshift mp_clz_tab udiv_qrnnd inlines \ |
348 | $(gmp-sysdep_routines)) | |
6075607b UD |
349 | $(objpfx)atest-exp: $(gmp-objs) |
350 | $(objpfx)atest-sincos: $(gmp-objs) | |
351 | $(objpfx)atest-exp2: $(gmp-objs) | |
79520f4b | 352 | $(objpfx)test-fenv-tls: $(shared-thread-library) |