2 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
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.
7 AC_DEFUN([gl_FUNC_ISNANL],
10 gl_HAVE_ISNANL_NO_LIBM
11 if test $gl_cv_func_isnanl_no_libm = no; then
12 gl_HAVE_ISNANL_IN_LIBM
13 if test $gl_cv_func_isnanl_in_libm = yes; then
17 if test $gl_cv_func_isnanl_no_libm = yes \
18 || test $gl_cv_func_isnanl_in_libm = yes; then
20 LIBS="$LIBS $ISNANL_LIBM"
23 case "$gl_cv_func_isnanl_works" in
24 *yes) gl_func_isnanl=yes ;;
25 *) gl_func_isnanl=no; ISNANL_LIBM= ;;
30 if test $gl_func_isnanl = yes; then
31 AC_DEFINE([HAVE_ISNANL], 1,
32 [Define if the isnan(long double) function is available.])
36 AC_SUBST([ISNANL_LIBM])
39 AC_DEFUN([gl_FUNC_ISNANL_NO_LIBM],
41 gl_HAVE_ISNANL_NO_LIBM
42 gl_func_isnanl_no_libm=$gl_cv_func_isnanl_no_libm
43 if test $gl_func_isnanl_no_libm = yes; then
45 case "$gl_cv_func_isnanl_works" in
47 *) gl_func_isnanl_no_libm=no ;;
50 if test $gl_func_isnanl_no_libm = yes; then
51 AC_DEFINE([HAVE_ISNANL_IN_LIBC], 1,
52 [Define if the isnan(long double) function is available in libc.])
58 dnl Pull in replacement isnanl definition.
59 AC_DEFUN([gl_BUILD_ISNANL],
62 gl_LONG_DOUBLE_EXPONENT_LOCATION
65 dnl Test whether isnanl() can be used without libm.
66 AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM],
68 AC_CACHE_CHECK([whether isnan(long double) can be used without linking with libm],
69 [gl_cv_func_isnanl_no_libm],
71 AC_TRY_LINK([#include <math.h>
74 # define isnanl(x) __builtin_isnanl ((long double)(x))
77 # define isnanl(x) isnan ((long double)(x))
81 [gl_cv_func_isnanl_no_libm=yes],
82 [gl_cv_func_isnanl_no_libm=no])
86 dnl Test whether isnanl() can be used with libm.
87 AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM],
89 AC_CACHE_CHECK([whether isnan(long double) can be used with libm],
90 [gl_cv_func_isnanl_in_libm],
94 AC_TRY_LINK([#include <math.h>
97 # define isnanl(x) __builtin_isnanl ((long double)(x))
100 # define isnanl(x) isnan ((long double)(x))
103 [return isnanl (x);],
104 [gl_cv_func_isnanl_in_libm=yes],
105 [gl_cv_func_isnanl_in_libm=no])
110 dnl Test whether isnanl() recognizes all numbers which are neither finite nor
111 dnl infinite. This test fails e.g. on NetBSD/i386 and on glibc/ia64.
112 dnl Also, the GCC >= 4.0 built-in __builtin_isnanl does not pass the tests
113 dnl - for pseudo-denormals on i686 and x86_64,
114 dnl - for pseudo-zeroes, unnormalized numbers, and pseudo-denormals on ia64.
115 AC_DEFUN([gl_FUNC_ISNANL_WORKS],
117 AC_REQUIRE([AC_PROG_CC])
118 AC_REQUIRE([AC_C_BIGENDIAN])
119 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
120 AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_works],
128 # define isnanl(x) __builtin_isnanl ((long double)(x))
131 # define isnanl(x) isnan ((long double)(x))
134 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
135 typedef union { unsigned int word[NWORDS]; long double value; }
139 memory_long_double m;
142 /* gcc-3.4.3 on IRIX 6.5 appears to have a problem with this. */
143 if (!isnanl (0.0L / 0.0L))
146 /* The isnanl function should be immune against changes in the sign bit and
147 in the mantissa bits. The xor operation twiddles a bit that can only be
148 a sign bit or a mantissa bit (since the exponent never extends to
150 m.value = 0.0L / 0.0L;
151 m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
152 for (i = 0; i < NWORDS; i++)
154 if (!isnanl (m.value))
157 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
158 /* Representation of an 80-bit 'long double' as an initializer for a sequence
159 of 'unsigned int' words. */
160 # ifdef WORDS_BIGENDIAN
161 # define LDBL80_WORDS(exponent,manthi,mantlo) \
162 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
163 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
164 (unsigned int) (mantlo) << 16 \
167 # define LDBL80_WORDS(exponent,manthi,mantlo) \
168 { mantlo, manthi, exponent }
171 static memory_long_double x =
172 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
173 if (!isnanl (x.value))
177 /* Signalling NaN. */
178 static memory_long_double x =
179 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
180 if (!isnanl (x.value))
183 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
184 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
185 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
186 Application Architecture.
187 Table 5-2 "Floating-Point Register Encodings"
188 Figure 5-6 "Memory to Floating-Point Register Data Translation"
191 static memory_long_double x =
192 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
193 if (!isnanl (x.value))
196 { /* Pseudo-Infinity. */
197 static memory_long_double x =
198 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
199 if (!isnanl (x.value))
203 static memory_long_double x =
204 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
205 if (!isnanl (x.value))
208 { /* Unnormalized number. */
209 static memory_long_double x =
210 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
211 if (!isnanl (x.value))
214 { /* Pseudo-Denormal. */
215 static memory_long_double x =
216 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
217 if (!isnanl (x.value))
223 }], [gl_cv_func_isnanl_works=yes], [gl_cv_func_isnanl_works=no],
225 # Guess no on ia64, x86_64, i386.
226 ia64 | x86_64 | i*86) gl_cv_func_isnanl_works="guessing no";;
229 netbsd*) gl_cv_func_isnanl_works="guessing no";;
230 *) gl_cv_func_isnanl_works="guessing yes";;
238 AC_DEFUN([gl_LONG_DOUBLE_EXPONENT_LOCATION],
240 AC_REQUIRE([AC_C_BIGENDIAN])
241 AC_CACHE_CHECK([where to find the exponent in a 'long double'],
242 [gl_cv_cc_long_double_expbit0],
250 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
251 typedef union { long double value; unsigned int word[NWORDS]; }
253 static unsigned int ored_words[NWORDS];
254 static unsigned int anded_words[NWORDS];
255 static void add_to_ored_words (long double x)
257 memory_long_double m;
259 /* Clear it first, in case
260 sizeof (long double) < sizeof (memory_long_double). */
261 memset (&m, 0, sizeof (memory_long_double));
263 for (i = 0; i < NWORDS; i++)
265 ored_words[i] |= m.word[i];
266 anded_words[i] &= m.word[i];
272 FILE *fp = fopen ("conftest.out", "w");
275 for (j = 0; j < NWORDS; j++)
276 anded_words[j] = ~ (unsigned int) 0;
277 add_to_ored_words (0.25L);
278 add_to_ored_words (0.5L);
279 add_to_ored_words (1.0L);
280 add_to_ored_words (2.0L);
281 add_to_ored_words (4.0L);
282 /* Remove bits that are common (e.g. if representation of the first mantissa
284 for (j = 0; j < NWORDS; j++)
285 ored_words[j] &= ~anded_words[j];
286 /* Now find the nonzero word. */
287 for (j = 0; j < NWORDS; j++)
288 if (ored_words[j] != 0)
293 for (i = j + 1; i < NWORDS; i++)
294 if (ored_words[i] != 0)
296 fprintf (fp, "unknown");
297 return (fclose (fp) != 0);
300 if ((ored_words[j] >> i) & 1)
302 fprintf (fp, "word %d bit %d", (int) j, (int) i);
303 return (fclose (fp) != 0);
306 fprintf (fp, "unknown");
307 return (fclose (fp) != 0);
310 [gl_cv_cc_long_double_expbit0=`cat conftest.out`],
311 [gl_cv_cc_long_double_expbit0="unknown"],
313 dnl When cross-compiling, we don't know. It depends on the
314 dnl ABI and compiler version. There are too many cases.
315 gl_cv_cc_long_double_expbit0="unknown"
319 case "$gl_cv_cc_long_double_expbit0" in
321 word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
322 bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
323 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
324 [Define as the word index where to find the exponent of 'long double'.])
325 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
326 [Define as the bit index in the word where to find bit 0 of the exponent of 'long double'.])