1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
dnl MPFR specific autoconf macros
dnl Copyright 2000, 2002, 2003 Free Software Foundation.
dnl Contributed by the Spaces project, INRIA Lorraine.
dnl
dnl This file is part of the MPFR Library.
dnl
dnl The MPFR Library is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU Lesser General Public License as published
dnl by the Free Software Foundation; either version 2.1 of the License, or (at
dnl your option) any later version.
dnl
dnl The MPFR Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
dnl License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public License
dnl along with the MPFR Library; see the file COPYING.LIB. If not, write to
dnl the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
dnl MA 02111-1307, USA.
dnl autoconf 2.50 is necessary because of the use of AH_VERBATIM,
dnl but it would be better to make the config file compatible with
dnl both autoconf 2.13 and autoconf 2.50.
dnl The following line allows the autoconf wrapper (when installed)
dnl to work as expected.
AC_PREREQ(2.50)
AC_DEFUN([AC_MY_LIBS],
[
if ` test "$1" `
then
AC_MSG_CHECKING($2 library)
if test -r "$1/lib$2.a"
then
LIBS="$LIBS $1/lib$2.a"
else
if test -r "$1/lib$2.so"
then
LIBS="$LIBS $1/lib$2.so"
else
AC_MSG_ERROR($1/lib$2.a/so not found)
fi
fi
AC_MSG_RESULT(yes)
else
AC_CHECK_LIB($2, main, , AC_MSG_ERROR($2 not found))
fi
]
)
dnl FIXME: Buggy?
AC_DEFUN([AC_MY_HEADERS],
[
if test "$1"
then
AC_CHECK_HEADER($1/$2, INCLUDES="$INCLUDES -I$1",AC_MSG_ERROR($2 not found in $1))
else
AC_CHECK_HEADER($2,, AC_MSG_ERROR($2 not found))
fi
])
AC_DEFUN([AC_CHECK_OS],
[
AC_CACHE_CHECK([OS type], mpfr_cv_os_type, [
mpfr_cv_os_type=`uname -s`
])
OS_TYPE=$mpfr_cv_os_type
])
AC_DEFUN([AC_CHECK_MACHTYPE],
[
AC_CACHE_CHECK([Mach type], mpfr_cv_mach_type, [
mpfr_cv_mach_type=`uname -m`
])
MACHTYPE=$mpfr_cv_mach_type
])
dnl ------------------------------------------------------------
AC_DEFUN([MPFR_CONFIGS],
[
AC_REQUIRE([AC_OBJEXT])
AC_REQUIRE([MPFR_CHECK_LIBM])
AC_REQUIRE([AC_HEADER_TIME])
# CPU-dependent objects for the test programs
case $host in
X86_PATTERN)
AC_SUBST(TESTS_ASM_OBJECTS, x86.$OBJEXT)
AC_DEFINE(MPFR_HAVE_TESTS_x86, 1,
[Define to 1 if mpfr x86/amd64 test routines are available.])
;;
amd64-*-*)
AC_SUBST(TESTS_ASM_OBJECTS, amd64.$OBJEXT)
AC_DEFINE(MPFR_HAVE_TESTS_x86, 1)
;;
esac
dnl Check for sizeof size_t
dnl AC_CHECK_SIZEOF
dnl AC_TYPE_SIZE_T
dnl
AC_CHECK_FUNCS([memset])
AC_CHECK_FUNCS([strtol])
AC_CHECK_HEADER([limits.h],, AC_MSG_ERROR([limits.h not found]))
AC_CHECK_HEADER([float.h],, AC_MSG_ERROR([float.h not found]))
dnl Check for stdargs
AC_CHECK_HEADER([stdarg.h],[AC_DEFINE([HAVE_STDARG])],
[AC_CHECK_HEADER([varargs.h],,
AC_MSG_ERROR([stdarg.h or varargs.h not found]))])
AC_CHECK_HEADERS(sys/time.h)
# Reasons for testing:
# gettimeofday - not in mingw
#
AC_CHECK_FUNCS(gettimeofday)
AC_REPLACE_FUNCS(strcasecmp strncasecmp)
dnl Check for IEEE-754 switches on Alpha
case $host in
alpha*-*-*)
saved_CFLAGS="$CFLAGS"
AC_CACHE_CHECK([for IEEE-754 switches], mpfr_cv_ieee_switches, [
if test -n "$GCC"; then
mpfr_cv_ieee_switches="-mfp-rounding-mode=d -mieee-with-inexact"
else
mpfr_cv_ieee_switches="-fprm d -ieee_with_inexact"
fi
CFLAGS="$CFLAGS $mpfr_cv_ieee_switches"
AC_TRY_COMPILE(,,, mpfr_cv_ieee_switches="none")
])
if test "$mpfr_cv_ieee_switches" = "none"; then
CFLAGS="$saved_CFLAGS"
else
CFLAGS="$saved_CFLAGS $mpfr_cv_ieee_switches"
fi
esac
# Reasons for testing:
# sys/fpu.h - MIPS specific
#
AC_CHECK_HEADERS(sys/fpu.h)
dnl Check for fesetround
AC_CACHE_CHECK([for fesetround], mpfr_cv_have_fesetround, [
saved_LIBS="$LIBS"
LIBS="$LIBS $MPFR_LIBM"
AC_TRY_LINK([#include <fenv.h>], [fesetround(FE_TONEAREST);],
mpfr_cv_have_fesetround=yes, mpfr_cv_have_fesetround=no)
LIBS="$saved_LIBS"
])
if test "$mpfr_cv_have_fesetround" = "yes"; then
AC_DEFINE(MPFR_HAVE_FESETROUND,1,[Define if you have the `fesetround' function via the <fenv.h> header file.])
fi
dnl Check whether 0/0, 1/0, -1/0, sqrt(-1) are valid expressions
AC_CACHE_CHECK([for valid NaN], mpfr_cv_valid_nan, [
AC_TRY_RUN([
#include <math.h>
int main()
{
double x = (0.0/0.0) + sqrt(-1.0);
return x == 1.0/0.0;
}
], mpfr_cv_valid_nan=yes, mpfr_cv_valid_nan=no, mpfr_cv_valid_nan=no)
])
if test "$mpfr_cv_valid_nan" = "yes"; then
AC_DEFINE(HAVE_INFS,1,[Define if 0/0, 1/0, -1/0 and sqrt(-1) work to generate NaN/infinities.])
fi
dnl Check for gcc float-conversion bug; if need be, -ffloat-store is used to
dnl force the conversion to the destination type when a value is stored to
dnl a variable (see ISO C99 standard 5.1.2.3#13, 6.3.1.5#2, 6.3.1.8#2). This
dnl is important concerning the exponent range. Note that this doesn't solve
dnl the double-rounding problem (x86 processors still have to be set to the
dnl IEEE-754 compatible rounding mode).
if test -n "$GCC"; then
AC_CACHE_CHECK([for gcc float-conversion bug], mpfr_cv_gcc_floatconv_bug, [
saved_LIBS="$LIBS"
LIBS="$LIBS $MPFR_LIBM"
AC_TRY_RUN([
#include <float.h>
#ifdef MPFR_HAVE_FESETROUND
#include <fenv.h>
#endif
int main()
{
double x = 0.5;
int i;
for (i = 1; i <= 11; i++)
x *= x;
if (x != 0)
return 1;
#ifdef MPFR_HAVE_FESETROUND
/* Useful test for the G4 PowerPC */
fesetround(FE_TOWARDZERO);
x = DBL_MAX;
x *= 2.0;
if (x != DBL_MAX)
return 1;
#endif
return 0;
}
], [mpfr_cv_gcc_floatconv_bug="no"],
[mpfr_cv_gcc_floatconv_bug="yes, use -ffloat-store"],
[mpfr_cv_gcc_floatconv_bug="cannot test, use -ffloat-store"])
LIBS="$saved_LIBS"
])
if test "$mpfr_cv_gcc_floatconv_bug" != "no"; then
CFLAGS="$CFLAGS -ffloat-store"
fi
fi
dnl Check if denormalized numbers are supported
AC_CACHE_CHECK([for denormalized numbers], mpfr_cv_have_denorms, [
AC_TRY_RUN([
#include <math.h>
#include <stdio.h>
int main()
{
double x = 2.22507385850720138309e-308;
fprintf (stderr, "%e\n", x / 2.0);
return 2.0 * (x / 2.0) != x;
}
], mpfr_cv_have_denorms=yes, mpfr_cv_have_denorms=no, mpfr_cv_have_denorms=no)
])
if test "$mpfr_cv_have_denorms" = "yes"; then
AC_DEFINE(HAVE_DENORMS,1,[Define if denormalized floats work.])
fi
dnl Check if HUGE_VAL is supported without the need of a specific library
AC_CACHE_CHECK([for HUGE_VAL], mpfr_cv_have_huge_val, [
AC_TRY_LINK([#include <math.h>], [HUGE_VAL;],
mpfr_cv_have_huge_val=yes, mpfr_cv_have_huge_val=no)
])
if test "$mpfr_cv_have_huge_val" = "yes"; then
AC_DEFINE(HAVE_HUGE_VAL,1,[Define if HUGE_VAL can be used without the need of a specific library.])
fi
MPFR_C_LONG_DOUBLE_FORMAT
])
dnl MPFR_C_LONG_DOUBLE_FORMAT
dnl -------------------------
dnl Determine the format of a long double.
dnl
dnl The object file is grepped, so as to work when cross compiling. A
dnl start and end sequence is included to avoid false matches, and
dnl allowance is made for the desired data crossing an "od -b" line
dnl boundary. The test number is a small integer so it should appear
dnl exactly, no rounding or truncation etc.
dnl
dnl "od -b" is supported even by Unix V7, and the awk script used doesn't
dnl have functions or anything, so even an "old" awk should suffice.
dnl
dnl The 10-byte IEEE extended format is generally padded to either 12 or 16
dnl bytes for alignment purposes. The SVR4 i386 ABI is 12 bytes, or i386
dnl gcc -m128bit-long-double selects 16 bytes. IA-64 is 16 bytes in LP64
dnl mode, or 12 bytes in ILP32 mode. The first 10 bytes is the relevant
dnl part in all cases (big and little endian).
dnl
dnl Enhancements:
dnl
dnl Could match more formats, but no need to worry until there's code
dnl wanting to use them.
dnl
dnl Don't want to duplicate the double matching from GMP_C_DOUBLE_FORMAT,
dnl perhaps we should merge with that macro, to match data formats
dnl irrespective of the C type in question. Or perhaps just let the code
dnl use DOUBLE macros when sizeof(double)==sizeof(long double).
AC_DEFUN([MPFR_C_LONG_DOUBLE_FORMAT],
[AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_PROG_AWK])
AC_REQUIRE([AC_OBJEXT])
AC_CHECK_TYPES([long double])
AC_CACHE_CHECK([format of `long double' floating point],
mpfr_cv_c_long_double_format,
[mpfr_cv_c_long_double_format=unknown
if test "$ac_cv_type_long_double" != yes; then
mpfr_cv_c_long_double_format="not available"
else
cat >conftest.c <<\EOF
[
/* "before" is 16 bytes to ensure there's no padding between it and "x".
We're not expecting any "long double" bigger than 16 bytes or with
alignment requirements stricter than 16 bytes. */
struct {
char before[16];
long double x;
char after[8];
} foo = {
{ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\001', '\043', '\105', '\147', '\211', '\253', '\315', '\357' },
-123456789.0,
{ '\376', '\334', '\272', '\230', '\166', '\124', '\062', '\020' }
};
]
EOF
mpfr_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC 2>&1"
if AC_TRY_EVAL(mpfr_compile); then
cat >conftest.awk <<\EOF
[
BEGIN {
found = 0
}
# got[] holds a sliding window of bytes read the input. got[0] is the most
# recent byte read, and got[31] the oldest byte read, so when looking to
# match some data the indices are "reversed".
#
{
for (f = 2; f <= NF; f++)
{
# new byte, shift others up
for (i = 31; i >= 0; i--)
got[i+1] = got[i];
got[0] = $f;
# end sequence
if (got[7] != "376") continue
if (got[6] != "334") continue
if (got[5] != "272") continue
if (got[4] != "230") continue
if (got[3] != "166") continue
if (got[2] != "124") continue
if (got[1] != "062") continue
if (got[0] != "020") continue
# start sequence, with 12-byte body
if (got[27] == "001" && \
got[26] == "043" && \
got[25] == "105" && \
got[24] == "147" && \
got[23] == "211" && \
got[22] == "253" && \
got[21] == "315" && \
got[20] == "357")
{
saw = " (" got[19] \
" " got[18] \
" " got[17] \
" " got[16] \
" " got[15] \
" " got[14] \
" " got[13] \
" " got[12] \
" " got[11] \
" " got[10] \
" " got[9] \
" " got[8] ")"
if (got[19] == "000" && \
got[18] == "000" && \
got[17] == "000" && \
got[16] == "000" && \
got[15] == "240" && \
got[14] == "242" && \
got[13] == "171" && \
got[12] == "353" && \
got[11] == "031" && \
got[10] == "300")
{
print "IEEE extended, little endian"
found = 1
exit
}
}
# start sequence, with 16-byte body
if (got[31] == "001" && \
got[30] == "043" && \
got[29] == "105" && \
got[28] == "147" && \
got[27] == "211" && \
got[26] == "253" && \
got[25] == "315" && \
got[24] == "357")
{
saw = " (" got[23] \
" " got[22] \
" " got[21] \
" " got[20] \
" " got[19] \
" " got[18] \
" " got[17] \
" " got[16] \
" " got[15] \
" " got[14] \
" " got[13] \
" " got[12] \
" " got[11] \
" " got[10] \
" " got[9] \
" " got[8] ")"
if (got[23] == "000" && \
got[22] == "000" && \
got[21] == "000" && \
got[20] == "000" && \
got[19] == "240" && \
got[18] == "242" && \
got[17] == "171" && \
got[16] == "353" && \
got[15] == "031" && \
got[14] == "300")
{
print "IEEE extended, little endian"
found = 1
exit
}
if (got[23] == "300" && \
got[22] == "031" && \
got[21] == "326" && \
got[20] == "363" && \
got[19] == "105" && \
got[18] == "100" && \
got[17] == "000" && \
got[16] == "000" && \
got[15] == "000" && \
got[14] == "000" && \
got[13] == "000" && \
got[12] == "000" && \
got[11] == "000" && \
got[10] == "000" && \
got[9] == "000" && \
got[8] == "000")
{
print "IEEE quad, big endian"
found = 1
exit
}
}
}
}
END {
if (! found)
print "unknown", saw
}
]
EOF
mpfr_cv_c_long_double_format=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`
case $mpfr_cv_c_long_double_format in
unknown*)
echo "cannot match anything, conftest.$OBJEXT contains" >&AC_FD_CC
od -b conftest.$OBJEXT >&AC_FD_CC
;;
esac
else
AC_MSG_WARN([oops, cannot compile test program])
fi
fi
rm -f conftest*
])
AH_VERBATIM([HAVE_LDOUBLE],
[/* Define one of the following to 1 for the format of a `long double'.
If your format is not among these choices, or you don't know what it is,
then leave all undefined.
IEEE_EXT is the 10-byte IEEE extended precision format.
IEEE_QUAD is the 16-byte IEEE quadruple precision format.
LITTLE or BIG is the endianness. */
#undef HAVE_LDOUBLE_IEEE_EXT_LITTLE
#undef HAVE_LDOUBLE_IEEE_QUAD_BIG])
case $mpfr_cv_c_long_double_format in
"IEEE extended, little endian")
AC_DEFINE(HAVE_LDOUBLE_IEEE_EXT_LITTLE, 1)
;;
"IEEE quad, big endian")
AC_DEFINE(HAVE_LDOUBLE_IEEE_QUAD_BIG, 1)
;;
unknown* | "not available")
;;
*)
AC_MSG_WARN([oops, unrecognised float format: $mpfr_cv_c_long_double_format])
;;
esac
])
dnl MPFR_CHECK_LIBM
dnl ---------------
dnl Determine a math library -lm to use.
AC_DEFUN([MPFR_CHECK_LIBM],
[AC_REQUIRE([AC_CANONICAL_HOST])
AC_SUBST(MPFR_LIBM,'')
case $host in
*-*-beos* | *-*-cygwin* | *-*-pw32*)
# According to libtool AC CHECK LIBM, these systems don't have libm
;;
*-*-hpux*)
# -lM means something subtly different to -lm, SVID style error handling
# or something. FIXME: Why exactly do we want this?
AC_CHECK_LIB(M, main, MPFR_LIBM="-lM")
;;
*-*-solaris*)
# On Solaris the math functions new in C99 are in -lm9x.
# FIXME: Do we need -lm9x as well as -lm, or just instead of?
AC_CHECK_LIB(m9x, main, MPFR_LIBM="-lm9x")
AC_CHECK_LIB(m, main, MPFR_LIBM="$MPFR_LIBM -lm")
;;
*-ncr-sysv4.3*)
# FIXME: What does -lmw mean? Libtool AC CHECK LIBM does it this way.
AC_CHECK_LIB(mw, _mwvalidcheckl, MPFR_LIBM="-lmw")
AC_CHECK_LIB(m, main, MPFR_LIBM="$MPFR_LIBM -lm")
;;
*)
AC_CHECK_LIB(m, main, MPFR_LIBM="-lm")
;;
esac
])
|