Mercurial > gnulib
annotate m4/fma.m4 @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
18993
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
1 # fma.m4 serial 3 |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 dnl Copyright (C) 2011-2019 Free Software Foundation, Inc. |
16038 | 3 dnl This file is free software; the Free Software Foundation |
4 dnl gives unlimited permission to copy and/or distribute it, | |
5 dnl with or without modifications, as long as this notice is preserved. | |
6 | |
7 AC_DEFUN([gl_FUNC_FMA], | |
8 [ | |
9 AC_REQUIRE([gl_MATH_H_DEFAULTS]) | |
10 | |
11 dnl Determine FMA_LIBM. | |
16611
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
12 gl_MATHFUNC([fma], [double], [(double, double, double)], |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
13 [extern |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
14 #ifdef __cplusplus |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
15 "C" |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
16 #endif |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
17 double fma (double, double, double); |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
18 ]) |
16038 | 19 if test $gl_cv_func_fma_no_libm = yes \ |
20 || test $gl_cv_func_fma_in_libm = yes; then | |
16611
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
21 dnl Also check whether it's declared. |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
22 dnl IRIX 6.5 has fma() in libm but doesn't declare it in <math.h>, |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
23 dnl and the function is buggy. |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
24 AC_CHECK_DECL([fma], , [REPLACE_FMA=1], [[#include <math.h>]]) |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
25 if test $REPLACE_FMA = 0; then |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
26 gl_FUNC_FMA_WORKS |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
27 case "$gl_cv_func_fma_works" in |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
28 *no) REPLACE_FMA=1 ;; |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
29 esac |
b0c15a5d5038
fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
30 fi |
16038 | 31 else |
32 HAVE_FMA=0 | |
33 fi | |
34 if test $HAVE_FMA = 0 || test $REPLACE_FMA = 1; then | |
35 dnl Find libraries needed to link lib/fmal.c. | |
36 AC_REQUIRE([gl_FUNC_FREXP]) | |
37 AC_REQUIRE([gl_FUNC_LDEXP]) | |
38 AC_REQUIRE([gl_FUNC_FEGETROUND]) | |
39 FMA_LIBM= | |
40 dnl Append $FREXP_LIBM to FMA_LIBM, avoiding gratuitous duplicates. | |
41 case " $FMA_LIBM " in | |
42 *" $FREXP_LIBM "*) ;; | |
43 *) FMA_LIBM="$FMA_LIBM $FREXP_LIBM" ;; | |
44 esac | |
45 dnl Append $LDEXP_LIBM to FMA_LIBM, avoiding gratuitous duplicates. | |
46 case " $FMA_LIBM " in | |
47 *" $LDEXP_LIBM "*) ;; | |
48 *) FMA_LIBM="$FMA_LIBM $LDEXP_LIBM" ;; | |
49 esac | |
50 dnl Append $FEGETROUND_LIBM to FMA_LIBM, avoiding gratuitous duplicates. | |
51 case " $FMA_LIBM " in | |
52 *" $FEGETROUND_LIBM "*) ;; | |
53 *) FMA_LIBM="$FMA_LIBM $FEGETROUND_LIBM" ;; | |
54 esac | |
55 fi | |
56 AC_SUBST([FMA_LIBM]) | |
57 ]) | |
58 | |
59 dnl Test whether fma() has any of the 7 known bugs of glibc 2.11.3 on x86_64. | |
60 AC_DEFUN([gl_FUNC_FMA_WORKS], | |
61 [ | |
62 AC_REQUIRE([AC_PROG_CC]) | |
63 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | |
64 AC_REQUIRE([gl_FUNC_LDEXP]) | |
65 save_LIBS="$LIBS" | |
66 LIBS="$LIBS $FMA_LIBM $LDEXP_LIBM" | |
67 AC_CACHE_CHECK([whether fma works], [gl_cv_func_fma_works], | |
68 [ | |
69 AC_RUN_IFELSE( | |
70 [AC_LANG_SOURCE([[ | |
71 #include <float.h> | |
72 #include <math.h> | |
73 double p0 = 0.0; | |
74 int main() | |
75 { | |
76 int failed_tests = 0; | |
77 /* These tests fail with glibc 2.11.3 on x86_64. */ | |
78 { | |
79 volatile double x = 1.5; /* 3 * 2^-1 */ | |
80 volatile double y = x; | |
81 volatile double z = ldexp (1.0, DBL_MANT_DIG + 1); /* 2^54 */ | |
82 /* x * y + z with infinite precision: 2^54 + 9 * 2^-2. | |
83 Lies between (2^52 + 0) * 2^2 and (2^52 + 1) * 2^2 | |
84 and is closer to (2^52 + 1) * 2^2, therefore the rounding | |
85 must round up and produce (2^52 + 1) * 2^2. */ | |
86 volatile double expected = z + 4.0; | |
87 volatile double result = fma (x, y, z); | |
88 if (result != expected) | |
89 failed_tests |= 1; | |
90 } | |
91 { | |
92 volatile double x = 1.25; /* 2^0 + 2^-2 */ | |
93 volatile double y = - x; | |
94 volatile double z = ldexp (1.0, DBL_MANT_DIG + 1); /* 2^54 */ | |
95 /* x * y + z with infinite precision: 2^54 - 2^0 - 2^-1 - 2^-4. | |
96 Lies between (2^53 - 1) * 2^1 and 2^53 * 2^1 | |
97 and is closer to (2^53 - 1) * 2^1, therefore the rounding | |
98 must round down and produce (2^53 - 1) * 2^1. */ | |
99 volatile double expected = (ldexp (1.0, DBL_MANT_DIG) - 1.0) * 2.0; | |
100 volatile double result = fma (x, y, z); | |
101 if (result != expected) | |
102 failed_tests |= 2; | |
103 } | |
104 { | |
105 volatile double x = 1.0 + ldexp (1.0, 1 - DBL_MANT_DIG); /* 2^0 + 2^-52 */ | |
106 volatile double y = x; | |
107 volatile double z = 4.0; /* 2^2 */ | |
108 /* x * y + z with infinite precision: 2^2 + 2^0 + 2^-51 + 2^-104. | |
109 Lies between (2^52 + 2^50) * 2^-50 and (2^52 + 2^50 + 1) * 2^-50 | |
110 and is closer to (2^52 + 2^50 + 1) * 2^-50, therefore the rounding | |
111 must round up and produce (2^52 + 2^50 + 1) * 2^-50. */ | |
112 volatile double expected = 4.0 + 1.0 + ldexp (1.0, 3 - DBL_MANT_DIG); | |
113 volatile double result = fma (x, y, z); | |
114 if (result != expected) | |
115 failed_tests |= 4; | |
116 } | |
117 { | |
118 volatile double x = 1.0 + ldexp (1.0, 1 - DBL_MANT_DIG); /* 2^0 + 2^-52 */ | |
119 volatile double y = - x; | |
120 volatile double z = 8.0; /* 2^3 */ | |
121 /* x * y + z with infinite precision: 2^2 + 2^1 + 2^0 - 2^-51 - 2^-104. | |
122 Lies between (2^52 + 2^51 + 2^50 - 1) * 2^-50 and | |
123 (2^52 + 2^51 + 2^50) * 2^-50 and is closer to | |
124 (2^52 + 2^51 + 2^50 - 1) * 2^-50, therefore the rounding | |
125 must round down and produce (2^52 + 2^51 + 2^50 - 1) * 2^-50. */ | |
126 volatile double expected = 7.0 - ldexp (1.0, 3 - DBL_MANT_DIG); | |
127 volatile double result = fma (x, y, z); | |
128 if (result != expected) | |
129 failed_tests |= 8; | |
130 } | |
131 { | |
132 volatile double x = 1.25; /* 2^0 + 2^-2 */ | |
133 volatile double y = - 0.75; /* - 2^0 + 2^-2 */ | |
134 volatile double z = ldexp (1.0, DBL_MANT_DIG); /* 2^53 */ | |
135 /* x * y + z with infinite precision: 2^53 - 2^0 + 2^-4. | |
136 Lies between (2^53 - 2^0) and 2^53 and is closer to (2^53 - 2^0), | |
137 therefore the rounding must round down and produce (2^53 - 2^0). */ | |
138 volatile double expected = ldexp (1.0, DBL_MANT_DIG) - 1.0; | |
139 volatile double result = fma (x, y, z); | |
140 if (result != expected) | |
141 failed_tests |= 16; | |
142 } | |
143 if ((DBL_MANT_DIG % 2) == 1) | |
144 { | |
145 volatile double x = 1.0 + ldexp (1.0, - (DBL_MANT_DIG + 1) / 2); /* 2^0 + 2^-27 */ | |
146 volatile double y = 1.0 - ldexp (1.0, - (DBL_MANT_DIG + 1) / 2); /* 2^0 - 2^-27 */ | |
147 volatile double z = - ldexp (1.0, DBL_MIN_EXP - DBL_MANT_DIG); /* - 2^-1074 */ | |
148 /* x * y + z with infinite precision: 2^0 - 2^-54 - 2^-1074. | |
149 Lies between (2^53 - 1) * 2^-53 and 2^53 * 2^-53 and is closer to | |
150 (2^53 - 1) * 2^-53, therefore the rounding must round down and | |
151 produce (2^53 - 1) * 2^-53. */ | |
152 volatile double expected = 1.0 - ldexp (1.0, - DBL_MANT_DIG); | |
153 volatile double result = fma (x, y, z); | |
154 if (result != expected) | |
155 failed_tests |= 32; | |
156 } | |
157 { | |
158 double minus_inf = -1.0 / p0; | |
159 volatile double x = ldexp (1.0, DBL_MAX_EXP - 1); | |
160 volatile double y = ldexp (1.0, DBL_MAX_EXP - 1); | |
161 volatile double z = minus_inf; | |
162 volatile double result = fma (x, y, z); | |
163 if (!(result == minus_inf)) | |
164 failed_tests |= 64; | |
165 } | |
166 return failed_tests; | |
167 }]])], | |
168 [gl_cv_func_fma_works=yes], | |
169 [gl_cv_func_fma_works=no], | |
18993
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
170 [dnl Guess yes on native Windows with MSVC. |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
171 dnl Otherwise guess no, even on glibc systems. |
16038 | 172 gl_cv_func_fma_works="guessing no" |
18993
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
173 case "$host_os" in |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
174 mingw*) |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
175 AC_EGREP_CPP([Known], [ |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
176 #ifdef _MSC_VER |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
177 Known |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
178 #endif |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
179 ], [gl_cv_func_fma_works="guessing yes"]) |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
180 ;; |
a75cfc731331
Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents:
18626
diff
changeset
|
181 esac |
16038 | 182 ]) |
183 ]) | |
184 LIBS="$save_LIBS" | |
185 ]) | |
186 | |
187 # Prerequisites of lib/fma.c. | |
188 AC_DEFUN([gl_PREREQ_FMA], [:]) |