xref: /netbsd-src/external/lgpl3/gmp/dist/acinclude.m4 (revision 75219f3a016dfaad1cb304eb017f9787b1de8292)
1dnl  GMP specific autoconf macros
2
3
4dnl  Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 Free Software
5dnl  Foundation, Inc.
6dnl
7dnl  This file is part of the GNU MP Library.
8dnl
9dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10dnl  it under the terms of the GNU Lesser General Public License as published
11dnl  by the Free Software Foundation; either version 3 of the License, or (at
12dnl  your option) any later version.
13dnl
14dnl  The GNU MP Library is distributed in the hope that it will be useful, but
15dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17dnl  License for more details.
18dnl
19dnl  You should have received a copy of the GNU Lesser General Public License
20dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
21
22
23dnl  Some tests use, or must delete, the default compiler output.  The
24dnl  possible filenames are based on what autoconf looks for, namely
25dnl
26dnl    a.out - normal unix style
27dnl    b.out - i960 systems, including gcc there
28dnl    a.exe - djgpp
29dnl    a_out.exe - OpenVMS DEC C called via GNV wrapper (gnv.sourceforge.net)
30dnl    conftest.exe - various DOS compilers
31
32
33define(IA64_PATTERN,
34[[ia64*-*-* | itanium-*-* | itanium2-*-*]])
35
36define(M5407_PATTERN,
37[[m5407-*-*]])
38
39dnl  Need to be careful not to match m6811, m6812, m68hc11 and m68hc12, all
40dnl  of which config.sub accepts.  (Though none of which are likely to work
41dnl  with GMP.)
42dnl
43define(M68K_PATTERN,
44[[m68k-*-* | m68[0-9][0-9][0-9]-*-*]])
45
46define(POWERPC64_PATTERN,
47[[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-* | powerpc970-*-* | power[3-9]-*-*]])
48
49define(X86_PATTERN,
50[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])
51
52define(X86_64_PATTERN,
53[[athlon64-*-* | pentium4-*-* | atom-*-* | core2-*-* | corei-*-* | x86_64-*-* | nano-*-*]])
54
55dnl  GMP_FAT_SUFFIX(DSTVAR, DIRECTORY)
56dnl  ---------------------------------
57dnl  Emit code to set shell variable DSTVAR to the suffix for a fat binary
58dnl  routine from DIRECTORY.  DIRECTORY can be a shell expression like $foo
59dnl  etc.
60dnl
61dnl  The suffix is directory separators / or \ changed to underscores, and
62dnl  if there's more than one directory part, then the first is dropped.
63dnl
64dnl  For instance,
65dnl
66dnl      x86         ->  x86
67dnl      x86/k6      ->  k6
68dnl      x86/k6/mmx  ->  k6_mmx
69
70define(GMP_FAT_SUFFIX,
71[[$1=`echo $2 | sed -e '/\//s:^[^/]*/::' -e 's:[\\/]:_:g'`]])
72
73
74dnl  GMP_REMOVE_FROM_LIST(listvar,item)
75dnl  ----------------------------------
76dnl  Emit code to remove any occurrence of ITEM from $LISTVAR.  ITEM can be a
77dnl  shell expression like $foo if desired.
78
79define(GMP_REMOVE_FROM_LIST,
80[remove_from_list_tmp=
81for remove_from_list_i in $[][$1]; do
82  if test $remove_from_list_i = [$2]; then :;
83  else
84     remove_from_list_tmp="$remove_from_list_tmp $remove_from_list_i"
85  fi
86done
87[$1]=$remove_from_list_tmp
88])
89
90
91dnl  GMP_STRIP_PATH(subdir)
92dnl  ----------------------
93dnl  Strip entries */subdir from $path and $fat_path.
94
95define(GMP_STRIP_PATH,
96[GMP_STRIP_PATH_VAR(path, [$1])
97GMP_STRIP_PATH_VAR(fat_path, [$1])
98])
99
100define(GMP_STRIP_PATH_VAR,
101[tmp_path=
102for i in $[][$1]; do
103  case $i in
104    */[$2]) ;;
105    *) tmp_path="$tmp_path $i" ;;
106  esac
107done
108[$1]="$tmp_path"
109])
110
111
112dnl  GMP_INCLUDE_GMP_H
113dnl  -----------------
114dnl  Expand to the right way to #include gmp-h.in.  This must be used
115dnl  instead of gmp.h, since that file isn't generated until the end of the
116dnl  configure.
117dnl
118dnl  Dummy value for GMP_LIMB_BITS is enough
119dnl  for all current configure-time uses of gmp.h.
120
121define(GMP_INCLUDE_GMP_H,
122[[#define __GMP_WITHIN_CONFIGURE 1   /* ignore template stuff */
123#define GMP_NAIL_BITS $GMP_NAIL_BITS
124#define GMP_LIMB_BITS 123
125$DEFN_LONG_LONG_LIMB
126#include "$srcdir/gmp-h.in"]
127])
128
129
130dnl  GMP_HEADER_GETVAL(NAME,FILE)
131dnl  ----------------------------
132dnl  Expand at autoconf time to the value of a "#define NAME" from the given
133dnl  FILE.  The regexps here aren't very rugged, but are enough for gmp.
134dnl  /dev/null as a parameter prevents a hang if $2 is accidentally omitted.
135
136define(GMP_HEADER_GETVAL,
137[patsubst(patsubst(
138esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
139[^.*$1[ 	]+],[]),
140[[
141 	]*$],[])])
142
143
144dnl  GMP_VERSION
145dnl  -----------
146dnl  The gmp version number, extracted from the #defines in gmp-h.in at
147dnl  autoconf time.  Two digits like 3.0 if patchlevel <= 0, or three digits
148dnl  like 3.0.1 if patchlevel > 0.
149
150define(GMP_VERSION,
151[GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp-h.in)[]dnl
152.GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp-h.in)[]dnl
153.GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in)])
154
155
156dnl  GMP_SUBST_CHECK_FUNCS(func,...)
157dnl  ------------------------------
158dnl  Setup an AC_SUBST of HAVE_FUNC_01 for each argument.
159
160AC_DEFUN([GMP_SUBST_CHECK_FUNCS],
161[m4_if([$1],,,
162[_GMP_SUBST_CHECK_FUNCS(ac_cv_func_[$1],HAVE_[]m4_translit([$1],[a-z],[A-Z])_01)
163GMP_SUBST_CHECK_FUNCS(m4_shift($@))])])
164
165dnl  Called: _GMP_SUBST_CHECK_FUNCS(cachevar,substvar)
166AC_DEFUN([_GMP_SUBST_CHECK_FUNCS],
167[case $[$1] in
168yes) AC_SUBST([$2],1) ;;
169no)  [$2]=0 ;;
170esac
171])
172
173
174dnl  GMP_SUBST_CHECK_HEADERS(foo.h,...)
175dnl  ----------------------------------
176dnl  Setup an AC_SUBST of HAVE_FOO_H_01 for each argument.
177
178AC_DEFUN([GMP_SUBST_CHECK_HEADERS],
179[m4_if([$1],,,
180[_GMP_SUBST_CHECK_HEADERS(ac_cv_header_[]m4_translit([$1],[./],[__]),
181HAVE_[]m4_translit([$1],[a-z./],[A-Z__])_01)
182GMP_SUBST_CHECK_HEADERS(m4_shift($@))])])
183
184dnl  Called: _GMP_SUBST_CHECK_HEADERS(cachevar,substvar)
185AC_DEFUN([_GMP_SUBST_CHECK_HEADERS],
186[case $[$1] in
187yes) AC_SUBST([$2],1) ;;
188no)  [$2]=0 ;;
189esac
190])
191
192
193dnl  GMP_COMPARE_GE(A1,B1, A2,B2, ...)
194dnl  ---------------------------------
195dnl  Compare two version numbers A1.A2.etc and B1.B2.etc.  Set
196dnl  $gmp_compare_ge to yes or no according to the result.  The A parts
197dnl  should be variables, the B parts fixed numbers.  As many parts as
198dnl  desired can be included.  An empty string in an A part is taken to be
199dnl  zero, the B parts should be non-empty and non-zero.
200dnl
201dnl  For example,
202dnl
203dnl      GMP_COMPARE($major,10, $minor,3, $subminor,1)
204dnl
205dnl  would test whether $major.$minor.$subminor is greater than or equal to
206dnl  10.3.1.
207
208AC_DEFUN([GMP_COMPARE_GE],
209[gmp_compare_ge=no
210GMP_COMPARE_GE_INTERNAL($@)
211])
212
213AC_DEFUN([GMP_COMPARE_GE_INTERNAL],
214[ifelse(len([$3]),0,
215[if test -n "$1" && test "$1" -ge $2; then
216  gmp_compare_ge=yes
217fi],
218[if test -n "$1"; then
219  if test "$1" -gt $2; then
220    gmp_compare_ge=yes
221  else
222    if test "$1" -eq $2; then
223      GMP_COMPARE_GE_INTERNAL(m4_shift(m4_shift($@)))
224    fi
225  fi
226fi])
227])
228
229
230dnl  GMP_PROG_AR
231dnl  -----------
232dnl  GMP additions to $AR.
233dnl
234dnl  A cross-"ar" may be necessary when cross-compiling since the build
235dnl  system "ar" might try to interpret the object files to build a symbol
236dnl  table index, hence the use of AC_CHECK_TOOL.
237dnl
238dnl  A user-selected $AR is always left unchanged.  AC_CHECK_TOOL is still
239dnl  run to get the "checking" message printed though.
240dnl
241dnl  If extra flags are added to AR, then ac_cv_prog_AR and
242dnl  ac_cv_prog_ac_ct_AR are set too, since libtool (cvs 2003-03-31 at
243dnl  least) will do an AC_CHECK_TOOL and that will AR from one of those two
244dnl  cached variables.  (ac_cv_prog_AR is used if there's an ac_tool_prefix,
245dnl  or ac_cv_prog_ac_ct_AR is used otherwise.)  FIXME: This is highly
246dnl  dependent on autoconf internals, perhaps it'd work to put our extra
247dnl  flags into AR_FLAGS instead.
248dnl
249dnl  $AR_FLAGS is set to "cq" rather than leaving it to libtool "cru".  The
250dnl  latter fails when libtool goes into piecewise mode and is unlucky
251dnl  enough to have two same-named objects in separate pieces, as happens
252dnl  for instance to random.o (and others) on vax-dec-ultrix4.5.  Naturally
253dnl  a user-selected $AR_FLAGS is left unchanged.
254dnl
255dnl  For reference, $ARFLAGS is used by automake (1.8) for its ".a" archive
256dnl  file rules.  This doesn't get used by the piecewise linking, so we
257dnl  leave it at the default "cru".
258dnl
259dnl  FIXME: Libtool 1.5.2 has its own arrangements for "cq", but that version
260dnl  is broken in other ways.  When we can upgrade, remove the forcible
261dnl  AR_FLAGS=cq.
262
263AC_DEFUN([GMP_PROG_AR],
264[dnl  Want to establish $AR before libtool initialization.
265AC_BEFORE([$0],[AC_PROG_LIBTOOL])
266gmp_user_AR=$AR
267AC_CHECK_TOOL(AR, ar, ar)
268if test -z "$gmp_user_AR"; then
269                        eval arflags=\"\$ar${abi1}_flags\"
270  test -n "$arflags" || eval arflags=\"\$ar${abi2}_flags\"
271  if test -n "$arflags"; then
272    AC_MSG_CHECKING([for extra ar flags])
273    AR="$AR $arflags"
274    ac_cv_prog_AR="$AR $arflags"
275    ac_cv_prog_ac_ct_AR="$AR $arflags"
276    AC_MSG_RESULT([$arflags])
277  fi
278fi
279if test -z "$AR_FLAGS"; then
280  AR_FLAGS=cq
281fi
282])
283
284
285dnl  GMP_PROG_M4
286dnl  -----------
287dnl  Find a working m4, either in $PATH or likely locations, and setup $M4
288dnl  and an AC_SUBST accordingly.  If $M4 is already set then it's a user
289dnl  choice and is accepted with no checks.  GMP_PROG_M4 is like
290dnl  AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's
291dnl  good enough.
292dnl
293dnl  See mpn/asm-defs.m4 for details on the known bad m4s.
294
295AC_DEFUN([GMP_PROG_M4],
296[AC_ARG_VAR(M4,[m4 macro processor])
297AC_CACHE_CHECK([for suitable m4],
298                gmp_cv_prog_m4,
299[if test -n "$M4"; then
300  gmp_cv_prog_m4="$M4"
301else
302  cat >conftest.m4 <<\EOF
303dnl  Must protect this against being expanded during autoconf m4!
304dnl  Dont put "dnl"s in this as autoconf will flag an error for unexpanded
305dnl  macros.
306[define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)',
307``bad: $][# not supported (SunOS /usr/bin/m4)
308'')ifelse(eval(89),89,`define(t2,Y)',
309`bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
310')ifelse(t1`'t2,YY,`good
311')]
312EOF
313dnl ' <- balance the quotes for emacs sh-mode
314  echo "trying m4" >&AC_FD_CC
315  gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC`
316  echo "$gmp_tmp_val" >&AC_FD_CC
317  if test "$gmp_tmp_val" = good; then
318    gmp_cv_prog_m4="m4"
319  else
320    IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
321dnl $ac_dummy forces splitting on constant user-supplied paths.
322dnl POSIX.2 word splitting is done only on the output of word expansions,
323dnl not every word.  This closes a longstanding sh security hole.
324    ac_dummy="$PATH:/usr/5bin"
325    for ac_dir in $ac_dummy; do
326      test -z "$ac_dir" && ac_dir=.
327      echo "trying $ac_dir/m4" >&AC_FD_CC
328      gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`
329      echo "$gmp_tmp_val" >&AC_FD_CC
330      if test "$gmp_tmp_val" = good; then
331        gmp_cv_prog_m4="$ac_dir/m4"
332        break
333      fi
334    done
335    IFS="$ac_save_ifs"
336    if test -z "$gmp_cv_prog_m4"; then
337      AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
338    fi
339  fi
340  rm -f conftest.m4
341fi])
342M4="$gmp_cv_prog_m4"
343AC_SUBST(M4)
344])
345
346
347dnl  GMP_M4_M4WRAP_SPURIOUS
348dnl  ----------------------
349dnl  Check for spurious output from m4wrap(), as described in mpn/asm-defs.m4.
350dnl
351dnl  The following systems have been seen with the problem.
352dnl
353dnl  - Unicos alpha, but its assembler doesn't seem to mind.
354dnl  - MacOS X Darwin, its assembler fails.
355dnl  - NetBSD 1.4.1 m68k, and gas 1.92.3 there gives a warning and ignores
356dnl    the bad last line since it doesn't have a newline.
357dnl  - NetBSD 1.4.2 alpha, but its assembler doesn't seem to mind.
358dnl  - HP-UX ia64.
359dnl
360dnl  Enhancement: Maybe this could be in GMP_PROG_M4, and attempt to prefer
361dnl  an m4 with a working m4wrap, if it can be found.
362
363AC_DEFUN([GMP_M4_M4WRAP_SPURIOUS],
364[AC_REQUIRE([GMP_PROG_M4])
365AC_CACHE_CHECK([if m4wrap produces spurious output],
366               gmp_cv_m4_m4wrap_spurious,
367[# hide the d-n-l from autoconf's error checking
368tmp_d_n_l=d""nl
369cat >conftest.m4 <<EOF
370[changequote({,})define(x,)m4wrap({x})$tmp_d_n_l]
371EOF
372echo test input is >&AC_FD_CC
373cat conftest.m4 >&AC_FD_CC
374tmp_chars=`$M4 conftest.m4 | wc -c`
375echo produces $tmp_chars chars output >&AC_FD_CC
376rm -f conftest.m4
377if test $tmp_chars = 0; then
378  gmp_cv_m4_m4wrap_spurious=no
379else
380  gmp_cv_m4_m4wrap_spurious=yes
381fi
382])
383GMP_DEFINE_RAW(["define(<M4WRAP_SPURIOUS>,<$gmp_cv_m4_m4wrap_spurious>)"])
384])
385
386
387dnl  GMP_PROG_NM
388dnl  -----------
389dnl  GMP additions to libtool AC_PROG_NM.
390dnl
391dnl  Note that if AC_PROG_NM can't find a working nm it still leaves
392dnl  $NM set to "nm", so $NM can't be assumed to actually work.
393dnl
394dnl  A user-selected $NM is always left unchanged.  AC_PROG_NM is still run
395dnl  to get the "checking" message printed though.
396dnl
397dnl  Perhaps it'd be worthwhile checking that nm works, by running it on an
398dnl  actual object file.  For instance on sparcv9 solaris old versions of
399dnl  GNU nm don't recognise 64-bit objects.  Checking would give a better
400dnl  error message than just a failure in later tests like GMP_ASM_W32 etc.
401dnl
402dnl  On the other hand it's not really normal autoconf practice to take too
403dnl  much trouble over detecting a broken set of tools.  And libtool doesn't
404dnl  do anything at all for say ranlib or strip.  So for now we're inclined
405dnl  to just demand that the user provides a coherent environment.
406
407AC_DEFUN([GMP_PROG_NM],
408[dnl  Make sure we're the first to call AC_PROG_NM, so our extra flags are
409dnl   used by everyone.
410AC_BEFORE([$0],[AC_PROG_NM])
411gmp_user_NM=$NM
412AC_PROG_NM
413
414# FIXME: When cross compiling (ie. $ac_tool_prefix not empty), libtool
415# defaults to plain "nm" if a "${ac_tool_prefix}nm" is not found.  In this
416# case run it again to try the native "nm", firstly so that likely locations
417# are searched, secondly so that -B or -p are added if necessary for BSD
418# format.  This is necessary for instance on OSF with "./configure
419# --build=alphaev5-dec-osf --host=alphaev6-dec-osf".
420#
421if test -z "$gmp_user_NM" && test -n "$ac_tool_prefix" && test "$NM" = nm; then
422  $as_unset lt_cv_path_NM
423  gmp_save_ac_tool_prefix=$ac_tool_prefix
424  ac_tool_prefix=
425  NM=
426  AC_PROG_NM
427  ac_tool_prefix=$gmp_save_ac_tool_prefix
428fi
429
430if test -z "$gmp_user_NM"; then
431                        eval nmflags=\"\$nm${abi1}_flags\"
432  test -n "$nmflags" || eval nmflags=\"\$nm${abi2}_flags\"
433  if test -n "$nmflags"; then
434    AC_MSG_CHECKING([for extra nm flags])
435    NM="$NM $nmflags"
436    AC_MSG_RESULT([$nmflags])
437  fi
438fi
439])
440
441
442dnl  GMP_PROG_CC_WORKS(cc+cflags,[ACTION-IF-WORKS][,ACTION-IF-NOT-WORKS])
443dnl  --------------------------------------------------------------------
444dnl  Check if cc+cflags can compile and link.
445dnl
446dnl  This test is designed to be run repeatedly with different cc+cflags
447dnl  selections, so the result is not cached.
448dnl
449dnl  For a native build, meaning $cross_compiling == no, we require that the
450dnl  generated program will run.  This is the same as AC_PROG_CC does in
451dnl  _AC_COMPILER_EXEEXT_WORKS, and checking here will ensure we don't pass
452dnl  a CC/CFLAGS combination that it rejects.
453dnl
454dnl  sparc-*-solaris2.7 can compile ABI=64 but won't run it if the kernel
455dnl  was booted in 32-bit mode.  The effect of requiring the compiler output
456dnl  will run is that a plain native "./configure" falls back on ABI=32, but
457dnl  ABI=64 is still available as a cross-compile.
458dnl
459dnl  The various specific problems we try to detect are done in separate
460dnl  compiles.  Although this is probably a bit slower than one test
461dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
462dnl  hence giving the user a clue about why we rejected the compiler.
463
464AC_DEFUN([GMP_PROG_CC_WORKS],
465[AC_MSG_CHECKING([compiler $1])
466gmp_prog_cc_works=yes
467
468# first see a simple "main()" works, then go on to other checks
469GMP_PROG_CC_WORKS_PART([$1], [])
470
471GMP_PROG_CC_WORKS_PART([$1], [function pointer return],
472[/* The following provokes an internal error from gcc 2.95.2 -mpowerpc64
473   (without -maix64), hence detecting an unusable compiler */
474void *g() { return (void *) 0; }
475void *f() { return g(); }
476])
477
478GMP_PROG_CC_WORKS_PART([$1], [cmov instruction],
479[/* The following provokes an invalid instruction syntax from i386 gcc
480   -march=pentiumpro on Solaris 2.8.  The native sun assembler
481   requires a non-standard syntax for cmov which gcc (as of 2.95.2 at
482   least) doesn't know.  */
483int n;
484int cmov () { return (n >= 0 ? n : 0); }
485])
486
487GMP_PROG_CC_WORKS_PART([$1], [double -> ulong conversion],
488[/* The following provokes a linker invocation problem with gcc 3.0.3
489   on AIX 4.3 under "-maix64 -mpowerpc64 -mcpu=630".  The -mcpu=630
490   option causes gcc to incorrectly select the 32-bit libgcc.a, not
491   the 64-bit one, and consequently it misses out on the __fixunsdfdi
492   helper (double -> uint64 conversion).  */
493double d;
494unsigned long gcc303 () { return (unsigned long) d; }
495])
496
497GMP_PROG_CC_WORKS_PART([$1], [double negation],
498[/* The following provokes an error from hppa gcc 2.95 under -mpa-risc-2-0 if
499   the assembler doesn't know hppa 2.0 instructions.  fneg is a 2.0
500   instruction, and a negation like this comes out using it.  */
501double fneg_data;
502unsigned long fneg () { return -fneg_data; }
503])
504
505GMP_PROG_CC_WORKS_PART([$1], [double -> float conversion],
506[/* The following makes gcc 3.3 -march=pentium4 generate an SSE2 xmm insn
507   (cvtsd2ss) which will provoke an error if the assembler doesn't recognise
508   those instructions.  Not sure how much of the gmp code will come out
509   wanting sse2, but it's easiest to reject an option we know is bad.  */
510double ftod_data;
511float ftod () { return (float) ftod_data; }
512])
513
514GMP_PROG_CC_WORKS_PART([$1], [gnupro alpha ev6 char spilling],
515[/* The following provokes an internal compiler error from gcc version
516   "2.9-gnupro-99r1" under "-O2 -mcpu=ev6", apparently relating to char
517   values being spilled into floating point registers.  The problem doesn't
518   show up all the time, but has occurred enough in GMP for us to reject
519   this compiler+flags.  */
520#include <string.h>  /* for memcpy */
521struct try_t
522{
523 char dst[2];
524 char size;
525 long d0, d1, d2, d3, d4, d5, d6;
526 char overlap;
527};
528struct try_t param[6];
529int
530param_init ()
531{
532 struct try_t *p;
533 memcpy (p, &param[ 2 ], sizeof (*p));
534 memcpy (p, &param[ 2 ], sizeof (*p));
535 p->size = 2;
536 memcpy (p, &param[ 1 ], sizeof (*p));
537 p->dst[0] = 1;
538 p->overlap = 2;
539 memcpy (p, &param[ 3 ], sizeof (*p));
540 p->dst[0] = 1;
541 p->overlap = 8;
542 memcpy (p, &param[ 4 ], sizeof (*p));
543 memcpy (p, &param[ 4 ], sizeof (*p));
544 p->overlap = 8;
545 memcpy (p, &param[ 5 ], sizeof (*p));
546 memcpy (p, &param[ 5 ], sizeof (*p));
547 memcpy (p, &param[ 5 ], sizeof (*p));
548 return 0;
549}
550])
551
552# __builtin_alloca is not available everywhere, check it exists before
553# seeing that it works
554GMP_PROG_CC_WORKS_PART_TEST([$1],[__builtin_alloca availability],
555[int k; int foo () { __builtin_alloca (k); }],
556  [GMP_PROG_CC_WORKS_PART([$1], [alloca array],
557[/* The following provokes an internal compiler error from Itanium HP-UX cc
558    under +O2 or higher.  We use this sort of code in mpn/generic/mul_fft.c. */
559int k;
560int foo ()
561{
562  int i, **a;
563  a = __builtin_alloca (k);
564  for (i = 0; i <= k; i++)
565    a[i] = __builtin_alloca (1 << i);
566}
567])])
568
569GMP_PROG_CC_WORKS_PART([$1], [abs int -> double conversion],
570[/* The following provokes an internal error from the assembler on
571   power2-ibm-aix4.3.1.0.  gcc -mrios2 compiles to nabs+fcirz, and this
572   results in "Internal error related to the source program domain".
573
574   For reference it seems to be the combination of nabs+fcirz which is bad,
575   not either alone.  This sort of thing occurs in mpz/get_str.c with the
576   way double chars_per_bit_exactly is applied in MPN_SIZEINBASE.  Perhaps
577   if that code changes to a scaled-integer style then we won't need this
578   test.  */
579
580double fp[1];
581int x;
582int f ()
583{
584  int a;
585  a = (x >= 0 ? x : -x);
586  return a * fp[0];
587}
588])
589
590GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 1],
591[/* The following provokes a segfault in the compiler on powerpc-apple-darwin.
592   Extracted from tests/mpn/t-iord_u.c.  Causes Apple's gcc 3.3 build 1640 and
593   1666 to segfault with e.g., -O2 -mpowerpc64.  */
594
595#if defined (__GNUC__) && ! defined (__cplusplus)
596typedef unsigned long long t1;typedef t1*t2;
597static __inline__ t1 e(t2 rp,t2 up,int n,t1 v0)
598{t1 c,x,r;int i;if(v0){c=1;for(i=1;i<n;i++){x=up[i];r=x+1;rp[i]=r;}}return c;}
599f(){static const struct{t1 n;t1 src[9];t1 want[9];}d[]={{1,{0},{1}},};t1 got[9];int i;
600for(i=0;i<1;i++){if(e(got,got,9,d[i].n)==0)h();g(i,d[i].src,d[i].n,got,d[i].want,9);if(d[i].n)h();}}
601h(){}g(){}
602#else
603int dummy;
604#endif
605])
606
607GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 2],
608[/* The following provokes an internal compiler error on powerpc-apple-darwin.
609   Extracted from mpz/cfdiv_q_2exp.c.  Causes Apple's gcc 3.3 build 1640 and
610   1666 to get an ICE with -O1 -mpowerpc64.  */
611
612#if defined (__GNUC__) && ! defined (__cplusplus)
613f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
614g(){}
615#else
616int dummy;
617#endif
618])
619
620GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization],
621[/* The following is mis-compiled by HP ia-64 cc version
622        cc: HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]
623   under "cc +O3", both in +DD32 and +DD64 modes.  The mpn_lshift_com gets
624   inlined and its return value somehow botched to be 0 instead of 1.  This
625   arises in the real mpn_lshift_com in mul_fft.c.  A lower optimization
626   level, like +O2 seems ok.  This code needs to be run to show the problem,
627   but that's fine, the offending cc is a native-only compiler so we don't
628   have to worry about cross compiling.  */
629
630#if ! defined (__cplusplus)
631unsigned long
632lshift_com (rp, up, n, cnt)
633  unsigned long *rp;
634  unsigned long *up;
635  long n;
636  unsigned cnt;
637{
638  unsigned long retval, high_limb, low_limb;
639  unsigned tnc;
640  long i;
641  tnc = 8 * sizeof (unsigned long) - cnt;
642  low_limb = *up++;
643  retval = low_limb >> tnc;
644  high_limb = low_limb << cnt;
645  for (i = n - 1; i != 0; i--)
646    {
647      low_limb = *up++;
648      *rp++ = ~(high_limb | (low_limb >> tnc));
649      high_limb = low_limb << cnt;
650    }
651  return retval;
652}
653int
654main ()
655{
656  unsigned long cy, rp[2], up[2];
657  up[0] = ~ 0L;
658  up[1] = 0;
659  cy = lshift_com (rp, up, 2L, 1);
660  if (cy != 1L)
661    return 1;
662  return 0;
663}
664#else
665int
666main ()
667{
668  return 0;
669}
670#endif
671])
672
673GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization 2],
674[/* The following is mis-compiled by Intel ia-64 icc version 1.8 under
675    "icc -O3",  After several calls, the function writes parial garbage to
676    the result vector.  Perhaps relates to the chk.a.nc insn.  This code needs
677    to be run to show the problem, but that's fine, the offending cc is a
678    native-only compiler so we don't have to worry about cross compiling.  */
679
680#if ! defined (__cplusplus)
681#include <stdlib.h>
682void
683lshift_com (rp, up, n, cnt)
684  unsigned long *rp;
685  unsigned long *up;
686  long n;
687  unsigned cnt;
688{
689  unsigned long high_limb, low_limb;
690  unsigned tnc;
691  long i;
692  up += n;
693  rp += n;
694  tnc = 8 * sizeof (unsigned long) - cnt;
695  low_limb = *--up;
696  high_limb = low_limb << cnt;
697  for (i = n - 1; i != 0; i--)
698    {
699      low_limb = *--up;
700      *--rp = ~(high_limb | (low_limb >> tnc));
701      high_limb = low_limb << cnt;
702    }
703  *--rp = ~high_limb;
704}
705int
706main ()
707{
708  unsigned long *r, *r2;
709  unsigned long a[88 + 1];
710  long i;
711  for (i = 0; i < 88 + 1; i++)
712    a[i] = ~0L;
713  r = malloc (10000 * sizeof (unsigned long));
714  r2 = r;
715  for (i = 0; i < 528; i += 22)
716    {
717      lshift_com (r2, a,
718		  i / (8 * sizeof (unsigned long)) + 1,
719		  i % (8 * sizeof (unsigned long)));
720      r2 += 88 + 1;
721    }
722  if (r[2048] != 0 || r[2049] != 0 || r[2050] != 0 || r[2051] != 0 ||
723      r[2052] != 0 || r[2053] != 0 || r[2054] != 0)
724    abort ();
725  return 0;
726}
727#else
728int
729main ()
730{
731  return 0;
732}
733#endif
734])
735
736
737# A certain _GLOBAL_OFFSET_TABLE_ problem in past versions of gas, tickled
738# by recent versions of gcc.
739#
740if test "$gmp_prog_cc_works" = yes; then
741  case $host in
742    X86_PATTERN)
743      # this problem only arises in PIC code, so don't need to test when
744      # --disable-shared.  We don't necessarily have $enable_shared set to
745      # yes at this point, it will still be unset for the default (which is
746      # yes); hence the use of "!= no".
747      if test "$enable_shared" != no; then
748        GMP_PROG_CC_X86_GOT_EAX_EMITTED([$1],
749          [GMP_ASM_X86_GOT_EAX_OK([$1],,
750            [gmp_prog_cc_works="no, bad gas GOT with eax"])])
751      fi
752      ;;
753  esac
754fi
755
756AC_MSG_RESULT($gmp_prog_cc_works)
757case $gmp_prog_cc_works in
758  yes)
759    [$2]
760    ;;
761  *)
762    [$3]
763    ;;
764esac
765])
766
767dnl  Called: GMP_PROG_CC_WORKS_PART(CC+CFLAGS,FAIL-MESSAGE [,CODE])
768dnl  A dummy main() is appended to the CODE given.
769dnl
770AC_DEFUN([GMP_PROG_CC_WORKS_PART],
771[GMP_PROG_CC_WORKS_PART_MAIN([$1],[$2],
772[$3]
773[int main () { return 0; }])
774])
775
776dnl  Called: GMP_PROG_CC_WORKS_PART_MAIN(CC+CFLAGS,FAIL-MESSAGE,CODE)
777dnl  CODE must include a main().
778dnl
779AC_DEFUN([GMP_PROG_CC_WORKS_PART_MAIN],
780[GMP_PROG_CC_WORKS_PART_TEST([$1],[$2],[$3],
781  [],
782  gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2]",
783  gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2][[, program does not run]]")
784])
785
786dnl  Called: GMP_PROG_CC_WORKS_PART_TEST(CC+CFLAGS,TITLE,[CODE],
787dnl            [ACTION-GOOD],[ACTION-BAD][ACTION-NORUN])
788dnl
789AC_DEFUN([GMP_PROG_CC_WORKS_PART_TEST],
790[if test "$gmp_prog_cc_works" = yes; then
791  # remove anything that might look like compiler output to our "||" expression
792  rm -f conftest* a.out b.out a.exe a_out.exe
793  cat >conftest.c <<EOF
794[$3]
795EOF
796  echo "Test compile: [$2]" >&AC_FD_CC
797  gmp_compile="$1 conftest.c >&AC_FD_CC"
798  if AC_TRY_EVAL(gmp_compile); then
799    cc_works_part=yes
800    if test "$cross_compiling" = no; then
801      if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
802      else
803        cc_works_part=norun
804      fi
805    fi
806  else
807    cc_works_part=no
808  fi
809  if test "$cc_works_part" != yes; then
810    echo "failed program was:" >&AC_FD_CC
811    cat conftest.c >&AC_FD_CC
812  fi
813  rm -f conftest* a.out b.out a.exe a_out.exe
814  case $cc_works_part in
815    yes)
816      $4
817      ;;
818    no)
819      $5
820      ;;
821    norun)
822      $6
823      ;;
824  esac
825fi
826])
827
828
829dnl  GMP_PROG_CC_WORKS_LONGLONG(cc+cflags,[ACTION-YES][,ACTION-NO])
830dnl  --------------------------------------------------------------
831dnl  Check that cc+cflags accepts "long long".
832dnl
833dnl  This test is designed to be run repeatedly with different cc+cflags
834dnl  selections, so the result is not cached.
835
836AC_DEFUN([GMP_PROG_CC_WORKS_LONGLONG],
837[AC_MSG_CHECKING([compiler $1 has long long])
838cat >conftest.c <<EOF
839long long  foo;
840long long  bar () { return foo; }
841int main () { return 0; }
842EOF
843gmp_prog_cc_works=no
844gmp_compile="$1 -c conftest.c >&AC_FD_CC"
845if AC_TRY_EVAL(gmp_compile); then
846  gmp_prog_cc_works=yes
847else
848  echo "failed program was:" >&AC_FD_CC
849  cat conftest.c >&AC_FD_CC
850fi
851rm -f conftest* a.out b.out a.exe a_out.exe
852AC_MSG_RESULT($gmp_prog_cc_works)
853if test $gmp_prog_cc_works = yes; then
854  ifelse([$2],,:,[$2])
855else
856  ifelse([$3],,:,[$3])
857fi
858])
859
860
861dnl  GMP_C_TEST_SIZEOF(cc/cflags,test,[ACTION-GOOD][,ACTION-BAD])
862dnl  ------------------------------------------------------------
863dnl  The given cc/cflags compiler is run to check the size of a type
864dnl  specified by the "test" argument.  "test" can either be a string, or a
865dnl  variable like $foo.  The value should be for instance "sizeof-long-4",
866dnl  to test that sizeof(long)==4.
867dnl
868dnl  This test is designed to be run for different compiler and/or flags
869dnl  combinations, so the result is not cached.
870dnl
871dnl  The idea for making an array that has a negative size if the desired
872dnl  condition test is false comes from autoconf AC_CHECK_SIZEOF.  The cast
873dnl  to "long" in the array dimension also follows autoconf, apparently it's
874dnl  a workaround for a HP compiler bug.
875
876AC_DEFUN([GMP_C_TEST_SIZEOF],
877[echo "configure: testlist $2" >&AC_FD_CC
878[gmp_sizeof_type=`echo "$2" | sed 's/sizeof-\([a-z]*\).*/\1/'`]
879[gmp_sizeof_want=`echo "$2" | sed 's/sizeof-[a-z]*-\([0-9]*\).*/\1/'`]
880AC_MSG_CHECKING([compiler $1 has sizeof($gmp_sizeof_type)==$gmp_sizeof_want])
881cat >conftest.c <<EOF
882[int
883main ()
884{
885  static int test_array [1 - 2 * (long) (sizeof ($gmp_sizeof_type) != $gmp_sizeof_want)];
886  test_array[0] = 0;
887  return 0;
888}]
889EOF
890gmp_c_testlist_sizeof=no
891gmp_compile="$1 -c conftest.c >&AC_FD_CC"
892if AC_TRY_EVAL(gmp_compile); then
893  gmp_c_testlist_sizeof=yes
894fi
895rm -f conftest*
896AC_MSG_RESULT($gmp_c_testlist_sizeof)
897if test $gmp_c_testlist_sizeof = yes; then
898  ifelse([$3],,:,[$3])
899else
900  ifelse([$4],,:,[$4])
901fi
902])
903
904
905dnl  GMP_PROG_CC_IS_GNU(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
906dnl  -------------------------------------------------------
907dnl  Determine whether the given compiler is GNU C.
908dnl
909dnl  This test is the same as autoconf _AC_LANG_COMPILER_GNU, but doesn't
910dnl  cache the result.  The same "ifndef" style test is used, to avoid
911dnl  problems with syntax checking cpp's used on NeXT and Apple systems.
912
913AC_DEFUN([GMP_PROG_CC_IS_GNU],
914[cat >conftest.c <<EOF
915#if ! defined (__GNUC__) || defined (__INTEL_COMPILER)
916  choke me
917#endif
918EOF
919gmp_compile="$1 -c conftest.c >&AC_FD_CC"
920if AC_TRY_EVAL(gmp_compile); then
921  rm -f conftest*
922  AC_MSG_CHECKING([whether $1 is gcc])
923  AC_MSG_RESULT(yes)
924  ifelse([$2],,:,[$2])
925else
926  rm -f conftest*
927  ifelse([$3],,:,[$3])
928fi
929])
930
931
932dnl  GMP_PROG_CC_IS_XLC(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
933dnl  -------------------------------------------------------
934dnl  Determine whether the given compiler is IBM xlc (on AIX).
935dnl
936dnl  There doesn't seem to be a preprocessor symbol to test for this, or if
937dnl  there is one then it's well hidden in xlc 3.1 on AIX 4.3, so just grep
938dnl  the man page printed when xlc is invoked with no arguments.
939
940AC_DEFUN([GMP_PROG_CC_IS_XLC],
941[gmp_command="$1 2>&1 | grep xlc >/dev/null"
942if AC_TRY_EVAL(gmp_command); then
943  AC_MSG_CHECKING([whether $1 is xlc])
944  AC_MSG_RESULT(yes)
945  ifelse([$2],,:,[$2])
946else
947  ifelse([$3],,:,[$3])
948fi
949])
950
951
952dnl  GMP_PROG_CC_X86_GOT_EAX_EMITTED(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
953dnl  ----------------------------------------------------------------------
954dnl  Determine whether CC+CFLAGS emits instructions using %eax with
955dnl  _GLOBAL_OFFSET_TABLE_.  This test is for use on x86 systems.
956dnl
957dnl  Recent versions of gcc will use %eax for the GOT in leaf functions, for
958dnl  instance gcc 3.3.3 with -O3.  This avoids having to save and restore
959dnl  %ebx which otherwise usually holds the GOT, and is what gcc used in the
960dnl  past.
961dnl
962dnl  %ecx and %edx are also candidates for this sort of optimization, and
963dnl  are used under lesser optimization levels, like -O2 in 3.3.3.  FIXME:
964dnl  It's not quite clear what the conditions for using %eax are, we might
965dnl  need more test code to provoke it.
966dnl
967dnl  The motivation for this test is that past versions of gas have bugs
968dnl  affecting this usage, see GMP_ASM_X86_GOT_EAX_OK.
969dnl
970dnl  This test is not specific to gcc, other compilers might emit %eax GOT
971dnl  insns like this, though we've not investigated that.
972dnl
973dnl  This is for use by compiler probing in GMP_PROG_CC_WORKS, so we doesn't
974dnl  cache the result.
975dnl
976dnl  -fPIC is hard coded here, because this test is for use before libtool
977dnl  has established the pic options.  It's right for gcc, but perhaps not
978dnl  other compilers.
979
980AC_DEFUN([GMP_PROG_CC_X86_GOT_EAX_EMITTED],
981[echo "Testing gcc GOT with eax emitted" >&AC_FD_CC
982cat >conftest.c <<\EOF
983[int foo;
984int bar () { return foo; }
985]EOF
986tmp_got_emitted=no
987gmp_compile="$1 -fPIC -S conftest.c >&AC_FD_CC 2>&1"
988if AC_TRY_EVAL(gmp_compile); then
989  if grep "addl.*_GLOBAL_OFFSET_TABLE_.*eax" conftest.s >/dev/null; then
990    tmp_got_emitted=yes
991  fi
992fi
993rm -f conftest.*
994echo "Result: $tmp_got_emitted" >&AC_FD_CC
995if test "$tmp_got_emitted" = yes; then
996  ifelse([$2],,:,[$2])
997else
998  ifelse([$3],,:,[$3])
999fi
1000])
1001
1002
1003dnl  GMP_HPC_HPPA_2_0(cc,[ACTION-IF-GOOD][,ACTION-IF-BAD])
1004dnl  ---------------------------------------------------------
1005dnl  Find out whether a HP compiler is good enough to generate hppa 2.0.
1006dnl
1007dnl  This test might be repeated for different compilers, so the result is
1008dnl  not cached.
1009
1010AC_DEFUN([GMP_HPC_HPPA_2_0],
1011[AC_MSG_CHECKING([whether HP compiler $1 is good for 64-bits])
1012# Bad compiler output:
1013#   ccom: HP92453-01 G.10.32.05 HP C Compiler
1014# Good compiler output:
1015#   ccom: HP92453-01 A.10.32.30 HP C Compiler
1016# Let A.10.32.30 or higher be ok.
1017echo >conftest.c
1018gmp_tmp_vs=`$1 $2 -V -c -o conftest.$OBJEXT conftest.c 2>&1 | grep "^ccom:"`
1019echo "Version string: $gmp_tmp_vs" >&AC_FD_CC
1020rm conftest*
1021gmp_tmp_v1=`echo $gmp_tmp_vs | sed 's/.* .\.\([[0-9]]*\).*/\1/'`
1022gmp_tmp_v2=`echo $gmp_tmp_vs | sed 's/.* .\..*\.\(.*\)\..* HP C.*/\1/'`
1023gmp_tmp_v3=`echo $gmp_tmp_vs | sed 's/.* .\..*\..*\.\(.*\) HP C.*/\1/'`
1024echo "Version number: $gmp_tmp_v1.$gmp_tmp_v2.$gmp_tmp_v3" >&AC_FD_CC
1025if test -z "$gmp_tmp_v1"; then
1026  gmp_hpc_64bit=not-applicable
1027else
1028  GMP_COMPARE_GE($gmp_tmp_v1, 10, $gmp_tmp_v2, 32, $gmp_tmp_v3, 30)
1029  gmp_hpc_64bit=$gmp_compare_ge
1030fi
1031AC_MSG_RESULT($gmp_hpc_64bit)
1032if test $gmp_hpc_64bit = yes; then
1033  ifelse([$2],,:,[$2])
1034else
1035  ifelse([$3],,:,[$3])
1036fi
1037])
1038
1039
1040dnl  GMP_GCC_ARM_UMODSI(CC,[ACTIONS-IF-GOOD][,ACTIONS-IF-BAD])
1041dnl  ---------------------------------------------------------
1042dnl  gcc 2.95.3 and earlier on arm has a bug in the libgcc __umodsi routine
1043dnl  making "%" give wrong results for some operands, eg. "0x90000000 % 3".
1044dnl  We're hoping it'll be fixed in 2.95.4, and we know it'll be fixed in
1045dnl  gcc 3.
1046dnl
1047dnl  There's only a couple of places gmp cares about this, one is the
1048dnl  size==1 case in mpn/generic/mode1o.c, and this shows up in
1049dnl  tests/mpz/t-jac.c as a wrong result from mpz_kronecker_ui.
1050
1051AC_DEFUN([GMP_GCC_ARM_UMODSI],
1052[AC_MSG_CHECKING([whether ARM gcc unsigned division works])
1053tmp_version=`$1 --version`
1054echo "$tmp_version" >&AC_FD_CC
1055case $tmp_version in
1056  [2.95 | 2.95.[123]])
1057    ifelse([$3],,:,[$3])
1058    gmp_gcc_arm_umodsi_result=["no, gcc 2.95.[0123]"] ;;
1059  *)
1060    ifelse([$2],,:,[$2])
1061    gmp_gcc_arm_umodsi_result=yes ;;
1062esac
1063AC_MSG_RESULT([$gmp_gcc_arm_umodsi_result])
1064])
1065
1066
1067dnl  GMP_GCC_MIPS_O32(gcc,[actions-yes][,[actions-no]])
1068dnl  -------------------------------------------------
1069dnl  Test whether gcc supports o32.
1070dnl
1071dnl  gcc 2.7.2.2 only does o32, and doesn't accept -mabi=32.
1072dnl
1073dnl  gcc 2.95 accepts -mabi=32 but it only works on irix5, on irix6 it gives
1074dnl  "cc1: The -mabi=32 support does not work yet".
1075
1076AC_DEFUN([GMP_GCC_MIPS_O32],
1077[AC_MSG_CHECKING([whether gcc supports o32])
1078echo 'int x;' >conftest.c
1079echo "$1 -mabi=32 -c conftest.c" >&AC_FD_CC
1080if $1 -mabi=32 -c conftest.c >conftest.out 2>&1; then
1081  result=yes
1082else
1083  cat conftest.out >&AC_FD_CC
1084  if grep "cc1: Invalid option \`abi=32'" conftest.out >/dev/null; then
1085    result=yes
1086  else
1087    result=no
1088  fi
1089fi
1090rm -f conftest.*
1091AC_MSG_RESULT($result)
1092if test $result = yes; then
1093  ifelse([$2],,:,[$2])
1094else
1095  ifelse([$3],,:,[$3])
1096fi
1097])
1098
1099
1100dnl  GMP_GCC_NO_CPP_PRECOMP(CCBASE,CC,CFLAGS,[ACTIONS-YES][,ACTIONS-NO])
1101dnl  -------------------------------------------------------------------
1102dnl  Check whether -no-cpp-precomp should be used on this compiler, and
1103dnl  execute the corresponding ACTIONS-YES or ACTIONS-NO.
1104dnl
1105dnl  -no-cpp-precomp is only meant for Apple's hacked version of gcc found
1106dnl  on powerpc*-*-darwin*, but we can give it a try on any gcc.  Normal gcc
1107dnl  (as of 3.0 at least) only gives a warning, not an actual error, and we
1108dnl  watch for that and decide against the option in that case, to avoid
1109dnl  confusing the user.
1110
1111AC_DEFUN([GMP_GCC_NO_CPP_PRECOMP],
1112[if test "$ccbase" = gcc; then
1113  AC_MSG_CHECKING([compiler $2 $3 -no-cpp-precomp])
1114  result=no
1115  cat >conftest.c <<EOF
1116int main () { return 0; }
1117EOF
1118  gmp_compile="$2 $3 -no-cpp-precomp conftest.c >conftest.out 2>&1"
1119  if AC_TRY_EVAL(gmp_compile); then
1120    if grep "unrecognized option.*-no-cpp-precomp" conftest.out >/dev/null; then : ;
1121    else
1122      result=yes
1123    fi
1124  fi
1125  cat conftest.out >&AC_FD_CC
1126  rm -f conftest* a.out b.out a.exe a_out.exe
1127  AC_MSG_RESULT($result)
1128  if test "$result" = yes; then
1129      ifelse([$4],,:,[$4])
1130  else
1131      ifelse([$5],,:,[$5])
1132  fi
1133fi
1134])
1135
1136
1137dnl  GMP_GCC_PENTIUM4_SSE2(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
1138dnl  ---------------------------------------------------------------
1139dnl  Determine whether gcc CC+CFLAGS is a good enough version for
1140dnl  -march=pentium4 with sse2.
1141dnl
1142dnl  Gcc 3.2.1 was seen generating incorrect code for raw double -> int
1143dnl  conversions through a union.  We believe the problem is in all 3.1 and
1144dnl  3.2 versions, but that it's fixed in 3.3.
1145
1146AC_DEFUN([GMP_GCC_PENTIUM4_SSE2],
1147[AC_MSG_CHECKING([whether gcc is good for sse2])
1148case `$1 -dumpversion` in
1149  [3.[012] | 3.[012].*]) result=no ;;
1150  *)                     result=yes ;;
1151esac
1152AC_MSG_RESULT($result)
1153if test "$result" = yes; then
1154  ifelse([$2],,:,[$2])
1155else
1156  ifelse([$3],,:,[$3])
1157fi
1158])
1159
1160
1161dnl  GMP_GCC_WA_MCPU(CC+CFLAGS, NEWFLAG [,ACTION-YES [,ACTION-NO]])
1162dnl  --------------------------------------------------------------
1163dnl  Check whether gcc (or gas rather) accepts a flag like "-Wa,-mev67".
1164dnl
1165dnl  Gas doesn't give an error for an unknown cpu, it only prints a warning
1166dnl  like "Warning: Unknown CPU identifier `ev78'".
1167dnl
1168dnl  This is intended for use on alpha, since only recent versions of gas
1169dnl  accept -mev67, but there's nothing here that's alpha specific.
1170
1171AC_DEFUN([GMP_GCC_WA_MCPU],
1172[AC_MSG_CHECKING([assembler $1 $2])
1173result=no
1174cat >conftest.c <<EOF
1175int main () {}
1176EOF
1177gmp_compile="$1 $2 -c conftest.c >conftest.out 2>&1"
1178if AC_TRY_EVAL(gmp_compile); then
1179  if grep "Unknown CPU identifier" conftest.out >/dev/null; then : ;
1180  else
1181    result=yes
1182  fi
1183fi
1184cat conftest.out >&AC_FD_CC
1185rm -f conftest*
1186AC_MSG_RESULT($result)
1187if test "$result" = yes; then
1188  ifelse([$3],,:,[$3])
1189else
1190  ifelse([$4],,:,[$4])
1191fi
1192])
1193
1194
1195dnl  GMP_GCC_WA_OLDAS(CC+CFLAGS [,ACTION-YES [,ACTION-NO]])
1196dnl  ------------------------------------------------------
1197dnl  Check whether gcc should be run with "-Wa,-oldas".
1198dnl
1199dnl  On systems alpha*-*-osf* (or maybe just osf5), apparently there's a
1200dnl  newish Compaq "as" which doesn't work with the gcc mips-tfile.
1201dnl  Compiling an empty file with "gcc -c foo.c" produces for instance
1202dnl
1203dnl      mips-tfile, /tmp/ccaqUNnF.s:7 Segmentation fault
1204dnl
1205dnl  The fix is to pass "-oldas" to that assembler, as noted by
1206dnl
1207dnl      http://gcc.gnu.org/install/specific.html#alpha*-dec-osf*
1208dnl
1209dnl  The test here tries to compile an empty file, and if that fails but
1210dnl  adding -Wa,-oldas makes it succeed, then that flag is considered
1211dnl  necessary.
1212dnl
1213dnl  We look for the failing case specifically, since it may not be a good
1214dnl  idea to use -Wa,-oldas in other circumstances.  For instance gas takes
1215dnl  "-oldas" to mean the "-o" option and will write a file called "ldas" as
1216dnl  its output.  Normally gcc puts its own "-o" after any -Wa options, so
1217dnl  -oldas ends up being harmless, but clearly that's only through good
1218dnl  luck.
1219dnl
1220dnl  This macro is designed for use while probing for a good compiler, and
1221dnl  so doesn't cache it's result.
1222
1223AC_DEFUN([GMP_GCC_WA_OLDAS],
1224[AC_MSG_CHECKING([for $1 -Wa,-oldas])
1225result=no
1226cat >conftest.c <<EOF
1227EOF
1228echo "with empty conftest.c" >&AC_FD_CC
1229gmp_compile="$1 -c conftest.c >&AC_FD_CC 2>&1"
1230if AC_TRY_EVAL(gmp_compile); then : ;
1231else
1232  # empty fails
1233  gmp_compile="$1 -Wa,-oldas -c conftest.c >&AC_FD_CC 2>&1"
1234  if AC_TRY_EVAL(gmp_compile); then
1235    # but with -Wa,-oldas it works
1236    result=yes
1237  fi
1238fi
1239rm -f conftest*
1240AC_MSG_RESULT($result)
1241if test "$result" = yes; then
1242  ifelse([$2],,:,[$2])
1243else
1244  ifelse([$3],,:,[$3])
1245fi
1246])
1247
1248
1249dnl  GMP_OS_X86_XMM(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
1250dnl  --------------------------------------------------------
1251dnl  Determine whether the operating system supports XMM registers.
1252dnl
1253dnl  If build==host then a test program is run, executing an SSE2
1254dnl  instruction using an XMM register.  This will give a SIGILL if the
1255dnl  system hasn't set the OSFXSR bit in CR4 to say it knows it must use
1256dnl  fxsave/fxrestor in a context switch (to save xmm registers).
1257dnl
1258dnl  If build!=host, we can fallback on:
1259dnl
1260dnl      - FreeBSD version 4 is the first supporting xmm.
1261dnl
1262dnl      - Linux kernel 2.4 might be the first stable series supporting xmm
1263dnl        (not sure).  But there's no version number in the GNU/Linux
1264dnl        config tuple to test anyway.
1265dnl
1266dnl  The default is to allow xmm.  This might seem rash, but it's likely
1267dnl  most systems know xmm by now, so this will normally be what's wanted.
1268dnl  And cross compiling is a bit hairy anyway, so hopefully anyone doing it
1269dnl  will be smart enough to know what to do.
1270dnl
1271dnl  In the test program, .text and .globl are hard coded because this macro
1272dnl  is wanted before GMP_ASM_TEXT and GMP_ASM_GLOBL are run.  A .byte
1273dnl  sequence is used (for xorps %xmm0, %xmm0) to make us independent of
1274dnl  tests for whether the assembler supports sse2/xmm.  Obviously we need
1275dnl  both assembler and OS support, but this means we don't force the order
1276dnl  in which we test.
1277dnl
1278dnl  FIXME: Maybe we should use $CCAS to assemble, if it's set.  (Would
1279dnl  still want $CC/$CFLAGS for the link.)  But this test is used before
1280dnl  AC_PROG_CC sets $OBJEXT, so we'd need to check for various object file
1281dnl  suffixes ourselves.
1282
1283AC_DEFUN([GMP_OS_X86_XMM],
1284[AC_CACHE_CHECK([whether the operating system supports XMM registers],
1285		gmp_cv_os_x86_xmm,
1286[if test "$build" = "$host"; then
1287  # remove anything that might look like compiler output to our "||" expression
1288  rm -f conftest* a.out b.out a.exe a_out.exe
1289  cat >conftest.s <<EOF
1290	.text
1291main:
1292_main:
1293	.globl	main
1294	.globl	_main
1295	.byte	0x0f, 0x57, 0xc0
1296	xorl	%eax, %eax
1297	ret
1298EOF
1299  gmp_compile="$1 conftest.s -o conftest >&AC_FD_CC"
1300  if AC_TRY_EVAL(gmp_compile); then
1301    if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then
1302      gmp_cv_os_x86_xmm=yes
1303    else
1304      gmp_cv_os_x86_xmm=no
1305    fi
1306  else
1307    AC_MSG_WARN([Oops, cannot compile test program])
1308  fi
1309  rm -f conftest*
1310fi
1311
1312if test -z "$gmp_cv_os_x86_xmm"; then
1313  case $host_os in
1314    [freebsd[123] | freebsd[123].*])
1315      gmp_cv_os_x86_xmm=no ;;
1316    freebsd*)
1317      gmp_cv_os_x86_xmm=yes ;;
1318    *)
1319      gmp_cv_os_x86_xmm=probably ;;
1320  esac
1321fi
1322])
1323
1324if test "$gmp_cv_os_x86_xmm" = probably; then
1325  AC_MSG_WARN([Not certain of OS support for xmm when cross compiling.])
1326  AC_MSG_WARN([Will assume it's ok, expect a SIGILL if this is wrong.])
1327fi
1328
1329case $gmp_cv_os_x86_xmm in
1330no)
1331  $3
1332  ;;
1333*)
1334  $2
1335  ;;
1336esac
1337])
1338
1339
1340dnl  GMP_CRAY_HOST_TYPES(C90/T90-IEEE, C90/T90-CFP, J90/SV1)
1341dnl  -------------------------------------------------------
1342dnl  Execute the actions in the arguments on the respective Cray vector
1343dnl  systems.  For other hosts, do nothing.
1344dnl
1345dnl  This macro should be used after the C compiler has been chosen, since
1346dnl  on c90 and t90 we ask the compiler whether we're in IEEE or CFP float
1347dnl  mode.
1348dnl
1349dnl  This code is in a macro so that any AC_REQUIRE pre-requisites of
1350dnl  AC_EGREP_CPP will be expanded at the top-level, ie. for all hosts not
1351dnl  merely c90 and t90.  In autoconf 2.57 for instance this means
1352dnl  AC_PROG_EGREP, which is needed by various other macros.
1353
1354AC_DEFUN([GMP_CRAY_OPTIONS],
1355[case $host_cpu in
1356  c90 | t90)
1357    AC_EGREP_CPP(yes,
1358[#ifdef _CRAYIEEE
1359yes
1360#endif],
1361    [$1],
1362    [$2])
1363    ;;
1364  j90 | sv1)
1365    [$3]
1366    ;;
1367esac
1368])
1369
1370
1371dnl  GMP_HPPA_LEVEL_20(cc/cflags [, ACTION-GOOD [,ACTION-BAD]])
1372dnl  ----------------------------------------------------------
1373dnl  Check that the given cc/cflags accepts HPPA 2.0n assembler code.
1374dnl
1375dnl  Old versions of gas don't know 2.0 instructions.  It rejects ".level
1376dnl  2.0" for a start, so just test that.
1377dnl
1378dnl  This test is designed to be run for various different compiler and
1379dnl  flags combinations, and hence doesn't cache its result.
1380
1381AC_DEFUN([GMP_HPPA_LEVEL_20],
1382[AC_MSG_CHECKING([$1 assembler knows hppa 2.0])
1383result=no
1384cat >conftest.s <<EOF
1385	.level 2.0
1386EOF
1387gmp_compile="$1 -c conftest.s >&AC_FD_CC 2>&1"
1388if AC_TRY_EVAL(gmp_compile); then
1389  result=yes
1390else
1391  echo "failed program was" >&AC_FD_CC
1392  cat conftest.s >&AC_FD_CC
1393fi
1394rm -f conftest*
1395AC_MSG_RESULT($result)
1396if test "$result" = yes; then
1397  ifelse([$2],,:,[$2])
1398else
1399  ifelse([$3],,:,[$3])
1400fi
1401])
1402
1403
1404dnl  GMP_PROG_CXX_WORKS(cxx/cxxflags [, ACTION-YES [,ACTION-NO]])
1405dnl  ------------------------------------------------------------
1406dnl  Check whether cxx/cxxflags can compile and link.
1407dnl
1408dnl  This test is designed to be run repeatedly with different cxx/cxxflags
1409dnl  selections, so the result is not cached.
1410dnl
1411dnl  For a native build, we insist on being able to run the program, so as
1412dnl  to detect any problems with the standard C++ library.  During
1413dnl  development various systems with broken or incomplete C++ installations
1414dnl  were seen.
1415dnl
1416dnl  The various features and problems we try to detect are done in separate
1417dnl  compiles.  Although this is probably a bit slower than one test
1418dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
1419dnl  hence giving the user a clue about why we rejected the compiler.
1420
1421AC_DEFUN([GMP_PROG_CXX_WORKS],
1422[AC_MSG_CHECKING([C++ compiler $1])
1423gmp_prog_cxx_works=yes
1424
1425# start with a plain "main()", then go on to further checks
1426GMP_PROG_CXX_WORKS_PART([$1], [])
1427
1428GMP_PROG_CXX_WORKS_PART([$1], [namespace],
1429[namespace foo { }
1430using namespace foo;
1431])
1432
1433# GMP requires the standard C++ iostream classes
1434GMP_PROG_CXX_WORKS_PART([$1], [std iostream],
1435[/* This test rejects g++ 2.7.2 which doesn't have <iostream>, only a
1436    pre-standard iostream.h. */
1437#include <iostream>
1438
1439/* This test rejects OSF 5.1 Compaq C++ in its default pre-standard iostream
1440   mode, since that mode puts cout in the global namespace, not "std".  */
1441void someoutput (void) { std::cout << 123; }
1442])
1443
1444AC_MSG_RESULT($gmp_prog_cxx_works)
1445case $gmp_prog_cxx_works in
1446  yes)
1447    [$2]
1448    ;;
1449  *)
1450    [$3]
1451    ;;
1452esac
1453])
1454
1455dnl  Called: GMP_PROG_CXX_WORKS_PART(CXX+CXXFLAGS, FAIL-MESSAGE [,CODE])
1456dnl
1457AC_DEFUN([GMP_PROG_CXX_WORKS_PART],
1458[if test "$gmp_prog_cxx_works" = yes; then
1459  # remove anything that might look like compiler output to our "||" expression
1460  rm -f conftest* a.out b.out a.exe a_out.exe
1461  cat >conftest.cc <<EOF
1462[$3]
1463int main (void) { return 0; }
1464EOF
1465  echo "Test compile: [$2]" >&AC_FD_CC
1466  gmp_cxxcompile="$1 conftest.cc >&AC_FD_CC"
1467  if AC_TRY_EVAL(gmp_cxxcompile); then
1468    if test "$cross_compiling" = no; then
1469      if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
1470      else
1471        gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2], program does not run"
1472      fi
1473    fi
1474  else
1475    gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2]"
1476  fi
1477  case $gmp_prog_cxx_works in
1478    no*)
1479      echo "failed program was:" >&AC_FD_CC
1480      cat conftest.cc >&AC_FD_CC
1481      ;;
1482  esac
1483  rm -f conftest* a.out b.out a.exe a_out.exe
1484fi
1485])
1486
1487
1488dnl  GMP_INIT([M4-DEF-FILE])
1489dnl  -----------------------
1490dnl  Initializations for GMP config.m4 generation.
1491dnl
1492dnl  FIXME: The generated config.m4 doesn't get recreated by config.status.
1493dnl  Maybe the relevant "echo"s should go through AC_CONFIG_COMMANDS.
1494
1495AC_DEFUN([GMP_INIT],
1496[ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
1497gmp_tmpconfigm4=cnfm4.tmp
1498gmp_tmpconfigm4i=cnfm4i.tmp
1499gmp_tmpconfigm4p=cnfm4p.tmp
1500rm -f $gmp_tmpconfigm4 $gmp_tmpconfigm4i $gmp_tmpconfigm4p
1501
1502# CONFIG_TOP_SRCDIR is a path from the mpn builddir to the top srcdir.
1503# The pattern here tests for an absolute path the same way as
1504# _AC_OUTPUT_FILES in autoconf acgeneral.m4.
1505case $srcdir in
1506[[\\/]]* | ?:[[\\/]]* )  tmp="$srcdir"    ;;
1507*)                       tmp="../$srcdir" ;;
1508esac
1509echo ["define(<CONFIG_TOP_SRCDIR>,<\`$tmp'>)"] >>$gmp_tmpconfigm4
1510
1511# All CPUs use asm-defs.m4
1512echo ["include][(CONFIG_TOP_SRCDIR\`/mpn/asm-defs.m4')"] >>$gmp_tmpconfigm4i
1513])
1514
1515
1516dnl  GMP_FINISH
1517dnl  ----------
1518dnl  Create config.m4 from its accumulated parts.
1519dnl
1520dnl  __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
1521dnl  of config.m4 is harmless.
1522dnl
1523dnl  A separate ifdef on the angle bracket quoted part ensures the quoting
1524dnl  style there is respected.  The basic defines from gmp_tmpconfigm4 are
1525dnl  fully quoted but are still put under an ifdef in case any have been
1526dnl  redefined by one of the m4 include files.
1527dnl
1528dnl  Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
1529dnl  work, since it'd interpret parentheses and quotes in dnl comments, and
1530dnl  having a whole file as a macro argument would overflow the string space
1531dnl  on BSD m4.
1532
1533AC_DEFUN([GMP_FINISH],
1534[AC_REQUIRE([GMP_INIT])
1535echo "creating $gmp_configm4"
1536echo ["d""nl $gmp_configm4.  Generated automatically by configure."] > $gmp_configm4
1537if test -f $gmp_tmpconfigm4; then
1538  echo ["changequote(<,>)"] >> $gmp_configm4
1539  echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
1540  cat $gmp_tmpconfigm4 >> $gmp_configm4
1541  echo [">)"] >> $gmp_configm4
1542  echo ["changequote(\`,')"] >> $gmp_configm4
1543  rm $gmp_tmpconfigm4
1544fi
1545echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
1546if test -f $gmp_tmpconfigm4i; then
1547  cat $gmp_tmpconfigm4i >> $gmp_configm4
1548  rm $gmp_tmpconfigm4i
1549fi
1550if test -f $gmp_tmpconfigm4p; then
1551  cat $gmp_tmpconfigm4p >> $gmp_configm4
1552  rm $gmp_tmpconfigm4p
1553fi
1554echo ["')"] >> $gmp_configm4
1555echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
1556])
1557
1558
1559dnl  GMP_INCLUDE_MPN(FILE)
1560dnl  ---------------------
1561dnl  Add an include_mpn(`FILE') to config.m4.  FILE should be a path
1562dnl  relative to the mpn source directory, for example
1563dnl
1564dnl      GMP_INCLUDE_MPN(`x86/x86-defs.m4')
1565dnl
1566
1567AC_DEFUN([GMP_INCLUDE_MPN],
1568[AC_REQUIRE([GMP_INIT])
1569echo ["include_mpn(\`$1')"] >> $gmp_tmpconfigm4i
1570])
1571
1572
1573dnl  GMP_DEFINE(MACRO, DEFINITION [, LOCATION])
1574dnl  ------------------------------------------
1575dnl  Define M4 macro MACRO as DEFINITION in temporary file.
1576dnl
1577dnl  If LOCATION is `POST', the definition will appear after any include()
1578dnl  directives inserted by GMP_INCLUDE.  Mind the quoting!  No shell
1579dnl  variables will get expanded.  Don't forget to invoke GMP_FINISH to
1580dnl  create file config.m4.  config.m4 uses `<' and '>' as quote characters
1581dnl  for all defines.
1582
1583AC_DEFUN([GMP_DEFINE],
1584[AC_REQUIRE([GMP_INIT])
1585echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST],
1586                              $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
1587])
1588
1589
1590dnl  GMP_DEFINE_RAW(STRING [, LOCATION])
1591dnl  ------------------------------------
1592dnl  Put STRING into config.m4 file.
1593dnl
1594dnl  If LOCATION is `POST', the definition will appear after any include()
1595dnl  directives inserted by GMP_INCLUDE.  Don't forget to invoke GMP_FINISH
1596dnl  to create file config.m4.
1597
1598AC_DEFUN([GMP_DEFINE_RAW],
1599[AC_REQUIRE([GMP_INIT])
1600echo [$1] >> ifelse([$2], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
1601])
1602
1603
1604dnl  GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
1605dnl  ----------------------------------------------------------
1606dnl  Attempt to assemble the given code.
1607dnl  Do "action-success" if this succeeds, "action-fail" if not.
1608dnl
1609dnl  conftest.o and conftest.out are available for inspection in
1610dnl  "action-success".  If either action does a "break" out of a loop then
1611dnl  an explicit "rm -f conftest*" will be necessary.
1612dnl
1613dnl  This is not unlike AC_TRY_COMPILE, but there's no default includes or
1614dnl  anything in "asm-code", everything wanted must be given explicitly.
1615
1616AC_DEFUN([GMP_TRY_ASSEMBLE],
1617[cat >conftest.s <<EOF
1618[$1]
1619EOF
1620gmp_assemble="$CCAS $CFLAGS $CPPFLAGS conftest.s >conftest.out 2>&1"
1621if AC_TRY_EVAL(gmp_assemble); then
1622  cat conftest.out >&AC_FD_CC
1623  ifelse([$2],,:,[$2])
1624else
1625  cat conftest.out >&AC_FD_CC
1626  echo "configure: failed program was:" >&AC_FD_CC
1627  cat conftest.s >&AC_FD_CC
1628  ifelse([$3],,:,[$3])
1629fi
1630rm -f conftest*
1631])
1632
1633
1634dnl Checks whether the stack can be marked nonexecutable by passing an option
1635dnl to the C-compiler when acting on .s files. Appends that option to ASFLAGS.
1636dnl This macro is adapted from one found in GLIBC-2.3.5.
1637AC_DEFUN([CL_AS_NOEXECSTACK],[
1638dnl AC_REQUIRE([AC_PROG_CC]) GMP uses something else
1639AC_CACHE_CHECK([whether assembler supports --noexecstack option],
1640cl_cv_as_noexecstack, [dnl
1641  cat > conftest.c <<EOF
1642void foo() {}
1643EOF
1644  if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS
1645                     -S -o conftest.s conftest.c >/dev/null]) \
1646     && grep .note.GNU-stack conftest.s >/dev/null \
1647     && AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -Wa,--noexecstack
1648                       -c -o conftest.o conftest.s >/dev/null])
1649  then
1650    cl_cv_as_noexecstack=yes
1651  else
1652    cl_cv_as_noexecstack=no
1653  fi
1654  rm -f conftest*])
1655  if test "$cl_cv_as_noexecstack" = yes; then
1656    ASMFLAGS="$ASMFLAGS -Wa,--noexecstack"
1657  fi
1658  AC_SUBST(ASMFLAGS)
1659])
1660
1661
1662dnl  GMP_ASM_LABEL_SUFFIX
1663dnl  --------------------
1664dnl  : - is usual.
1665dnl  empty - hppa on HP-UX doesn't use a :, just the label name
1666dnl
1667dnl  Note that it's necessary to test the empty case first, since HP "as"
1668dnl  will accept "somelabel:", and take it to mean a label with a name that
1669dnl  happens to end in a colon.
1670
1671AC_DEFUN([GMP_ASM_LABEL_SUFFIX],
1672[AC_REQUIRE([GMP_ASM_TEXT])
1673AC_CACHE_CHECK([for assembler label suffix],
1674                gmp_cv_asm_label_suffix,
1675[gmp_cv_asm_label_suffix=unknown
1676for i in "" ":"; do
1677  echo "trying $i" >&AC_FD_CC
1678  GMP_TRY_ASSEMBLE(
1679[	$gmp_cv_asm_text
1680somelabel$i],
1681    [gmp_cv_asm_label_suffix=$i
1682     rm -f conftest*
1683     break],
1684    [cat conftest.out >&AC_FD_CC])
1685done
1686if test "$gmp_cv_asm_label_suffix" = "unknown"; then
1687  AC_MSG_ERROR([Cannot determine label suffix])
1688fi
1689])
1690echo ["define(<LABEL_SUFFIX>, <$gmp_cv_asm_label_suffix>)"] >> $gmp_tmpconfigm4
1691])
1692
1693
1694dnl  GMP_ASM_UNDERSCORE
1695dnl  ------------------
1696dnl  Determine whether global symbols need to be prefixed with an underscore.
1697dnl  The output from "nm" is grepped to see what a typical symbol looks like.
1698dnl
1699dnl  This test used to grep the .o file directly, but that failed with greps
1700dnl  that don't like binary files (eg. SunOS 4).
1701dnl
1702dnl  This test also used to construct an assembler file with and without an
1703dnl  underscore and try to link that to a C file, to see which worked.
1704dnl  Although that's what will happen in the real build we don't really want
1705dnl  to depend on creating asm files within configure for every possible CPU
1706dnl  (or at least we don't want to do that more than we have to).
1707dnl
1708dnl  The fallback on no underscore is based on the assumption that the world
1709dnl  is moving towards non-underscore systems.  There should actually be no
1710dnl  good reason for nm to fail though.
1711
1712AC_DEFUN([GMP_ASM_UNDERSCORE],
1713[AC_REQUIRE([GMP_PROG_NM])
1714AC_CACHE_CHECK([if globals are prefixed by underscore],
1715               gmp_cv_asm_underscore,
1716[gmp_cv_asm_underscore="unknown"
1717cat >conftest.c <<EOF
1718int gurkmacka;
1719EOF
1720gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC"
1721if AC_TRY_EVAL(gmp_compile); then
1722  $NM conftest.$OBJEXT >conftest.out
1723  if grep _gurkmacka conftest.out >/dev/null; then
1724    gmp_cv_asm_underscore=yes
1725  elif grep gurkmacka conftest.out >/dev/null; then
1726    gmp_cv_asm_underscore=no
1727  else
1728    echo "configure: $NM doesn't have gurkmacka:" >&AC_FD_CC
1729    cat conftest.out >&AC_FD_CC
1730  fi
1731else
1732  echo "configure: failed program was:" >&AC_FD_CC
1733  cat conftest.c >&AC_FD_CC
1734fi
1735rm -f conftest*
1736])
1737case $gmp_cv_asm_underscore in
1738  yes)
1739    GMP_DEFINE(GSYM_PREFIX, [_]) ;;
1740  no)
1741    GMP_DEFINE(GSYM_PREFIX, []) ;;
1742  *)
1743    AC_MSG_WARN([+----------------------------------------------------------])
1744    AC_MSG_WARN([| Cannot determine global symbol prefix.])
1745    AC_MSG_WARN([| $NM output doesn't contain a global data symbol.])
1746    AC_MSG_WARN([| Will proceed with no underscore.])
1747    AC_MSG_WARN([| If this is wrong then you'll get link errors referring])
1748    AC_MSG_WARN([| to ___gmpn_add_n (note three underscores).])
1749    AC_MSG_WARN([| In this case do a fresh build with an override,])
1750    AC_MSG_WARN([|     ./configure gmp_cv_asm_underscore=yes])
1751    AC_MSG_WARN([+----------------------------------------------------------])
1752    GMP_DEFINE(GSYM_PREFIX, [])
1753    ;;
1754esac
1755])
1756
1757
1758dnl  GMP_ASM_ALIGN_LOG
1759dnl  -----------------
1760dnl  Is parameter to `.align' logarithmic?
1761
1762AC_DEFUN([GMP_ASM_ALIGN_LOG],
1763[AC_REQUIRE([GMP_ASM_GLOBL])
1764AC_REQUIRE([GMP_ASM_BYTE])
1765AC_REQUIRE([GMP_ASM_DATA])
1766AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1767AC_REQUIRE([GMP_PROG_NM])
1768AC_CACHE_CHECK([if .align assembly directive is logarithmic],
1769               gmp_cv_asm_align_log,
1770[GMP_TRY_ASSEMBLE(
1771[      	$gmp_cv_asm_data
1772      	.align  4
1773	$gmp_cv_asm_globl	foo
1774	$gmp_cv_asm_byte	1
1775	.align	4
1776foo$gmp_cv_asm_label_suffix
1777	$gmp_cv_asm_byte	2],
1778  [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
1779     sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
1780  if test "$gmp_tmp_val" = "10" || test "$gmp_tmp_val" = "16"; then
1781    gmp_cv_asm_align_log=yes
1782  else
1783    gmp_cv_asm_align_log=no
1784  fi],
1785  [AC_MSG_ERROR([cannot assemble alignment test])])])
1786
1787GMP_DEFINE_RAW(["define(<ALIGN_LOGARITHMIC>,<$gmp_cv_asm_align_log>)"])
1788])
1789
1790
1791dnl  GMP_ASM_ALIGN_FILL_0x90
1792dnl  -----------------------
1793dnl  Determine whether a ",0x90" suffix works on a .align directive.
1794dnl  This is only meant for use on x86, 0x90 being a "nop".
1795dnl
1796dnl  Old gas, eg. 1.92.3
1797dnl       Needs ",0x90" or else the fill is 0x00, which can't be executed
1798dnl       across.
1799dnl
1800dnl  New gas, eg. 2.91
1801dnl       Generates multi-byte nop fills even when ",0x90" is given.
1802dnl
1803dnl  Solaris 2.6 as
1804dnl       ",0x90" is not allowed, causes a fatal error.
1805dnl
1806dnl  Solaris 2.8 as
1807dnl       ",0x90" does nothing, generates a warning that it's being ignored.
1808dnl
1809dnl  SCO OpenServer 5 as
1810dnl       Second parameter is max bytes to fill, not a fill pattern.
1811dnl       ",0x90" is an error due to being bigger than the first parameter.
1812dnl       Multi-byte nop fills are generated in text segments.
1813dnl
1814dnl  Note that both solaris "as"s only care about ",0x90" if they actually
1815dnl  have to use it to fill something, hence the .byte in the test.  It's
1816dnl  the second .align which provokes the error or warning.
1817dnl
1818dnl  The warning from solaris 2.8 is suppressed to stop anyone worrying that
1819dnl  something might be wrong.
1820
1821AC_DEFUN([GMP_ASM_ALIGN_FILL_0x90],
1822[AC_REQUIRE([GMP_ASM_TEXT])
1823AC_CACHE_CHECK([if the .align directive accepts an 0x90 fill in .text],
1824               gmp_cv_asm_align_fill_0x90,
1825[GMP_TRY_ASSEMBLE(
1826[      	$gmp_cv_asm_text
1827      	.align  4, 0x90
1828	.byte   0
1829      	.align  4, 0x90],
1830[if grep "Warning: Fill parameter ignored for executable section" conftest.out >/dev/null; then
1831  echo "Supressing this warning by omitting 0x90" 1>&AC_FD_CC
1832  gmp_cv_asm_align_fill_0x90=no
1833else
1834  gmp_cv_asm_align_fill_0x90=yes
1835fi],
1836[gmp_cv_asm_align_fill_0x90=no])])
1837
1838GMP_DEFINE_RAW(["define(<ALIGN_FILL_0x90>,<$gmp_cv_asm_align_fill_0x90>)"])
1839])
1840
1841
1842dnl  GMP_ASM_BYTE
1843dnl  ------------
1844dnl  .byte - is usual.
1845dnl  data1 - required by ia64 (on hpux at least).
1846dnl
1847dnl  This macro is just to support other configure tests, not any actual asm
1848dnl  code.
1849
1850AC_DEFUN([GMP_ASM_BYTE],
1851[AC_REQUIRE([GMP_ASM_TEXT])
1852AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1853AC_CACHE_CHECK([for assembler byte directive],
1854                gmp_cv_asm_byte,
1855[for i in .byte data1; do
1856  echo "trying $i" >&AC_FD_CC
1857  GMP_TRY_ASSEMBLE(
1858[	$gmp_cv_asm_data
1859	$i	0
1860],
1861    [gmp_cv_asm_byte=$i
1862     rm -f conftest*
1863     break],
1864    [cat conftest.out >&AC_FD_CC])
1865done
1866if test -z "$gmp_cv_asm_byte"; then
1867  AC_MSG_ERROR([Cannot determine how to emit a data byte])
1868fi
1869])
1870])
1871
1872
1873dnl  GMP_ASM_TEXT
1874dnl  ------------
1875dnl  .text - is usual.
1876dnl  .code - is needed by the hppa on HP-UX (but ia64 HP-UX uses .text)
1877dnl  .csect .text[PR] - is for AIX.
1878
1879AC_DEFUN([GMP_ASM_TEXT],
1880[AC_CACHE_CHECK([how to switch to text section],
1881                gmp_cv_asm_text,
1882[for i in ".text" ".code" [".csect .text[PR]"]; do
1883  echo "trying $i" >&AC_FD_CC
1884  GMP_TRY_ASSEMBLE([	$i],
1885    [gmp_cv_asm_text=$i
1886     rm -f conftest*
1887     break])
1888done
1889if test -z "$gmp_cv_asm_text"; then
1890  AC_MSG_ERROR([Cannot determine text section directive])
1891fi
1892])
1893echo ["define(<TEXT>, <$gmp_cv_asm_text>)"] >> $gmp_tmpconfigm4
1894])
1895
1896
1897dnl  GMP_ASM_DATA
1898dnl  ------------
1899dnl  Can we say `.data'?
1900
1901AC_DEFUN([GMP_ASM_DATA],
1902[AC_CACHE_CHECK([how to switch to data section],
1903                gmp_cv_asm_data,
1904[case $host in
1905  *-*-aix*) gmp_cv_asm_data=[".csect .data[RW]"] ;;
1906  *)        gmp_cv_asm_data=".data" ;;
1907esac
1908])
1909echo ["define(<DATA>, <$gmp_cv_asm_data>)"] >> $gmp_tmpconfigm4
1910])
1911
1912
1913dnl  GMP_ASM_RODATA
1914dnl  --------------
1915dnl  Find out how to switch to the read-only data section.
1916dnl
1917dnl  The compiler output is grepped for the right directive.  It's not
1918dnl  considered wise to just probe for ".section .rodata" or whatever works,
1919dnl  since arbitrary section names might be accepted, but not necessarily do
1920dnl  the right thing when they get to the linker.
1921dnl
1922dnl  Only a few asm files use RODATA, so this code is perhaps a bit
1923dnl  excessive right now, but should find more uses in the future.
1924dnl
1925dnl  FIXME: gcc on aix generates something like ".csect _foo.ro_c[RO],3"
1926dnl  where foo is the object file.  Might need to check for that if we use
1927dnl  RODATA there.
1928
1929AC_DEFUN([GMP_ASM_RODATA],
1930[AC_REQUIRE([GMP_ASM_TEXT])
1931AC_REQUIRE([GMP_ASM_DATA])
1932AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1933AC_REQUIRE([GMP_ASM_UNDERSCORE])
1934AC_CACHE_CHECK([how to switch to read-only data section],
1935               gmp_cv_asm_rodata,
1936[
1937dnl Default to DATA on CPUs with split code/data caching, and TEXT
1938dnl elsewhere.  i386 means generic x86, so use DATA on it.
1939case $host in
1940X86_PATTERN | x86_64-*-*)
1941  gmp_cv_asm_rodata="$gmp_cv_asm_data" ;;
1942*)
1943  gmp_cv_asm_rodata="$gmp_cv_asm_text" ;;
1944esac
1945
1946cat >conftest.c <<EOF
1947extern const int foo[];		/* Suppresses C++'s suppression of foo */
1948const int foo[] = {1,2,3};
1949EOF
1950echo "Test program:" >&AC_FD_CC
1951cat conftest.c >&AC_FD_CC
1952gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
1953if AC_TRY_EVAL(gmp_compile); then
1954  echo "Compiler output:" >&AC_FD_CC
1955  cat conftest.s >&AC_FD_CC
1956  if test $gmp_cv_asm_underscore = yes; then
1957    tmp_gsym_prefix=_
1958  else
1959    tmp_gsym_prefix=
1960  fi
1961  # must see our label
1962  if grep "^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" conftest.s >/dev/null 2>&AC_FD_CC; then
1963    # take the last directive before our label (hence skipping segments
1964    # getting debugging info etc)
1965    tmp_match=`sed -n ["/^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix/q
1966                        /^[. 	]*data/p
1967                        /^[. 	]*rdata/p
1968                        /^[. 	]*text/p
1969                        /^[. 	]*section/p
1970                        /^[. 	]*csect/p
1971                        /^[. 	]*CSECT/p"] conftest.s | sed -n '$p'`
1972    echo "Match: $tmp_match" >&AC_FD_CC
1973    if test -n "$tmp_match"; then
1974      gmp_cv_asm_rodata=$tmp_match
1975    fi
1976  else
1977    echo "Couldn't find label: ^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" >&AC_FD_CC
1978  fi
1979fi
1980rm -f conftest*
1981])
1982echo ["define(<RODATA>, <$gmp_cv_asm_rodata>)"] >> $gmp_tmpconfigm4
1983])
1984
1985
1986dnl  GMP_ASM_GLOBL
1987dnl  -------------
1988dnl  The assembler directive to mark a label as a global symbol.
1989dnl
1990dnl  ia64 - .global is standard, according to the Intel documentation.
1991dnl
1992dnl  hppa - ".export foo,entry" is demanded by HP hppa "as".  ".global" is a
1993dnl      kind of import.
1994dnl
1995dnl  other - .globl is usual.
1996dnl
1997dnl  "gas" tends to accept .globl everywhere, in addition to .export or
1998dnl  .global or whatever the system assembler demands.
1999
2000AC_DEFUN([GMP_ASM_GLOBL],
2001[AC_REQUIRE([GMP_ASM_TEXT])
2002AC_CACHE_CHECK([for assembler global directive],
2003                gmp_cv_asm_globl,
2004[case $host in
2005  hppa*-*-*)     gmp_cv_asm_globl=.export ;;
2006  IA64_PATTERN)  gmp_cv_asm_globl=.global ;;
2007  *)             gmp_cv_asm_globl=.globl  ;;
2008esac
2009])
2010echo ["define(<GLOBL>, <$gmp_cv_asm_globl>)"] >> $gmp_tmpconfigm4
2011])
2012
2013
2014dnl  GMP_ASM_GLOBL_ATTR
2015dnl  ------------------
2016dnl  Do we need something after `GLOBL symbol'?
2017
2018AC_DEFUN([GMP_ASM_GLOBL_ATTR],
2019[AC_REQUIRE([GMP_ASM_GLOBL])
2020AC_CACHE_CHECK([for assembler global directive attribute],
2021                gmp_cv_asm_globl_attr,
2022[case $gmp_cv_asm_globl in
2023  .export) gmp_cv_asm_globl_attr=",entry" ;;
2024  *)       gmp_cv_asm_globl_attr="" ;;
2025esac
2026])
2027echo ["define(<GLOBL_ATTR>, <$gmp_cv_asm_globl_attr>)"] >> $gmp_tmpconfigm4
2028])
2029
2030
2031dnl  GMP_ASM_TYPE
2032dnl  ------------
2033dnl  Can we say ".type", and how?
2034dnl
2035dnl  For i386 GNU/Linux ELF systems, and very likely other ELF systems,
2036dnl  .type and .size are important on functions in shared libraries.  If
2037dnl  .type is omitted and the mainline program references that function then
2038dnl  the code will be copied down to the mainline at load time like a piece
2039dnl  of data.  If .size is wrong or missing (it defaults to 4 bytes or some
2040dnl  such) then incorrect bytes will be copied and a segv is the most likely
2041dnl  result.  In any case such copying is not what's wanted, a .type
2042dnl  directive will ensure a PLT entry is used.
2043dnl
2044dnl  In GMP the assembler functions are normally only used from within the
2045dnl  library (since most programs are not interested in the low level
2046dnl  routines), and in those circumstances a missing .type isn't fatal,
2047dnl  letting the problem go unnoticed.  tests/mpn/t-asmtype.c aims to check
2048dnl  for it.
2049
2050AC_DEFUN([GMP_ASM_TYPE],
2051[AC_CACHE_CHECK([for assembler .type directive],
2052                gmp_cv_asm_type,
2053[gmp_cv_asm_type=
2054for gmp_tmp_prefix in @ \# %; do
2055  GMP_TRY_ASSEMBLE([	.type	sym,${gmp_tmp_prefix}function],
2056    [if grep "\.type pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
2057    else
2058      gmp_cv_asm_type=".type	\$][1,${gmp_tmp_prefix}\$][2"
2059      break
2060    fi])
2061done
2062rm -f conftest*
2063])
2064echo ["define(<TYPE>, <$gmp_cv_asm_type>)"] >> $gmp_tmpconfigm4
2065])
2066
2067
2068dnl  GMP_ASM_SIZE
2069dnl  ------------
2070dnl  Can we say `.size'?
2071
2072AC_DEFUN([GMP_ASM_SIZE],
2073[AC_CACHE_CHECK([for assembler .size directive],
2074                gmp_cv_asm_size,
2075[gmp_cv_asm_size=
2076GMP_TRY_ASSEMBLE([	.size	sym,1],
2077  [if grep "\.size pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
2078  else
2079    gmp_cv_asm_size=".size	\$][1,\$][2"
2080  fi])
2081])
2082echo ["define(<SIZE>, <$gmp_cv_asm_size>)"] >> $gmp_tmpconfigm4
2083])
2084
2085
2086dnl  GMP_ASM_COFF_TYPE
2087dnl  -----------------
2088dnl  Determine whether the assembler supports COFF type information.
2089dnl
2090dnl  Currently this is only needed for mingw (and cygwin perhaps) and so is
2091dnl  run only on the x86s, but it ought to work anywhere.
2092dnl
2093dnl  On MINGW, recent versions of the linker have an automatic import scheme
2094dnl  for data in a DLL which is referenced by a mainline but without
2095dnl  __declspec (__dllimport__) on the prototype.  It seems functions
2096dnl  without type information are treated as data, or something, and calls
2097dnl  to them from the mainline will crash.  gcc puts type information on the
2098dnl  C functions it generates, we need to do the same for assembler
2099dnl  functions.
2100dnl
2101dnl  This applies only to functions without __declspec(__dllimport__),
2102dnl  ie. without __GMP_DECLSPEC in the case of libgmp, so it also works just
2103dnl  to ensure all assembler functions used from outside libgmp have
2104dnl  __GMP_DECLSPEC on their prototypes.  But this isn't an ideal situation,
2105dnl  since we don't want perfectly valid calls going wrong just because
2106dnl  there wasn't a prototype in scope.
2107dnl
2108dnl  When an auto-import takes place, the following warning is given by the
2109dnl  linker.  This shouldn't be seen for any functions.
2110dnl
2111dnl      Info: resolving _foo by linking to __imp__foo (auto-import)
2112dnl
2113dnl
2114dnl  COFF type directives look like the following
2115dnl
2116dnl      .def    _foo
2117dnl      .scl    2
2118dnl      .type   32
2119dnl      .endef
2120dnl
2121dnl  _foo is the symbol with GSYM_PREFIX (_).  .scl is the storage class, 2
2122dnl  for external, 3 for static.  .type is the object type, 32 for a
2123dnl  function.
2124dnl
2125dnl  On an ELF system, this is (correctly) rejected due to .def, .endef and
2126dnl  .scl being invalid, and .type not having enough arguments.
2127
2128AC_DEFUN([GMP_ASM_COFF_TYPE],
2129[AC_REQUIRE([GMP_ASM_TEXT])
2130AC_REQUIRE([GMP_ASM_GLOBL])
2131AC_REQUIRE([GMP_ASM_GLOBL_ATTR])
2132AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2133AC_REQUIRE([GMP_ASM_UNDERSCORE])
2134AC_CACHE_CHECK([for assembler COFF type directives],
2135		gmp_cv_asm_x86_coff_type,
2136[GMP_TRY_ASSEMBLE(
2137[	$gmp_cv_asm_text
2138	$gmp_cv_asm_globl ${tmp_gsym_prefix}foo$gmp_cv_asm_globl_attr
2139	.def	${tmp_gsym_prefix}foo
2140	.scl	2
2141	.type	32
2142	.endef
2143${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix
2144],
2145  [gmp_cv_asm_x86_coff_type=yes],
2146  [gmp_cv_asm_x86_coff_type=no])
2147])
2148echo ["define(<HAVE_COFF_TYPE>, <$gmp_cv_asm_x86_coff_type>)"] >> $gmp_tmpconfigm4
2149])
2150
2151
2152dnl  GMP_ASM_LSYM_PREFIX
2153dnl  -------------------
2154dnl  What is the prefix for a local label?
2155dnl
2156dnl  The prefixes tested are,
2157dnl
2158dnl      L  - usual for underscore systems
2159dnl      .L - usual for non-underscore systems
2160dnl      $  - alpha (gas and OSF system assembler)
2161dnl      L$ - hppa (gas and HP-UX system assembler)
2162dnl
2163dnl  The default is "L" if the tests fail for any reason.  There's a good
2164dnl  chance this will be adequate, since on most systems labels are local
2165dnl  anyway unless given a ".globl", and an "L" will avoid clashes with
2166dnl  other identifers.
2167dnl
2168dnl  For gas, ".L" is normally purely local to the assembler, it doesn't get
2169dnl  put into the object file at all.  This style is preferred, to keep the
2170dnl  object files nice and clean.
2171dnl
2172dnl  BSD format nm produces a line like
2173dnl
2174dnl      00000000 t Lgurkmacka
2175dnl
2176dnl  The symbol code is normally "t" for text, but any lower case letter
2177dnl  indicates a local definition.
2178dnl
2179dnl  Code "n" is for a debugging symbol, OSF "nm -B" gives that as an upper
2180dnl  case "N" for a local.
2181dnl
2182dnl  HP-UX nm prints an error message (though seems to give a 0 exit) if
2183dnl  there's no symbols at all in an object file, hence the use of "dummy".
2184
2185AC_DEFUN([GMP_ASM_LSYM_PREFIX],
2186[AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2187AC_REQUIRE([GMP_ASM_TEXT])
2188AC_REQUIRE([GMP_PROG_NM])
2189AC_CACHE_CHECK([for assembler local label prefix],
2190               gmp_cv_asm_lsym_prefix,
2191[gmp_tmp_pre_appears=yes
2192for gmp_tmp_pre in L .L $L $ L$; do
2193  echo "Trying $gmp_tmp_pre" >&AC_FD_CC
2194  GMP_TRY_ASSEMBLE(
2195[	$gmp_cv_asm_text
2196dummy${gmp_cv_asm_label_suffix}
2197${gmp_tmp_pre}gurkmacka${gmp_cv_asm_label_suffix}],
2198  [if $NM conftest.$OBJEXT >conftest.nm 2>&AC_FD_CC; then : ; else
2199    cat conftest.nm >&AC_FD_CC
2200    AC_MSG_WARN(["$NM" failure])
2201    break
2202  fi
2203  cat conftest.nm >&AC_FD_CC
2204  if grep gurkmacka conftest.nm >/dev/null; then : ; else
2205    # no mention of the symbol, this is good
2206    echo "$gmp_tmp_pre label doesn't appear in object file at all (good)" >&AC_FD_CC
2207    gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
2208    gmp_tmp_pre_appears=no
2209    break
2210  fi
2211  if grep [' [a-zN] .*gurkmacka'] conftest.nm >/dev/null; then
2212    # symbol mentioned as a local, use this if nothing better
2213    echo "$gmp_tmp_pre label is local but still in object file" >&AC_FD_CC
2214    if test -z "$gmp_cv_asm_lsym_prefix"; then
2215      gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
2216    fi
2217  else
2218    echo "$gmp_tmp_pre label is something unknown" >&AC_FD_CC
2219  fi
2220  ])
2221done
2222rm -f conftest*
2223if test -z "$gmp_cv_asm_lsym_prefix"; then
2224  gmp_cv_asm_lsym_prefix=L
2225  AC_MSG_WARN([cannot determine local label, using default $gmp_cv_asm_lsym_prefix])
2226fi
2227# for development purposes, note whether we got a purely temporary local label
2228echo "Local label appears in object files: $gmp_tmp_pre_appears" >&AC_FD_CC
2229])
2230echo ["define(<LSYM_PREFIX>, <${gmp_cv_asm_lsym_prefix}>)"] >> $gmp_tmpconfigm4
2231AC_DEFINE_UNQUOTED(LSYM_PREFIX, "$gmp_cv_asm_lsym_prefix",
2232                   [Assembler local label prefix])
2233])
2234
2235
2236dnl  GMP_ASM_W32
2237dnl  -----------
2238dnl  How to define a 32-bit word.
2239dnl
2240dnl  FIXME: This test is not right for ia64-*-hpux*.  The directive should
2241dnl  be "data4", but the W32 macro is not currently used by the mpn/ia64 asm
2242dnl  files.
2243
2244AC_DEFUN([GMP_ASM_W32],
2245[AC_REQUIRE([GMP_ASM_DATA])
2246AC_REQUIRE([GMP_ASM_BYTE])
2247AC_REQUIRE([GMP_ASM_GLOBL])
2248AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2249AC_REQUIRE([GMP_PROG_NM])
2250AC_CACHE_CHECK([how to define a 32-bit word],
2251	       gmp_cv_asm_w32,
2252[case $host in
2253  *-*-hpux*)
2254    # FIXME: HPUX puts first symbol at 0x40000000, breaking our assumption
2255    # that it's at 0x0.  We'll have to declare another symbol before the
2256    # .long/.word and look at the distance between the two symbols.  The
2257    # only problem is that the sed expression(s) barfs (on Solaris, for
2258    # example) for the symbol with value 0.  For now, HPUX uses .word.
2259    gmp_cv_asm_w32=".word"
2260    ;;
2261  *-*-*)
2262    gmp_tmp_val=
2263    for gmp_tmp_op in .long .word data4; do
2264      GMP_TRY_ASSEMBLE(
2265[	$gmp_cv_asm_data
2266	$gmp_cv_asm_globl	foo
2267	$gmp_tmp_op	0
2268foo$gmp_cv_asm_label_suffix
2269	$gmp_cv_asm_byte	0],
2270        [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
2271          sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
2272        if test "$gmp_tmp_val" = 4; then
2273          gmp_cv_asm_w32="$gmp_tmp_op"
2274          break
2275        fi])
2276    done
2277    rm -f conftest*
2278    ;;
2279esac
2280if test -z "$gmp_cv_asm_w32"; then
2281  AC_MSG_ERROR([cannot determine how to define a 32-bit word])
2282fi
2283])
2284echo ["define(<W32>, <$gmp_cv_asm_w32>)"] >> $gmp_tmpconfigm4
2285])
2286
2287
2288dnl  GMP_X86_ASM_GOT_UNDERSCORE
2289dnl  --------------------------
2290dnl  Determine whether i386 _GLOBAL_OFFSET_TABLE_ needs an additional
2291dnl  underscore prefix.
2292dnl
2293dnl    SVR4      - the standard is _GLOBAL_OFFSET_TABLE_
2294dnl    GNU/Linux - follows SVR4
2295dnl    OpenBSD   - an a.out underscore system, uses __GLOBAL_OFFSET_TABLE_
2296dnl    NetBSD    - also an a.out underscore system, but _GLOBAL_OFFSET_TABLE_
2297dnl
2298dnl  The test attempts to link a program using _GLOBAL_OFFSET_TABLE_ or
2299dnl  __GLOBAL_OFFSET_TABLE_ to see which works.
2300dnl
2301dnl  $lt_prog_compiler_pic is included in the compile because old versions
2302dnl  of gas wouldn't accept PIC idioms without the right option (-K).  This
2303dnl  is the same as what libtool and mpn/Makeasm.am will do.
2304dnl
2305dnl  $lt_prog_compiler_pic is also included in the link because OpenBSD ld
2306dnl  won't accept an R_386_GOTPC relocation without the right options.  This
2307dnl  is not what's done by the Makefiles when building executables, but
2308dnl  let's hope it's ok (it works fine with gcc).
2309dnl
2310dnl  The fallback is no additional underscore, on the basis that this will
2311dnl  suit SVR4/ELF style systems, which should be much more common than
2312dnl  a.out systems with shared libraries.
2313dnl
2314dnl  Note that it's not an error for the tests to fail, since for instance
2315dnl  cygwin, mingw and djgpp don't have a _GLOBAL_OFFSET_TABLE_ scheme at
2316dnl  all.
2317dnl
2318dnl  Perhaps $CCAS could be asked to do the linking as well as the
2319dnl  assembling, but in the Makefiles it's only used for assembling, so lets
2320dnl  keep it that way.
2321dnl
2322dnl  The test here is run even under --disable-shared, so that PIC objects
2323dnl  can be built and tested by the tune/many.pl development scheme.  The
2324dnl  tests will be reasonably quick and won't give a fatal error, so this
2325dnl  arrangement is ok.  AC_LIBTOOL_PROG_COMPILER_PIC does its
2326dnl  $lt_prog_compiler_pic setups even for --disable-shared too.
2327
2328AC_DEFUN([GMP_ASM_X86_GOT_UNDERSCORE],
2329[AC_REQUIRE([GMP_ASM_TEXT])
2330AC_REQUIRE([GMP_ASM_GLOBL])
2331AC_REQUIRE([GMP_ASM_GLOBL_ATTR])
2332AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2333AC_REQUIRE([GMP_ASM_UNDERSCORE])
2334AC_REQUIRE([AC_LIBTOOL_PROG_COMPILER_PIC])
2335AC_CACHE_CHECK([if _GLOBAL_OFFSET_TABLE_ is prefixed by underscore],
2336               gmp_cv_asm_x86_got_underscore,
2337[gmp_cv_asm_x86_got_underscore="not applicable"
2338if test $gmp_cv_asm_underscore = yes; then
2339  tmp_gsym_prefix=_
2340else
2341  tmp_gsym_prefix=
2342fi
2343for tmp_underscore in "" "_"; do
2344  cat >conftest.s <<EOF
2345	$gmp_cv_asm_text
2346	$gmp_cv_asm_globl ${tmp_gsym_prefix}main$gmp_cv_asm_globl_attr
2347${tmp_gsym_prefix}main$gmp_cv_asm_label_suffix
2348	addl	$ ${tmp_underscore}_GLOBAL_OFFSET_TABLE_, %ebx
2349EOF
2350  gmp_compile="$CCAS $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.s >&AC_FD_CC && $CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.$OBJEXT >&AC_FD_CC"
2351  if AC_TRY_EVAL(gmp_compile); then
2352    if test "$tmp_underscore" = "_"; then
2353      gmp_cv_asm_x86_got_underscore=yes
2354    else
2355      gmp_cv_asm_x86_got_underscore=no
2356    fi
2357    break
2358  fi
2359done
2360rm -f conftest* a.out b.out a.exe a_out.exe
2361])
2362if test "$gmp_cv_asm_x86_got_underscore" = "yes"; then
2363  GMP_DEFINE(GOT_GSYM_PREFIX, [_])
2364else
2365  GMP_DEFINE(GOT_GSYM_PREFIX, [])
2366fi
2367])
2368
2369
2370dnl  GMP_ASM_X86_GOT_EAX_OK(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
2371dnl  -------------------------------------------------------------
2372dnl  Determine whether _GLOBAL_OFFSET_TABLE_ used with %eax is ok.
2373dnl
2374dnl  An instruction
2375dnl
2376dnl          addl  $_GLOBAL_OFFSET_TABLE_, %eax
2377dnl
2378dnl  is incorrectly assembled by gas 2.12 (or thereabouts) and earlier.  It
2379dnl  puts an addend 2 into the R_386_GOTPC relocation, but it should be 1
2380dnl  for this %eax form being a 1 byte opcode (with other registers it's 2
2381dnl  opcode bytes).  See note about this in mpn/x86/README too.
2382dnl
2383dnl  We assemble this, surrounded by some unlikely byte sequences as
2384dnl  delimiters, and check for the bad output.
2385dnl
2386dnl  This is for use by compiler probing in GMP_PROG_CC_WORKS, so the result
2387dnl  is not cached.
2388dnl
2389dnl  This test is not specific to gas, but old gas is the only assembler we
2390dnl  know of with this problem.  The Solaris has been seen coming out ok.
2391dnl
2392dnl  ".text" is hard coded because this macro is wanted before GMP_ASM_TEXT.
2393dnl  This should be fine, ".text" is normal on x86 systems, and certainly
2394dnl  will be fine with the offending gas.
2395dnl
2396dnl  If an error occurs when assembling, we consider the assembler ok, since
2397dnl  the bad output does not occur.  This happens for instance on mingw,
2398dnl  where _GLOBAL_OFFSET_TABLE_ results in a bfd error, since there's no
2399dnl  GOT etc in PE object files.
2400dnl
2401dnl  This test is used before the object file extension has been determined,
2402dnl  so we force output to conftest.o.  Using -o with -c is not portable,
2403dnl  but we think all x86 compilers will accept -o with -c, certainly gcc
2404dnl  does.
2405dnl
2406dnl  -fPIC is hard coded here, because this test is for use before libtool
2407dnl  has established the pic options.  It's right for gcc, but perhaps not
2408dnl  other compilers.
2409
2410AC_DEFUN([GMP_ASM_X86_GOT_EAX_OK],
2411[echo "Testing gas GOT with eax good" >&AC_FD_CC
2412cat >conftest.awk <<\EOF
2413[BEGIN {
2414  want[0]  = "001"
2415  want[1]  = "043"
2416  want[2]  = "105"
2417  want[3]  = "147"
2418  want[4]  = "211"
2419  want[5]  = "253"
2420  want[6]  = "315"
2421  want[7]  = "357"
2422
2423  want[8]  = "005"
2424  want[9]  = "002"
2425  want[10] = "000"
2426  want[11] = "000"
2427  want[12] = "000"
2428
2429  want[13] = "376"
2430  want[14] = "334"
2431  want[15] = "272"
2432  want[16] = "230"
2433  want[17] = "166"
2434  want[18] = "124"
2435  want[19] = "062"
2436  want[20] = "020"
2437
2438  result = "yes"
2439}
2440{
2441  for (f = 2; f <= NF; f++)
2442    {
2443      for (i = 0; i < 20; i++)
2444        got[i] = got[i+1];
2445      got[20] = $f;
2446
2447      found = 1
2448      for (i = 0; i < 21; i++)
2449        if (got[i] != want[i])
2450          {
2451            found = 0
2452            break
2453          }
2454      if (found)
2455        {
2456          result = "no"
2457          exit
2458        }
2459    }
2460}
2461END {
2462  print result
2463}
2464]EOF
2465cat >conftest.s <<\EOF
2466[	.text
2467	.byte	1, 35, 69, 103, 137, 171, 205, 239
2468	addl	$_GLOBAL_OFFSET_TABLE_, %eax
2469	.byte	254, 220, 186, 152, 118, 84, 50, 16
2470]EOF
2471tmp_got_good=yes
2472gmp_compile="$1 -fPIC -o conftest.o -c conftest.s >&AC_FD_CC 2>&1"
2473if AC_TRY_EVAL(gmp_compile); then
2474  tmp_got_good=`od -b conftest.o | $AWK -f conftest.awk`
2475fi
2476rm -f conftest.*
2477echo "Result: $tmp_got_good" >&AC_FD_CC
2478if test "$tmp_got_good" = no; then
2479  ifelse([$3],,:,[$3])
2480else
2481  ifelse([$2],,:,[$2])
2482fi
2483])
2484
2485
2486dnl  GMP_ASM_X86_MMX([ACTION-IF-YES][,ACTION-IF-NO])
2487dnl  -----------------------------------------------
2488dnl  Determine whether the assembler supports MMX instructions.
2489dnl
2490dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
2491dnl  here.  ".text" is believed to be correct on all x86 systems.  Actually
2492dnl  ".text" probably isn't needed at all, at least for just checking
2493dnl  instruction syntax.
2494dnl
2495dnl  "movq %mm0, %mm1" should assemble to "0f 6f c8", but Solaris 2.6 and
2496dnl  2.7 wrongly assemble it to "0f 6f c1" (that being the reverse "movq
2497dnl  %mm1, %mm0").  It seems more trouble than it's worth to work around
2498dnl  this in the code, so just detect and reject.
2499
2500AC_DEFUN([GMP_ASM_X86_MMX],
2501[AC_CACHE_CHECK([if the assembler knows about MMX instructions],
2502		gmp_cv_asm_x86_mmx,
2503[GMP_TRY_ASSEMBLE(
2504[	.text
2505	movq	%mm0, %mm1],
2506[gmp_cv_asm_x86_mmx=yes
2507case $host in
2508*-*-solaris*)
2509  if (dis conftest.$OBJEXT >conftest.out) 2>/dev/null; then
2510    if grep "0f 6f c1" conftest.out >/dev/null; then
2511      gmp_cv_asm_x86_mmx=movq-bug
2512    fi
2513  else
2514    AC_MSG_WARN(["dis" not available to check for "as" movq bug])
2515  fi
2516esac],
2517[gmp_cv_asm_x86_mmx=no])])
2518
2519case $gmp_cv_asm_x86_mmx in
2520movq-bug)
2521  AC_MSG_WARN([+----------------------------------------------------------])
2522  AC_MSG_WARN([| WARNING WARNING WARNING])
2523  AC_MSG_WARN([| Host CPU has MMX code, but the assembler])
2524  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
2525  AC_MSG_WARN([| has the Solaris 2.6 and 2.7 bug where register to register])
2526  AC_MSG_WARN([| movq operands are reversed.])
2527  AC_MSG_WARN([| Non-MMX replacements will be used.])
2528  AC_MSG_WARN([| This will be an inferior build.])
2529  AC_MSG_WARN([+----------------------------------------------------------])
2530  ;;
2531no)
2532  AC_MSG_WARN([+----------------------------------------------------------])
2533  AC_MSG_WARN([| WARNING WARNING WARNING])
2534  AC_MSG_WARN([| Host CPU has MMX code, but it can't be assembled by])
2535  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
2536  AC_MSG_WARN([| Non-MMX replacements will be used.])
2537  AC_MSG_WARN([| This will be an inferior build.])
2538  AC_MSG_WARN([+----------------------------------------------------------])
2539  ;;
2540esac
2541if test "$gmp_cv_asm_x86_mmx" = yes; then
2542  ifelse([$1],,:,[$1])
2543else
2544  ifelse([$2],,:,[$2])
2545fi
2546])
2547
2548
2549dnl  GMP_ASM_X86_SHLDL_CL
2550dnl  --------------------
2551
2552AC_DEFUN([GMP_ASM_X86_SHLDL_CL],
2553[AC_REQUIRE([GMP_ASM_TEXT])
2554AC_CACHE_CHECK([if the assembler takes cl with shldl],
2555		gmp_cv_asm_x86_shldl_cl,
2556[GMP_TRY_ASSEMBLE(
2557[	$gmp_cv_asm_text
2558	shldl	%cl, %eax, %ebx],
2559  gmp_cv_asm_x86_shldl_cl=yes,
2560  gmp_cv_asm_x86_shldl_cl=no)
2561])
2562if test "$gmp_cv_asm_x86_shldl_cl" = "yes"; then
2563  GMP_DEFINE(WANT_SHLDL_CL,1)
2564else
2565  GMP_DEFINE(WANT_SHLDL_CL,0)
2566fi
2567])
2568
2569
2570dnl  GMP_ASM_X86_SSE2([ACTION-IF-YES][,ACTION-IF-NO])
2571dnl  ------------------------------------------------
2572dnl  Determine whether the assembler supports SSE2 instructions.
2573dnl
2574dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
2575dnl  here.  ".text" is believed to be correct on all x86 systems, certainly
2576dnl  it's all GMP_ASM_TEXT gives currently.  Actually ".text" probably isn't
2577dnl  needed at all, at least for just checking instruction syntax.
2578
2579AC_DEFUN([GMP_ASM_X86_SSE2],
2580[AC_CACHE_CHECK([if the assembler knows about SSE2 instructions],
2581		gmp_cv_asm_x86_sse2,
2582[GMP_TRY_ASSEMBLE(
2583[	.text
2584	paddq	%mm0, %mm1],
2585  [gmp_cv_asm_x86_sse2=yes],
2586  [gmp_cv_asm_x86_sse2=no])
2587])
2588case $gmp_cv_asm_x86_sse2 in
2589yes)
2590  ifelse([$1],,:,[$1])
2591  ;;
2592*)
2593  AC_MSG_WARN([+----------------------------------------------------------])
2594  AC_MSG_WARN([| WARNING WARNING WARNING])
2595  AC_MSG_WARN([| Host CPU has SSE2 code, but it can't be assembled by])
2596  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
2597  AC_MSG_WARN([| Non-SSE2 replacements will be used.])
2598  AC_MSG_WARN([| This will be an inferior build.])
2599  AC_MSG_WARN([+----------------------------------------------------------])
2600  ifelse([$2],,:,[$2])
2601  ;;
2602esac
2603])
2604
2605
2606dnl  GMP_ASM_X86_MCOUNT
2607dnl  ------------------
2608dnl  Find out how to call mcount for profiling on an x86 system.
2609dnl
2610dnl  A dummy function is compiled and the ".s" output examined.  The pattern
2611dnl  matching might be a bit fragile, but should work at least with gcc on
2612dnl  sensible systems.  Certainly it's better than hard coding a table of
2613dnl  conventions.
2614dnl
2615dnl  For non-PIC, any ".data" is taken to mean a counter might be passed.
2616dnl  It's assumed a movl will set it up, and the right register is taken
2617dnl  from that movl.  Any movl involving %esp is ignored (a frame pointer
2618dnl  setup normally).
2619dnl
2620dnl  For PIC, any ".data" is similarly interpreted, but a GOTOFF identifies
2621dnl  the line setting up the right register.
2622dnl
2623dnl  In both cases a line with "mcount" identifies the call and that line is
2624dnl  used literally.
2625dnl
2626dnl  On some systems (eg. FreeBSD 3.5) gcc emits ".data" but doesn't use it,
2627dnl  so it's not an error to have .data but then not find a register.
2628dnl
2629dnl  Variations in mcount conventions on different x86 systems can be found
2630dnl  in gcc config/i386.  mcount can have a "_" prefix or be .mcount or
2631dnl  _mcount_ptr, and for PIC it can be called through a GOT entry, or via
2632dnl  the PLT.  If a pointer to a counter is required it's passed in %eax or
2633dnl  %edx.
2634dnl
2635dnl  Flags to specify PIC are taken from $lt_prog_compiler_pic set by
2636dnl  AC_PROG_LIBTOOL.
2637dnl
2638dnl  Enhancement: Cache the values determined here. But what's the right way
2639dnl  to get two variables (mcount_nonpic_reg and mcount_nonpic_call say) set
2640dnl  from one block of commands?
2641
2642AC_DEFUN([GMP_ASM_X86_MCOUNT],
2643[AC_REQUIRE([AC_ENABLE_SHARED])
2644AC_REQUIRE([AC_PROG_LIBTOOL])
2645AC_MSG_CHECKING([how to call x86 mcount])
2646cat >conftest.c <<EOF
2647foo(){bar();}
2648EOF
2649
2650if test "$enable_static" = yes; then
2651  gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c 1>&AC_FD_CC"
2652  if AC_TRY_EVAL(gmp_asmout_compile); then
2653    if grep '\.data' conftest.s >/dev/null; then
2654      mcount_nonpic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
2655    else
2656      mcount_nonpic_reg=
2657    fi
2658    mcount_nonpic_call=`grep 'call.*mcount' conftest.s`
2659    if test -z "$mcount_nonpic_call"; then
2660      AC_MSG_ERROR([Cannot find mcount call for non-PIC])
2661    fi
2662  else
2663    AC_MSG_ERROR([Cannot compile test program for non-PIC])
2664  fi
2665fi
2666
2667if test "$enable_shared" = yes; then
2668  gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic -S conftest.c 1>&AC_FD_CC"
2669  if AC_TRY_EVAL(gmp_asmout_compile); then
2670    if grep '\.data' conftest.s >/dev/null; then
2671      case $lt_prog_compiler_pic in
2672        *-DDLL_EXPORT*)
2673          # Windows DLLs have non-PIC style mcount
2674          mcount_pic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
2675          ;;
2676        *)
2677          mcount_pic_reg=`sed -n ['s/.*GOTOFF.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
2678          ;;
2679      esac
2680    else
2681      mcount_pic_reg=
2682    fi
2683    mcount_pic_call=`grep 'call.*mcount' conftest.s`
2684    if test -z "$mcount_pic_call"; then
2685      AC_MSG_ERROR([Cannot find mcount call for PIC])
2686    fi
2687  else
2688    AC_MSG_ERROR([Cannot compile test program for PIC])
2689  fi
2690fi
2691
2692GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_REG>, <\`$mcount_nonpic_reg'>)"])
2693GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_CALL>,<\`$mcount_nonpic_call'>)"])
2694GMP_DEFINE_RAW(["define(<MCOUNT_PIC_REG>,    <\`$mcount_pic_reg'>)"])
2695GMP_DEFINE_RAW(["define(<MCOUNT_PIC_CALL>,   <\`$mcount_pic_call'>)"])
2696
2697rm -f conftest.*
2698AC_MSG_RESULT([determined])
2699])
2700
2701
2702dnl  GMP_ASM_IA64_ALIGN_OK
2703dnl  ---------------------
2704dnl  Determine whether .align correctly pads with nop instructions in a text
2705dnl  segment.
2706dnl
2707dnl  gas 2.14 and earlier byte swaps its padding bundle on big endian
2708dnl  systems, which is incorrect (endianness only changes data).  What
2709dnl  should be "nop.m / nop.f / nop.i" comes out as "break" instructions.
2710dnl
2711dnl  The test here detects the bad case, and assumes anything else is ok
2712dnl  (there are many sensible nop bundles, so it'd be impractical to try to
2713dnl  match everything good).
2714
2715AC_DEFUN([GMP_ASM_IA64_ALIGN_OK],
2716[AC_CACHE_CHECK([whether assembler .align padding is good],
2717		gmp_cv_asm_ia64_align_ok,
2718[cat >conftest.awk <<\EOF
2719[BEGIN {
2720  want[0]  = "011"
2721  want[1]  = "160"
2722  want[2]  = "074"
2723  want[3]  = "040"
2724  want[4]  = "000"
2725  want[5]  = "040"
2726  want[6]  = "020"
2727  want[7]  = "221"
2728  want[8]  = "114"
2729  want[9]  = "000"
2730  want[10] = "100"
2731  want[11] = "200"
2732  want[12] = "122"
2733  want[13] = "261"
2734  want[14] = "000"
2735  want[15] = "200"
2736
2737  want[16] = "000"
2738  want[17] = "004"
2739  want[18] = "000"
2740  want[19] = "000"
2741  want[20] = "000"
2742  want[21] = "000"
2743  want[22] = "002"
2744  want[23] = "000"
2745  want[24] = "000"
2746  want[25] = "000"
2747  want[26] = "000"
2748  want[27] = "001"
2749  want[28] = "000"
2750  want[29] = "000"
2751  want[30] = "000"
2752  want[31] = "014"
2753
2754  want[32] = "011"
2755  want[33] = "270"
2756  want[34] = "140"
2757  want[35] = "062"
2758  want[36] = "000"
2759  want[37] = "040"
2760  want[38] = "240"
2761  want[39] = "331"
2762  want[40] = "160"
2763  want[41] = "000"
2764  want[42] = "100"
2765  want[43] = "240"
2766  want[44] = "343"
2767  want[45] = "371"
2768  want[46] = "000"
2769  want[47] = "200"
2770
2771  result = "yes"
2772}
2773{
2774  for (f = 2; f <= NF; f++)
2775    {
2776      for (i = 0; i < 47; i++)
2777        got[i] = got[i+1];
2778      got[47] = $f;
2779
2780      found = 1
2781      for (i = 0; i < 48; i++)
2782        if (got[i] != want[i])
2783          {
2784            found = 0
2785            break
2786          }
2787      if (found)
2788        {
2789          result = "no"
2790          exit
2791        }
2792    }
2793}
2794END {
2795  print result
2796}
2797]EOF
2798GMP_TRY_ASSEMBLE(
2799[	.text
2800	.align	32
2801{ .mmi;	add	r14 = r15, r16
2802	add	r17 = r18, r19
2803	add	r20 = r21, r22 ;; }
2804	.align	32
2805{ .mmi;	add	r23 = r24, r25
2806	add	r26 = r27, r28
2807	add	r29 = r30, r31 ;; }
2808],
2809  [gmp_cv_asm_ia64_align_ok=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`],
2810  [AC_MSG_WARN([oops, cannot compile test program])
2811   gmp_cv_asm_ia64_align_ok=yes])
2812])
2813GMP_DEFINE_RAW(["define(<IA64_ALIGN_OK>, <\`$gmp_cv_asm_ia64_align_ok'>)"])
2814])
2815
2816
2817
2818
2819dnl  GMP_ASM_M68K_INSTRUCTION
2820dnl  ------------------------
2821dnl  Not sure if ".l" and "%" are independent settings, but it doesn't hurt
2822dnl  to try all four possibilities.  Note that the % ones must be first, so
2823dnl  "d0" won't be interpreted as a label.
2824dnl
2825dnl  gas 1.92.3 on NetBSD 1.4 needs to be tested with a two operand
2826dnl  instruction.  It takes registers without "%", but a single operand
2827dnl  "clrl %d0" only gives a warning, not an error.
2828
2829AC_DEFUN([GMP_ASM_M68K_INSTRUCTION],
2830[AC_REQUIRE([GMP_ASM_TEXT])
2831AC_CACHE_CHECK([assembler instruction and register style],
2832		gmp_cv_asm_m68k_instruction,
2833[for i in "addl %d0,%d1" "add.l %d0,%d1" "addl d0,d1" "add.l d0,d1"; do
2834  GMP_TRY_ASSEMBLE(
2835    [	$gmp_cv_asm_text
2836	$i],
2837    [gmp_cv_asm_m68k_instruction=$i
2838    rm -f conftest*
2839    break])
2840done
2841if test -z "$gmp_cv_asm_m68k_instruction"; then
2842  AC_MSG_ERROR([cannot determine assembler instruction and register style])
2843fi
2844])
2845case $gmp_cv_asm_m68k_instruction in
2846"addl d0,d1")    want_dot_size=no;  want_register_percent=no  ;;
2847"addl %d0,%d1")  want_dot_size=no;  want_register_percent=yes ;;
2848"add.l d0,d1")   want_dot_size=yes; want_register_percent=no  ;;
2849"add.l %d0,%d1") want_dot_size=yes; want_register_percent=yes ;;
2850*) AC_MSG_ERROR([oops, unrecognised instruction and register style]) ;;
2851esac
2852GMP_DEFINE_RAW(["define(<WANT_REGISTER_PERCENT>, <\`$want_register_percent'>)"])
2853GMP_DEFINE_RAW(["define(<WANT_DOT_SIZE>, <\`$want_dot_size'>)"])
2854])
2855
2856
2857dnl  GMP_ASM_M68K_ADDRESSING
2858dnl  -----------------------
2859
2860AC_DEFUN([GMP_ASM_M68K_ADDRESSING],
2861[AC_REQUIRE([GMP_ASM_TEXT])
2862AC_REQUIRE([GMP_ASM_M68K_INSTRUCTION])
2863AC_CACHE_CHECK([assembler addressing style],
2864		gmp_cv_asm_m68k_addressing,
2865[case $gmp_cv_asm_m68k_instruction in
2866addl*)  movel=movel ;;
2867add.l*) movel=move.l ;;
2868*) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
2869esac
2870case $gmp_cv_asm_m68k_instruction in
2871*"%d0,%d1") dreg=%d0; areg=%a0 ;;
2872*"d0,d1")   dreg=d0;  areg=a0  ;;
2873*) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
2874esac
2875GMP_TRY_ASSEMBLE(
2876[	$gmp_cv_asm_text
2877	$movel	$dreg, $areg@-],
2878  [gmp_cv_asm_m68k_addressing=mit],
2879[GMP_TRY_ASSEMBLE(
2880[	$gmp_cv_asm_text
2881	$movel	$dreg, -($areg)],
2882  [gmp_cv_asm_m68k_addressing=motorola],
2883[AC_MSG_ERROR([cannot determine assembler addressing style])])])
2884])
2885GMP_DEFINE_RAW(["define(<WANT_ADDRESSING>, <\`$gmp_cv_asm_m68k_addressing'>)"])
2886])
2887
2888
2889dnl  GMP_ASM_M68K_BRANCHES
2890dnl  ---------------------
2891dnl  "bra" is the standard branch instruction.  "jra" or "jbra" are
2892dnl  preferred where available, since on gas for instance they give a
2893dnl  displacement only as big as it needs to be, whereas "bra" is always
2894dnl  16-bits.  This applies to the conditional branches "bcc" etc too.
2895dnl  However "dbcc" etc on gas are already only as big as they need to be.
2896
2897AC_DEFUN([GMP_ASM_M68K_BRANCHES],
2898[AC_REQUIRE([GMP_ASM_TEXT])
2899AC_CACHE_CHECK([assembler shortest branches],
2900		gmp_cv_asm_m68k_branches,
2901[for i in jra jbra bra; do
2902  GMP_TRY_ASSEMBLE(
2903[	$gmp_cv_asm_text
2904foo$gmp_cv_asm_label_suffix
2905	$i	foo],
2906  [gmp_cv_asm_m68k_branches=$i
2907  rm -f conftest*
2908  break])
2909done
2910if test -z "$gmp_cv_asm_m68k_branches"; then
2911  AC_MSG_ERROR([cannot determine assembler branching style])
2912fi
2913])
2914GMP_DEFINE_RAW(["define(<WANT_BRANCHES>, <\`$gmp_cv_asm_m68k_branches'>)"])
2915])
2916
2917
2918dnl  GMP_ASM_POWERPC_PIC_ALWAYS
2919dnl  --------------------------
2920dnl  Determine whether PIC is the default compiler output.
2921dnl
2922dnl  SVR4 style "foo@ha" addressing is interpreted as non-PIC, and anything
2923dnl  else is assumed to require PIC always (Darwin or AIX).  SVR4 is the
2924dnl  only non-PIC addressing syntax the asm files have at the moment anyway.
2925dnl
2926dnl  Libtool does this by taking "*-*-aix* | *-*-darwin* | *-*-rhapsody*" to
2927dnl  mean PIC always, but it seems more reliable to grep the compiler
2928dnl  output.
2929dnl
2930dnl The next paragraph is untrue for Tiger.  Was it ever true?  For tiger,
2931dnl "cc -fast" makes non-PIC the default (and the binaries do run).
2932dnl  On Darwin "cc -static" is non-PIC with syntax "ha16(_foo)", but that's
2933dnl  apparently only for use in the kernel, which we're not attempting to
2934dnl  target at the moment, so don't look for that.
2935
2936AC_DEFUN([GMP_ASM_POWERPC_PIC_ALWAYS],
2937[AC_REQUIRE([AC_PROG_CC])
2938AC_CACHE_CHECK([whether compiler output is PIC by default],
2939               gmp_cv_asm_powerpc_pic,
2940[gmp_cv_asm_powerpc_pic=yes
2941cat >conftest.c <<EOF
2942int foo;
2943int *bar() { return &foo; }
2944EOF
2945echo "Test program:" >&AC_FD_CC
2946cat conftest.c >&AC_FD_CC
2947gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
2948if AC_TRY_EVAL(gmp_compile); then
2949  echo "Compiler output:" >&AC_FD_CC
2950  cat conftest.s >&AC_FD_CC
2951  if grep 'foo@ha' conftest.s >/dev/null 2>&AC_FD_CC; then
2952    gmp_cv_asm_powerpc_pic=no
2953  fi
2954  if grep 'ha16(_foo)' conftest.s >/dev/null 2>&AC_FD_CC; then
2955    gmp_cv_asm_powerpc_pic=no
2956  fi
2957fi
2958rm -f conftest*
2959])
2960GMP_DEFINE_RAW(["define(<PIC_ALWAYS>,<$gmp_cv_asm_powerpc_pic>)"])
2961])
2962
2963
2964dnl  GMP_ASM_POWERPC_R_REGISTERS
2965dnl  ---------------------------
2966dnl  Determine whether the assembler takes powerpc registers with an "r" as
2967dnl  in "r6", or as plain "6".  The latter is standard, but NeXT, Rhapsody,
2968dnl  and MacOS-X require the "r" forms.
2969dnl
2970dnl  See also mpn/powerpc32/powerpc-defs.m4 which uses the result of this
2971dnl  test.
2972
2973AC_DEFUN([GMP_ASM_POWERPC_R_REGISTERS],
2974[AC_REQUIRE([GMP_ASM_TEXT])
2975AC_CACHE_CHECK([if the assembler needs r on registers],
2976               gmp_cv_asm_powerpc_r_registers,
2977[GMP_TRY_ASSEMBLE(
2978[	$gmp_cv_asm_text
2979	mtctr	6],
2980[gmp_cv_asm_powerpc_r_registers=no],
2981[GMP_TRY_ASSEMBLE(
2982[	$gmp_cv_asm_text
2983	mtctr	r6],
2984[gmp_cv_asm_powerpc_r_registers=yes],
2985[AC_MSG_ERROR([neither "mtctr 6" nor "mtctr r6" works])])])])
2986
2987GMP_DEFINE_RAW(["define(<WANT_R_REGISTERS>,<$gmp_cv_asm_powerpc_r_registers>)"])
2988])
2989
2990
2991dnl  GMP_ASM_SPARC_REGISTER
2992dnl  ----------------------
2993dnl  Determine whether the assembler accepts the ".register" directive.
2994dnl  Old versions of solaris "as" don't.
2995dnl
2996dnl  See also mpn/sparc32/sparc-defs.m4 which uses the result of this test.
2997
2998AC_DEFUN([GMP_ASM_SPARC_REGISTER],
2999[AC_REQUIRE([GMP_ASM_TEXT])
3000AC_CACHE_CHECK([if the assembler accepts ".register"],
3001               gmp_cv_asm_sparc_register,
3002[GMP_TRY_ASSEMBLE(
3003[	$gmp_cv_asm_text
3004	.register	%g2,#scratch
3005],
3006[gmp_cv_asm_sparc_register=yes],
3007[gmp_cv_asm_sparc_register=no])])
3008
3009GMP_DEFINE_RAW(["define(<HAVE_REGISTER>,<$gmp_cv_asm_sparc_register>)"])
3010])
3011
3012
3013dnl  GMP_C_ATTRIBUTE_CONST
3014dnl  ---------------------
3015
3016AC_DEFUN([GMP_C_ATTRIBUTE_CONST],
3017[AC_CACHE_CHECK([whether gcc __attribute__ ((const)) works],
3018                gmp_cv_c_attribute_const,
3019[AC_TRY_COMPILE([int foo (int x) __attribute__ ((const));], ,
3020  gmp_cv_c_attribute_const=yes, gmp_cv_c_attribute_const=no)
3021])
3022if test $gmp_cv_c_attribute_const = yes; then
3023  AC_DEFINE(HAVE_ATTRIBUTE_CONST, 1,
3024  [Define to 1 if the compiler accepts gcc style __attribute__ ((const))])
3025fi
3026])
3027
3028
3029dnl  GMP_C_ATTRIBUTE_MALLOC
3030dnl  ----------------------
3031dnl  gcc 2.95.x accepts __attribute__ ((malloc)) but with a warning that
3032dnl  it's ignored.  Pretend it doesn't exist in this case, to avoid that
3033dnl  warning.
3034
3035AC_DEFUN([GMP_C_ATTRIBUTE_MALLOC],
3036[AC_CACHE_CHECK([whether gcc __attribute__ ((malloc)) works],
3037                gmp_cv_c_attribute_malloc,
3038[cat >conftest.c <<EOF
3039void *foo (int x) __attribute__ ((malloc));
3040EOF
3041gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >conftest.out 2>&1"
3042if AC_TRY_EVAL(gmp_compile); then
3043  if grep "attribute directive ignored" conftest.out >/dev/null; then
3044    gmp_cv_c_attribute_malloc=no
3045  else
3046    gmp_cv_c_attribute_malloc=yes
3047  fi
3048else
3049  gmp_cv_c_attribute_malloc=no
3050fi
3051cat conftest.out >&AC_FD_CC
3052rm -f conftest*
3053])
3054if test $gmp_cv_c_attribute_malloc = yes; then
3055  AC_DEFINE(HAVE_ATTRIBUTE_MALLOC, 1,
3056  [Define to 1 if the compiler accepts gcc style __attribute__ ((malloc))])
3057fi
3058])
3059
3060
3061dnl  GMP_C_ATTRIBUTE_MODE
3062dnl  --------------------
3063dnl  Introduced in gcc 2.2, but perhaps not in all Apple derived versions.
3064
3065AC_DEFUN([GMP_C_ATTRIBUTE_MODE],
3066[AC_CACHE_CHECK([whether gcc __attribute__ ((mode (XX))) works],
3067                gmp_cv_c_attribute_mode,
3068[AC_TRY_COMPILE([typedef int SItype __attribute__ ((mode (SI)));], ,
3069  gmp_cv_c_attribute_mode=yes, gmp_cv_c_attribute_mode=no)
3070])
3071if test $gmp_cv_c_attribute_mode = yes; then
3072  AC_DEFINE(HAVE_ATTRIBUTE_MODE, 1,
3073  [Define to 1 if the compiler accepts gcc style __attribute__ ((mode (XX)))])
3074fi
3075])
3076
3077
3078dnl  GMP_C_ATTRIBUTE_NORETURN
3079dnl  ------------------------
3080
3081AC_DEFUN([GMP_C_ATTRIBUTE_NORETURN],
3082[AC_CACHE_CHECK([whether gcc __attribute__ ((noreturn)) works],
3083                gmp_cv_c_attribute_noreturn,
3084[AC_TRY_COMPILE([void foo (int x) __attribute__ ((noreturn));], ,
3085  gmp_cv_c_attribute_noreturn=yes, gmp_cv_c_attribute_noreturn=no)
3086])
3087if test $gmp_cv_c_attribute_noreturn = yes; then
3088  AC_DEFINE(HAVE_ATTRIBUTE_NORETURN, 1,
3089  [Define to 1 if the compiler accepts gcc style __attribute__ ((noreturn))])
3090fi
3091])
3092
3093
3094dnl  GMP_C_DOUBLE_FORMAT
3095dnl  -------------------
3096dnl  Determine the floating point format.
3097dnl
3098dnl  The object file is grepped, in order to work when cross compiling.  A
3099dnl  start and end sequence is included to avoid false matches, and
3100dnl  allowance is made for the desired data crossing an "od -b" line
3101dnl  boundary.  The test number is a small integer so it should appear
3102dnl  exactly, no rounding or truncation etc.
3103dnl
3104dnl  "od -b", incidentally, is supported even by Unix V7, and the awk script
3105dnl  used doesn't have functions or anything, so even an "old" awk should
3106dnl  suffice.
3107
3108AC_DEFUN([GMP_C_DOUBLE_FORMAT],
3109[AC_REQUIRE([AC_PROG_CC])
3110AC_REQUIRE([AC_PROG_AWK])
3111AC_CACHE_CHECK([format of `double' floating point],
3112                gmp_cv_c_double_format,
3113[gmp_cv_c_double_format=unknown
3114cat >conftest.c <<\EOF
3115[struct {
3116  char    before[8];
3117  double  x;
3118  char    after[8];
3119} foo = {
3120  { '\001', '\043', '\105', '\147', '\211', '\253', '\315', '\357' },
3121  -123456789.0,
3122  { '\376', '\334', '\272', '\230', '\166', '\124', '\062', '\020' },
3123};]
3124EOF
3125gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC 2>&1"
3126if AC_TRY_EVAL(gmp_compile); then
3127cat >conftest.awk <<\EOF
3128[
3129BEGIN {
3130  found = 0
3131}
3132
3133{
3134  for (f = 2; f <= NF; f++)
3135    {
3136      for (i = 0; i < 23; i++)
3137        got[i] = got[i+1];
3138      got[23] = $f;
3139
3140      # match the special begin and end sequences
3141      if (got[0] != "001") continue
3142      if (got[1] != "043") continue
3143      if (got[2] != "105") continue
3144      if (got[3] != "147") continue
3145      if (got[4] != "211") continue
3146      if (got[5] != "253") continue
3147      if (got[6] != "315") continue
3148      if (got[7] != "357") continue
3149      if (got[16] != "376") continue
3150      if (got[17] != "334") continue
3151      if (got[18] != "272") continue
3152      if (got[19] != "230") continue
3153      if (got[20] != "166") continue
3154      if (got[21] != "124") continue
3155      if (got[22] != "062") continue
3156      if (got[23] != "020") continue
3157
3158      saw = " (" got[8] " " got[9] " " got[10] " " got[11] " " got[12] " " got[13] " " got[14] " " got[15] ")"
3159
3160      if (got[8]  == "000" &&  \
3161          got[9]  == "000" &&  \
3162          got[10] == "000" &&  \
3163          got[11] == "124" &&  \
3164          got[12] == "064" &&  \
3165          got[13] == "157" &&  \
3166          got[14] == "235" &&  \
3167          got[15] == "301")
3168        {
3169          print "IEEE little endian"
3170          found = 1
3171          exit
3172        }
3173
3174      # Little endian with the two 4-byte halves swapped, as used by ARM
3175      # when the chip is in little endian mode.
3176      #
3177      if (got[8]  == "064" &&  \
3178          got[9]  == "157" &&  \
3179          got[10] == "235" &&  \
3180          got[11] == "301" &&  \
3181          got[12] == "000" &&  \
3182          got[13] == "000" &&  \
3183          got[14] == "000" &&  \
3184          got[15] == "124")
3185        {
3186          print "IEEE little endian, swapped halves"
3187          found = 1
3188          exit
3189        }
3190
3191      # gcc 2.95.4 on one GNU/Linux ARM system was seen generating 000 in
3192      # the last byte, whereas 124 is correct.  Not sure where the bug
3193      # actually lies, but a running program didn't seem to get a full
3194      # mantissa worth of working bits.
3195      #
3196      # We match this case explicitly so we can give a nice result message,
3197      # but we deliberately exclude it from the normal IEEE double setups
3198      # since it's too broken.
3199      #
3200      if (got[8]  == "064" &&  \
3201          got[9]  == "157" &&  \
3202          got[10] == "235" &&  \
3203          got[11] == "301" &&  \
3204          got[12] == "000" &&  \
3205          got[13] == "000" &&  \
3206          got[14] == "000" &&  \
3207          got[15] == "000")
3208        {
3209          print "bad ARM software floats"
3210          found = 1
3211          exit
3212        }
3213
3214      if (got[8]  == "301" &&  \
3215          got[9]  == "235" &&  \
3216          got[10] == "157" &&  \
3217          got[11] == "064" &&  \
3218          got[12] == "124" &&  \
3219          got[13] == "000" &&  \
3220          got[14] == "000" &&  \
3221	  got[15] == "000")
3222        {
3223          print "IEEE big endian"
3224          found = 1
3225          exit
3226        }
3227
3228      if (got[8]  == "353" &&  \
3229          got[9]  == "315" &&  \
3230          got[10] == "242" &&  \
3231          got[11] == "171" &&  \
3232          got[12] == "000" &&  \
3233          got[13] == "240" &&  \
3234          got[14] == "000" &&  \
3235          got[15] == "000")
3236        {
3237          print "VAX D"
3238          found = 1
3239          exit
3240        }
3241
3242      if (got[8]  == "275" &&  \
3243          got[9]  == "301" &&  \
3244          got[10] == "064" &&  \
3245          got[11] == "157" &&  \
3246          got[12] == "000" &&  \
3247          got[13] == "124" &&  \
3248          got[14] == "000" &&  \
3249          got[15] == "000")
3250        {
3251          print "VAX G"
3252          found = 1
3253          exit
3254        }
3255
3256      if (got[8]  == "300" &&  \
3257          got[9]  == "033" &&  \
3258          got[10] == "353" &&  \
3259          got[11] == "171" &&  \
3260          got[12] == "242" &&  \
3261          got[13] == "240" &&  \
3262          got[14] == "000" &&  \
3263          got[15] == "000")
3264        {
3265          print "Cray CFP"
3266          found = 1
3267          exit
3268        }
3269    }
3270}
3271
3272END {
3273  if (! found)
3274    print "unknown", saw
3275}
3276]
3277EOF
3278  gmp_cv_c_double_format=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`
3279  case $gmp_cv_c_double_format in
3280  unknown*)
3281    echo "cannot match anything, conftest.$OBJEXT contains" >&AC_FD_CC
3282    od -b conftest.$OBJEXT >&AC_FD_CC
3283    ;;
3284  esac
3285else
3286  AC_MSG_WARN([oops, cannot compile test program])
3287fi
3288rm -f conftest*
3289])
3290
3291AH_VERBATIM([HAVE_DOUBLE],
3292[/* Define one of the following to 1 for the format of a `double'.
3293   If your format is not among these choices, or you don't know what it is,
3294   then leave all undefined.
3295   IEEE_LITTLE_SWAPPED means little endian, but with the two 4-byte halves
3296   swapped, as used by ARM CPUs in little endian mode.  */
3297#undef HAVE_DOUBLE_IEEE_BIG_ENDIAN
3298#undef HAVE_DOUBLE_IEEE_LITTLE_ENDIAN
3299#undef HAVE_DOUBLE_IEEE_LITTLE_SWAPPED
3300#undef HAVE_DOUBLE_VAX_D
3301#undef HAVE_DOUBLE_VAX_G
3302#undef HAVE_DOUBLE_CRAY_CFP])
3303
3304case $gmp_cv_c_double_format in
3305  "IEEE big endian")
3306    AC_DEFINE(HAVE_DOUBLE_IEEE_BIG_ENDIAN, 1)
3307    GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_DOUBLE_IEEE_BIG_ENDIAN')", POST)
3308    ;;
3309  "IEEE little endian")
3310    AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_ENDIAN, 1)
3311    GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_DOUBLE_IEEE_LITTLE_ENDIAN')", POST)
3312    ;;
3313  "IEEE little endian, swapped halves")
3314    AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_SWAPPED, 1) ;;
3315  "VAX D")
3316    AC_DEFINE(HAVE_DOUBLE_VAX_D, 1) ;;
3317  "VAX G")
3318    AC_DEFINE(HAVE_DOUBLE_VAX_G, 1) ;;
3319  "Cray CFP")
3320    AC_DEFINE(HAVE_DOUBLE_CRAY_CFP, 1) ;;
3321  "bad ARM software floats")
3322    ;;
3323  unknown*)
3324    AC_MSG_WARN([Could not determine float format.])
3325    AC_MSG_WARN([Conversions to and from "double" may be slow.])
3326    ;;
3327  *)
3328    AC_MSG_WARN([oops, unrecognised float format: $gmp_cv_c_double_format])
3329    ;;
3330esac
3331])
3332
3333
3334dnl  GMP_C_STDARG
3335dnl  ------------
3336dnl  Test whether to use <stdarg.h> or <varargs.h>.
3337dnl
3338dnl  Notice the AC_DEFINE here is HAVE_STDARG to avoid clashing with
3339dnl  HAVE_STDARG_H which could arise from AC_CHECK_HEADERS.
3340dnl
3341dnl  This test might be slight overkill, after all there's really only going
3342dnl  to be ANSI or K&R and the two can be differentiated by AC_PROG_CC_STDC
3343dnl  or very likely by the setups for _PROTO in gmp.h.  On the other hand
3344dnl  this test is nice and direct, being what we're going to actually use.
3345
3346AC_DEFUN([GMP_C_STDARG],
3347[AC_CACHE_CHECK([whether <stdarg.h> exists and works],
3348                gmp_cv_c_stdarg,
3349[AC_TRY_COMPILE(
3350[#include <stdarg.h>
3351int foo (int x, ...)
3352{
3353  va_list  ap;
3354  int      y;
3355  va_start (ap, x);
3356  y = va_arg (ap, int);
3357  va_end (ap);
3358  return y;
3359}],,
3360gmp_cv_c_stdarg=yes, gmp_cv_c_stdarg=no)
3361])
3362if test $gmp_cv_c_stdarg = yes; then
3363  AC_DEFINE(HAVE_STDARG, 1, [Define to 1 if <stdarg.h> exists and works])
3364fi
3365])
3366
3367
3368dnl  GMP_FUNC_ALLOCA
3369dnl  ---------------
3370dnl  Determine whether "alloca" is available.  This is AC_FUNC_ALLOCA from
3371dnl  autoconf, but changed so it doesn't use alloca.c if alloca() isn't
3372dnl  available, and also to use gmp-impl.h for the conditionals detecting
3373dnl  compiler builtin alloca's.
3374
3375AC_DEFUN([GMP_FUNC_ALLOCA],
3376[AC_REQUIRE([GMP_HEADER_ALLOCA])
3377AC_CACHE_CHECK([for alloca (via gmp-impl.h)],
3378               gmp_cv_func_alloca,
3379[AC_TRY_LINK(
3380GMP_INCLUDE_GMP_H
3381[#include "$srcdir/gmp-impl.h"
3382],
3383  [char *p = (char *) alloca (1);],
3384  gmp_cv_func_alloca=yes,
3385  gmp_cv_func_alloca=no)])
3386if test $gmp_cv_func_alloca = yes; then
3387  AC_DEFINE(HAVE_ALLOCA, 1, [Define to 1 if alloca() works (via gmp-impl.h).])
3388fi
3389])
3390
3391AC_DEFUN([GMP_HEADER_ALLOCA],
3392[# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
3393# for constant arguments.  Useless!
3394AC_CACHE_CHECK([for working alloca.h],
3395               gmp_cv_header_alloca,
3396[AC_TRY_LINK([#include <alloca.h>],
3397  [char *p = (char *) alloca (2 * sizeof (int));],
3398  gmp_cv_header_alloca=yes,
3399  gmp_cv_header_alloca=no)])
3400if test $gmp_cv_header_alloca = yes; then
3401  AC_DEFINE(HAVE_ALLOCA_H, 1,
3402  [Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).])
3403fi
3404])
3405
3406
3407dnl  GMP_OPTION_ALLOCA
3408dnl  -----------------
3409dnl  Decide what to do about --enable-alloca from the user.
3410dnl  This is a macro so it can require GMP_FUNC_ALLOCA.
3411
3412AC_DEFUN([GMP_OPTION_ALLOCA],
3413[AC_REQUIRE([GMP_FUNC_ALLOCA])
3414AC_CACHE_CHECK([how to allocate temporary memory],
3415               gmp_cv_option_alloca,
3416[case $enable_alloca in
3417  yes)
3418    gmp_cv_option_alloca=alloca
3419    ;;
3420  no)
3421    gmp_cv_option_alloca=malloc-reentrant
3422    ;;
3423  reentrant | notreentrant)
3424    case $gmp_cv_func_alloca in
3425    yes)  gmp_cv_option_alloca=alloca ;;
3426    *)    gmp_cv_option_alloca=malloc-$enable_alloca ;;
3427    esac
3428    ;;
3429  *)
3430    gmp_cv_option_alloca=$enable_alloca
3431    ;;
3432esac
3433])
3434
3435AH_VERBATIM([WANT_TMP],
3436[/* Define one of these to 1 for the desired temporary memory allocation
3437   method, per --enable-alloca. */
3438#undef WANT_TMP_ALLOCA
3439#undef WANT_TMP_REENTRANT
3440#undef WANT_TMP_NOTREENTRANT
3441#undef WANT_TMP_DEBUG])
3442
3443case $gmp_cv_option_alloca in
3444  alloca)
3445    if test $gmp_cv_func_alloca = no; then
3446      AC_MSG_ERROR([--enable-alloca=alloca specified, but alloca not available])
3447    fi
3448    AC_DEFINE(WANT_TMP_ALLOCA)
3449    TAL_OBJECT=tal-reent$U.lo
3450    ;;
3451  malloc-reentrant)
3452    AC_DEFINE(WANT_TMP_REENTRANT)
3453    TAL_OBJECT=tal-reent$U.lo
3454    ;;
3455  malloc-notreentrant)
3456    AC_DEFINE(WANT_TMP_NOTREENTRANT)
3457    TAL_OBJECT=tal-notreent$U.lo
3458    ;;
3459  debug)
3460    AC_DEFINE(WANT_TMP_DEBUG)
3461    TAL_OBJECT=tal-debug$U.lo
3462    ;;
3463  *)
3464    # checks at the start of configure.in should protect us
3465    AC_MSG_ERROR([unrecognised --enable-alloca=$gmp_cv_option_alloca])
3466    ;;
3467esac
3468AC_SUBST(TAL_OBJECT)
3469])
3470
3471
3472dnl  GMP_FUNC_SSCANF_WRITABLE_INPUT
3473dnl  ------------------------------
3474dnl  Determine whether sscanf requires a writable input string.
3475dnl
3476dnl  It might be nicer to run a program to determine this when doing a
3477dnl  native build, but the systems afflicted are few and far between these
3478dnl  days, so it seems good enough just to list them.
3479
3480AC_DEFUN([GMP_FUNC_SSCANF_WRITABLE_INPUT],
3481[AC_CACHE_CHECK([whether sscanf needs writable input],
3482                 gmp_cv_func_sscanf_writable_input,
3483[case $host in
3484  *-*-hpux9 | *-*-hpux9.*)
3485     gmp_cv_func_sscanf_writable_input=yes ;;
3486  *) gmp_cv_func_sscanf_writable_input=no  ;;
3487esac
3488])
3489case $gmp_cv_func_sscanf_writable_input in
3490  yes) AC_DEFINE(SSCANF_WRITABLE_INPUT, 1,
3491                 [Define to 1 if sscanf requires writable inputs]) ;;
3492  no)  ;;
3493  *)   AC_MSG_ERROR([unrecognised \$gmp_cv_func_sscanf_writable_input]) ;;
3494esac
3495])
3496
3497
3498dnl  GMP_FUNC_VSNPRINTF
3499dnl  ------------------
3500dnl  Check whether vsnprintf exists, and works properly.
3501dnl
3502dnl  Systems without vsnprintf include mingw32, OSF 4.
3503dnl
3504dnl  Sparc Solaris 2.7 in 64-bit mode doesn't always truncate, making
3505dnl  vsnprintf like vsprintf, and hence completely useless.  On one system a
3506dnl  literal string is enough to provoke the problem, on another a "%n" was
3507dnl  needed.  There seems to be something weird going on with the optimizer
3508dnl  or something, since on the first system adding a second check with
3509dnl  "%n", or even just an initialized local variable, makes it work.  In
3510dnl  any case, without bothering to get to the bottom of this, the two
3511dnl  program runs in the code below end up successfully detecting the
3512dnl  problem.
3513dnl
3514dnl  glibc 2.0.x returns either -1 or bufsize-1 for an overflow (both seen,
3515dnl  not sure which 2.0.x does which), but still puts the correct null
3516dnl  terminated result into the buffer.
3517
3518AC_DEFUN([GMP_FUNC_VSNPRINTF],
3519[AC_REQUIRE([GMP_C_STDARG])
3520AC_CHECK_FUNC(vsnprintf,
3521              [gmp_vsnprintf_exists=yes],
3522              [gmp_vsnprintf_exists=no])
3523if test "$gmp_vsnprintf_exists" = no; then
3524  gmp_cv_func_vsnprintf=no
3525else
3526  AC_CACHE_CHECK([whether vsnprintf works],
3527                 gmp_cv_func_vsnprintf,
3528  [gmp_cv_func_vsnprintf=yes
3529   for i in 'check ("hello world");' 'int n; check ("%nhello world", &n);'; do
3530     AC_TRY_RUN([
3531#include <string.h>  /* for strcmp */
3532#include <stdio.h>   /* for vsnprintf */
3533
3534#if HAVE_STDARG
3535#include <stdarg.h>
3536#else
3537#include <varargs.h>
3538#endif
3539
3540int
3541#if HAVE_STDARG
3542check (const char *fmt, ...)
3543#else
3544check (va_alist)
3545     va_dcl
3546#endif
3547{
3548  static char  buf[128];
3549  va_list  ap;
3550  int      ret;
3551
3552#if HAVE_STDARG
3553  va_start (ap, fmt);
3554#else
3555  char *fmt;
3556  va_start (ap);
3557  fmt = va_arg (ap, char *);
3558#endif
3559
3560  ret = vsnprintf (buf, 4, fmt, ap);
3561
3562  if (strcmp (buf, "hel") != 0)
3563    exit (1);
3564
3565  /* allowed return values */
3566  if (ret != -1 && ret != 3 && ret != 11)
3567    exit (2);
3568
3569  return 0;
3570}
3571
3572int
3573main ()
3574{
3575$i
3576  exit (0);
3577}
3578],
3579      [:],
3580      [gmp_cv_func_vsnprintf=no; break],
3581      [gmp_cv_func_vsnprintf=probably; break])
3582  done
3583  ])
3584  if test "$gmp_cv_func_vsnprintf" = probably; then
3585    AC_MSG_WARN([cannot check for properly working vsnprintf when cross compiling, will assume it's ok])
3586  fi
3587  if test "$gmp_cv_func_vsnprintf" != no; then
3588    AC_DEFINE(HAVE_VSNPRINTF,1,
3589    [Define to 1 if you have the `vsnprintf' function and it works properly.])
3590  fi
3591fi
3592])
3593
3594
3595dnl  GMP_H_ANSI
3596dnl  ----------
3597dnl  Check whether gmp.h recognises the compiler as ANSI capable.
3598
3599AC_DEFUN([GMP_H_ANSI],
3600[AC_REQUIRE([AC_PROG_CC_STDC])
3601case $ac_cv_prog_cc_stdc in
3602  no)
3603    ;;
3604  *)
3605    AC_TRY_COMPILE(
3606GMP_INCLUDE_GMP_H
3607[#if ! __GMP_HAVE_PROTOTYPES
3608die die die
3609#endif
3610],,,
3611    [AC_MSG_WARN([gmp.h doesnt recognise compiler as ANSI, prototypes and "const" will be unavailable])])
3612    ;;
3613esac
3614])
3615
3616
3617dnl  GMP_H_EXTERN_INLINE
3618dnl  -------------------
3619dnl  If the compiler has an "inline" of some sort, check whether the
3620dnl  #ifdef's in gmp.h recognise it.
3621
3622AC_DEFUN([GMP_H_EXTERN_INLINE],
3623[AC_REQUIRE([AC_C_INLINE])
3624case $ac_cv_c_inline in
3625no) ;;
3626*)
3627  AC_TRY_COMPILE(
3628[#define __GMP_WITHIN_CONFIGURE_INLINE 1
3629]GMP_INCLUDE_GMP_H[
3630#ifndef __GMP_EXTERN_INLINE
3631die die die
3632#endif
3633],,,
3634  [case $ac_cv_c_inline in
3635  yes) tmp_inline=inline ;;
3636  *)   tmp_inline=$ac_cv_c_inline ;;
3637  esac
3638  AC_MSG_WARN([gmp.h doesnt recognise compiler "$tmp_inline", inlines will be unavailable])])
3639  ;;
3640esac
3641])
3642
3643
3644dnl  GMP_H_HAVE_FILE
3645dnl  ---------------
3646dnl  Check whether the #ifdef's in gmp.h recognise when stdio.h has been
3647dnl  included to get FILE.
3648
3649AC_DEFUN([GMP_H_HAVE_FILE],
3650[AC_TRY_COMPILE(
3651[#include <stdio.h>]
3652GMP_INCLUDE_GMP_H
3653[#if ! _GMP_H_HAVE_FILE
3654die die die
3655#endif
3656],,,
3657  [AC_MSG_WARN([gmp.h doesnt recognise <stdio.h>, FILE prototypes will be unavailable])])
3658])
3659
3660
3661dnl  GMP_PROG_CC_FOR_BUILD
3662dnl  ---------------------
3663dnl  Establish CC_FOR_BUILD, a C compiler for the build system.
3664dnl
3665dnl  If CC_FOR_BUILD is set then it's expected to work, likewise the old
3666dnl  style HOST_CC, otherwise some likely candidates are tried, the same as
3667dnl  configfsf.guess.
3668
3669AC_DEFUN([GMP_PROG_CC_FOR_BUILD],
3670[AC_REQUIRE([AC_PROG_CC])
3671if test -n "$CC_FOR_BUILD"; then
3672  GMP_PROG_CC_FOR_BUILD_WORKS($CC_FOR_BUILD,,
3673    [AC_MSG_ERROR([Specified CC_FOR_BUILD doesn't seem to work])])
3674elif test -n "$HOST_CC"; then
3675  GMP_PROG_CC_FOR_BUILD_WORKS($HOST_CC,
3676    [CC_FOR_BUILD=$HOST_CC],
3677    [AC_MSG_ERROR([Specified HOST_CC doesn't seem to work])])
3678else
3679  for i in "$CC" "$CC $CFLAGS $CPPFLAGS" cc gcc c89 c99; do
3680    GMP_PROG_CC_FOR_BUILD_WORKS($i,
3681      [CC_FOR_BUILD=$i
3682       break])
3683  done
3684  if test -z "$CC_FOR_BUILD"; then
3685    AC_MSG_ERROR([Cannot find a build system compiler])
3686  fi
3687fi
3688
3689AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
3690AC_SUBST(CC_FOR_BUILD)
3691])
3692
3693
3694dnl  GMP_PROG_CC_FOR_BUILD_WORKS(cc/cflags[,[action-if-good][,action-if-bad]])
3695dnl  -------------------------------------------------------------------------
3696dnl  See if the given cc/cflags works on the build system.
3697dnl
3698dnl  It seems easiest to just use the default compiler output, rather than
3699dnl  figuring out the .exe or whatever at this stage.
3700
3701AC_DEFUN([GMP_PROG_CC_FOR_BUILD_WORKS],
3702[AC_MSG_CHECKING([build system compiler $1])
3703# remove anything that might look like compiler output to our "||" expression
3704rm -f conftest* a.out b.out a.exe a_out.exe
3705cat >conftest.c <<EOF
3706int
3707main ()
3708{
3709  exit(0);
3710}
3711EOF
3712gmp_compile="$1 conftest.c"
3713cc_for_build_works=no
3714if AC_TRY_EVAL(gmp_compile); then
3715  if (./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest) >&AC_FD_CC 2>&1; then
3716    cc_for_build_works=yes
3717  fi
3718fi
3719rm -f conftest* a.out b.out a.exe a_out.exe
3720AC_MSG_RESULT($cc_for_build_works)
3721if test "$cc_for_build_works" = yes; then
3722  ifelse([$2],,:,[$2])
3723else
3724  ifelse([$3],,:,[$3])
3725fi
3726])
3727
3728
3729dnl  GMP_PROG_CPP_FOR_BUILD
3730dnl  ---------------------
3731dnl  Establish CPP_FOR_BUILD, the build system C preprocessor.
3732dnl  The choices tried here are the same as AC_PROG_CPP, but with
3733dnl  CC_FOR_BUILD.
3734
3735AC_DEFUN([GMP_PROG_CPP_FOR_BUILD],
3736[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3737AC_MSG_CHECKING([for build system preprocessor])
3738if test -z "$CPP_FOR_BUILD"; then
3739  AC_CACHE_VAL(gmp_cv_prog_cpp_for_build,
3740  [cat >conftest.c <<EOF
3741#define FOO BAR
3742EOF
3743  for i in "$CC_FOR_BUILD -E" "$CC_FOR_BUILD -E -traditional-cpp" "/lib/cpp"; do
3744    gmp_compile="$i conftest.c"
3745    if AC_TRY_EVAL(gmp_compile) >&AC_FD_CC 2>&1; then
3746      gmp_cv_prog_cpp_for_build=$i
3747      break
3748    fi
3749  done
3750  rm -f conftest* a.out b.out a.exe a_out.exe
3751  if test -z "$gmp_cv_prog_cpp_for_build"; then
3752    AC_MSG_ERROR([Cannot find build system C preprocessor.])
3753  fi
3754  ])
3755  CPP_FOR_BUILD=$gmp_cv_prog_cpp_for_build
3756fi
3757AC_MSG_RESULT([$CPP_FOR_BUILD])
3758
3759AC_ARG_VAR(CPP_FOR_BUILD,[build system C preprocessor])
3760AC_SUBST(CPP_FOR_BUILD)
3761])
3762
3763
3764dnl  GMP_PROG_EXEEXT_FOR_BUILD
3765dnl  -------------------------
3766dnl  Determine EXEEXT_FOR_BUILD, the build system executable suffix.
3767dnl
3768dnl  The idea is to find what "-o conftest$foo" will make it possible to run
3769dnl  the program with ./conftest.  On Unix-like systems this is of course
3770dnl  nothing, for DOS it's ".exe", or for a strange RISC OS foreign file
3771dnl  system cross compile it can be ",ff8" apparently.  Not sure if the
3772dnl  latter actually applies to a build-system executable, maybe it doesn't,
3773dnl  but it won't hurt to try.
3774
3775AC_DEFUN([GMP_PROG_EXEEXT_FOR_BUILD],
3776[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3777AC_CACHE_CHECK([for build system executable suffix],
3778               gmp_cv_prog_exeext_for_build,
3779[cat >conftest.c <<EOF
3780int
3781main ()
3782{
3783  exit (0);
3784}
3785EOF
3786for i in .exe ,ff8 ""; do
3787  gmp_compile="$CC_FOR_BUILD conftest.c -o conftest$i"
3788  if AC_TRY_EVAL(gmp_compile); then
3789    if (./conftest) 2>&AC_FD_CC; then
3790      gmp_cv_prog_exeext_for_build=$i
3791      break
3792    fi
3793  fi
3794done
3795rm -f conftest*
3796if test "${gmp_cv_prog_exeext_for_build+set}" != set; then
3797  AC_MSG_ERROR([Cannot determine executable suffix])
3798fi
3799])
3800AC_SUBST(EXEEXT_FOR_BUILD,$gmp_cv_prog_exeext_for_build)
3801])
3802
3803
3804dnl  GMP_C_FOR_BUILD_ANSI
3805dnl  --------------------
3806dnl  Determine whether CC_FOR_BUILD is ANSI, and establish U_FOR_BUILD
3807dnl  accordingly.
3808dnl
3809dnl  FIXME: Use AC_PROG_CC sets ac_cv_prog_cc_c89 which could be used instead
3810
3811AC_DEFUN([GMP_C_FOR_BUILD_ANSI],
3812[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3813AC_CACHE_CHECK([whether build system compiler is ANSI],
3814               gmp_cv_c_for_build_ansi,
3815[cat >conftest.c <<EOF
3816int
3817main (int argc, char **argv)
3818{
3819  exit(0);
3820}
3821EOF
3822gmp_compile="$CC_FOR_BUILD conftest.c"
3823if AC_TRY_EVAL(gmp_compile); then
3824  gmp_cv_c_for_build_ansi=yes
3825else
3826  gmp_cv_c_for_build_ansi=no
3827fi
3828rm -f conftest* a.out b.out a.exe a_out.exe
3829])
3830if test "$gmp_cv_c_for_build_ansi" = yes; then
3831  U_FOR_BUILD=
3832else
3833  AC_SUBST(U_FOR_BUILD,_)
3834fi
3835])
3836
3837
3838dnl  GMP_CHECK_LIBM_FOR_BUILD
3839dnl  ------------------------
3840dnl  Establish LIBM_FOR_BUILD as -lm, if that seems to work.
3841dnl
3842dnl  Libtool AC_CHECK_LIBM also uses -lmw on *-ncr-sysv4.3*, if it works.
3843dnl  Don't know what that does, lets assume it's not needed just for log().
3844
3845AC_DEFUN([GMP_CHECK_LIBM_FOR_BUILD],
3846[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3847AC_CACHE_CHECK([for build system compiler math library],
3848               gmp_cv_check_libm_for_build,
3849[cat >conftest.c <<EOF
3850int
3851main ()
3852{
3853  exit(0);
3854}
3855double d;
3856double
3857foo ()
3858{
3859  return log (d);
3860}
3861EOF
3862gmp_compile="$CC_FOR_BUILD conftest.c -lm"
3863if AC_TRY_EVAL(gmp_compile); then
3864  gmp_cv_check_libm_for_build=-lm
3865else
3866  gmp_cv_check_libm_for_build=no
3867fi
3868rm -f conftest* a.out b.out a.exe a_out.exe
3869])
3870case $gmp_cv_check_libm_for_build in
3871  yes) AC_SUBST(LIBM_FOR_BUILD,-lm) ;;
3872  no)  LIBM_FOR_BUILD= ;;
3873  *)   LIBM_FOR_BUILD=$gmp_cv_check_libm_for_build ;;
3874esac
3875])
3876