summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-06 13:27:05 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-06 13:27:05 +0000
commit19767e6f6f9089ef12f81e9f3b64f5c71ff71c84 (patch)
tree388f8324eb4f2595b607ac0b1afa7352ca4c9c5d
parent6e0b309b6faf9353e1732c77a95099a5aa5d86c0 (diff)
downloadmpfr-19767e6f6f9089ef12f81e9f3b64f5c71ff71c84.tar.gz
+ Better support of non IEEE doubles.
+ You can compile MPFR without gmp internal files (ie gmp-impl.h, gmp-mparam.h, and config.h). You only need gmp.h and libgmp.a. But you can still compile with GMP internal files (configure detects them). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2665 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--Makefile.am2
-rw-r--r--acinclude.m421
-rw-r--r--acos.c4
-rw-r--r--acosh.c4
-rw-r--r--add.c4
-rw-r--r--add1.c4
-rw-r--r--add_one_ulp.c14
-rw-r--r--add_ui.c6
-rw-r--r--agm.c4
-rw-r--r--asin.c4
-rw-r--r--asinh.c4
-rw-r--r--atan.c4
-rw-r--r--atanh.c4
-rw-r--r--cbrt.c4
-rw-r--r--clear.c7
-rw-r--r--clears.c6
-rw-r--r--cmp.c4
-rw-r--r--cmp2.c6
-rw-r--r--cmp_abs.c4
-rw-r--r--cmp_d.c4
-rw-r--r--cmp_si.c6
-rw-r--r--cmp_ui.c6
-rw-r--r--comparisons.c4
-rw-r--r--configure.in74
-rw-r--r--const_euler.c6
-rw-r--r--const_log2.c6
-rw-r--r--const_pi.c6
-rw-r--r--copysign.c4
-rw-r--r--cos.c4
-rw-r--r--cosh.c4
-rw-r--r--dim.c4
-rw-r--r--div.c6
-rw-r--r--div_2exp.c4
-rw-r--r--div_2si.c4
-rw-r--r--div_2ui.c4
-rw-r--r--div_ui.c9
-rw-r--r--dump.c4
-rw-r--r--eq.c4
-rw-r--r--erf.c4
-rw-r--r--exceptions.c4
-rw-r--r--exp.c4
-rw-r--r--exp10.c4
-rw-r--r--exp2.c4
-rw-r--r--exp3.c4
-rw-r--r--exp_2.c6
-rw-r--r--expm1.c4
-rw-r--r--extract.c4
-rw-r--r--factorial.c4
-rw-r--r--fits_s.h5
-rw-r--r--fits_u.h6
-rw-r--r--fma.c4
-rw-r--r--frac.c6
-rw-r--r--gamma.c4
-rw-r--r--get_d.c6
-rw-r--r--get_exp.c4
-rw-r--r--get_ld.c4
-rw-r--r--get_si.c11
-rw-r--r--get_str.c16
-rw-r--r--get_ui.c8
-rw-r--r--get_z_exp.c6
-rw-r--r--hypot.c4
-rw-r--r--init.c4
-rw-r--r--init2.c4
-rw-r--r--inits.c6
-rw-r--r--inits2.c8
-rw-r--r--inp_str.c4
-rw-r--r--isinf.c4
-rw-r--r--isinteger.c4
-rw-r--r--isnan.c4
-rw-r--r--isnum.c4
-rw-r--r--log.c4
-rw-r--r--log10.c4
-rw-r--r--log1p.c4
-rw-r--r--log2.c4
-rw-r--r--longlong.h1685
-rw-r--r--minmax.c4
-rw-r--r--mp_clz_tab.c39
-rw-r--r--mpfr-gmp.c377
-rw-r--r--mpfr-gmp.h267
-rw-r--r--mpfr-impl.h76
-rw-r--r--mpfr-test.h5
-rw-r--r--mpn_exp.c6
-rw-r--r--mul.c4
-rw-r--r--mul_2exp.c4
-rw-r--r--mul_2si.c4
-rw-r--r--mul_2ui.c4
-rw-r--r--mul_ui.c6
-rw-r--r--neg.c3
-rw-r--r--next.c4
-rw-r--r--out_str.c4
-rw-r--r--pow.c6
-rw-r--r--pow_si.c4
-rw-r--r--pow_ui.c4
-rw-r--r--powerof2.c4
-rw-r--r--print_rnd_mode.c7
-rw-r--r--random.c6
-rw-r--r--random2.c12
-rw-r--r--reldiff.c4
-rw-r--r--rint.c4
-rw-r--r--round_prec.c4
-rw-r--r--save_expo.c3
-rw-r--r--set.c4
-rw-r--r--set_d.c15
-rw-r--r--set_dfl_prec.c4
-rw-r--r--set_exp.c4
-rw-r--r--set_f.c6
-rw-r--r--set_inf.c4
-rw-r--r--set_nan.c4
-rw-r--r--set_prc_raw.c3
-rw-r--r--set_prec.c3
-rw-r--r--set_q.c6
-rw-r--r--set_rnd.c4
-rw-r--r--set_si.c6
-rw-r--r--set_str.c6
-rw-r--r--set_str_raw.c6
-rw-r--r--set_ui.c6
-rw-r--r--set_z.c6
-rw-r--r--setmax.c4
-rw-r--r--setmin.c4
-rw-r--r--sgn.c4
-rw-r--r--sin.c4
-rw-r--r--sin_cos.c4
-rw-r--r--sinh.c4
-rw-r--r--sqrt.c7
-rw-r--r--sqrt_ui.c6
-rw-r--r--sub.c4
-rw-r--r--sub1.c4
-rw-r--r--sub1sp.c17
-rw-r--r--sub_one_ulp.c10
-rw-r--r--sub_ui.c6
-rw-r--r--swap.c3
-rw-r--r--tan.c4
-rw-r--r--tanh.c4
-rw-r--r--tests/memory.c3
-rw-r--r--tests/tacos.c4
-rw-r--r--tests/tadd.c4
-rw-r--r--tests/tasin.c4
-rw-r--r--tests/tatan.c4
-rw-r--r--tests/tcan_round.c4
-rw-r--r--tests/tconst_log2.c2
-rw-r--r--tests/tdiv.c2
-rw-r--r--tests/tests.c2
-rw-r--r--tests/texceptions.c6
-rw-r--r--tests/texp.c2
-rw-r--r--tests/tfma.c2
-rw-r--r--tests/tfrac.c2
-rw-r--r--tests/tgeneric.c2
-rw-r--r--tests/tget_d_2exp.c2
-rw-r--r--tests/tget_str.c2
-rw-r--r--tests/tgmpop.c4
-rw-r--r--tests/thypot.c2
-rw-r--r--tests/tmul.c2
-rw-r--r--tests/tout_str.c2
-rw-r--r--tests/tpow3.c2
-rw-r--r--tests/trint.c6
-rw-r--r--tests/tset_f.c4
-rw-r--r--tests/tset_q.c6
-rw-r--r--tests/tset_si.c4
-rw-r--r--tests/tset_str.c3
-rw-r--r--tests/tset_z.c6
-rw-r--r--tests/tsqrt.c2
-rw-r--r--tests/tsub.c11
-rw-r--r--tests/tsub1sp.c4
-rw-r--r--tests/tui_pow.c2
-rw-r--r--uceil_log2.c4
-rw-r--r--ui_div.c6
-rw-r--r--ui_pow.c4
-rw-r--r--ui_pow_ui.c4
-rw-r--r--ui_sub.c6
-rw-r--r--urandomb.c6
-rw-r--r--version.c4
-rw-r--r--volatile.c4
172 files changed, 2757 insertions, 571 deletions
diff --git a/Makefile.am b/Makefile.am
index d02e287e6..fc9445d8a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,7 @@ include_HEADERS = mpfr.h mpf2mpfr.h
lib_LIBRARIES = libmpfr.a
-libmpfr_a_SOURCES = mpfr.h mpf2mpfr.h mpfr-impl.h mpfr-test.h log_b2.h exceptions.c save_expo.c extract.c uceil_exp2.c uceil_log2.c ufloor_log2.c add.c add1.c add_one_ulp.c add_ui.c agm.c clear.c cmp.c cmp_abs.c cmp_si.c cmp_ui.c comparisons.c div_2exp.c div_2si.c div_2ui.c div.c div_ui.c dump.c eq.c exp10.c exp2.c exp3.c exp.c frac.c get_d.c get_exp.c get_str.c init.c inp_str.c isinteger.c isinf.c isnan.c isnum.c const_log2.c log.c mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.c out_str.c const_pi.c pow.c pow_si.c pow_ui.c print_raw.c print_rnd_mode.c random2.c random.c reldiff.c round_prec.c set.c setmax.c setmin.c set_d.c set_dfl_prec.c set_exp.c set_rnd.c set_f.c set_prc_raw.c set_prec.c set_q.c set_si.c set_str.c set_str_raw.c set_ui.c set_z.c sqrt.c sqrt_ui.c sub.c sub1.c sub_one_ulp.c sub_ui.c rint.c ui_div.c ui_sub.c urandomb.c get_z_exp.c swap.c factorial.c cosh.c sinh.c tanh.c acosh.c asinh.c atanh.c atan.c cmp2.c exp_2.c asin.c const_euler.c cos.c sin.c tan.c fma.c hypot.c log1p.c expm1.c log2.c log10.c ui_pow.c ui_pow_ui.c minmax.c dim.c copysign.c gmp_op.c init2.c acos.c sin_cos.c set_nan.c set_inf.c powerof2.c gamma.c set_ld.c get_ld.c cbrt.c volatile.c fits_s.h fits_sshort.c fits_sint.c fits_slong.c fits_u.h fits_ushort.c fits_uint.c fits_ulong.c get_si.c get_ui.c zeta.c cmp_d.c erf.c inits.c inits2.c clears.c sgn.c check.c sub1sp.c version.c mpn_exp.c
+libmpfr_a_SOURCES = mpfr.h mpf2mpfr.h mpfr-impl.h mpfr-test.h log_b2.h exceptions.c save_expo.c extract.c uceil_exp2.c uceil_log2.c ufloor_log2.c add.c add1.c add_one_ulp.c add_ui.c agm.c clear.c cmp.c cmp_abs.c cmp_si.c cmp_ui.c comparisons.c div_2exp.c div_2si.c div_2ui.c div.c div_ui.c dump.c eq.c exp10.c exp2.c exp3.c exp.c frac.c get_d.c get_exp.c get_str.c init.c inp_str.c isinteger.c isinf.c isnan.c isnum.c const_log2.c log.c mul_2exp.c mul_2si.c mul_2ui.c mul.c mul_ui.c neg.c next.c out_str.c const_pi.c pow.c pow_si.c pow_ui.c print_raw.c print_rnd_mode.c random2.c random.c reldiff.c round_prec.c set.c setmax.c setmin.c set_d.c set_dfl_prec.c set_exp.c set_rnd.c set_f.c set_prc_raw.c set_prec.c set_q.c set_si.c set_str.c set_str_raw.c set_ui.c set_z.c sqrt.c sqrt_ui.c sub.c sub1.c sub_one_ulp.c sub_ui.c rint.c ui_div.c ui_sub.c urandomb.c get_z_exp.c swap.c factorial.c cosh.c sinh.c tanh.c acosh.c asinh.c atanh.c atan.c cmp2.c exp_2.c asin.c const_euler.c cos.c sin.c tan.c fma.c hypot.c log1p.c expm1.c log2.c log10.c ui_pow.c ui_pow_ui.c minmax.c dim.c copysign.c gmp_op.c init2.c acos.c sin_cos.c set_nan.c set_inf.c powerof2.c gamma.c set_ld.c get_ld.c cbrt.c volatile.c fits_s.h fits_sshort.c fits_sint.c fits_slong.c fits_u.h fits_ushort.c fits_uint.c fits_ulong.c get_si.c get_ui.c zeta.c cmp_d.c erf.c inits.c inits2.c clears.c sgn.c check.c sub1sp.c version.c mpn_exp.c mpfr-gmp.c mp_clz_tab.c
libmpfr_a_LIBADD = @LIBOBJS@
diff --git a/acinclude.m4 b/acinclude.m4
index 55f9046c6..93909ed83 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -45,11 +45,12 @@ fi
]
)
+dnl FIXME: Buggy?
AC_DEFUN([AC_MY_HEADERS],
[
if test "$1"
then
- AC_CHECK_HEADER($1/$2, INCLUDES="$INCLUDES -I$1",AC_MSG_ERROR(echo $2 not found in $1))
+ AC_CHECK_HEADER($1/$2, INCLUDES="$INCLUDES -I$1",AC_MSG_ERROR($2 not found in $1))
else
AC_CHECK_HEADER($2,, AC_MSG_ERROR($2 not found))
fi
@@ -92,6 +93,21 @@ case $host in
;;
esac
+dnl Check for sizeof size_t
+dnl AC_CHECK_SIZEOF
+dnl AC_TYPE_SIZE_T
+
+dnl
+AC_CHECK_FUNCS([memset])
+AC_CHECK_FUNCS([strtol])
+AC_CHECK_HEADER([limits.h],, AC_MSG_ERROR([limits.h not found]))
+AC_CHECK_HEADER([float.h],, AC_MSG_ERROR([float.h not found]))
+
+dnl Check for stdargs
+AC_CHECK_HEADER([stdarg.h],[AC_DEFINE([HAVE_STDARG])],
+ [AC_CHECK_HEADER([varargs.h],,
+ AC_MSG_ERROR([stdarg.h or varargs.h not found]))])
+
AC_CHECK_HEADERS(sys/time.h)
# Reasons for testing:
@@ -121,7 +137,6 @@ alpha*-*-*)
esac
# Reasons for testing:
-#
# sys/fpu.h - MIPS specific
#
AC_CHECK_HEADERS(sys/fpu.h)
@@ -260,7 +275,7 @@ AC_DEFUN([MPFR_C_LONG_DOUBLE_FORMAT],
AC_REQUIRE([AC_PROG_AWK])
AC_REQUIRE([AC_OBJEXT])
AC_CHECK_TYPES([long double])
-AC_CACHE_CHECK([format of \`long double' floating point],
+AC_CACHE_CHECK([format of `long double' floating point],
mpfr_cv_c_long_double_format,
[mpfr_cv_c_long_double_format=unknown
if test "$ac_cv_type_long_double" != yes; then
diff --git a/acos.c b/acos.c
index d38c43af2..831d18b6e 100644
--- a/acos.c
+++ b/acos.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/acosh.c b/acosh.c
index 1d1e40fb7..b2d6f107f 100644
--- a/acosh.c
+++ b/acosh.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of acosh is done by
diff --git a/add.c b/add.c
index 01cc1a0df..5c5717d15 100644
--- a/add.c
+++ b/add.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/add1.c b/add1.c
index c523b9f16..9eac7a4b4 100644
--- a/add1.c
+++ b/add1.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* compute sign(b) * (|b| + |c|) */
diff --git a/add_one_ulp.c b/add_one_ulp.c
index b56248467..d12e0f382 100644
--- a/add_one_ulp.c
+++ b/add_one_ulp.c
@@ -1,6 +1,6 @@
/* mpfr_add_one_ulp -- add one unit in last place
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* sets x to x+sign(x)*ulp(x) */
@@ -42,10 +40,10 @@ mpfr_add_one_ulp (mpfr_ptr x, mp_rnd_t rnd_mode)
MPFR_ASSERTN(0);
}
- xn = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
- sh = (mp_prec_t) xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
+ xn = MPFR_LIMB_SIZE(x);
+ MPFR_UNSIGNED_MINUS_MODULO(sh, MPFR_PREC(x) );
xp = MPFR_MANT(x);
- if (mpn_add_1 (xp, xp, xn, MP_LIMB_T_ONE << sh)) /* got 1.0000... */
+ if (mpn_add_1 (xp, xp, xn, MPFR_LIMB_ONE << sh)) /* got 1.0000... */
{
mp_exp_t exp = MPFR_EXP (x);
if (MPFR_UNLIKELY(exp == __gmpfr_emax))
@@ -57,5 +55,5 @@ mpfr_add_one_ulp (mpfr_ptr x, mp_rnd_t rnd_mode)
xp[xn-1] = MPFR_LIMB_HIGHBIT;
}
}
- return 0;
+ MPFR_RET(0);
}
diff --git a/add_ui.c b/add_ui.c
index a4b737f97..989eb7255 100644
--- a/add_ui.c
+++ b/add_ui.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/agm.c b/agm.c
index f3a747063..fc555aec6 100644
--- a/agm.c
+++ b/agm.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/asin.c b/asin.c
index 8fe72cd33..5d6d59bb3 100644
--- a/asin.c
+++ b/asin.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/asinh.c b/asinh.c
index ad0ae5040..7d6e9bc65 100644
--- a/asinh.c
+++ b/asinh.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of asinh is done by
diff --git a/atan.c b/atan.c
index fb10c57af..d8bf14006 100644
--- a/atan.c
+++ b/atan.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
#define CST 2.27 /* CST=1+ln(2.4)/ln(2) */
diff --git a/atanh.c b/atanh.c
index 26620a66d..aa0e84c16 100644
--- a/atanh.c
+++ b/atanh.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of acosh is done by
diff --git a/cbrt.c b/cbrt.c
index 3b7ce5a30..10f94e951 100644
--- a/cbrt.c
+++ b/cbrt.c
@@ -22,9 +22,7 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of y = x^(1/3) is done as follows:
diff --git a/clear.c b/clear.c
index df4b6ea6a..45882da17 100644
--- a/clear.c
+++ b/clear.c
@@ -20,9 +20,7 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
void
@@ -30,6 +28,7 @@ mpfr_clear (mpfr_ptr m)
{
/* be careful to always free an entire number of limbs */
(*__gmp_free_func)
- (MPFR_GET_REAL_PTR(m), MPFR_MALLOC_SIZE(MPFR_GET_ALLOC_SIZE(m)));
+ (MPFR_GET_REAL_PTR(m),
+ MPFR_MALLOC_SIZE(MPFR_GET_ALLOC_SIZE(m)));
MPFR_MANT(m) = NULL;
}
diff --git a/clears.c b/clears.c
index bf4afa33e..10b21cc43 100644
--- a/clears.c
+++ b/clears.c
@@ -20,9 +20,9 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-/* Needed for build with GMP */
-#ifndef HAVE_STDARG
-# include "config.h"
+#if HAVE_CONFIG_H
+#undef HAVE_STDARG
+#include "config.h" /* for a build within gmp */
#endif
#if HAVE_STDARG
diff --git a/cmp.c b/cmp.c
index 00308f8e5..21d9d58af 100644
--- a/cmp.c
+++ b/cmp.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* returns 0 iff b = sign(s) * c
diff --git a/cmp2.c b/cmp2.c
index 055b5a903..cc5b4205a 100644
--- a/cmp2.c
+++ b/cmp2.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* If |b| != |c|, puts the number of canceled bits when one subtracts |c|
diff --git a/cmp_abs.c b/cmp_abs.c
index 1990ff656..68d736175 100644
--- a/cmp_abs.c
+++ b/cmp_abs.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* Return a positive value if abs(b) > abs(c), 0 if abs(b) = abs(c), and
diff --git a/cmp_d.c b/cmp_d.c
index 9a0eb67c7..b52fa430f 100644
--- a/cmp_d.c
+++ b/cmp_d.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/cmp_si.c b/cmp_si.c
index 88c258db5..39fb9ea3b 100644
--- a/cmp_si.c
+++ b/cmp_si.c
@@ -20,10 +20,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* returns a positive value if b > i*2^f,
diff --git a/cmp_ui.c b/cmp_ui.c
index 5ca59dfa0..eb544bebe 100644
--- a/cmp_ui.c
+++ b/cmp_ui.c
@@ -20,10 +20,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* returns a positive value if b > i*2^f,
diff --git a/comparisons.c b/comparisons.c
index 6d6e62ef1..0af66d2c9 100644
--- a/comparisons.c
+++ b/comparisons.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* Note: these functions currently use mpfr_cmp; they could have their
diff --git a/configure.in b/configure.in
index 1f4316b38..3901664d9 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
-AC_INIT()
+AC_INIT
mpfr_version=`cat $srcdir/VERSION`
AM_INIT_AUTOMAKE(mpfr, $mpfr_version, [no-define])
@@ -10,6 +10,22 @@ AC_ARG_WITH(gmp, [ --with-gmp=DIR GMP directory ], with_gmp_include=$wi
AC_ARG_WITH(irix64, [ --with-irix64=on/off Irix 32/64 bits support ], with_irix64=$withval, with_irix64=off)
+AC_ARG_ENABLE(assert,
+AS_HELP_STRING(--enable-assert,enable ASSERT checking [[default=no]]),
+[case $enableval in
+yes|no|full) ;;
+*) AC_MSG_ERROR([bad value $enableval for --enable-assert, need yes, no or full]) ;;
+esac],
+[enable_assert=no])
+if test "$enable_assert" = "yes"; then
+ AC_DEFINE([WANT_ASSERT],1)
+fi
+if test "$enable_assert" = "full"; then
+ AC_DEFINE([WANT_ASSERT],1)
+ AC_DEFINE([CHECK_AGAINST_SUB1],1)
+fi
+
+
test_CFLAGS=${CFLAGS+set}
dnl Same as in gmp acinclude.m4, though currently we're using the normal
@@ -47,25 +63,33 @@ case $OS_TYPE in
esac
dnl Tests concerning the include directories.
-AC_MSG_CHECKING(for gmp files)
if test -d "$with_gmp_include"; then
CPPFLAGS="$CPPFLAGS -I$with_gmp_include"
else
with_gmp_include=
fi
-AC_TRY_COMPILE([
+
+AC_C_CONST
+AC_C_VOLATILE
+MPFR_CONFIGS
+
+AC_MSG_CHECKING(for gmp.h)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include "gmp.h"
+]], [[]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
+ AC_MSG_ERROR([gmp.h may be missing ${with_gmp_include:+in $with_gmp_include}])
+])
+
+AC_MSG_CHECKING(for gmp internal files)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
-], , AC_MSG_RESULT(yes),
- [AC_MSG_RESULT(no)
- AC_MSG_ERROR([gmp.h or gmp-impl.h or config.h or gmp-mparam.h or
-longlong.h may be missing ${with_gmp_include:+in $with_gmp_include}])]
-)
-
-dnl Check for valid BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB
-AC_MSG_CHECKING(for valid BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB)
-AC_TRY_RUN([
+]], [[]])],[AC_MSG_RESULT(yes)
+ AC_DEFINE([MPFR_HAVE_GMP_IMPL],1)
+ dnl Check for valid BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB
+ AC_MSG_CHECKING(for valid BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB)
+ AC_TRY_RUN([
#include <limits.h>
#include "gmp.h"
#include "gmp-impl.h"
@@ -74,16 +98,27 @@ int main()
return BITS_PER_MP_LIMB == BYTES_PER_MP_LIMB * CHAR_BIT
&& sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ? 0 : 1;
}
-], AC_MSG_RESULT(yes),
- [AC_MSG_RESULT(no)
- AC_MSG_ERROR([BITS_PER_MP_LIMB and/or BYTES_PER_MP_LIMB are incorrect.
+ ], AC_MSG_RESULT(yes),
+ [AC_MSG_RESULT(no)
+ AC_MSG_ERROR([BITS_PER_MP_LIMB or BYTES_PER_MP_LIMB are incorrect.
You probably need to change some of the GMP or MPFR compile options:
MPFR doesn't currently do as many architecture checks as GMP, so the
default target architecture may be different, hence the error.])],
- AC_MSG_RESULT([can't test])
-)
+ AC_MSG_RESULT([can't test])
+ )
+ ],[AC_MSG_RESULT(no) AC_FUNC_ALLOCA
+])
+
+AC_MSG_CHECKING(for valid GMP)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include "gmp.h"
+#if (__GNU_MP_VERSION < 4)
+# error "min: GMP 4.0.0"
+#endif
+]], [[]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
+ AC_MSG_ERROR([GMP 4.0.0 min required])
+])
-MPFR_CONFIGS
# Recent autoconf creates AC_DEFINEs of PACKAGE_VERSION etc, unfortunately
# those -D defines in $DEFS conflict with the same defines in config.h from
@@ -101,6 +136,7 @@ AC_SUBST(INCLUDES)
AC_SUBST(LDADD)
AC_SUBST(LDFLAGS)
AC_SUBST(CFLAGS)
-AC_OUTPUT(Makefile tests/Makefile)
+AC_CONFIG_FILES([Makefile tests/Makefile])
+AC_OUTPUT
dnl NEWS README AUTHORS Changelog
diff --git a/const_euler.c b/const_euler.c
index c62ec78ec..aa0aba38a 100644
--- a/const_euler.c
+++ b/const_euler.c
@@ -20,10 +20,8 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdlib.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
static void mpfr_const_euler_S _MPFR_PROTO ((mpfr_ptr, unsigned long));
diff --git a/const_log2.c b/const_log2.c
index df00e9c98..7a9c8fbdf 100644
--- a/const_log2.c
+++ b/const_log2.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
mpfr_t __mpfr_const_log2; /* stored value of log(2) */
diff --git a/const_pi.c b/const_pi.c
index e77f088dd..d62162adf 100644
--- a/const_pi.c
+++ b/const_pi.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
static int mpfr_aux_pi _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, long, int));
diff --git a/copysign.c b/copysign.c
index 5599d9ec5..e6cda23a6 100644
--- a/copysign.c
+++ b/copysign.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of z with magnitude of x and sign of y
diff --git a/cos.c b/cos.c
index 328061615..4ba000d10 100644
--- a/cos.c
+++ b/cos.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
static int mpfr_cos2_aux _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr));
diff --git a/cosh.c b/cosh.c
index d6ff83bc3..b20a7061e 100644
--- a/cosh.c
+++ b/cosh.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of cosh is done by
diff --git a/dim.c b/dim.c
index 7a636c9f0..e1d1ad118 100644
--- a/dim.c
+++ b/dim.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of z=dim(x,y)
diff --git a/div.c b/div.c
index 2aeaba225..40749eb69 100644
--- a/div.c
+++ b/div.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/div_2exp.c b/div_2exp.c
index 41a730a09..f15c34f30 100644
--- a/div_2exp.c
+++ b/div_2exp.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* Obsolete function, use mpfr_div_2ui or mpfr_div_2si instead. */
diff --git a/div_2si.c b/div_2si.c
index 30c13cd13..655f4257b 100644
--- a/div_2si.c
+++ b/div_2si.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/div_2ui.c b/div_2ui.c
index 190cfdf44..49675303a 100644
--- a/div_2ui.c
+++ b/div_2ui.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/div_ui.c b/div_ui.c
index 2c755311c..0b2ec597d 100644
--- a/div_ui.c
+++ b/div_ui.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* returns 0 if result exact, non-zero otherwise */
@@ -186,7 +184,8 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
else
MPFR_RET(-MPFR_INT_SIGN(x));
}
+ default:
+ MPFR_ASSERTN(0);
}
- MPFR_ASSERTN(0); /* should never go here */
return 0; /* To avoid warning*/
}
diff --git a/dump.c b/dump.c
index cf34f9eed..ca0859a76 100644
--- a/dump.c
+++ b/dump.c
@@ -22,9 +22,7 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <string.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
void
diff --git a/eq.c b/eq.c
index 54d18e87a..0ca311cf8 100644
--- a/eq.c
+++ b/eq.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* return non-zero if the first n_bits bits of u, v are equal,
diff --git a/erf.c b/erf.c
index 3e51601da..5dd33f5f4 100644
--- a/erf.c
+++ b/erf.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* #define DEBUG */
diff --git a/exceptions.c b/exceptions.c
index 93b37d33a..35d7cbe8e 100644
--- a/exceptions.c
+++ b/exceptions.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
unsigned int __gmpfr_flags = 0;
diff --git a/exp.c b/exp.c
index 3c5eb9928..687d63415 100644
--- a/exp.c
+++ b/exp.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* #define DEBUG */
diff --git a/exp10.c b/exp10.c
index e91d84ec3..920401394 100644
--- a/exp10.c
+++ b/exp10.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/exp2.c b/exp2.c
index dea132a01..cf807a8ba 100644
--- a/exp2.c
+++ b/exp2.c
@@ -20,9 +20,7 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <limits.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of y = 2^z is done by
diff --git a/exp3.c b/exp3.c
index 6faa7c732..1ea66f927 100644
--- a/exp3.c
+++ b/exp3.c
@@ -21,9 +21,7 @@ MA 02111-1307, USA. */
#include <stddef.h>
#include <limits.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
static int
diff --git a/exp_2.c b/exp_2.c
index 7b42e74dc..b72f7250e 100644
--- a/exp_2.c
+++ b/exp_2.c
@@ -20,10 +20,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h" /* for count_leading_zeros */
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H /* for count_leading_zeros */
#include "mpfr-impl.h"
static int mpfr_exp2_aux _MPFR_PROTO ((mpz_t, mpfr_srcptr, int, int*));
diff --git a/expm1.c b/expm1.c
index 68da0a9e1..f8ce88fa7 100644
--- a/expm1.c
+++ b/expm1.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of expm1 is done by
diff --git a/extract.c b/extract.c
index 292f4b9d6..827831999 100644
--- a/extract.c
+++ b/extract.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* given 0 <= |p| < 1, this function extracts limbs of p and puts them in y.
diff --git a/factorial.c b/factorial.c
index 1c2b71a37..9a9ee67ca 100644
--- a/factorial.c
+++ b/factorial.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of n! is done by
diff --git a/fits_s.h b/fits_s.h
index c126d00fd..64e7fc0b2 100644
--- a/fits_s.h
+++ b/fits_s.h
@@ -1,6 +1,6 @@
/* mpfr_fits_*_p -- test whether an mpfr fits a C signed type.
-Copyright 2003 Free Software Foundation.
+Copyright 2003, 2004 Free Software Foundation.
Contributed by the Spaces project, INRIA Lorraine.
Copied from mpf/fits_s.h.
@@ -21,9 +21,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
#include "mpfr-impl.h"
int
diff --git a/fits_u.h b/fits_u.h
index 5d5225976..4d282adca 100644
--- a/fits_u.h
+++ b/fits_u.h
@@ -1,6 +1,6 @@
/* mpfr_fits_*_p -- test whether an mpfr fits a C unsigned type.
-Copyright 2003 Free Software Foundation.
+Copyright 2003, 2004 Free Software Foundation.
Contributed by the Spaces project, INRIA Lorraine.
This file is part of the MPFR Library.
@@ -20,10 +20,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include <limits.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
#include "mpfr-impl.h"
int
diff --git a/fma.c b/fma.c
index a37b9cce4..ecd747ea2 100644
--- a/fma.c
+++ b/fma.c
@@ -22,9 +22,7 @@ the file COPYING.LIB. If not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
diff --git a/frac.c b/frac.c
index 79acaaaf0..8f8cb6655 100644
--- a/frac.c
+++ b/frac.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* Optimization note: it is not a good idea to call mpfr_integer_p,
diff --git a/gamma.c b/gamma.c
index 93d69831f..0c7907c35 100644
--- a/gamma.c
+++ b/gamma.c
@@ -24,9 +24,7 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#endif
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* We use the reflection formula
diff --git a/get_d.c b/get_d.c
index ff01151f2..1c04d981d 100644
--- a/get_d.c
+++ b/get_d.c
@@ -22,10 +22,8 @@ MA 02111-1307, USA. */
#include <float.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* "double" NaN and infinities are written as explicit bytes to be sure of
diff --git a/get_exp.c b/get_exp.c
index 3640e4248..705e3e513 100644
--- a/get_exp.c
+++ b/get_exp.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
mp_exp_t
diff --git a/get_ld.c b/get_ld.c
index 0be458d9a..459406e15 100644
--- a/get_ld.c
+++ b/get_ld.c
@@ -22,9 +22,7 @@ MA 02111-1307, USA. */
#include <float.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
long double
diff --git a/get_si.c b/get_si.c
index 68c4aecb8..44c5d092f 100644
--- a/get_si.c
+++ b/get_si.c
@@ -1,6 +1,6 @@
/* mpfr_get_si -- convert a floating-point number to a signed long.
-Copyright 2003 Free Software Foundation, Inc.
+Copyright 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
long
@@ -43,13 +41,10 @@ mpfr_get_si (mpfr_srcptr f, mp_rnd_t rnd)
mpfr_init2 (x, prec);
mpfr_set (x, f, rnd);
- ASSERT(GMP_NAIL_BITS == 0); /* otherwise we may have to consider two or
- more limbs */
-
/* now the result is in the most significant limb of x */
exp = MPFR_GET_EXP (x); /* since |x| >= 1, exp >= 1 */
n = MPFR_LIMB_SIZE(x);
- s = MPFR_MANT(x)[n - 1] >> (GMP_NUMB_BITS - exp);
+ s = MPFR_MANT(x)[n - 1] >> (BITS_PER_MP_LIMB - exp);
mpfr_clear (x);
diff --git a/get_str.c b/get_str.c
index fd9e99ff4..03c82dfad 100644
--- a/get_str.c
+++ b/get_str.c
@@ -25,10 +25,8 @@ MA 02111-1307, USA. */
#include <string.h>
#include <ctype.h>
#include <limits.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
static double mpfr_ceil_double _MPFR_PROTO ((double));
@@ -43,8 +41,7 @@ static char num_to_text[] = "0123456789abcdefghijklmnopqrstuvwxyz";
bits only. These approximations were computed with the following program.
#include <stdio.h>
-#include "gmp.h"
-#include "mpfr.h"
+
double log_b2[35], log_b2_low[35];
@@ -206,8 +203,9 @@ mpfr_ceil_double (double x)
- 2 otherwise (rounding is not possible)
*/
static int
-mpfr_get_str_aux (char *str, mp_exp_t *exp, mp_limb_t *r, mp_size_t n,
- mp_exp_t f, long e, int b, size_t m, mp_rnd_t rnd)
+mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r,
+ mp_size_t n, mp_exp_t f, long e, int b, size_t m,
+ mp_rnd_t rnd)
{
int dir; /* direction of the rounded result */
mp_limb_t ret = 0; /* possible carry in addition */
@@ -351,7 +349,7 @@ mpfr_get_str_aux (char *str, mp_exp_t *exp, mp_limb_t *r, mp_size_t n,
/* copy str1 into str and convert to ASCII */
for (i = 0; i < m; i++)
str[i] = num_to_text[(int) str1[i]];
- str[m] = 0;
+ str[m] = 0;
}
/* mpfr_can_round_raw failed: rounding is not possible */
else
diff --git a/get_ui.c b/get_ui.c
index fec2eeafb..4ed644dae 100644
--- a/get_ui.c
+++ b/get_ui.c
@@ -1,6 +1,6 @@
/* mpfr_get_ui -- convert a floating-point number to an unsigned long.
-Copyright 2003 Free Software Foundation, Inc.
+Copyright 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
unsigned long
@@ -46,7 +44,7 @@ mpfr_get_ui (mpfr_srcptr f, mp_rnd_t rnd)
/* now the result is in the most significant limb of x */
exp = MPFR_GET_EXP (x); /* since |x| >= 1, exp >= 1 */
n = MPFR_LIMB_SIZE(x);
- s = MPFR_MANT(x)[n - 1] >> (GMP_NUMB_BITS - exp);
+ s = MPFR_MANT(x)[n - 1] >> (BITS_PER_MP_LIMB - exp);
mpfr_clear (x);
diff --git a/get_z_exp.c b/get_z_exp.c
index 80fc3df1b..d17464367 100644
--- a/get_z_exp.c
+++ b/get_z_exp.c
@@ -20,10 +20,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* puts the mantissa of f into z, and returns 'exp' such that f = z * 2^exp
diff --git a/hypot.c b/hypot.c
index 01e02d040..eefbf2ce2 100644
--- a/hypot.c
+++ b/hypot.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of hypot of x and y is done by
diff --git a/init.c b/init.c
index dbc0c645f..7f6b8eefd 100644
--- a/init.c
+++ b/init.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
void
diff --git a/init2.c b/init2.c
index 80e59c005..227b15039 100644
--- a/init2.c
+++ b/init2.c
@@ -19,6 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
+#include <limits.h>
#include <stdlib.h>
#include "mpfr-impl.h"
@@ -31,6 +32,9 @@ mpfr_init2 (mpfr_ptr x, mp_prec_t p)
/* Check if we can represent the number of limbs
* associated to the maximum of mpfr_prec_t*/
MPFR_ASSERTN( MP_SIZE_T_MAX >= (MPFR_PREC_MAX/BYTES_PER_MP_LIMB) );
+ /* Check for correct BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB */
+ MPFR_ASSERTN( BITS_PER_MP_LIMB == BYTES_PER_MP_LIMB * CHAR_BIT
+ && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB );
/* p=1 is not allowed since the rounding to nearest even rule requires at
least two bits of mantissa: the neighbours of 3/2 are 1*2^0 and 1*2^1,
diff --git a/inits.c b/inits.c
index 362a4cf07..52bbd1380 100644
--- a/inits.c
+++ b/inits.c
@@ -19,9 +19,9 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-/* Needed for build with GMP */
-#ifndef HAVE_STDARG
-# include "config.h"
+#if HAVE_CONFIG_H
+#undef HAVE_STDARG
+#include "config.h" /* for a build within gmp */
#endif
#if HAVE_STDARG
diff --git a/inits2.c b/inits2.c
index 4a26881cf..47d214d6c 100644
--- a/inits2.c
+++ b/inits2.c
@@ -1,7 +1,7 @@
/* mpfr_inits2 -- initialize several floating-point numbers with given
precision
-Copyright 2003 Free Software Foundation, Inc.
+Copyright 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -20,9 +20,9 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-/* Needed for build with GMP */
-#ifndef HAVE_STDARG
-# include "config.h"
+#if HAVE_CONFIG_H
+#undef HAVE_STDARG
+#include "config.h" /* for a build within gmp */
#endif
#if HAVE_STDARG
diff --git a/inp_str.c b/inp_str.c
index b30da2fee..a32313124 100644
--- a/inp_str.c
+++ b/inp_str.c
@@ -23,9 +23,7 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <ctype.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
size_t
diff --git a/isinf.c b/isinf.c
index b7105ac95..af33ddba8 100644
--- a/isinf.c
+++ b/isinf.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/isinteger.c b/isinteger.c
index a2f805e61..563a83825 100644
--- a/isinteger.c
+++ b/isinteger.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/isnan.c b/isnan.c
index 3d164be66..c77d13727 100644
--- a/isnan.c
+++ b/isnan.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/isnum.c b/isnum.c
index 905b90041..51954a932 100644
--- a/isnum.c
+++ b/isnum.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/log.c b/log.c
index 8c1fc6622..fb37b5011 100644
--- a/log.c
+++ b/log.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of log(a) is done using the formula :
diff --git a/log10.c b/log10.c
index 1a6b0b91a..8bced1af8 100644
--- a/log10.c
+++ b/log10.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of r=log10(a)
diff --git a/log1p.c b/log1p.c
index 185d16ad4..a4e095255 100644
--- a/log1p.c
+++ b/log1p.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of log1p is done by
diff --git a/log2.c b/log2.c
index 37fcd2e75..12b987886 100644
--- a/log2.c
+++ b/log2.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of r=log2(a)
diff --git a/longlong.h b/longlong.h
new file mode 100644
index 000000000..5e2a119c8
--- /dev/null
+++ b/longlong.h
@@ -0,0 +1,1685 @@
+/* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
+
+Copyright 1991, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001, 2002 Free
+Software Foundation, Inc.
+
+This file is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+This file is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this file; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+/* You have to define the following before including this file:
+
+ UWtype -- An unsigned type, default type for operations (typically a "word")
+ UHWtype -- An unsigned type, at least half the size of UWtype.
+ UDWtype -- An unsigned type, at least twice as large a UWtype
+ W_TYPE_SIZE -- size in bits of UWtype
+
+ SItype, USItype -- Signed and unsigned 32 bit types.
+ DItype, UDItype -- Signed and unsigned 64 bit types.
+
+ On a 32 bit machine UWtype should typically be USItype;
+ on a 64 bit machine, UWtype should typically be UDItype.
+*/
+
+#define __BITS4 (W_TYPE_SIZE / 4)
+#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
+#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
+#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
+
+/* This is used to make sure no undesirable sharing between different libraries
+ that use this file takes place. */
+#ifndef __MPN
+#define __MPN(x) __##x
+#endif
+
+#ifndef _PROTO
+#if (__STDC__-0) || defined (__cplusplus)
+#define _PROTO(x) x
+#else
+#define _PROTO(x) ()
+#endif
+#endif
+
+/* Define auxiliary asm macros.
+
+ 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
+ UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype
+ word product in HIGH_PROD and LOW_PROD.
+
+ 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
+ UDWtype product. This is just a variant of umul_ppmm.
+
+ 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
+ denominator) divides a UDWtype, composed by the UWtype integers
+ HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
+ in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
+ than DENOMINATOR for correct operation. If, in addition, the most
+ significant bit of DENOMINATOR must be 1, then the pre-processor symbol
+ UDIV_NEEDS_NORMALIZATION is defined to 1.
+
+ 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
+ denominator). Like udiv_qrnnd but the numbers are signed. The quotient
+ is rounded towards 0.
+
+ 5) count_leading_zeros(count, x) counts the number of zero-bits from the
+ msb to the first non-zero bit in the UWtype X. This is the number of
+ steps X needs to be shifted left to set the msb. Undefined for X == 0,
+ unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
+
+ 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
+ from the least significant end.
+
+ 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
+ high_addend_2, low_addend_2) adds two UWtype integers, composed by
+ HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
+ respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow
+ (i.e. carry out) is not stored anywhere, and is lost.
+
+ 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
+ high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
+ composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
+ LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE
+ and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
+ and is lost.
+
+ If any of these macros are left undefined for a particular CPU,
+ C macros are used. */
+
+/* The CPUs come in alphabetical order below.
+
+ Please add support for more CPUs here, or improve the current support
+ for the CPUs below! */
+
+/* FIXME: The macros using external routines like __MPN(count_leading_zeros)
+ don't need to be under !NO_ASM */
+#if ! defined (NO_ASM)
+
+#if defined (__alpha) && W_TYPE_SIZE == 64
+/* Most alpha-based machines, except Cray systems. */
+#if defined (__GNUC__)
+#define umul_ppmm(ph, pl, m0, m1) \
+ do { \
+ UDItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("umulh %r1,%2,%0" \
+ : "=r" (ph) \
+ : "%rJ" (m0), "rI" (m1)); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#define UMUL_TIME 18
+#else /* ! __GNUC__ */
+#include <machine/builtins.h>
+#define umul_ppmm(ph, pl, m0, m1) \
+ do { \
+ UDItype __m0 = (m0), __m1 = (m1); \
+ (ph) = __UMULH (m0, m1); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#endif
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __di; \
+ __di = __MPN(invert_limb) (d); \
+ udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
+ } while (0)
+#define UDIV_PREINV_ALWAYS 1
+#define UDIV_NEEDS_NORMALIZATION 1
+#define UDIV_TIME 220
+#endif /* LONGLONG_STANDALONE */
+/* clz_tab is required by mpn/alpha/cntlz.asm, and that file is built for
+ all alphas, even though ev67 and ev68 don't need it. */
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+#if defined (__GNUC__) && (HAVE_HOST_CPU_alphaev67 || HAVE_HOST_CPU_alphaev68)
+#define count_leading_zeros(COUNT,X) \
+ __asm__("ctlz %1,%0" : "=r"(COUNT) : "r"(X))
+#define count_trailing_zeros(COUNT,X) \
+ __asm__("cttz %1,%0" : "=r"(COUNT) : "r"(X))
+#else /* ! (ev67 || ev68) */
+#ifndef LONGLONG_STANDALONE
+#if HAVE_ATTRIBUTE_CONST
+long __MPN(count_leading_zeros) _PROTO ((UDItype)) __attribute__ ((const));
+#else
+long __MPN(count_leading_zeros) _PROTO ((UDItype));
+#endif
+#define count_leading_zeros(count, x) \
+ ((count) = __MPN(count_leading_zeros) (x))
+#endif /* LONGLONG_STANDALONE */
+#endif /* ! (ev67 || ev68) */
+#endif /* __alpha */
+
+#if defined (_CRAY) && W_TYPE_SIZE == 64
+#include <intrinsics.h>
+#define UDIV_PREINV_ALWAYS 1
+#define UDIV_NEEDS_NORMALIZATION 1
+#define UDIV_TIME 220
+long __MPN(count_leading_zeros) _PROTO ((UDItype));
+#define count_leading_zeros(count, x) \
+ ((count) = _leadz ((UWtype) (x)))
+#if defined (_CRAYIEEE) /* I.e., Cray T90/ieee, T3D, and T3E */
+#define umul_ppmm(ph, pl, m0, m1) \
+ do { \
+ UDItype __m0 = (m0), __m1 = (m1); \
+ (ph) = _int_mult_upper (m0, m1); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __di; \
+ __di = __MPN(invert_limb) (d); \
+ udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
+ } while (0)
+#endif /* LONGLONG_STANDALONE */
+#endif /* _CRAYIEEE */
+#endif /* _CRAY */
+
+#if defined (__hppa) && W_TYPE_SIZE == 64
+#if defined (__GNUC__)
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add %4,%5,%1\n\tadd,dc %2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%rM" (ah), "rM" (bh), "%rM" (al), "rM" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub %4,%5,%1\n\tsub,db %2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rM" (ah), "rM" (bh), "rM" (al), "rM" (bl))
+#endif
+/* We put the result pointer parameter last here, since it makes passing
+ of the other parameters more efficient. */
+#ifndef LONGLONG_STANDALONE
+#define umul_ppmm(wh, wl, u, v) \
+ do { \
+ UWtype __p0; \
+ (wh) = __MPN(umul_ppmm) (u, v, &__p0); \
+ (wl) = __p0; \
+ } while (0)
+extern UWtype __MPN(umul_ppmm) _PROTO ((UWtype, UWtype, UWtype *));
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __r; \
+ (q) = __MPN(udiv_qrnnd) (n1, n0, d, &__r); \
+ (r) = __r; \
+ } while (0)
+extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype, UWtype, UWtype, UWtype *));
+#define UMUL_TIME 8
+#define UDIV_TIME 60
+#endif /* LONGLONG_STANDALONE */
+#endif /* hppa */
+
+#if defined (__ia64) && W_TYPE_SIZE == 64
+#if defined (__GNUC__)
+#define umul_ppmm(ph, pl, m0, m1) \
+ do { \
+ UDItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("xma.hu %0 = %1, %2, f0" \
+ : "=f" (ph) \
+ : "f" (m0), "f" (m1)); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#define UMUL_TIME 14
+#define count_leading_zeros(count, x) \
+ do { \
+ UWtype _x = (x), _y, _a, _c; \
+ __asm__ ("mux1 %0 = %1, @rev" : "=r" (_y) : "r" (_x)); \
+ __asm__ ("czx1.l %0 = %1" : "=r" (_a) : "r" (-_y | _y)); \
+ _c = (_a - 1) << 3; \
+ _x >>= _c; \
+ if (_x >= 1 << 4) \
+ _x >>= 4, _c += 4; \
+ if (_x >= 1 << 2) \
+ _x >>= 2, _c += 2; \
+ _c += _x >> 1; \
+ (count) = W_TYPE_SIZE - 1 - _c; \
+ } while (0)
+#endif
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __di; \
+ __di = __MPN(invert_limb) (d); \
+ udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
+ } while (0)
+#define UDIV_PREINV_ALWAYS 1
+#define UDIV_NEEDS_NORMALIZATION 1
+#endif
+#define UDIV_TIME 220
+#endif
+
+
+#if defined (__GNUC__)
+
+/* We sometimes need to clobber "cc" with gcc2, but that would not be
+ understood by gcc1. Use cpp to avoid major code duplication. */
+#if __GNUC__ < 2
+#define __CLOBBER_CC
+#define __AND_CLOBBER_CC
+#else /* __GNUC__ >= 2 */
+#define __CLOBBER_CC : "cc"
+#define __AND_CLOBBER_CC , "cc"
+#endif /* __GNUC__ < 2 */
+
+#if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add %1,%4,%5\n\taddc %0,%2,%3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%r" (ah), "rI" (bh), "%r" (al), "rI" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub %1,%4,%5\n\tsubc %0,%2,%3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "r" (ah), "rI" (bh), "r" (al), "rI" (bl))
+#define umul_ppmm(xh, xl, m0, m1) \
+ do { \
+ USItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("multiplu %0,%1,%2" \
+ : "=r" (xl) \
+ : "r" (__m0), "r" (__m1)); \
+ __asm__ ("multmu %0,%1,%2" \
+ : "=r" (xh) \
+ : "r" (__m0), "r" (__m1)); \
+ } while (0)
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ __asm__ ("dividu %0,%3,%4" \
+ : "=r" (q), "=q" (r) \
+ : "1" (n1), "r" (n0), "r" (d))
+#define count_leading_zeros(count, x) \
+ __asm__ ("clz %0,%1" \
+ : "=r" (count) \
+ : "r" (x))
+#define COUNT_LEADING_ZEROS_0 32
+#endif /* __a29k__ */
+
+#if defined (__arc__)
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add.f\t%1, %4, %5\n\tadc\t%0, %2, %3" \
+ : "=r" ((USItype) (sh)), \
+ "=&r" ((USItype) (sl)) \
+ : "%r" ((USItype) (ah)), \
+ "rIJ" ((USItype) (bh)), \
+ "%r" ((USItype) (al)), \
+ "rIJ" ((USItype) (bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub.f\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
+ : "=r" ((USItype) (sh)), \
+ "=&r" ((USItype) (sl)) \
+ : "r" ((USItype) (ah)), \
+ "rIJ" ((USItype) (bh)), \
+ "r" ((USItype) (al)), \
+ "rIJ" ((USItype) (bl)))
+#endif
+
+#if defined (__arm__) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%r" (ah), "rI" (bh), "%r" (al), "rI" (bl) __CLOBBER_CC)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ do { \
+ if (__builtin_constant_p (al)) \
+ { \
+ if (__builtin_constant_p (ah)) \
+ __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
+ else \
+ __asm__ ("rsbs\t%1, %5, %4\n\tsbc\t%0, %2, %3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "r" (ah), "rI" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
+ } \
+ else if (__builtin_constant_p (ah)) \
+ { \
+ if (__builtin_constant_p (bl)) \
+ __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
+ else \
+ __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
+ } \
+ else if (__builtin_constant_p (bl)) \
+ { \
+ if (__builtin_constant_p (bh)) \
+ __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
+ else \
+ __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
+ } \
+ else /* only bh might be a constant */ \
+ __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC);\
+ } while (0)
+#if 1 || defined (__arm_m__) /* `M' series has widening multiply support */
+#define umul_ppmm(xh, xl, a, b) \
+ __asm__ ("umull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b))
+#define UMUL_TIME 5
+#define smul_ppmm(xh, xl, a, b) \
+ __asm__ ("smull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b))
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __di; \
+ __di = __MPN(invert_limb) (d); \
+ udiv_qrnnd_preinv (q, r, n1, n0, d, __di); \
+ } while (0)
+#define UDIV_PREINV_ALWAYS 1
+#define UDIV_NEEDS_NORMALIZATION 1
+#define UDIV_TIME 70
+#endif /* LONGLONG_STANDALONE */
+#else
+#define umul_ppmm(xh, xl, a, b) \
+ __asm__ ("%@ Inlined umul_ppmm\n" \
+" mov %|r0, %2, lsr #16\n" \
+" mov %|r2, %3, lsr #16\n" \
+" bic %|r1, %2, %|r0, lsl #16\n" \
+" bic %|r2, %3, %|r2, lsl #16\n" \
+" mul %1, %|r1, %|r2\n" \
+" mul %|r2, %|r0, %|r2\n" \
+" mul %|r1, %0, %|r1\n" \
+" mul %0, %|r0, %0\n" \
+" adds %|r1, %|r2, %|r1\n" \
+" addcs %0, %0, #65536\n" \
+" adds %1, %1, %|r1, lsl #16\n" \
+" adc %0, %0, %|r1, lsr #16" \
+ : "=&r" (xh), "=r" (xl) \
+ : "r" (a), "r" (b) \
+ : "r0", "r1", "r2")
+#define UMUL_TIME 20
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __r; \
+ (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d)); \
+ (r) = __r; \
+ } while (0)
+extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype *, UWtype, UWtype, UWtype));
+#define UDIV_TIME 200
+#endif /* LONGLONG_STANDALONE */
+#endif
+#endif /* __arm__ */
+
+#if defined (__clipper__) && W_TYPE_SIZE == 32
+#define umul_ppmm(w1, w0, u, v) \
+ ({union {UDItype __ll; \
+ struct {USItype __l, __h;} __i; \
+ } __x; \
+ __asm__ ("mulwux %2,%0" \
+ : "=r" (__x.__ll) \
+ : "%0" ((USItype)(u)), "r" ((USItype)(v))); \
+ (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
+#define smul_ppmm(w1, w0, u, v) \
+ ({union {DItype __ll; \
+ struct {SItype __l, __h;} __i; \
+ } __x; \
+ __asm__ ("mulwx %2,%0" \
+ : "=r" (__x.__ll) \
+ : "%0" ((SItype)(u)), "r" ((SItype)(v))); \
+ (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
+#define __umulsidi3(u, v) \
+ ({UDItype __w; \
+ __asm__ ("mulwux %2,%0" \
+ : "=r" (__w) : "%0" ((USItype)(u)), "r" ((USItype)(v))); \
+ __w; })
+#endif /* __clipper__ */
+
+/* Fujitsu vector computers. */
+#if defined (__uxp__) && W_TYPE_SIZE == 32
+#define umul_ppmm(ph, pl, u, v) \
+ do { \
+ union {UDItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x; \
+ __asm__ ("mult.lu %1,%2,%0" : "=r" (__x.__ll) : "%r" (u), "rK" (v));\
+ (ph) = __x.__i.__h; \
+ (pl) = __x.__i.__l; \
+ } while (0)
+#define smul_ppmm(ph, pl, u, v) \
+ do { \
+ union {UDItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x; \
+ __asm__ ("mult.l %1,%2,%0" : "=r" (__x.__ll) : "%r" (u), "rK" (v)); \
+ (ph) = __x.__i.__h; \
+ (pl) = __x.__i.__l; \
+ } while (0)
+#endif
+
+#if defined (__gmicro__) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add.w %5,%1\n\taddx %3,%0" \
+ : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \
+ : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub.w %5,%1\n\tsubx %3,%0" \
+ : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \
+ : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define umul_ppmm(ph, pl, m0, m1) \
+ __asm__ ("mulx %3,%0,%1" \
+ : "=g" ((USItype)(ph)), "=r" ((USItype)(pl)) \
+ : "%0" ((USItype)(m0)), "g" ((USItype)(m1)))
+#define udiv_qrnnd(q, r, nh, nl, d) \
+ __asm__ ("divx %4,%0,%1" \
+ : "=g" ((USItype)(q)), "=r" ((USItype)(r)) \
+ : "1" ((USItype)(nh)), "0" ((USItype)(nl)), "g" ((USItype)(d)))
+#define count_leading_zeros(count, x) \
+ __asm__ ("bsch/1 %1,%0" \
+ : "=g" (count) : "g" ((USItype)(x)), "0" ((USItype)0))
+#endif
+
+#if defined (__hppa) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%rM" (ah), "rM" (bh), "%rM" (al), "rM" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rM" (ah), "rM" (bh), "rM" (al), "rM" (bl))
+#if defined (_PA_RISC1_1)
+#define umul_ppmm(wh, wl, u, v) \
+ do { \
+ union {UDItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x; \
+ __asm__ ("xmpyu %1,%2,%0" : "=*f" (__x.__ll) : "*f" (u), "*f" (v)); \
+ (wh) = __x.__i.__h; \
+ (wl) = __x.__i.__l; \
+ } while (0)
+#define UMUL_TIME 8
+#define UDIV_TIME 60
+#else
+#define UMUL_TIME 40
+#define UDIV_TIME 80
+#endif
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __r; \
+ (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d)); \
+ (r) = __r; \
+ } while (0)
+extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype *, UWtype, UWtype, UWtype));
+#endif /* LONGLONG_STANDALONE */
+#define count_leading_zeros(count, x) \
+ do { \
+ USItype __tmp; \
+ __asm__ ( \
+ "ldi 1,%0\n" \
+" extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
+" extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n" \
+" ldo 16(%0),%0 ; Yes. Perform add.\n" \
+" extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
+" extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n" \
+" ldo 8(%0),%0 ; Yes. Perform add.\n" \
+" extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
+" extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n" \
+" ldo 4(%0),%0 ; Yes. Perform add.\n" \
+" extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
+" extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n" \
+" ldo 2(%0),%0 ; Yes. Perform add.\n" \
+" extru %1,30,1,%1 ; Extract bit 1.\n" \
+" sub %0,%1,%0 ; Subtract it.\n" \
+ : "=r" (count), "=r" (__tmp) : "1" (x)); \
+ } while (0)
+#endif /* hppa */
+
+#if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
+#define smul_ppmm(xh, xl, m0, m1) \
+ do { \
+ union {DItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x; \
+ __asm__ ("lr %N0,%1\n\tmr %0,%2" \
+ : "=&r" (__x.__ll) \
+ : "r" (m0), "r" (m1)); \
+ (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
+ } while (0)
+#define sdiv_qrnnd(q, r, n1, n0, d) \
+ do { \
+ union {DItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x; \
+ __x.__i.__h = n1; __x.__i.__l = n0; \
+ __asm__ ("dr %0,%2" \
+ : "=r" (__x.__ll) \
+ : "0" (__x.__ll), "r" (d)); \
+ (q) = __x.__i.__l; (r) = __x.__i.__h; \
+ } while (0)
+#endif
+
+#if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("addl %5,%1\n\tadcl %3,%0" \
+ : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \
+ : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("subl %5,%1\n\tsbbl %3,%0" \
+ : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \
+ : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("mull %3" \
+ : "=a" (w0), "=d" (w1) \
+ : "%0" ((USItype)(u)), "rm" ((USItype)(v)))
+#define udiv_qrnnd(q, r, n1, n0, dx) /* d renamed to dx avoiding "=d" */\
+ __asm__ ("divl %4" /* stringification in K&R C */ \
+ : "=a" (q), "=d" (r) \
+ : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "rm" ((USItype)(dx)))
+
+/* P5 bsrl takes between 10 and 72 cycles depending where the most
+ significant 1 bit is, hence the use of the alternatives below. bsfl is
+ slow too, between 18 and 42 depending where the least significant 1 bit
+ is. The faster count_leading_zeros are pressed into service via the
+ generic count_trailing_zeros at the end of the file. */
+
+#if HAVE_HOST_CPU_i586 || HAVE_HOST_CPU_pentium
+
+/* The following should be a fixed 14 cycles or so. Some scheduling
+ opportunities should be available between the float load/store too. This
+ is used (with "n&-n" to get trailing zeros) in gcc 3 for __builtin_ffs
+ and is apparently suggested by the Intel optimizing manual (don't know
+ exactly where). gcc 2.95 or up will be best for this, so the "double" is
+ correctly aligned on the stack. */
+
+#define count_leading_zeros(c,n) \
+ do { \
+ union { \
+ double d; \
+ unsigned a[2]; \
+ } __u; \
+ ASSERT ((n) != 0); \
+ __u.d = (UWtype) (n); \
+ (c) = 0x3FF + 31 - (__u.a[1] >> 20); \
+ } while (0)
+#define COUNT_LEADING_ZEROS_0 (0x3FF + 31)
+
+#else /* ! pentium */
+#if HAVE_HOST_CPU_pentiummmx
+
+/* The following should be a fixed 14 or 15 cycles, but possibly plus an L1
+ cache miss reading from __clz_tab. It's favoured over the float above so
+ as to avoid mixing MMX and x87, since the penalty for switching between
+ the two is about 100 cycles.
+
+ The asm block sets __shift to -3 if the high 24 bits are clear, -2 for
+ 16, -1 for 8, or 0 otherwise. This could be written equivalently as
+ follows, but as of gcc 2.95.2 it results in conditional jumps.
+
+ __shift = -(__n < 0x1000000);
+ __shift -= (__n < 0x10000);
+ __shift -= (__n < 0x100);
+
+ The middle two sbbl and cmpl's pair, and with luck something gcc
+ generates might pair with the first cmpl and the last sbbl. The "32+1"
+ constant could be folded into __clz_tab[], but it doesn't seem worth
+ making a different table just for that. */
+
+#define count_leading_zeros(c,n) \
+ do { \
+ USItype __n = (n); \
+ USItype __shift; \
+ __asm__ ("cmpl $0x1000000, %1\n" \
+ "sbbl %0, %0\n" \
+ "cmpl $0x10000, %1\n" \
+ "sbbl $0, %0\n" \
+ "cmpl $0x100, %1\n" \
+ "sbbl $0, %0\n" \
+ : "=&r" (__shift) : "r" (__n)); \
+ __shift = __shift*8 + 24 + 1; \
+ (c) = 32 + 1 - __shift - __clz_tab[__n >> __shift]; \
+ } while (0)
+
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+#define COUNT_LEADING_ZEROS_0 31 /* n==0 indistinguishable from n==1 */
+
+#else /* !pentiummmx */
+/* On P6, gcc prior to 3.0 generates a partial register stall for
+ __cbtmp^31, due to using "xorb $31" instead of "xorl $31", the former
+ being 1 code byte smaller. "31-__cbtmp" is a workaround, probably at the
+ cost of one extra instruction. Do this for "i386" too, since that means
+ generic x86. */
+#if __GNUC__ < 3 \
+ && (HAVE_HOST_CPU_i386 \
+ || HAVE_HOST_CPU_i686 \
+ || HAVE_HOST_CPU_pentiumpro \
+ || HAVE_HOST_CPU_pentium2 \
+ || HAVE_HOST_CPU_pentium3)
+#define count_leading_zeros(count, x) \
+ do { \
+ USItype __cbtmp; \
+ ASSERT ((x) != 0); \
+ __asm__ ("bsrl %1,%0" : "=r" (__cbtmp) : "rm" ((USItype)(x))); \
+ (count) = 31 - __cbtmp; \
+ } while (0)
+#else
+#define count_leading_zeros(count, x) \
+ do { \
+ USItype __cbtmp; \
+ ASSERT ((x) != 0); \
+ __asm__ ("bsrl %1,%0" : "=r" (__cbtmp) : "rm" ((USItype)(x))); \
+ (count) = __cbtmp ^ 31; \
+ } while (0)
+#endif
+
+#define count_trailing_zeros(count, x) \
+ do { \
+ ASSERT ((x) != 0); \
+ __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x))); \
+ } while (0)
+#endif /* ! pentiummmx */
+#endif /* ! pentium */
+
+#ifndef UMUL_TIME
+#define UMUL_TIME 10
+#endif
+#ifndef UDIV_TIME
+#define UDIV_TIME 40
+#endif
+#endif /* 80x86 */
+
+#if defined (__x86_64__) && W_TYPE_SIZE == 64
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("addq %5,%1\n\tadcq %3,%0" \
+ : "=r" ((UDItype)(sh)), "=&r" ((UDItype)(sl)) \
+ : "%0" ((UDItype)(ah)), "g" ((UDItype)(bh)), \
+ "%1" ((UDItype)(al)), "g" ((UDItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("subq %5,%1\n\tsbbq %3,%0" \
+ : "=r" ((UDItype)(sh)), "=&r" ((UDItype)(sl)) \
+ : "0" ((UDItype)(ah)), "g" ((UDItype)(bh)), \
+ "1" ((UDItype)(al)), "g" ((UDItype)(bl)))
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("mulq %3" \
+ : "=a" (w0), "=d" (w1) \
+ : "%0" ((UDItype)(u)), "rm" ((UDItype)(v)))
+#define udiv_qrnnd(q, r, n1, n0, dx) /* d renamed to dx avoiding "=d" */\
+ __asm__ ("divq %4" /* stringification in K&R C */ \
+ : "=a" (q), "=d" (r) \
+ : "0" ((UDItype)(n0)), "1" ((UDItype)(n1)), "rm" ((UDItype)(dx)))
+#define count_leading_zeros(count, x) \
+ do { \
+ UDItype __cbtmp; \
+ ASSERT ((x) != 0); \
+ __asm__ ("bsrq %1,%0" : "=r" (__cbtmp) : "rm" ((UDItype)(x))); \
+ (count) = __cbtmp ^ 63; \
+ } while (0)
+#define count_trailing_zeros(count, x) \
+ do { \
+ ASSERT ((x) != 0); \
+ __asm__ ("bsfq %1,%0" : "=r" (count) : "rm" ((UDItype)(x))); \
+ } while (0)
+#endif /* x86_64 */
+
+#if defined (__i860__) && W_TYPE_SIZE == 32
+#define rshift_rhlc(r,h,l,c) \
+ __asm__ ("shr %3,r0,r0\;shrd %1,%2,%0" \
+ "=r" (r) : "r" (h), "r" (l), "rn" (c))
+#endif /* i860 */
+
+#if defined (__i960__) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("cmpo 1,0\;addc %5,%4,%1\;addc %3,%2,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%dI" (ah), "dI" (bh), "%dI" (al), "dI" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("cmpo 0,0\;subc %5,%4,%1\;subc %3,%2,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "dI" (ah), "dI" (bh), "dI" (al), "dI" (bl))
+#define umul_ppmm(w1, w0, u, v) \
+ ({union {UDItype __ll; \
+ struct {USItype __l, __h;} __i; \
+ } __x; \
+ __asm__ ("emul %2,%1,%0" \
+ : "=d" (__x.__ll) : "%dI" (u), "dI" (v)); \
+ (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
+#define __umulsidi3(u, v) \
+ ({UDItype __w; \
+ __asm__ ("emul %2,%1,%0" : "=d" (__w) : "%dI" (u), "dI" (v)); \
+ __w; })
+#define udiv_qrnnd(q, r, nh, nl, d) \
+ do { \
+ union {UDItype __ll; \
+ struct {USItype __l, __h;} __i; \
+ } __nn; \
+ __nn.__i.__h = (nh); __nn.__i.__l = (nl); \
+ __asm__ ("ediv %d,%n,%0" \
+ : "=d" (__rq.__ll) : "dI" (__nn.__ll), "dI" (d)); \
+ (r) = __rq.__i.__l; (q) = __rq.__i.__h; \
+ } while (0)
+#define count_leading_zeros(count, x) \
+ do { \
+ USItype __cbtmp; \
+ __asm__ ("scanbit %1,%0" : "=r" (__cbtmp) : "r" (x)); \
+ (count) = __cbtmp ^ 31; \
+ } while (0)
+#define COUNT_LEADING_ZEROS_0 (-32) /* sic */
+#if defined (__i960mx) /* what is the proper symbol to test??? */
+#define rshift_rhlc(r,h,l,c) \
+ do { \
+ union {UDItype __ll; \
+ struct {USItype __l, __h;} __i; \
+ } __nn; \
+ __nn.__i.__h = (h); __nn.__i.__l = (l); \
+ __asm__ ("shre %2,%1,%0" : "=d" (r) : "dI" (__nn.__ll), "dI" (c)); \
+ }
+#endif /* i960mx */
+#endif /* i960 */
+
+#if (defined (__mc68000__) || defined (__mc68020__) || defined(mc68020) \
+ || defined (__m68k__) || defined (__mc5200__) || defined (__mc5206e__) \
+ || defined (__mc5307__)) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0" \
+ : "=d" ((USItype)(sh)), "=&d" ((USItype)(sl)) \
+ : "%0" ((USItype)(ah)), "d" ((USItype)(bh)), \
+ "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0" \
+ : "=d" ((USItype)(sh)), "=&d" ((USItype)(sl)) \
+ : "0" ((USItype)(ah)), "d" ((USItype)(bh)), \
+ "1" ((USItype)(al)), "g" ((USItype)(bl)))
+/* The '020, '030, '040 and CPU32 have 32x32->64 and 64/32->32q-32r. */
+#if defined (__mc68020__) || defined(mc68020) \
+ || defined (__mc68030__) || defined (mc68030) \
+ || defined (__mc68040__) || defined (mc68040) \
+ || defined (__mcpu32__) || defined (mcpu32) \
+ || defined (__NeXT__)
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("mulu%.l %3,%1:%0" \
+ : "=d" ((USItype)(w0)), "=d" ((USItype)(w1)) \
+ : "%0" ((USItype)(u)), "dmi" ((USItype)(v)))
+#define UMUL_TIME 45
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ __asm__ ("divu%.l %4,%1:%0" \
+ : "=d" ((USItype)(q)), "=d" ((USItype)(r)) \
+ : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d)))
+#define UDIV_TIME 90
+#define sdiv_qrnnd(q, r, n1, n0, d) \
+ __asm__ ("divs%.l %4,%1:%0" \
+ : "=d" ((USItype)(q)), "=d" ((USItype)(r)) \
+ : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d)))
+#else /* for other 68k family members use 16x16->32 multiplication */
+#define umul_ppmm(xh, xl, a, b) \
+ do { USItype __umul_tmp1, __umul_tmp2; \
+ __asm__ ("| Inlined umul_ppmm\n" \
+" move%.l %5,%3\n" \
+" move%.l %2,%0\n" \
+" move%.w %3,%1\n" \
+" swap %3\n" \
+" swap %0\n" \
+" mulu%.w %2,%1\n" \
+" mulu%.w %3,%0\n" \
+" mulu%.w %2,%3\n" \
+" swap %2\n" \
+" mulu%.w %5,%2\n" \
+" add%.l %3,%2\n" \
+" jcc 1f\n" \
+" add%.l %#0x10000,%0\n" \
+"1: move%.l %2,%3\n" \
+" clr%.w %2\n" \
+" swap %2\n" \
+" swap %3\n" \
+" clr%.w %3\n" \
+" add%.l %3,%1\n" \
+" addx%.l %2,%0\n" \
+" | End inlined umul_ppmm" \
+ : "=&d" ((USItype)(xh)), "=&d" ((USItype)(xl)), \
+ "=d" (__umul_tmp1), "=&d" (__umul_tmp2) \
+ : "%2" ((USItype)(a)), "d" ((USItype)(b))); \
+ } while (0)
+#define UMUL_TIME 100
+#define UDIV_TIME 400
+#endif /* not mc68020 */
+/* The '020, '030, '040 and '060 have bitfield insns. */
+#if defined (__mc68020__) || defined (mc68020) \
+ || defined (__mc68030__) || defined (mc68030) \
+ || defined (__mc68040__) || defined (mc68040) \
+ || defined (__mc68060__) || defined (mc68060) \
+ || defined (__NeXT__)
+#define count_leading_zeros(count, x) \
+ __asm__ ("bfffo %1{%b2:%b2},%0" \
+ : "=d" ((USItype) (count)) \
+ : "od" ((USItype) (x)), "n" (0))
+#define COUNT_LEADING_ZEROS_0 32
+#endif
+#endif /* mc68000 */
+
+#if defined (__m88000__) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%rJ" (ah), "rJ" (bh), "%rJ" (al), "rJ" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rJ" (ah), "rJ" (bh), "rJ" (al), "rJ" (bl))
+#define count_leading_zeros(count, x) \
+ do { \
+ USItype __cbtmp; \
+ __asm__ ("ff1 %0,%1" : "=r" (__cbtmp) : "r" (x)); \
+ (count) = __cbtmp ^ 31; \
+ } while (0)
+#define COUNT_LEADING_ZEROS_0 63 /* sic */
+#if defined (__m88110__)
+#define umul_ppmm(wh, wl, u, v) \
+ do { \
+ union {UDItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x; \
+ __asm__ ("mulu.d %0,%1,%2" : "=r" (__x.__ll) : "r" (u), "r" (v)); \
+ (wh) = __x.__i.__h; \
+ (wl) = __x.__i.__l; \
+ } while (0)
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ ({union {UDItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x, __q; \
+ __x.__i.__h = (n1); __x.__i.__l = (n0); \
+ __asm__ ("divu.d %0,%1,%2" \
+ : "=r" (__q.__ll) : "r" (__x.__ll), "r" (d)); \
+ (r) = (n0) - __q.__l * (d); (q) = __q.__l; })
+#define UMUL_TIME 5
+#define UDIV_TIME 25
+#else
+#define UMUL_TIME 17
+#define UDIV_TIME 150
+#endif /* __m88110__ */
+#endif /* __m88000__ */
+
+#if defined (__mips) && W_TYPE_SIZE == 32
+#if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
+#else
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("multu %2,%3\n\tmflo %0\n\tmfhi %1" \
+ : "=d" (w0), "=d" (w1) : "d" (u), "d" (v))
+#endif
+#define UMUL_TIME 10
+#define UDIV_TIME 100
+#endif /* __mips */
+
+#if (defined (__mips) && __mips >= 3) && W_TYPE_SIZE == 64
+#if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("dmultu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
+#else
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("dmultu %2,%3\n\tmflo %0\n\tmfhi %1" \
+ : "=d" (w0), "=d" (w1) : "d" (u), "d" (v))
+#endif
+#define UMUL_TIME 20
+#define UDIV_TIME 140
+#endif /* __mips */
+
+#if defined (__ns32000__) && W_TYPE_SIZE == 32
+#define umul_ppmm(w1, w0, u, v) \
+ ({union {UDItype __ll; \
+ struct {USItype __l, __h;} __i; \
+ } __x; \
+ __asm__ ("meid %2,%0" \
+ : "=g" (__x.__ll) \
+ : "%0" ((USItype)(u)), "g" ((USItype)(v))); \
+ (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
+#define __umulsidi3(u, v) \
+ ({UDItype __w; \
+ __asm__ ("meid %2,%0" \
+ : "=g" (__w) \
+ : "%0" ((USItype)(u)), "g" ((USItype)(v))); \
+ __w; })
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ ({union {UDItype __ll; \
+ struct {USItype __l, __h;} __i; \
+ } __x; \
+ __x.__i.__h = (n1); __x.__i.__l = (n0); \
+ __asm__ ("deid %2,%0" \
+ : "=g" (__x.__ll) \
+ : "0" (__x.__ll), "g" ((USItype)(d))); \
+ (r) = __x.__i.__l; (q) = __x.__i.__h; })
+#define count_trailing_zeros(count,x) \
+ do { \
+ __asm__ ("ffsd %2,%0" \
+ : "=r" ((USItype) (count)) \
+ : "0" ((USItype) 0), "r" ((USItype) (x))); \
+ } while (0)
+#endif /* __ns32000__ */
+
+/* FIXME: We should test _IBMR2 here when we add assembly support for the
+ system vendor compilers.
+ FIXME: What's needed for gcc PowerPC VxWorks? __vxworks__ is not good
+ enough, since that hits ARM and m68k too. */
+#if (defined (_ARCH_PPC) /* AIX */ \
+ || defined (_ARCH_PWR) /* AIX */ \
+ || defined (__powerpc__) /* gcc */ \
+ || defined (__POWERPC__) /* BEOS */ \
+ || defined (__ppc__) /* Darwin */ \
+ || defined (PPC) /* GNU/Linux, SysV */ \
+ ) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ do { \
+ if (__builtin_constant_p (bh) && (bh) == 0) \
+ __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+ else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
+ __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+ else \
+ __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
+ } while (0)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ do { \
+ if (__builtin_constant_p (ah) && (ah) == 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+ else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+ else if (__builtin_constant_p (bh) && (bh) == 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+ else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+ else \
+ __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
+ : "=r" (sh), "=&r" (sl) \
+ : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
+ } while (0)
+#define count_leading_zeros(count, x) \
+ __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x))
+#define COUNT_LEADING_ZEROS_0 32
+#if defined (_ARCH_PPC) || defined (__powerpc__) || defined (__POWERPC__) \
+ || defined (__ppc__) || defined (PPC) || defined (__vxworks__)
+#define umul_ppmm(ph, pl, m0, m1) \
+ do { \
+ USItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#define UMUL_TIME 15
+#define smul_ppmm(ph, pl, m0, m1) \
+ do { \
+ SItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#define SMUL_TIME 14
+#define UDIV_TIME 120
+#else
+#define UMUL_TIME 8
+#define smul_ppmm(xh, xl, m0, m1) \
+ __asm__ ("mul %0,%2,%3" : "=r" (xh), "=q" (xl) : "r" (m0), "r" (m1))
+#define SMUL_TIME 4
+#define sdiv_qrnnd(q, r, nh, nl, d) \
+ __asm__ ("div %0,%2,%4" : "=r" (q), "=q" (r) : "r" (nh), "1" (nl), "r" (d))
+#define UDIV_TIME 100
+#endif
+#endif /* 32-bit POWER architecture variants. */
+
+/* We should test _IBMR2 here when we add assembly support for the system
+ vendor compilers. */
+#if (defined (_ARCH_PPC) || defined (__powerpc__)) && W_TYPE_SIZE == 64
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ do { \
+ if (__builtin_constant_p (bh) && (bh) == 0) \
+ __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+ else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
+ __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+ else \
+ __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
+ } while (0)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ do { \
+ if (__builtin_constant_p (ah) && (ah) == 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+ else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+ else if (__builtin_constant_p (bh) && (bh) == 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+ else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
+ __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
+ : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+ else \
+ __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
+ : "=r" (sh), "=&r" (sl) \
+ : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
+ } while (0)
+#define count_leading_zeros(count, x) \
+ __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
+#define COUNT_LEADING_ZEROS_0 64
+#define umul_ppmm(ph, pl, m0, m1) \
+ do { \
+ UDItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#define UMUL_TIME 15
+#define smul_ppmm(ph, pl, m0, m1) \
+ do { \
+ DItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
+ (pl) = __m0 * __m1; \
+ } while (0)
+#define SMUL_TIME 14 /* ??? */
+#define UDIV_TIME 120 /* ??? */
+#endif /* 64-bit PowerPC. */
+
+#if defined (__pyr__) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("addw %5,%1\n\taddwc %3,%0" \
+ : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \
+ : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("subw %5,%1\n\tsubwb %3,%0" \
+ : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \
+ : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "1" ((USItype)(al)), "g" ((USItype)(bl)))
+/* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP. */
+#define umul_ppmm(w1, w0, u, v) \
+ ({union {UDItype __ll; \
+ struct {USItype __h, __l;} __i; \
+ } __x; \
+ __asm__ ("movw %1,%R0\n\tuemul %2,%0" \
+ : "=&r" (__x.__ll) \
+ : "g" ((USItype) (u)), "g" ((USItype)(v))); \
+ (w1) = __x.__i.__h; (w0) = __x.__i.__l;})
+#endif /* __pyr__ */
+
+#if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("a %1,%5\n\tae %0,%3" \
+ : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \
+ : "%0" ((USItype)(ah)), "r" ((USItype)(bh)), \
+ "%1" ((USItype)(al)), "r" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("s %1,%5\n\tse %0,%3" \
+ : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl)) \
+ : "0" ((USItype)(ah)), "r" ((USItype)(bh)), \
+ "1" ((USItype)(al)), "r" ((USItype)(bl)))
+#define smul_ppmm(ph, pl, m0, m1) \
+ __asm__ ( \
+ "s r2,r2\n" \
+" mts r10,%2\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" m r2,%3\n" \
+" cas %0,r2,r0\n" \
+" mfs r10,%1" \
+ : "=r" ((USItype)(ph)), "=r" ((USItype)(pl)) \
+ : "%r" ((USItype)(m0)), "r" ((USItype)(m1)) \
+ : "r2")
+#define UMUL_TIME 20
+#define UDIV_TIME 200
+#define count_leading_zeros(count, x) \
+ do { \
+ if ((x) >= 0x10000) \
+ __asm__ ("clz %0,%1" \
+ : "=r" ((USItype)(count)) : "r" ((USItype)(x) >> 16)); \
+ else \
+ { \
+ __asm__ ("clz %0,%1" \
+ : "=r" ((USItype)(count)) : "r" ((USItype)(x))); \
+ (count) += 16; \
+ } \
+ } while (0)
+#endif /* RT/ROMP */
+
+#if defined (__sh2__) && W_TYPE_SIZE == 32
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("dmulu.l %2,%3\n\tsts macl,%1\n\tsts mach,%0" \
+ : "=r" (w1), "=r" (w0) : "r" (u), "r" (v) : "macl", "mach")
+#define UMUL_TIME 5
+#endif
+
+#if defined (__sparc__) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%rJ" (ah), "rI" (bh),"%rJ" (al), "rI" (bl) \
+ __CLOBBER_CC)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rJ" (ah), "rI" (bh), "rJ" (al), "rI" (bl) \
+ __CLOBBER_CC)
+/* FIXME: When gcc -mcpu=v9 is used on solaris, gcc/config/sol2-sld-64.h
+ doesn't define anything to indicate that to us, it only sets __sparcv8. */
+#if defined (__sparc_v9__) || defined (__sparcv9)
+/* Perhaps we should use floating-point operations here? */
+#if 0
+/* Triggers a bug making mpz/tests/t-gcd.c fail.
+ Perhaps we simply need explicitly zero-extend the inputs? */
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("mulx %2,%3,%%g1; srl %%g1,0,%1; srlx %%g1,32,%0" : \
+ "=r" (w1), "=r" (w0) : "r" (u), "r" (v) : "g1")
+#else
+/* Use v8 umul until above bug is fixed. */
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v))
+#endif
+/* Use a plain v8 divide for v9. */
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { \
+ USItype __q; \
+ __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
+ : "=r" (__q) : "r" (n1), "r" (n0), "r" (d)); \
+ (r) = (n0) - __q * (d); \
+ (q) = __q; \
+ } while (0)
+#else
+#if defined (__sparc_v8__) /* gcc normal */ \
+ || defined (__sparcv8) /* gcc solaris */
+/* Don't match immediate range because, 1) it is not often useful,
+ 2) the 'I' flag thinks of the range as a 13 bit signed interval,
+ while we want to match a 13 bit interval, sign extended to 32 bits,
+ but INTERPRETED AS UNSIGNED. */
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v))
+#define UMUL_TIME 5
+
+#if HAVE_HOST_CPU_supersparc
+#define UDIV_TIME 60 /* SuperSPARC timing */
+#else
+/* Don't use this on SuperSPARC because its udiv only handles 53 bit
+ dividends and will trap to the kernel for the rest. */
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { \
+ USItype __q; \
+ __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0" \
+ : "=r" (__q) : "r" (n1), "r" (n0), "r" (d)); \
+ (r) = (n0) - __q * (d); \
+ (q) = __q; \
+ } while (0)
+#define UDIV_TIME 25
+#endif /* HAVE_HOST_CPU_supersparc */
+
+#else /* ! __sparc_v8__ */
+#if defined (__sparclite__)
+/* This has hardware multiply but not divide. It also has two additional
+ instructions scan (ffs from high bit) and divscc. */
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=r" (w1), "=r" (w0) : "r" (u), "r" (v))
+#define UMUL_TIME 5
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ __asm__ ("! Inlined udiv_qrnnd\n" \
+" wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
+" tst %%g0\n" \
+" divscc %3,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%%g1\n" \
+" divscc %%g1,%4,%0\n" \
+" rd %%y,%1\n" \
+" bl,a 1f\n" \
+" add %1,%4,%1\n" \
+"1: ! End of inline udiv_qrnnd" \
+ : "=r" (q), "=r" (r) : "r" (n1), "r" (n0), "rI" (d) \
+ : "%g1" __AND_CLOBBER_CC)
+#define UDIV_TIME 37
+#define count_leading_zeros(count, x) \
+ __asm__ ("scan %1,1,%0" : "=r" (count) : "r" (x))
+/* Early sparclites return 63 for an argument of 0, but they warn that future
+ implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
+ undefined. */
+#endif /* __sparclite__ */
+#endif /* __sparc_v8__ */
+#endif /* __sparc_v9__ */
+/* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd. */
+#ifndef umul_ppmm
+#define umul_ppmm(w1, w0, u, v) \
+ __asm__ ("! Inlined umul_ppmm\n" \
+" wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n" \
+" sra %3,31,%%g2 ! Don't move this insn\n" \
+" and %2,%%g2,%%g2 ! Don't move this insn\n" \
+" andcc %%g0,0,%%g1 ! Don't move this insn\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,%3,%%g1\n" \
+" mulscc %%g1,0,%%g1\n" \
+" add %%g1,%%g2,%0\n" \
+" rd %%y,%1" \
+ : "=r" (w1), "=r" (w0) : "%rI" (u), "r" (v) \
+ : "%g1", "%g2" __AND_CLOBBER_CC)
+#define UMUL_TIME 39 /* 39 instructions */
+#endif
+#ifndef udiv_qrnnd
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { UWtype __r; \
+ (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d)); \
+ (r) = __r; \
+ } while (0)
+extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype *, UWtype, UWtype, UWtype));
+#ifndef UDIV_TIME
+#define UDIV_TIME 140
+#endif
+#endif /* LONGLONG_STANDALONE */
+#endif /* udiv_qrnnd */
+#endif /* __sparc__ */
+
+#if defined (__sparc__) && W_TYPE_SIZE == 64
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ( \
+ "addcc %r4,%5,%1\n" \
+ " addccc %r6,%7,%%g0\n" \
+ " addc %r2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "%rJ" (ah), "rI" (bh), "%rJ" (al), "rI" (bl), \
+ "%rJ" ((al) >> 32), "rI" ((bl) >> 32) \
+ __CLOBBER_CC)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ( \
+ "subcc %r4,%5,%1\n" \
+ " subccc %r6,%7,%%g0\n" \
+ " subc %r2,%3,%0" \
+ : "=r" (sh), "=&r" (sl) \
+ : "rJ" (ah), "rI" (bh), "rJ" (al), "rI" (bl), \
+ "rJ" ((al) >> 32), "rI" ((bl) >> 32) \
+ __CLOBBER_CC)
+#endif
+
+#if defined (__vax__) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("addl2 %5,%1\n\tadwc %3,%0" \
+ : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \
+ : "%0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("subl2 %5,%1\n\tsbwc %3,%0" \
+ : "=g" ((USItype)(sh)), "=&g" ((USItype)(sl)) \
+ : "0" ((USItype)(ah)), "g" ((USItype)(bh)), \
+ "1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define smul_ppmm(xh, xl, m0, m1) \
+ do { \
+ union {UDItype __ll; \
+ struct {USItype __l, __h;} __i; \
+ } __x; \
+ USItype __m0 = (m0), __m1 = (m1); \
+ __asm__ ("emul %1,%2,$0,%0" \
+ : "=g" (__x.__ll) : "g" (__m0), "g" (__m1)); \
+ (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
+ } while (0)
+#define sdiv_qrnnd(q, r, n1, n0, d) \
+ do { \
+ union {DItype __ll; \
+ struct {SItype __l, __h;} __i; \
+ } __x; \
+ __x.__i.__h = n1; __x.__i.__l = n0; \
+ __asm__ ("ediv %3,%2,%0,%1" \
+ : "=g" (q), "=g" (r) : "g" (__x.__ll), "g" (d)); \
+ } while (0)
+#if 0
+/* FIXME: This instruction appears to be unimplemented on some systems (vax
+ 8800 maybe). */
+#define count_trailing_zeros(count,x) \
+ do { \
+ __asm__ ("ffs 0, 31, %1, %0" \
+ : "=g" ((USItype) (count)) \
+ : "g" ((USItype) (x))); \
+ } while (0)
+#endif
+#endif /* __vax__ */
+
+#if defined (__z8000__) && W_TYPE_SIZE == 16
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
+ : "=r" ((unsigned int)(sh)), "=&r" ((unsigned int)(sl)) \
+ : "%0" ((unsigned int)(ah)), "r" ((unsigned int)(bh)), \
+ "%1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
+ : "=r" ((unsigned int)(sh)), "=&r" ((unsigned int)(sl)) \
+ : "0" ((unsigned int)(ah)), "r" ((unsigned int)(bh)), \
+ "1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl)))
+#define umul_ppmm(xh, xl, m0, m1) \
+ do { \
+ union {long int __ll; \
+ struct {unsigned int __h, __l;} __i; \
+ } __x; \
+ unsigned int __m0 = (m0), __m1 = (m1); \
+ __asm__ ("mult %S0,%H3" \
+ : "=r" (__x.__i.__h), "=r" (__x.__i.__l) \
+ : "%1" (m0), "rQR" (m1)); \
+ (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
+ (xh) += ((((signed int) __m0 >> 15) & __m1) \
+ + (((signed int) __m1 >> 15) & __m0)); \
+ } while (0)
+#endif /* __z8000__ */
+
+#endif /* __GNUC__ */
+
+#endif /* NO_ASM */
+
+
+#if !defined (umul_ppmm) && defined (__umulsidi3)
+#define umul_ppmm(ph, pl, m0, m1) \
+ { \
+ UDWtype __ll = __umulsidi3 (m0, m1); \
+ ph = (UWtype) (__ll >> W_TYPE_SIZE); \
+ pl = (UWtype) __ll; \
+ }
+#endif
+
+#if !defined (__umulsidi3)
+#define __umulsidi3(u, v) \
+ ({UWtype __hi, __lo; \
+ umul_ppmm (__hi, __lo, u, v); \
+ ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
+#endif
+
+
+/* Note the prototypes are under !define(umul_ppmm) etc too, since the HPPA
+ versions above are different and we don't want to conflict. */
+
+#if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm
+#define mpn_umul_ppmm __MPN(umul_ppmm)
+extern mp_limb_t mpn_umul_ppmm _PROTO ((mp_limb_t *, mp_limb_t, mp_limb_t));
+#define umul_ppmm(wh, wl, u, v) \
+ do { \
+ mp_limb_t __umul_ppmm__p0; \
+ (wh) = __MPN(umul_ppmm) (&__umul_ppmm__p0, \
+ (mp_limb_t) (u), (mp_limb_t) (v)); \
+ (wl) = __umul_ppmm__p0; \
+ } while (0)
+#endif
+
+#if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd
+#define mpn_udiv_qrnnd __MPN(udiv_qrnnd)
+extern mp_limb_t mpn_udiv_qrnnd _PROTO ((mp_limb_t *,
+ mp_limb_t, mp_limb_t, mp_limb_t));
+#define udiv_qrnnd(q, r, n1, n0, d) \
+ do { \
+ mp_limb_t __udiv_qrnnd__r; \
+ (q) = mpn_udiv_qrnnd (&__udiv_qrnnd__r, \
+ (mp_limb_t) (n1), (mp_limb_t) (n0), (mp_limb_t) d); \
+ (r) = __udiv_qrnnd__r; \
+ } while (0)
+#endif
+
+
+/* If this machine has no inline assembler, use C macros. */
+
+#if !defined (add_ssaaaa)
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ do { \
+ UWtype __x; \
+ __x = (al) + (bl); \
+ (sh) = (ah) + (bh) + (__x < (al)); \
+ (sl) = __x; \
+ } while (0)
+#endif
+
+#if !defined (sub_ddmmss)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ do { \
+ UWtype __x; \
+ __x = (al) - (bl); \
+ (sh) = (ah) - (bh) - (__x > (al)); \
+ (sl) = __x; \
+ } while (0)
+#endif
+
+/* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
+ smul_ppmm. */
+#if !defined (umul_ppmm) && defined (smul_ppmm)
+#define umul_ppmm(w1, w0, u, v) \
+ do { \
+ UWtype __w1; \
+ UWtype __xm0 = (u), __xm1 = (v); \
+ smul_ppmm (__w1, w0, __xm0, __xm1); \
+ (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \
+ + (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \
+ } while (0)
+#endif
+
+/* If we still don't have umul_ppmm, define it using plain C. */
+#if !defined (umul_ppmm)
+#define umul_ppmm(w1, w0, u, v) \
+ do { \
+ UWtype __x0, __x1, __x2, __x3; \
+ UHWtype __ul, __vl, __uh, __vh; \
+ UWtype __u = (u), __v = (v); \
+ \
+ __ul = __ll_lowpart (__u); \
+ __uh = __ll_highpart (__u); \
+ __vl = __ll_lowpart (__v); \
+ __vh = __ll_highpart (__v); \
+ \
+ __x0 = (UWtype) __ul * __vl; \
+ __x1 = (UWtype) __ul * __vh; \
+ __x2 = (UWtype) __uh * __vl; \
+ __x3 = (UWtype) __uh * __vh; \
+ \
+ __x1 += __ll_highpart (__x0);/* this can't give carry */ \
+ __x1 += __x2; /* but this indeed can */ \
+ if (__x1 < __x2) /* did we get it? */ \
+ __x3 += __ll_B; /* yes, add it in the proper pos. */ \
+ \
+ (w1) = __x3 + __ll_highpart (__x1); \
+ (w0) = (__x1 << W_TYPE_SIZE/2) + __ll_lowpart (__x0); \
+ } while (0)
+#endif
+
+/* If we don't have smul_ppmm, define it using umul_ppmm (which surely will
+ exist in one form or another. */
+#if !defined (smul_ppmm)
+#define smul_ppmm(w1, w0, u, v) \
+ do { \
+ UWtype __w1; \
+ UWtype __xm0 = (u), __xm1 = (v); \
+ umul_ppmm (__w1, w0, __xm0, __xm1); \
+ (w1) = __w1 - (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \
+ - (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \
+ } while (0)
+#endif
+
+/* Define this unconditionally, so it can be used for debugging. */
+#define __udiv_qrnnd_c(q, r, n1, n0, d) \
+ do { \
+ UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
+ \
+ ASSERT ((d) != 0); \
+ ASSERT ((n1) < (d)); \
+ \
+ __d1 = __ll_highpart (d); \
+ __d0 = __ll_lowpart (d); \
+ \
+ __q1 = (n1) / __d1; \
+ __r1 = (n1) - __q1 * __d1; \
+ __m = (UWtype) __q1 * __d0; \
+ __r1 = __r1 * __ll_B | __ll_highpart (n0); \
+ if (__r1 < __m) \
+ { \
+ __q1--, __r1 += (d); \
+ if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
+ if (__r1 < __m) \
+ __q1--, __r1 += (d); \
+ } \
+ __r1 -= __m; \
+ \
+ __q0 = __r1 / __d1; \
+ __r0 = __r1 - __q0 * __d1; \
+ __m = (UWtype) __q0 * __d0; \
+ __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
+ if (__r0 < __m) \
+ { \
+ __q0--, __r0 += (d); \
+ if (__r0 >= (d)) \
+ if (__r0 < __m) \
+ __q0--, __r0 += (d); \
+ } \
+ __r0 -= __m; \
+ \
+ (q) = (UWtype) __q1 * __ll_B | __q0; \
+ (r) = __r0; \
+ } while (0)
+
+/* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
+ __udiv_w_sdiv (defined in libgcc or elsewhere). */
+#if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
+#define udiv_qrnnd(q, r, nh, nl, d) \
+ do { \
+ UWtype __r; \
+ (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
+ (r) = __r; \
+ } while (0)
+#endif
+
+/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
+#if !defined (udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#if !defined (count_leading_zeros)
+#define count_leading_zeros(count, x) \
+ do { \
+ UWtype __xr = (x); \
+ UWtype __a; \
+ \
+ if (W_TYPE_SIZE == 32) \
+ { \
+ __a = __xr < ((UWtype) 1 << 2*__BITS4) \
+ ? (__xr < ((UWtype) 1 << __BITS4) ? 1 : __BITS4 + 1) \
+ : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 + 1 \
+ : 3*__BITS4 + 1); \
+ } \
+ else \
+ { \
+ for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+ if (((__xr >> __a) & 0xff) != 0) \
+ break; \
+ ++__a; \
+ } \
+ \
+ (count) = W_TYPE_SIZE + 1 - __a - __clz_tab[__xr >> __a]; \
+ } while (0)
+/* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 (W_TYPE_SIZE - 1)
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+#endif
+
+#ifdef COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+extern const unsigned char __GMP_DECLSPEC __clz_tab[128];
+#endif
+
+#if !defined (count_trailing_zeros)
+/* Define count_trailing_zeros using count_leading_zeros. The latter might be
+ defined in asm, but if it is not, the C version above is good enough. */
+#define count_trailing_zeros(count, x) \
+ do { \
+ UWtype __ctz_x = (x); \
+ UWtype __ctz_c; \
+ ASSERT (__ctz_x != 0); \
+ count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
+ (count) = W_TYPE_SIZE - 1 - __ctz_c; \
+ } while (0)
+#endif
+
+#ifndef UDIV_NEEDS_NORMALIZATION
+#define UDIV_NEEDS_NORMALIZATION 0
+#endif
+
+/* Whether udiv_qrnnd is actually implemented with udiv_qrnnd_preinv, and
+ that hence the latter should always be used. */
+#ifndef UDIV_PREINV_ALWAYS
+#define UDIV_PREINV_ALWAYS 0
+#endif
+
+/* Give defaults for UMUL_TIME and UDIV_TIME. */
+#ifndef UMUL_TIME
+#define UMUL_TIME 1
+#endif
+
+#ifndef UDIV_TIME
+#define UDIV_TIME UMUL_TIME
+#endif
diff --git a/minmax.c b/minmax.c
index 58b6c7069..8f9fb3e04 100644
--- a/minmax.c
+++ b/minmax.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of z=min(x,y)
diff --git a/mp_clz_tab.c b/mp_clz_tab.c
new file mode 100644
index 000000000..92dc48ec6
--- /dev/null
+++ b/mp_clz_tab.c
@@ -0,0 +1,39 @@
+/* __clz_tab -- support for longlong.h
+
+ THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND MAY CHANGE
+ INCOMPATIBLY OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
+
+Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2004 Free Software
+Foundation,Inc.
+
+This file is part of the GNU MP Library.
+Adapted to be used by the MPFR library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#define MPFR_NEED_LONGLONG_H
+#include "mpfr-impl.h"
+
+#if defined(COUNT_LEADING_ZEROS_NEED_CLZ_TAB) && defined(__GMPFR_GMP_H__)
+const
+unsigned char __clz_tab[128] =
+{
+ 1,2,3,3,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
+};
+#endif
diff --git a/mpfr-gmp.c b/mpfr-gmp.c
new file mode 100644
index 000000000..4ef97f3a6
--- /dev/null
+++ b/mpfr-gmp.c
@@ -0,0 +1,377 @@
+/* mpfr_gmp -- Limited gmp-impl emulator
+ Modified version of the GMP files.
+
+Copyright 2004 Free Software Foundation.
+
+This file is part of the MPFR Library.
+
+The MPFR Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPFR Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPFR Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdlib.h> /* For malloc, free, realloc and abort*/
+#include <stdio.h> /* For fprintf and stderr */
+
+#include "mpfr-impl.h"
+
+#ifndef MPFR_HAVE_GMP_IMPL
+
+char mpfr_rands_initialized = 0;
+gmp_randstate_t mpfr_rands;
+
+const struct bases mpfr_bases[257] =
+{
+ /* 0 */ {0.0},
+ /* 1 */ {1e37},
+ /* 2 */ {1.0000000000000000},
+ /* 3 */ {0.6309297535714574},
+ /* 4 */ {0.5000000000000000},
+ /* 5 */ {0.4306765580733931},
+ /* 6 */ {0.3868528072345416},
+ /* 7 */ {0.3562071871080222},
+ /* 8 */ {0.3333333333333333},
+ /* 9 */ {0.3154648767857287},
+ /* 10 */ {0.3010299956639812},
+ /* 11 */ {0.2890648263178878},
+ /* 12 */ {0.2789429456511298},
+ /* 13 */ {0.2702381544273197},
+ /* 14 */ {0.2626495350371935},
+ /* 15 */ {0.2559580248098155},
+ /* 16 */ {0.2500000000000000},
+ /* 17 */ {0.2446505421182260},
+ /* 18 */ {0.2398124665681314},
+ /* 19 */ {0.2354089133666382},
+ /* 20 */ {0.2313782131597592},
+ /* 21 */ {0.2276702486969530},
+ /* 22 */ {0.2242438242175754},
+ /* 23 */ {0.2210647294575037},
+ /* 24 */ {0.2181042919855316},
+ /* 25 */ {0.2153382790366965},
+ /* 26 */ {0.2127460535533632},
+ /* 27 */ {0.2103099178571525},
+ /* 28 */ {0.2080145976765095},
+ /* 29 */ {0.2058468324604344},
+ /* 30 */ {0.2037950470905062},
+ /* 31 */ {0.2018490865820999},
+ /* 32 */ {0.2000000000000000},
+ /* 33 */ {0.1982398631705605},
+ /* 34 */ {0.1965616322328226},
+ /* 35 */ {0.1949590218937863},
+ /* 36 */ {0.1934264036172708},
+ /* 37 */ {0.1919587200065601},
+ /* 38 */ {0.1905514124267734},
+ /* 39 */ {0.1892003595168700},
+ /* 40 */ {0.1879018247091076},
+ /* 41 */ {0.1866524112389434},
+ /* 42 */ {0.1854490234153689},
+ /* 43 */ {0.1842888331487062},
+ /* 44 */ {0.1831692509136336},
+ /* 45 */ {0.1820879004699383},
+ /* 46 */ {0.1810425967800402},
+ /* 47 */ {0.1800313266566926},
+ /* 48 */ {0.1790522317510414},
+ /* 49 */ {0.1781035935540111},
+ /* 50 */ {0.1771838201355579},
+ /* 51 */ {0.1762914343888821},
+ /* 52 */ {0.1754250635819545},
+ /* 53 */ {0.1745834300480449},
+ /* 54 */ {0.1737653428714400},
+ /* 55 */ {0.1729696904450771},
+ /* 56 */ {0.1721954337940981},
+ /* 57 */ {0.1714416005739134},
+ /* 58 */ {0.1707072796637201},
+ /* 59 */ {0.1699916162869140},
+ /* 60 */ {0.1692938075987814},
+ /* 61 */ {0.1686130986895011},
+ /* 62 */ {0.1679487789570419},
+ /* 63 */ {0.1673001788101741},
+ /* 64 */ {0.1666666666666667},
+ /* 65 */ {0.1660476462159378},
+ /* 66 */ {0.1654425539190583},
+ /* 67 */ {0.1648508567221603},
+ /* 68 */ {0.1642720499620502},
+ /* 69 */ {0.1637056554452156},
+ /* 70 */ {0.1631512196835108},
+ /* 71 */ {0.1626083122716342},
+ /* 72 */ {0.1620765243931223},
+ /* 73 */ {0.1615554674429964},
+ /* 74 */ {0.1610447717564444},
+ /* 75 */ {0.1605440854340214},
+ /* 76 */ {0.1600530732548213},
+ /* 77 */ {0.1595714156699382},
+ /* 78 */ {0.1590988078692941},
+ /* 79 */ {0.1586349589155960},
+ /* 80 */ {0.1581795909397823},
+ /* 81 */ {0.1577324383928644},
+ /* 82 */ {0.1572932473495469},
+ /* 83 */ {0.1568617748594410},
+ /* 84 */ {0.1564377883420715},
+ /* 85 */ {0.1560210650222250},
+ /* 86 */ {0.1556113914024939},
+ /* 87 */ {0.1552085627701551},
+ /* 88 */ {0.1548123827357682},
+ /* 89 */ {0.1544226628011101},
+ /* 90 */ {0.1540392219542636},
+ /* 91 */ {0.1536618862898642},
+ /* 92 */ {0.1532904886526781},
+ /* 93 */ {0.1529248683028321},
+ /* 94 */ {0.1525648706011593},
+ /* 95 */ {0.1522103467132434},
+ /* 96 */ {0.1518611533308632},
+ /* 97 */ {0.1515171524096389},
+ /* 98 */ {0.1511782109217764},
+ /* 99 */ {0.1508442006228941},
+ /* 100 */ {0.1505149978319906},
+ /* 101 */ {0.1501904832236880},
+ /* 102 */ {0.1498705416319474},
+ /* 103 */ {0.1495550618645152},
+ /* 104 */ {0.1492439365274121},
+ /* 105 */ {0.1489370618588283},
+ /* 106 */ {0.1486343375718350},
+ /* 107 */ {0.1483356667053617},
+ /* 108 */ {0.1480409554829326},
+ /* 109 */ {0.1477501131786861},
+ /* 110 */ {0.1474630519902391},
+ /* 111 */ {0.1471796869179852},
+ /* 112 */ {0.1468999356504447},
+ /* 113 */ {0.1466237184553111},
+ /* 114 */ {0.1463509580758620},
+ /* 115 */ {0.1460815796324244},
+ /* 116 */ {0.1458155105286054},
+ /* 117 */ {0.1455526803620167},
+ /* 118 */ {0.1452930208392429},
+ /* 119 */ {0.1450364656948130},
+ /* 120 */ {0.1447829506139581},
+ /* 121 */ {0.1445324131589439},
+ /* 122 */ {0.1442847926987864},
+ /* 123 */ {0.1440400303421672},
+ /* 124 */ {0.1437980688733776},
+ /* 125 */ {0.1435588526911310},
+ /* 126 */ {0.1433223277500932},
+ /* 127 */ {0.1430884415049874},
+ /* 128 */ {0.1428571428571428},
+ /* 129 */ {0.1426283821033600},
+ /* 130 */ {0.1424021108869747},
+ /* 131 */ {0.1421782821510107},
+ /* 132 */ {0.1419568500933153},
+ /* 133 */ {0.1417377701235801},
+ /* 134 */ {0.1415209988221527},
+ /* 135 */ {0.1413064939005528},
+ /* 136 */ {0.1410942141636095},
+ /* 137 */ {0.1408841194731412},
+ /* 138 */ {0.1406761707131039},
+ /* 139 */ {0.1404703297561400},
+ /* 140 */ {0.1402665594314587},
+ /* 141 */ {0.1400648234939879},
+ /* 142 */ {0.1398650865947379},
+ /* 143 */ {0.1396673142523192},
+ /* 144 */ {0.1394714728255649},
+ /* 145 */ {0.1392775294872041},
+ /* 146 */ {0.1390854521985406},
+ /* 147 */ {0.1388952096850913},
+ /* 148 */ {0.1387067714131417},
+ /* 149 */ {0.1385201075671774},
+ /* 150 */ {0.1383351890281539},
+ /* 151 */ {0.1381519873525671},
+ /* 152 */ {0.1379704747522905},
+ /* 153 */ {0.1377906240751463},
+ /* 154 */ {0.1376124087861776},
+ /* 155 */ {0.1374358029495937},
+ /* 156 */ {0.1372607812113589},
+ /* 157 */ {0.1370873187823978},
+ /* 158 */ {0.1369153914223921},
+ /* 159 */ {0.1367449754241439},
+ /* 160 */ {0.1365760475984821},
+ /* 161 */ {0.1364085852596902},
+ /* 162 */ {0.1362425662114337},
+ /* 163 */ {0.1360779687331669},
+ /* 164 */ {0.1359147715670014},
+ /* 165 */ {0.1357529539050150},
+ /* 166 */ {0.1355924953769864},
+ /* 167 */ {0.1354333760385373},
+ /* 168 */ {0.1352755763596663},
+ /* 169 */ {0.1351190772136599},
+ /* 170 */ {0.1349638598663645},
+ /* 171 */ {0.1348099059658080},
+ /* 172 */ {0.1346571975321549},
+ /* 173 */ {0.1345057169479844},
+ /* 174 */ {0.1343554469488779},
+ /* 175 */ {0.1342063706143054},
+ /* 176 */ {0.1340584713587979},
+ /* 177 */ {0.1339117329233981},
+ /* 178 */ {0.1337661393673756},
+ /* 179 */ {0.1336216750601996},
+ /* 180 */ {0.1334783246737591},
+ /* 181 */ {0.1333360731748201},
+ /* 182 */ {0.1331949058177136},
+ /* 183 */ {0.1330548081372441},
+ /* 184 */ {0.1329157659418126},
+ /* 185 */ {0.1327777653067443},
+ /* 186 */ {0.1326407925678156},
+ /* 187 */ {0.1325048343149731},
+ /* 188 */ {0.1323698773862368},
+ /* 189 */ {0.1322359088617821},
+ /* 190 */ {0.1321029160581950},
+ /* 191 */ {0.1319708865228925},
+ /* 192 */ {0.1318398080287045},
+ /* 193 */ {0.1317096685686114},
+ /* 194 */ {0.1315804563506306},
+ /* 195 */ {0.1314521597928493},
+ /* 196 */ {0.1313247675185968},
+ /* 197 */ {0.1311982683517524},
+ /* 198 */ {0.1310726513121843},
+ /* 199 */ {0.1309479056113158},
+ /* 200 */ {0.1308240206478128},
+ /* 201 */ {0.1307009860033912},
+ /* 202 */ {0.1305787914387386},
+ /* 203 */ {0.1304574268895465},
+ /* 204 */ {0.1303368824626505},
+ /* 205 */ {0.1302171484322746},
+ /* 206 */ {0.1300982152363760},
+ /* 207 */ {0.1299800734730872},
+ /* 208 */ {0.1298627138972530},
+ /* 209 */ {0.1297461274170591},
+ /* 210 */ {0.1296303050907487},
+ /* 211 */ {0.1295152381234257},
+ /* 212 */ {0.1294009178639407},
+ /* 213 */ {0.1292873358018581},
+ /* 214 */ {0.1291744835645007},
+ /* 215 */ {0.1290623529140715},
+ /* 216 */ {0.1289509357448472},
+ /* 217 */ {0.1288402240804449},
+ /* 218 */ {0.1287302100711566},
+ /* 219 */ {0.1286208859913518},
+ /* 220 */ {0.1285122442369443},
+ /* 221 */ {0.1284042773229231},
+ /* 222 */ {0.1282969778809442},
+ /* 223 */ {0.1281903386569819},
+ /* 224 */ {0.1280843525090381},
+ /* 225 */ {0.1279790124049077},
+ /* 226 */ {0.1278743114199984},
+ /* 227 */ {0.1277702427352035},
+ /* 228 */ {0.1276667996348261},
+ /* 229 */ {0.1275639755045533},
+ /* 230 */ {0.1274617638294791},
+ /* 231 */ {0.1273601581921740},
+ /* 232 */ {0.1272591522708010},
+ /* 233 */ {0.1271587398372755},
+ /* 234 */ {0.1270589147554692},
+ /* 235 */ {0.1269596709794558},
+ /* 236 */ {0.1268610025517973},
+ /* 237 */ {0.1267629036018709},
+ /* 238 */ {0.1266653683442337},
+ /* 239 */ {0.1265683910770258},
+ /* 240 */ {0.1264719661804097},
+ /* 241 */ {0.1263760881150453},
+ /* 242 */ {0.1262807514205999},
+ /* 243 */ {0.1261859507142915},
+ /* 244 */ {0.1260916806894653},
+ /* 245 */ {0.1259979361142023},
+ /* 246 */ {0.1259047118299582},
+ /* 247 */ {0.1258120027502338},
+ /* 248 */ {0.1257198038592741},
+ /* 249 */ {0.1256281102107963},
+ /* 250 */ {0.1255369169267456},
+ /* 251 */ {0.1254462191960791},
+ /* 252 */ {0.1253560122735751},
+ /* 253 */ {0.1252662914786691},
+ /* 254 */ {0.1251770521943144},
+ /* 255 */ {0.1250882898658681},
+ /* 256 */ {0.1250000000000000},
+};
+
+void
+mpfr_assert_fail (const char *filename, int linenum,
+ const char *expr)
+{
+ if (filename != NULL && filename[0] != '\0')
+ {
+ fprintf (stderr, "%s:", filename);
+ if (linenum != -1)
+ fprintf (stderr, "%d: ", linenum);
+ }
+ fprintf (stderr, " assertion failed: %s\n", expr);
+ abort();
+}
+
+void
+mpfr_rand_raw (mp_ptr mp, gmp_randstate_t rstate, unsigned long int nbits)
+{
+ mpz_t z;
+
+ /* To be sure to avoid the potential allocation of mpz_urandomb */
+ ALLOC(z) = SIZ(z) = (nbits / GMP_NUMB_BITS) + 1;
+ PTR(z) = mp;
+ mpz_urandomb(z, rstate, nbits);
+}
+
+
+void * (*mpfr_allocate_func) (size_t) = mpfr_default_allocate;
+void * (*mpfr_reallocate_func)(void*,size_t,size_t) = mpfr_default_reallocate;
+void (*mpfr_free_func) (void*,size_t) = mpfr_default_free;
+
+void *
+mpfr_default_allocate (size_t size)
+{
+ void *ret;
+ ret = malloc (size);
+ if (ret == NULL)
+ {
+ fprintf (stderr, "MPFR: Can't allocate memory (size=%lu)\n",
+ (unsigned long) size);
+ abort ();
+ }
+ return ret;
+}
+
+void *
+mpfr_default_reallocate (void *oldptr, size_t old_size, size_t new_size)
+{
+ void *ret;
+ ret = realloc (oldptr, new_size);
+ if (ret == NULL)
+ {
+ fprintf (stderr,
+ "MPFR: Can't reallocate memory (old_size=%lu new_size=\%lu)\n",
+ (unsigned long) old_size, (unsigned long) new_size);
+ abort ();
+ }
+ return ret;
+}
+
+void
+mpfr_default_free (void *blk_ptr, size_t blk_size)
+{
+ free (blk_ptr);
+}
+
+void
+mpfr_set_memory_functions (void *(*alloc_func) (size_t),
+ void *(*realloc_func) (void *, size_t, size_t),
+ void (*free_func) (void *, size_t))
+{
+ if (alloc_func == ((void*(*)(size_t)) 0))
+ alloc_func = mpfr_default_allocate;
+ if (realloc_func == ((void*(*)(void*,size_t,size_t))0))
+ realloc_func = mpfr_default_reallocate;
+ if (free_func == ((void(*)(void*,size_t))0))
+ free_func = mpfr_default_free;
+
+ __gmp_allocate_func = alloc_func;
+ __gmp_reallocate_func = realloc_func;
+ __gmp_free_func = free_func;
+}
+
+#endif
+
diff --git a/mpfr-gmp.h b/mpfr-gmp.h
new file mode 100644
index 000000000..746a1704c
--- /dev/null
+++ b/mpfr-gmp.h
@@ -0,0 +1,267 @@
+/* Interface to replace gmp-impl.h
+
+Copyright 2004 Free Software Foundation, Inc.
+
+This file is part of the MPFR Library.
+
+The MPFR Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPFR Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPFR Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#ifndef __GMPFR_GMP_H__
+#define __GMPFR_GMP_H__
+
+#ifndef __MPFR_IMPL_H__
+# error "mpfr-impl.h not included"
+#endif
+
+#include <limits.h> /* For INT_MAX, ... */
+#include <string.h> /* For memcpy, memset and memmove*/
+
+/* The following tries to get a good version of alloca.
+ See gmp-impl.h for implementation details */
+#ifndef alloca
+# if defined ( __GNUC__ )
+# define alloca __builtin_alloca
+# elif defined (__DECC)
+# define alloca(x) __ALLOCA(x)
+# elif defined (_MSC_VER)
+# include <malloc.h>
+# define alloca _alloca
+# elif defined (HAVE_ALLOCA_H)
+# include <alloca.h>
+# elif defined (_AIX) || defined (_IBMR2)
+ #pragma alloca
+# else
+char *alloca ();
+# endif
+#endif
+
+/* Define BITS_PER_MP_LIMB
+ Can't use sizeof(mp_limb_t) since it should be a preprocessor constant */
+#if defined(GMP_NUMB_BITS) /* GMP 4.1.2 or above */
+# define BITS_PER_MP_LIMB (GMP_NUMB_BITS+GMP_NAIL_BITS)
+#elif defined (__GMP_BITS_PER_MP_LIMB) /* Older versions 4.x.x */
+# define BITS_PER_MP_LIMB __GMP_BITS_PER_MP_LIMB
+# define GMP_NUMB_BITS BITS_PER_MP_LIMB
+# ifndef GMP_NAIL_BITS
+# define GMP_NAIL_BITS 0
+# endif
+#else
+# error "Could not detect BITS_PER_MP_LIMB. Try with gmp internal files."
+#endif
+
+/* Define some macros */
+#define BYTES_PER_MP_LIMB (BITS_PER_MP_LIMB/CHAR_BIT)
+
+#define MP_LIMB_T_MAX (~(mp_limb_t)0)
+
+#define ULONG_HIGHBIT (ULONG_MAX ^ ((unsigned long) ULONG_MAX >> 1))
+#define UINT_HIGHBIT (UINT_MAX ^ ((unsigned) UINT_MAX >> 1))
+#define USHRT_HIGHBIT ((unsigned short) (USHRT_MAX ^ ((unsigned short) USHRT_MAX >> 1)))
+
+#define GMP_LIMB_HIGHBIT (MP_LIMB_T_MAX ^ (MP_LIMB_T_MAX >> 1))
+
+
+#if __GMP_MP_SIZE_T_INT
+#define MP_SIZE_T_MAX INT_MAX
+#define MP_SIZE_T_MIN INT_MIN
+#else
+#define MP_SIZE_T_MAX LONG_MAX
+#define MP_SIZE_T_MIN LONG_MIN
+#endif
+
+#define LONG_HIGHBIT LONG_MIN
+#define INT_HIGHBIT INT_MIN
+#define SHRT_HIGHBIT SHRT_MIN
+
+/* MP_LIMB macros */
+#define MPN_ZERO(dst, n) memset((dst), 0, (n)*BYTES_PER_MP_LIMB)
+#define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
+#define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
+#define MPN_COPY(dst,src,n) memcpy((dst),(src),(n)*BYTES_PER_MP_LIMB)
+
+/* MPN macros taken from gmp-impl.h */
+#define MPN_NORMALIZE(DST, NLIMBS) \
+ do { \
+ while (NLIMBS > 0) \
+ { \
+ if ((DST)[(NLIMBS) - 1] != 0) \
+ break; \
+ NLIMBS--; \
+ } \
+ } while (0)
+#define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \
+ do { \
+ MPFR_ASSERTD ((NLIMBS) >= 1); \
+ while (1) \
+ { \
+ if ((DST)[(NLIMBS) - 1] != 0) \
+ break; \
+ NLIMBS--; \
+ } \
+ } while (0)
+#define MPN_OVERLAP_P(xp, xsize, yp, ysize) \
+ ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp))
+#define MPN_SAME_OR_INCR2_P(dst, dsize, src, ssize) \
+ ((dst) <= (src) || ! MPN_OVERLAP_P (dst, dsize, src, ssize))
+#define MPN_SAME_OR_INCR_P(dst, src, size) \
+ MPN_SAME_OR_INCR2_P(dst, size, src, size)
+#define MPN_SAME_OR_DECR2_P(dst, dsize, src, ssize) \
+ ((dst) >= (src) || ! MPN_OVERLAP_P (dst, dsize, src, ssize))
+#define MPN_SAME_OR_DECR_P(dst, src, size) \
+ MPN_SAME_OR_DECR2_P(dst, size, src, size)
+
+/* If sqr_n is not exported, used mpn_mul_n instead */
+#ifndef mpn_sqr_n
+# define mpn_sqr_n(dst,src,n) mpn_mul_n((dst),(src),(src),(n))
+#endif
+
+/* ASSERT */
+void mpfr_assert_fail _MPFR_PROTO((const char *filename, int linenum, const char *expr));
+
+#define ASSERT_FAIL(expr) mpfr_assert_fail (__FILE__, __LINE__, #expr)
+#define ASSERT(expr) MPFR_ASSERTD(expr)
+
+/* Access fileds of GMP struct */
+#define SIZ(x) ((x)->_mp_size)
+#define ABSIZ(x) ABS (SIZ (x))
+#define PTR(x) ((x)->_mp_d)
+#define LIMBS(x) ((x)->_mp_d)
+#define EXP(x) ((x)->_mp_exp)
+#define PREC(x) ((x)->_mp_prec)
+#define ALLOC(x) ((x)->_mp_alloc)
+#define MPZ_REALLOC(z,n) ((n) > ALLOC(z) ? _mpz_realloc(z,n) : PTR(z))
+
+/* Non IEEE float supports */
+#undef XDEBUG
+#define XDEBUG
+
+/* Temp memory allocate */
+#define TMP_DECL(m)
+#define TMP_ALLOC(x) alloca(x)
+#define TMP_MARK(m)
+#define TMP_FREE(m)
+
+/* For longlong.h */
+#ifdef HAVE_ATTRIBUTE_MODE
+typedef unsigned int UQItype __attribute__ ((mode (QI)));
+typedef int SItype __attribute__ ((mode (SI)));
+typedef unsigned int USItype __attribute__ ((mode (SI)));
+typedef int DItype __attribute__ ((mode (DI)));
+typedef unsigned int UDItype __attribute__ ((mode (DI)));
+#else
+typedef unsigned char UQItype;
+typedef long SItype;
+typedef unsigned long USItype;
+#ifdef HAVE_LONG_LONG
+typedef long long int DItype;
+typedef unsigned long long int UDItype;
+#else /* Assume `long' gives us a wide enough type. Needed for hppa2.0w. */
+typedef long int DItype;
+typedef unsigned long int UDItype;
+#endif
+#endif
+typedef mp_limb_t UWtype;
+typedef unsigned int UHWtype;
+#define W_TYPE_SIZE BITS_PER_MP_LIMB
+
+/* Remap names of internal mpn functions (for longlong.h). */
+#undef __clz_tab
+#define __clz_tab mpfr_clz_tab
+
+/* Use (4.0 * ...) instead of (2.0 * ...) to work around buggy compilers
+ that don't convert ulong->double correctly (eg. SunOS 4 native cc). */
+#undef MP_BASE_AS_DOUBLE
+#define MP_BASE_AS_DOUBLE (4.0 * ((mp_limb_t) 1 << (GMP_NUMB_BITS - 2)))
+
+/* Structure for conversion between internal binary format and
+ strings in base 2..36. */
+struct bases
+{
+ /* log(2)/log(conversion_base) */
+ double chars_per_bit_exactly;
+};
+#undef __mp_bases
+#define __mp_bases mpfr_bases
+extern const struct bases __mp_bases[257];
+
+/* Standard macros */
+#undef ABS
+#undef MIN
+#undef MAX
+#undef numberof
+#define ABS(x) ((x) >= 0 ? (x) : -(x))
+#define MIN(l,o) ((l) < (o) ? (l) : (o))
+#define MAX(h,i) ((h) > (i) ? (h) : (i))
+#define numberof(x) (sizeof (x) / sizeof ((x)[0]))
+
+/* Random */
+#undef __gmp_rands_initialized
+#undef __gmp_rands
+#define __gmp_rands_initialized mpfr_rands_initialized
+#define __gmp_rands mpfr_rands
+
+extern char __gmp_rands_initialized;
+extern gmp_randstate_t __gmp_rands;
+
+#undef RANDS
+#define RANDS \
+ ((__gmp_rands_initialized ? 0 \
+ : (__gmp_rands_initialized = 1, \
+ gmp_randinit_default (__gmp_rands), 0)), \
+ __gmp_rands)
+
+#undef RANDS_CLEAR
+#define RANDS_CLEAR() \
+ do { \
+ if (__gmp_rands_initialized) \
+ { \
+ __gmp_rands_initialized = 0; \
+ gmp_randclear (__gmp_rands); \
+ } \
+ } while (0)
+
+typedef __gmp_randstate_struct *gmp_randstate_ptr;
+
+#undef _gmp_rand
+#define _gmp_rand mpfr_rand_raw
+void _gmp_rand _MPFR_PROTO((mp_ptr, gmp_randstate_t, unsigned long int));
+
+/* Allocate func (define as internal in gmp) */
+#undef __gmp_allocate_func
+#undef __gmp_reallocate_func
+#undef __gmp_free_func
+#undef __gmp_default_allocate
+#undef __gmp_default_reallocate
+#undef __gmp_default_free
+#undef mp_set_memory_functions
+#define __gmp_allocate_func mpfr_allocate_func
+#define __gmp_reallocate_func mpfr_reallocate_func
+#define __gmp_free_func mpfr_free_func
+#define __gmp_default_allocate mpfr_default_allocate
+#define __gmp_default_reallocate mpfr_default_reallocate
+#define __gmp_default_free mpfr_default_free
+#define mp_set_memory_functions mpfr_set_memory_functions
+extern void * (*__gmp_allocate_func) _MPFR_PROTO ((size_t));
+extern void * (*__gmp_reallocate_func) _MPFR_PROTO ((void *, size_t, size_t));
+extern void (*__gmp_free_func) _MPFR_PROTO ((void *, size_t));
+void *__gmp_default_allocate _MPFR_PROTO ((size_t));
+void *__gmp_default_reallocate _MPFR_PROTO ((void *, size_t, size_t));
+void __gmp_default_free _MPFR_PROTO ((void *, size_t));
+void mp_set_memory_functions _MPFR_PROTO ((void *(*) (size_t),
+ void *(*) (void *, size_t, size_t),
+ void (*) (void *, size_t)));
+
+#endif /* Gmp internal emulator */
diff --git a/mpfr-impl.h b/mpfr-impl.h
index 3475fd4b0..4f0361dd2 100644
--- a/mpfr-impl.h
+++ b/mpfr-impl.h
@@ -22,25 +22,38 @@ MA 02111-1307, USA. */
#ifndef __MPFR_IMPL_H__
#define __MPFR_IMPL_H__
-/* Auto-include limits.h (Before gmp-impl.h) if needed */
-#ifdef MPFR_USE_LIMITS_H
-# include <limits.h>
-#endif
+#ifdef MPFR_HAVE_GMP_IMPL /* Build with gmp internals*/
-/* Auto include local gmp.h if not included */
-#ifndef __GMP_H__
-# include "gmp.h"
-#endif
+# ifndef __GMP_H__
+# include "gmp.h"
+# endif
+# ifndef __GMP_IMPL_H__
+# include "gmp-impl.h"
+# endif
+# ifdef MPFR_NEED_LONGLONG_H
+# include "longlong.h"
+# endif
+# ifndef __MPFR_H
+# include "mpfr.h"
+# endif
-/* Auto include local gmp-impl.h if not included */
-#ifndef __GMP_IMPL_H__
-# include "gmp-impl.h"
-#endif
+#else /* Build without gmp internals */
+
+# ifndef __GMP_H__
+# include "gmp.h"
+# endif
+# ifndef __MPFR_H
+# include "mpfr.h"
+# endif
+# ifndef __GMPFR_GMP_H__
+# include "mpfr-gmp.h"
+# endif
+# ifdef MPFR_NEED_LONGLONG_H
+# include "longlong.h"
+# endif
-/* Auto include local mpfr.h if not included */
-#ifndef __MPFR_H
-# include "mpfr.h"
#endif
+#undef MPFR_NEED_LONGLONG_H
#ifndef HAVE_STRCASECMP
# define strcasecmp mpfr_strcasecmp
@@ -55,11 +68,11 @@ MA 02111-1307, USA. */
# error "MPFR doesn't support nonzero values of GMP_NAIL_BITS"
#endif
-#if (BITS_PER_MP_LIMB & (BITS_PER_MP_LIMB - 1))
-# error "BITS_PER_MP_LIMB must be a power of 2"
+#if (BITS_PER_MP_LIMB<32) || (BITS_PER_MP_LIMB & (BITS_PER_MP_LIMB - 1))
+# error "BITS_PER_MP_LIMB must be a power of 2, and >= 32"
#endif
- /* Definition of MPFR_LIMB_HIGHBIT and MPFR_LIMB_ONE */
+ /* Definition of MPFR_LIMB_HIGHBIT */
#if defined(GMP_LIMB_HIGHBIT)
# define MPFR_LIMB_HIGHBIT GMP_LIMB_HIGHBIT
#elif defined(MP_LIMB_T_HIGHBIT)
@@ -68,7 +81,10 @@ MA 02111-1307, USA. */
# error "Neither GMP_LIMB_HIGHBIT nor MP_LIMB_T_HIGHBIT defined in GMP"
#endif
-/* Use GMP macro for limb constant if it exists */
+/* Mask to get the MSB of a limb (excluding nails) */
+#define MPFR_LIMB_MSB(l) ((l)&MPFR_LIMB_HIGHBIT)
+
+/* Definition of MPFR_LIMB_ONE */
#ifdef CNST_LIMB
# define MPFR_LIMB_ONE CNST_LIMB(1)
#else
@@ -123,7 +139,7 @@ typedef unsigned long int mpfr_uexp_t;
((void) ((MPFR_UNLIKELY(expr)) || MPFR_UNLIKELY((ASSERT_FAIL (expr), 0))))
/* MPFR_ASSERTD(expr): assertions that should be checked when testing */
-#if WANT_ASSERT
+#ifdef WANT_ASSERT
# define MPFR_EXP_CHECK 1
# define MPFR_ASSERTD(expr) MPFR_ASSERTN (expr)
#else
@@ -163,7 +179,7 @@ typedef unsigned long int mpfr_uexp_t;
don't use WANT_ASSERT (for speed reasons), you can still define
MPFR_EXP_CHECK by setting -DMPFR_EXP_CHECK in $CFLAGS. */
-#if MPFR_EXP_CHECK
+#ifdef MPFR_EXP_CHECK
# define MPFR_GET_EXP(x) mpfr_get_exp (x)
# define MPFR_SET_EXP(x, exp) MPFR_ASSERTN (!mpfr_set_exp ((x), (exp)))
# define MPFR_SET_INVALID_EXP(x) ((void) (MPFR_EXP (x) = MPFR_EXP_INVALID))
@@ -209,9 +225,8 @@ typedef union ieee_double_extract Ieee_double_extract;
((((Ieee_double_extract *)&(x))->s.manl != 0) || \
(((Ieee_double_extract *)&(x))->s.manh != 0)))
#else
-# include <math.h> /* For isnan and isinf */
-# define DOUBLE_ISINF(x) (isinf(x))
-# define DOUBLE_ISNAN(x) (isnan(x))
+# define DOUBLE_ISINF(x) (((x)==((double)+1.0/0.0))||((x)==((double)-1.0/0.0)))
+# define DOUBLE_ISNAN(x) ((x)!=(x))
#endif
#define DBL_POS_INF (1.0/0.0)
@@ -229,7 +244,7 @@ typedef union ieee_double_extract Ieee_double_extract;
/* Various i386 systems have been seen with incorrect LDBL constants in
float.h (notes in set_ld.c), so force the value we know is right for IEEE
extended. */
-#if HAVE_LDOUBLE_IEEE_EXT_LITTLE
+#ifdef HAVE_LDOUBLE_IEEE_EXT_LITTLE
# define MPFR_LDBL_MANT_DIG 64
#else
# define MPFR_LDBL_MANT_DIG LDBL_MANT_DIG
@@ -241,7 +256,7 @@ typedef union ieee_double_extract Ieee_double_extract;
has been seen false, meaning NaNs are not detected. This seemed to
happen only after other comparisons, not sure what's really going on. In
any case we can pick apart the bytes to identify a NaN. */
-#if HAVE_LDOUBLE_IEEE_QUAD_BIG
+#ifdef HAVE_LDOUBLE_IEEE_QUAD_BIG
# define LONGDOUBLE_NAN_ACTION(x, action) \
do { \
union { \
@@ -278,7 +293,7 @@ typedef union ieee_double_extract Ieee_double_extract;
/* If we don't have a proper "volatile" then volatile is #defined to empty,
in this case call through an external function to stop the compiler
optimizing anything. */
-#if WANT_LONGDOUBLE_VOLATILE
+#ifdef WANT_LONGDOUBLE_VOLATILE
# ifdef volatile
long double __gmpfr_longdouble_volatile _MPFR_PROTO ((long double)) ATTRIBUTE_CONST;
# define LONGDOUBLE_VOLATILE(x) (__gmpfr_longdouble_volatile (x))
@@ -400,16 +415,17 @@ long double __gmpfr_longdouble_volatile _MPFR_PROTO ((long double)) ATTRIBUTE_CO
#define MPFR_RET_NAN return (__gmpfr_flags |= MPFR_FLAGS_NAN), 0
/* Heap Memory gestion */
+typedef union { mp_size_t s; mp_limb_t l; } mpfr_size_limb_t;
#define MPFR_GET_ALLOC_SIZE(x) \
( ((mp_size_t*) MPFR_MANT(x))[-1] + 0)
#define MPFR_SET_ALLOC_SIZE(x, n) \
( ((mp_size_t*) MPFR_MANT(x))[-1] = n)
#define MPFR_MALLOC_SIZE(s) \
- ( sizeof(mp_size_t) * 1 + BYTES_PER_MP_LIMB * ((size_t) s) )
+ ( sizeof(mpfr_size_limb_t) + BYTES_PER_MP_LIMB * ((size_t) s) )
#define MPFR_SET_MANT_PTR(x,p) \
- (MPFR_MANT(x) = (mp_limb_t*) ((mp_size_t*) p + 1))
+ (MPFR_MANT(x) = (mp_limb_t*) ((mpfr_size_limb_t*) p + 1))
#define MPFR_GET_REAL_PTR(x) \
- ((mp_limb_t*) ((mp_size_t*) MPFR_MANT(x) - 1))
+ ((mp_limb_t*) ((mpfr_size_limb_t*) MPFR_MANT(x) - 1))
/* Temporary memory gestion */
/* temporary allocate 1 limb at xp, and initialize mpfr variable x */
diff --git a/mpfr-test.h b/mpfr-test.h
index b59eecce0..0c3c1b71d 100644
--- a/mpfr-test.h
+++ b/mpfr-test.h
@@ -22,9 +22,6 @@ MA 02111-1307, USA. */
#ifndef __MPFR_TEST_H__
#define __MPFR_TEST_H__
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
#include "mpfr-impl.h"
#if HAVE_CONFIG_H
@@ -39,7 +36,7 @@ MA 02111-1307, USA. */
#define MAXNORM 1.7976931348623157081e308 /* 2^(1023)*(2-2^(-52)) */
/* Generates a random rounding mode */
-#define RND_RAND() (randlimb() % 4)
+#define RND_RAND() (randlimb() % GMP_RND_MAX)
/* Generates a random sign */
#define SIGN_RAND() ( (randlimb()%2) ? MPFR_SIGN_POS : MPFR_SIGN_NEG)
diff --git a/mpn_exp.c b/mpn_exp.c
index 2b8abaac1..0fe89febe 100644
--- a/mpn_exp.c
+++ b/mpn_exp.c
@@ -20,10 +20,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* this function computes an approximation of b^e in {a, n}, with exponent
diff --git a/mul.c b/mul.c
index d7b180dc5..c12dc8375 100644
--- a/mul.c
+++ b/mul.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/mul_2exp.c b/mul_2exp.c
index 8e47da840..9b552aaa2 100644
--- a/mul_2exp.c
+++ b/mul_2exp.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* Obsolete function, use mpfr_mul_2ui or mpfr_mul_2si instead. */
diff --git a/mul_2si.c b/mul_2si.c
index 96f3a1ebc..536fe7c63 100644
--- a/mul_2si.c
+++ b/mul_2si.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/mul_2ui.c b/mul_2ui.c
index c32acf5f4..f71bd7fc5 100644
--- a/mul_2ui.c
+++ b/mul_2ui.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/mul_ui.c b/mul_ui.c
index 24dc483ae..1e384251e 100644
--- a/mul_ui.c
+++ b/mul_ui.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/neg.c b/neg.c
index a4f6c40cf..8278bb454 100644
--- a/neg.c
+++ b/neg.c
@@ -20,8 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/next.c b/next.c
index fc400544d..847ea505b 100644
--- a/next.c
+++ b/next.c
@@ -21,9 +21,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
static void
diff --git a/out_str.c b/out_str.c
index 215734b0c..07ee037bf 100644
--- a/out_str.c
+++ b/out_str.c
@@ -22,9 +22,7 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <string.h>
#include <limits.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
size_t
diff --git a/pow.c b/pow.c
index 289abe138..a84062884 100644
--- a/pow.c
+++ b/pow.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* return non zero iff x^y is exact.
diff --git a/pow_si.c b/pow_si.c
index 5ce846dbf..c197806f6 100644
--- a/pow_si.c
+++ b/pow_si.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of y=pow(x,z) is done by
diff --git a/pow_ui.c b/pow_ui.c
index 3e6b76cab..85c600737 100644
--- a/pow_ui.c
+++ b/pow_ui.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* sets x to y^n, and return 0 if exact, non-zero otherwise */
diff --git a/powerof2.c b/powerof2.c
index 9326d5811..22605aeb9 100644
--- a/powerof2.c
+++ b/powerof2.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* This is an internal function and one assumes that x is a real number. */
diff --git a/print_rnd_mode.c b/print_rnd_mode.c
index b9b9bace5..49d33a449 100644
--- a/print_rnd_mode.c
+++ b/print_rnd_mode.c
@@ -19,8 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "mpfr.h"
+#include "mpfr-impl.h"
const char *
mpfr_print_rnd_mode (mp_rnd_t rnd_mode)
@@ -35,7 +34,7 @@ mpfr_print_rnd_mode (mp_rnd_t rnd_mode)
return "GMP_RNDN";
case GMP_RNDZ:
return "GMP_RNDZ";
+ default:
+ return (const char*) 0;
}
-
- return (char *) 0;
}
diff --git a/random.c b/random.c
index fc80ed532..7825c9b4b 100644
--- a/random.c
+++ b/random.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* Computes a random mpfr in [0, 1[ with precision MPFR_PREC */
diff --git a/random2.c b/random2.c
index e65d2bf66..cf5ad4b23 100644
--- a/random2.c
+++ b/random2.c
@@ -22,10 +22,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
void
@@ -40,7 +38,7 @@ mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp)
MPFR_CLEAR_FLAGS(x);
MPFR_SET_POS(x);
xn = ABS (size);
- prec = (MPFR_PREC(x) - 1) / GMP_NUMB_BITS;
+ prec = (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
xp = MPFR_MANT(x);
if (xn == 0)
@@ -59,11 +57,11 @@ mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp)
xp[xn - 1] |= MPFR_LIMB_HIGHBIT;
/* Generate random exponent. */
- _gmp_rand (&elimb, RANDS, GMP_NUMB_BITS);
+ _gmp_rand (&elimb, RANDS, BITS_PER_MP_LIMB);
exp = ABS (exp);
MPFR_SET_EXP (x, elimb % (2 * exp + 1) - exp);
/* Mask off non significant bits in the low limb. */
- cnt = xn * GMP_NUMB_BITS - MPFR_PREC(x);
+ cnt = xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
xp[0] &= ~((MP_LIMB_T_ONE << cnt) - 1);
}
diff --git a/reldiff.c b/reldiff.c
index df2a467bb..b381af5c4 100644
--- a/reldiff.c
+++ b/reldiff.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* reldiff(b, c) = abs(b-c)/b */
diff --git a/rint.c b/rint.c
index 6a5a4a0c4..905d91285 100644
--- a/rint.c
+++ b/rint.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* This may be a standard rounding mode in the future. */
diff --git a/round_prec.c b/round_prec.c
index 15fcc3c52..c2c5d5d0a 100644
--- a/round_prec.c
+++ b/round_prec.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
#define mpfr_round_raw_generic mpfr_round_raw
diff --git a/save_expo.c b/save_expo.c
index 33c4d70d3..0cffd74f7 100644
--- a/save_expo.c
+++ b/save_expo.c
@@ -19,8 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
static unsigned int saved_flags;
diff --git a/set.c b/set.c
index f53a78fdd..50ac2511d 100644
--- a/set.c
+++ b/set.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* set a to abs(b) * signb: a=b when signb = SIGN(b), a=abs(b) when signb=1 */
diff --git a/set_d.c b/set_d.c
index f3c928617..a5176730f 100644
--- a/set_d.c
+++ b/set_d.c
@@ -20,10 +20,9 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+#include <string.h> /* For memcmp if _GMP_IEEE_FLOAT == 0 */
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
#if (BITS_PER_MP_LIMB==32)
@@ -66,7 +65,7 @@ __mpfr_extract_double (mp_ptr rp, double d)
exp = x.s.exp;
if (exp)
{
-#if BITS_PER_MP_LIMB == 64
+#if BITS_PER_MP_LIMB >= 64
manl = ((MP_LIMB_T_ONE << 63)
| ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11));
#else
@@ -76,7 +75,7 @@ __mpfr_extract_double (mp_ptr rp, double d)
}
else /* denormalized number */
{
-#if BITS_PER_MP_LIMB == 64
+#if BITS_PER_MP_LIMB >= 64
manl = ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11);
#else
manh = (x.s.manh << 11) /* high 21 bits */
@@ -125,7 +124,7 @@ __mpfr_extract_double (mp_ptr rp, double d)
}
d *= MP_BASE_AS_DOUBLE;
-#if BITS_PER_MP_LIMB == 64
+#if BITS_PER_MP_LIMB >= 64
manl = d;
#else
manh = d;
@@ -135,7 +134,7 @@ __mpfr_extract_double (mp_ptr rp, double d)
#endif /* _GMP_IEEE_FLOATS */
-#if BITS_PER_MP_LIMB == 64
+#if BITS_PER_MP_LIMB >= 64
rp[0] = manl;
#else
rp[1] = manh;
diff --git a/set_dfl_prec.c b/set_dfl_prec.c
index 27ae0cd1a..6a1a13773 100644
--- a/set_dfl_prec.c
+++ b/set_dfl_prec.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* default is IEEE double precision, i.e. 53 bits */
diff --git a/set_exp.c b/set_exp.c
index 8fc628554..f30bd3af9 100644
--- a/set_exp.c
+++ b/set_exp.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/set_f.c b/set_f.c
index 39f628af6..2525758e5 100644
--- a/set_f.c
+++ b/set_f.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/set_inf.c b/set_inf.c
index 59eee2a1d..f7afc3bb8 100644
--- a/set_inf.c
+++ b/set_inf.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
void
diff --git a/set_nan.c b/set_nan.c
index a32694487..8f6978175 100644
--- a/set_nan.c
+++ b/set_nan.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
void
diff --git a/set_prc_raw.c b/set_prc_raw.c
index aa1eb5afe..13b2a72ad 100644
--- a/set_prc_raw.c
+++ b/set_prc_raw.c
@@ -19,9 +19,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
#include "mpfr-impl.h"
void
diff --git a/set_prec.c b/set_prec.c
index 7a01cbd8a..87ef0c32b 100644
--- a/set_prec.c
+++ b/set_prec.c
@@ -19,9 +19,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
#include "mpfr-impl.h"
void
diff --git a/set_q.c b/set_q.c
index 24bf35176..8e17e1698 100644
--- a/set_q.c
+++ b/set_q.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* set f to the rational q */
diff --git a/set_rnd.c b/set_rnd.c
index 6505463a1..3d0dc6ff3 100644
--- a/set_rnd.c
+++ b/set_rnd.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
mp_rnd_t __gmpfr_default_rounding_mode = GMP_RNDN;
diff --git a/set_si.c b/set_si.c
index c0847c98e..e48b4454d 100644
--- a/set_si.c
+++ b/set_si.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/set_str.c b/set_str.c
index 108122e1a..6903618e5 100644
--- a/set_str.c
+++ b/set_str.c
@@ -22,10 +22,8 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
#include "log_b2.h"
diff --git a/set_str_raw.c b/set_str_raw.c
index 03bcead14..9704651a4 100644
--- a/set_str_raw.c
+++ b/set_str_raw.c
@@ -22,10 +22,8 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* Currently the number should be of the form +/- xxxx.xxxxxxEyy, with
diff --git a/set_ui.c b/set_ui.c
index bdcced2c0..ddff4909d 100644
--- a/set_ui.c
+++ b/set_ui.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/set_z.c b/set_z.c
index 95bfbc92f..70b02d116 100644
--- a/set_z.c
+++ b/set_z.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
/* set f to the integer z */
diff --git a/setmax.c b/setmax.c
index 5c09361ae..8386e1545 100644
--- a/setmax.c
+++ b/setmax.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* Note: the flags are not cleared and the current sign is kept. */
diff --git a/setmin.c b/setmin.c
index 5cb80d081..1804c6987 100644
--- a/setmin.c
+++ b/setmin.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* Note: the flags are not cleared and the current sign is kept. */
diff --git a/sgn.c b/sgn.c
index 1c7cdcea0..1f326eeeb 100644
--- a/sgn.c
+++ b/sgn.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/sin.c b/sin.c
index 0f830cfb7..432141391 100644
--- a/sin.c
+++ b/sin.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* determine the sign of sin(x) using argument reduction.
diff --git a/sin_cos.c b/sin_cos.c
index d0c211c2c..c5867ee9c 100644
--- a/sin_cos.c
+++ b/sin_cos.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* (y, z) <- (sin(x), cos(x)), return value is 0 iff both results are exact */
diff --git a/sinh.c b/sinh.c
index b1afab725..f5bacc243 100644
--- a/sinh.c
+++ b/sinh.c
@@ -20,9 +20,7 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of sinh is done by
diff --git a/sqrt.c b/sqrt.c
index d2d378ce8..1061a8bfe 100644
--- a/sqrt.c
+++ b/sqrt.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* #define DEBUG */
@@ -252,6 +250,9 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
t != 0 ?
MP_LIMB_T_ONE << (BITS_PER_MP_LIMB - t) :
MP_LIMB_T_ONE);
+ break;
+ default:
+ MPFR_ASSERTN(0);
}
}
diff --git a/sqrt_ui.c b/sqrt_ui.c
index 4b59e086d..c16eb42fc 100644
--- a/sqrt_ui.c
+++ b/sqrt_ui.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/sub.c b/sub.c
index aecfc7429..3d2b5e5ab 100644
--- a/sub.c
+++ b/sub.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/sub1.c b/sub1.c
index 0c37684d0..28f2c63bf 100644
--- a/sub1.c
+++ b/sub1.c
@@ -20,9 +20,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* compute sign(b) * (|b| - |c|), with |b| > |c|, diff_exp = EXP(b) - EXP(c)
diff --git a/sub1sp.c b/sub1sp.c
index 326c60bf0..7c874f54c 100644
--- a/sub1sp.c
+++ b/sub1sp.c
@@ -22,8 +22,9 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
-#include "longlong.h"
/*
compute sgn(b)*(|b| - |c|) if |b|>|c| else -sgn(b)*(|c| -|b|)
@@ -583,7 +584,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* Normalize: we lose at max one bit*/
limb = ap[n-1];
- if (MPFR_UNLIKELY(limb < ~limb))
+ if (MPFR_UNLIKELY(!MPFR_LIMB_MSB(limb)))
{
/* High bit is not set and we have to fix it! */
/* Ap >= 010000xxx001 */
@@ -593,7 +594,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* Since Cp == -1, we have to substract one more */
{
mpn_sub_1(ap, ap, n, MPFR_LIMB_ONE<<sh);
- MPFR_ASSERTD(ap[n-1] > ~ap[n-1]);
+ MPFR_ASSERTD(MPFR_LIMB_MSB(ap[n-1]));
}
/* Ap >= 10000xxx001 */
/* Final exponent -1 since we have shifted the mantissa */
@@ -632,7 +633,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
inexact = -1;
/* Check normalisation */
limb = ap[n-1];
- if (MPFR_UNLIKELY(limb < ~limb))
+ if (MPFR_UNLIKELY(!MPFR_LIMB_MSB(limb)))
{
/* ap was a power of 2, and we lose a bit */
/* Now it is 0111111111111111111[00000 */
@@ -645,9 +646,9 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
DEBUG( printf("(SubOneUlp)Cp=%lu, Cp+1=%lu C'p+1=%lu\n", bcp,bbcp,bcp1));
/* Compute the last bit (Since we have shifted the mantissa)
we need one more bit!*/
- if ((rnd_mode == GMP_RNDZ && bcp==0)
- || (rnd_mode==GMP_RNDN && bbcp ==0)
- || (bcp && bcp1==0 )) /*Exact result*/
+ if ( (rnd_mode == GMP_RNDZ && bcp==0)
+ || (rnd_mode==GMP_RNDN && bbcp==0)
+ || (bcp && bcp1==0) ) /*Exact result*/
{
ap[0] |= MPFR_LIMB_ONE<<sh;
if (rnd_mode == GMP_RNDN)
@@ -657,7 +658,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* Result could be exact if C'p+1 = 0 and rnd == Zero
since we have had one more bit to the result */
/* Fixme: rnd_mode == GMP_RNDZ needed ? */
- if (bcp1==0 && rnd_mode == GMP_RNDZ)
+ if (bcp1==0 && rnd_mode==GMP_RNDZ)
{
DEBUG( printf("(SubOneUlp) Exact result\n") );
inexact = 0;
diff --git a/sub_one_ulp.c b/sub_one_ulp.c
index 55d80ed5f..a1cfc97e7 100644
--- a/sub_one_ulp.c
+++ b/sub_one_ulp.c
@@ -1,6 +1,6 @@
/* mpfr_sub_one_ulp -- subtract one unit in last place
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* sets x to x-sign(x)*ulp(x) */
@@ -42,8 +40,8 @@ mpfr_sub_one_ulp(mpfr_ptr x, mp_rnd_t rnd_mode)
MPFR_ASSERTN(MPFR_PREC_MIN > 1);
- xn = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
- sh = (mp_prec_t) xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
+ xn = MPFR_LIMB_SIZE(x);
+ MPFR_UNSIGNED_MINUS_MODULO(sh, MPFR_PREC(x) );
xp = MPFR_MANT(x);
mpn_sub_1 (xp, xp, xn, MP_LIMB_T_ONE << sh);
if (xp[xn-1] >> (BITS_PER_MP_LIMB - 1) == 0)
diff --git a/sub_ui.c b/sub_ui.c
index 1a9a82c5e..635672e0a 100644
--- a/sub_ui.c
+++ b/sub_ui.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/swap.c b/swap.c
index c4b3eee5e..bce94b513 100644
--- a/swap.c
+++ b/swap.c
@@ -20,8 +20,7 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <string.h>
-#include "gmp.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/*
diff --git a/tan.c b/tan.c
index 132f138d9..03ce70963 100644
--- a/tan.c
+++ b/tan.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* computes tan(x) = sign(x)*sqrt(1/cos(x)^2-1) */
diff --git a/tanh.c b/tanh.c
index fcf168f12..b837259bd 100644
--- a/tanh.c
+++ b/tanh.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* The computation of cosh is done by
diff --git a/tests/memory.c b/tests/memory.c
index a145e0328..8a2877e3d 100644
--- a/tests/memory.c
+++ b/tests/memory.c
@@ -26,8 +26,7 @@ MA 02111-1307, USA. */
#include <stdlib.h> /* for abort */
#include <limits.h>
-#include "gmp.h"
-#include "gmp-impl.h"
+
#include "mpfr-test.h"
/* Each block allocated is a separate malloc, for the benefit of a redzoning
diff --git a/tests/tacos.c b/tests/tacos.c
index aaa3a1f1a..f566de22d 100644
--- a/tests/tacos.c
+++ b/tests/tacos.c
@@ -106,7 +106,7 @@ main (void)
}
/* acos (0) = Pi/2 */
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX; r++)
{
mpfr_set_ui (x, 0, GMP_RNDN); /* exact */
mpfr_acos (y, x, r);
@@ -121,7 +121,7 @@ main (void)
}
/* acos (-1) = Pi */
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX; r++)
{
mpfr_set_si (x, -1, GMP_RNDN); /* exact */
mpfr_acos (y, x, r);
diff --git a/tests/tadd.c b/tests/tadd.c
index 8a4e956e8..ae4c980ab 100644
--- a/tests/tadd.c
+++ b/tests/tadd.c
@@ -492,7 +492,7 @@ check_inexact (void)
abs(EXP(x)-EXP(u)) + max(prec(x), prec(u)) + 1 */
pz = pz + MAX(MPFR_PREC(x), MPFR_PREC(u)) + 1;
mpfr_set_prec (z, pz);
- rnd = randlimb () % 4;
+ rnd = RND_RAND();
if (mpfr_add (z, x, u, rnd))
{
printf ("z <- x + u should be exact\n");
@@ -502,7 +502,7 @@ check_inexact (void)
exit (1);
}
{
- rnd = randlimb () % 4;
+ rnd = RND_RAND();
inexact = mpfr_add (y, x, u, rnd);
cmp = mpfr_cmp (y, z);
if (((inexact == 0) && (cmp != 0)) ||
diff --git a/tests/tasin.c b/tests/tasin.c
index e3694d9c9..12f5037d8 100644
--- a/tests/tasin.c
+++ b/tests/tasin.c
@@ -95,7 +95,7 @@ special (void)
}
/* asin(1) = Pi/2 */
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX; r++)
{
mpfr_set_ui (x, 1, GMP_RNDN); /* exact */
mpfr_asin (y, x, r);
@@ -110,7 +110,7 @@ special (void)
}
/* asin(-1) = -Pi/2 */
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX; r++)
{
mpfr_set_si (x, -1, GMP_RNDN); /* exact */
mpfr_asin (y, x, r);
diff --git a/tests/tatan.c b/tests/tatan.c
index 52e7a8b50..4967205f5 100644
--- a/tests/tatan.c
+++ b/tests/tatan.c
@@ -52,7 +52,7 @@ special (void)
}
/* atan(+Inf) = Pi/2 */
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX ; r++)
{
mpfr_set_inf (x, 1);
mpfr_atan (y, x, r);
@@ -66,7 +66,7 @@ special (void)
}
/* atan(-Inf) = - Pi/2 */
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX ; r++)
{
mpfr_set_inf (x, -1);
mpfr_atan (y, x, r);
diff --git a/tests/tcan_round.c b/tests/tcan_round.c
index f9c2b4a40..e0b1d0119 100644
--- a/tests/tcan_round.c
+++ b/tests/tcan_round.c
@@ -63,8 +63,8 @@ main (void)
for (j = 30; j < 99; j++)
{
mp_rnd_t r1, r2;
- for (r1 = 0; r1 < 4; r1++)
- for (r2 = 0; r2 < 4; r2++)
+ for (r1 = 0; r1 < GMP_RND_MAX ; r1++)
+ for (r2 = 0; r2 < GMP_RND_MAX ; r2++)
mpfr_can_round (x, i, r1, r2, j); /* test for assertions */
}
diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c
index c458cdb88..df5b7c1e8 100644
--- a/tests/tconst_log2.c
+++ b/tests/tconst_log2.c
@@ -43,7 +43,7 @@ check (mp_prec_t p0, mp_prec_t p1)
mpfr_set_prec (x, p0);
mpfr_set_prec (y, p0);
{
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
mpfr_const_log2 (x, rnd);
mpfr_set (y, z, rnd);
if (mpfr_cmp (x, y) && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN,
diff --git a/tests/tdiv.c b/tests/tdiv.c
index b565a2bbc..0093d5e95 100644
--- a/tests/tdiv.c
+++ b/tests/tdiv.c
@@ -427,7 +427,7 @@ check_inexact (void)
mpfr_set_prec (y, py);
mpfr_set_prec (z, py + pu);
{
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
inexact = mpfr_div (y, x, u, rnd);
if (mpfr_mul (z, y, u, rnd))
{
diff --git a/tests/tests.c b/tests/tests.c
index f71f6dbd5..b39506f6d 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -193,7 +193,7 @@ randlimb (void)
{
mp_limb_t limb;
- _gmp_rand (&limb, RANDS, GMP_NUMB_BITS);
+ _gmp_rand (&limb, RANDS, BITS_PER_MP_LIMB);
return limb;
}
diff --git a/tests/texceptions.c b/tests/texceptions.c
index cf13f5a44..55fb5d8b6 100644
--- a/tests/texceptions.c
+++ b/tests/texceptions.c
@@ -29,7 +29,7 @@ static void
check_default_rnd(void)
{
mp_rnd_t r, t;
- for(r = 0 ; r < 4 ; r++)
+ for(r = 0 ; r < GMP_RND_MAX ; r++)
{
mpfr_set_default_rounding_mode (r);
t = mpfr_get_default_rounding_mode();
@@ -92,7 +92,7 @@ test_set_underflow (void)
r[1] = r[3] = zero;
for (s = 1; s > 0; s = -1)
{
- for (i = 0; i < 4; i++)
+ for (i = 0; i < GMP_RND_MAX ; i++)
{
int j;
int inex;
@@ -135,7 +135,7 @@ test_set_overflow (void)
r[1] = r[3] = max;
for (s = 1; s > 0; s = -1)
{
- for (i = 0; i < 4; i++)
+ for (i = 0; i < GMP_RND_MAX ; i++)
{
int j;
int inex;
diff --git a/tests/texp.c b/tests/texp.c
index 3765ff550..ba2f9c193 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -170,7 +170,7 @@ compare_exp2_exp3 (int n)
mpfr_set_prec (y, prec);
mpfr_set_prec (z, prec);
mpfr_random (x);
- rnd = randlimb () % 4;
+ rnd = RND_RAND() ;
mpfr_exp_2 (y, x, rnd);
mpfr_exp3 (z, x, rnd);
if (mpfr_cmp (y,z))
diff --git a/tests/tfma.c b/tests/tfma.c
index e1f3cc543..051d90e00 100644
--- a/tests/tfma.c
+++ b/tests/tfma.c
@@ -273,7 +273,7 @@ main (int argc, char *argv[])
if (randlimb () % 2)
mpfr_neg (z, z, GMP_RNDN);
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
mpfr_set_prec (slong, 2 * prec);
if (mpfr_mul (slong, x, y, rnd))
{
diff --git a/tests/tfrac.c b/tests/tfrac.c
index 7f51133c6..67f2c7128 100644
--- a/tests/tfrac.c
+++ b/tests/tfrac.c
@@ -115,7 +115,7 @@ check1 (mpfr_ptr ip, mpfr_ptr fp)
{
mp_rnd_t rnd;
- for (rnd = 0; rnd < 4; rnd++)
+ for (rnd = 0; rnd < GMP_RND_MAX ; rnd++)
{
check0 (ip, fp, PMAX, rnd);
check0 (ip, fp, 70, rnd);
diff --git a/tests/tgeneric.c b/tests/tgeneric.c
index f1fc39f9e..b55cb8e1c 100644
--- a/tests/tgeneric.c
+++ b/tests/tgeneric.c
@@ -48,7 +48,7 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N)
#else
mpfr_random (x);
#endif
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
mpfr_set_prec (y, yprec);
compare = TEST_FUNCTION (y, x, rnd);
if (mpfr_can_round (y, yprec, rnd, rnd, prec))
diff --git a/tests/tget_d_2exp.c b/tests/tget_d_2exp.c
index 989f990a0..c8646c61b 100644
--- a/tests/tget_d_2exp.c
+++ b/tests/tget_d_2exp.c
@@ -39,7 +39,7 @@ check_round (void)
mpfr_init2 (f, 1024L);
- for (rnd_mode = 0; rnd_mode < 4; rnd_mode++)
+ for (rnd_mode = 0; rnd_mode < GMP_RND_MAX ; rnd_mode++)
{
for (i = 0; i < (int) numberof (data); i++)
{
diff --git a/tests/tget_str.c b/tests/tget_str.c
index 8fbbdf0f1..081ae2d92 100644
--- a/tests/tget_str.c
+++ b/tests/tget_str.c
@@ -524,7 +524,7 @@ main (int argc, char *argv[])
mpfr_set_exp (x, (e == -10) ? mpfr_get_emin () :
((e == 10) ? mpfr_get_emax () : e));
b = 2 + (randlimb () % 35);
- r = randlimb () % 4;
+ r = RND_RAND();
mpfr_get_str (s, &f, b, m, x, r);
}
mpfr_clear (x);
diff --git a/tests/tgmpop.c b/tests/tgmpop.c
index 299184b29..eecd02fe0 100644
--- a/tests/tgmpop.c
+++ b/tests/tgmpop.c
@@ -98,7 +98,7 @@ test_genericz (mp_prec_t p0, mp_prec_t p1, unsigned int N,
{
mpfr_urandomb (arg1, RANDS);
mpz_urandomb (arg2, RANDS, 1024);
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
mpfr_set_prec (dst_big, 2*prec);
compare = func(dst_big, arg1, arg2, rnd);
if (mpfr_can_round (dst_big, 2*prec, rnd, rnd, prec))
@@ -175,7 +175,7 @@ test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N,
{
mpfr_urandomb (arg1, RANDS);
mpq_set_ui (arg2, randlimb (), randlimb() );
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
mpfr_set_prec (dst_big, prec+10);
compare = func(dst_big, arg1, arg2, rnd);
if (mpfr_can_round (dst_big, prec+10, rnd, rnd, prec))
diff --git a/tests/thypot.c b/tests/thypot.c
index b17e8c7a7..a93247331 100644
--- a/tests/thypot.c
+++ b/tests/thypot.c
@@ -122,7 +122,7 @@ main (int argc, char *argv[])
mpfr_neg (x1, x1, GMP_RNDN);
if (randlimb () % 2)
mpfr_neg (x2, x2, GMP_RNDN);
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
mpfr_set_prec (y, yprec);
compare =TEST_FUNCTION (y, x1,x2, rnd);
diff --git a/tests/tmul.c b/tests/tmul.c
index aeff45690..9cd2ce08c 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -217,7 +217,7 @@ check_exact (void)
{
mpfr_random (a);
mpfr_random (b);
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
inexact = mpfr_mul (c, a, b, rnd);
if (mpfr_mul (d, a, b, rnd)) /* should be always exact */
{
diff --git a/tests/tout_str.c b/tests/tout_str.c
index 82362390f..12d222339 100644
--- a/tests/tout_str.c
+++ b/tests/tout_str.c
@@ -147,7 +147,7 @@ main (int argc, char *argv[])
#else
while (ABS(d) < DBL_MIN);
#endif
- r = randlimb () % 4;
+ r = RND_RAND ();
p = 2 + randlimb () % 35;
check (d, r, p);
}
diff --git a/tests/tpow3.c b/tests/tpow3.c
index 02010ec69..0626d51dc 100644
--- a/tests/tpow3.c
+++ b/tests/tpow3.c
@@ -65,7 +65,7 @@ main (int argc, char *argv[])
mpfr_random (s);
if (randlimb () % 2)
mpfr_neg (s, s, GMP_RNDN);
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
mpfr_set_prec (y, yprec);
compare = mpfr_pow (y, x, s, rnd);
err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
diff --git a/tests/trint.c b/tests/trint.c
index 5275a170d..a773f195c 100644
--- a/tests/trint.c
+++ b/tests/trint.c
@@ -80,13 +80,13 @@ test_fct (double (*f)(double), int (*g)(), char *s, mp_rnd_t r)
static void
test_against_libc (void)
{
- int r = 0;
+ mp_rnd_t r;
TEST_FCT (round);
TEST_FCT (trunc);
TEST_FCT (floor);
TEST_FCT (ceil);
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX ; r++)
if (mpfr_set_machine_rnd_mode (r) == 0)
test_fct (&nearbyint, &mpfr_rint, "rint", r);
}
@@ -151,7 +151,7 @@ main (int argc, char *argv[])
int trint;
mpfr_set_prec (y, p);
mpfr_set_prec (v, p);
- for (r = 0; r < 4; r++)
+ for (r = 0; r < GMP_RND_MAX ; r++)
for (trint = 0; trint < 2; trint++)
{
if (trint)
diff --git a/tests/tset_f.c b/tests/tset_f.c
index 8f1666061..37c80485c 100644
--- a/tests/tset_f.c
+++ b/tests/tset_f.c
@@ -46,7 +46,7 @@ main (void)
mpfr_set_f (x, y, GMP_RNDN);
mpf_random2(y, 10, 0);
- mpfr_set_f(x, y, randlimb () & 3);
+ mpfr_set_f(x, y, RND_RAND() );
/* bug found by Jean-Pierre Merlet */
mpfr_set_prec(x, 256);
@@ -86,7 +86,7 @@ main (void)
mpfr_set_prec(x, 53);
mpf_set_prec(y, 53);
mpf_set_ui(y, 0);
- for(r = 0 ; r < 4 ; r++)
+ for(r = 0 ; r < GMP_RND_MAX ; r++)
{
inexact = mpfr_set_f(x, y, r);
if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact)
diff --git a/tests/tset_q.c b/tests/tset_q.c
index 732b25443..02853c5e6 100644
--- a/tests/tset_q.c
+++ b/tests/tset_q.c
@@ -74,12 +74,14 @@ static void check0(void)
{
mpq_t y;
mpfr_t x;
- int inexact, r;
+ int inexact;
+ mp_rnd_t r;
+
/* Check for +0 */
mpfr_init(x);
mpq_init(y);
mpq_set_si(y, 0, 1);
- for(r = 0 ; r < 4 ; r++)
+ for(r = 0 ; r < GMP_RND_MAX ; r++)
{
inexact = mpfr_set_q(x, y, r);
if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact)
diff --git a/tests/tset_si.c b/tests/tset_si.c
index f6fdfc22a..bd234a955 100644
--- a/tests/tset_si.c
+++ b/tests/tset_si.c
@@ -36,7 +36,7 @@ main (int argc, char *argv[])
long k, z, d, N;
unsigned long zl, dl;
int inex;
- int r;
+ mp_rnd_t r;
tests_start_mpfr ();
@@ -130,7 +130,7 @@ main (int argc, char *argv[])
exit (1);
}
- for(r = 0 ; r < 4 ; r++)
+ for(r = 0 ; r < GMP_RND_MAX ; r++)
{
mpfr_set_si (x, -1, r);
mpfr_set_ui (x, 0, r);
diff --git a/tests/tset_str.c b/tests/tset_str.c
index be36a1a33..b0c62c7fa 100644
--- a/tests/tset_str.c
+++ b/tests/tset_str.c
@@ -149,7 +149,7 @@ main (int argc, char *argv[])
for (i=0;i<N;i++)
{
mpfr_random (x);
- k = randlimb () % 4;
+ k = RND_RAND ();
logbase = (randlimb () % 5) + 1;
base = 1 << logbase;
/* Warning: the number of bits needed to print exactly a number of
@@ -422,6 +422,7 @@ main (int argc, char *argv[])
printf ("return : ");
mpfr_print_binary (y);
puts ("");
+ exit (1);
}
}
diff --git a/tests/tset_z.c b/tests/tset_z.c
index bf72f0e71..630b6e950 100644
--- a/tests/tset_z.c
+++ b/tests/tset_z.c
@@ -35,7 +35,7 @@ static void check0(void)
mpfr_init(x);
mpz_init(y);
mpz_set_si(y, 0);
- for(r = 0 ; r < 4 ; r++)
+ for(r = 0 ; r < GMP_RND_MAX ; r++)
{
inexact = mpfr_set_z(x, y, r);
if (!MPFR_IS_ZERO(x) || !MPFR_IS_POS(x) || inexact)
@@ -54,7 +54,7 @@ static void check0(void)
mpfr_get_si is a rather indirect test of a low level routine. */
static void
-check (long i, unsigned char rnd)
+check (long i, mp_rnd_t rnd)
{
mpfr_t f;
mpz_t z;
@@ -104,7 +104,7 @@ main (int argc, char *argv[])
check_large ();
check (0, 0);
for (j = 0; j < 200000; j++)
- check (randlimb () & LONG_MAX, randlimb () % 4);
+ check (randlimb () & LONG_MAX, RND_RAND () );
check0();
tests_end_mpfr ();
diff --git a/tests/tsqrt.c b/tests/tsqrt.c
index afad39df9..3acc7749f 100644
--- a/tests/tsqrt.c
+++ b/tests/tsqrt.c
@@ -242,7 +242,7 @@ check_inexact (mp_prec_t p)
mpfr_init2 (y, p);
mpfr_init2 (z, 2*p);
mpfr_random (x);
- rnd = randlimb () % 4;
+ rnd = RND_RAND();
inexact = mpfr_sqrt (y, x, rnd);
if (mpfr_mul (z, y, y, rnd)) /* exact since prec(z) = 2*prec(y) */
{
diff --git a/tests/tsub.c b/tests/tsub.c
index d94d77a7b..806b7316e 100644
--- a/tests/tsub.c
+++ b/tests/tsub.c
@@ -307,11 +307,10 @@ check_two_sum (mp_prec_t p)
mpfr_random (y);
if (mpfr_cmpabs (x, y) < 0)
mpfr_swap (x, y);
- rnd = randlimb () % 4;
rnd = GMP_RNDN;
- inexact = mpfr_sub (u, x, y, GMP_RNDN);
- mpfr_sub (v, u, x, GMP_RNDN);
- mpfr_add (w, v, y, GMP_RNDN);
+ inexact = mpfr_sub (u, x, y, rnd);
+ mpfr_sub (v, u, x, rnd);
+ mpfr_add (w, v, y, rnd);
/* as u = (x-y) - w, we should have inexact and w of opposite signs */
if (((inexact == 0) && mpfr_cmp_ui (w, 0)) ||
((inexact > 0) && (mpfr_cmp_ui (w, 0) <= 0)) ||
@@ -386,14 +385,14 @@ check_inexact (void)
: MPFR_EXP(u) - MPFR_EXP(x);
pz = pz + MAX(MPFR_PREC(x), MPFR_PREC(u));
mpfr_set_prec (z, pz);
- rnd = randlimb () % 4;
+ rnd = RND_RAND();
if (mpfr_sub (z, x, u, rnd))
{
printf ("z <- x - u should be exact\n");
exit (1);
}
{
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
inexact = mpfr_sub (y, x, u, rnd);
cmp = mpfr_cmp (y, z);
if (((inexact == 0) && (cmp != 0)) ||
diff --git a/tests/tsub1sp.c b/tests/tsub1sp.c
index 4cbf8ca0a..64250eda2 100644
--- a/tests/tsub1sp.c
+++ b/tests/tsub1sp.c
@@ -81,7 +81,7 @@ void check_random(mpfr_prec_t p)
mpfr_urandomb(y, state);
mpfr_urandomb(z, state);
if (MPFR_IS_PURE_FP(y) && MPFR_IS_PURE_FP(z))
- for(r = 0 ; r < 4 ; r++)
+ for(r = 0 ; r < GMP_RND_MAX ; r++)
{
inexact1 = mpfr_sub1(x2, y, z, r);
inexact2 = mpfr_sub1sp(x, y, z, r);
@@ -105,7 +105,7 @@ void check_special(void)
mpfr_inits(x,y,z,x2,NULL);
- for(r = 0 ; r < 4 ; r++)
+ for(r = 0 ; r < GMP_RND_MAX ; r++)
{
p = 53;
mpfr_set_prec(x, 53);
diff --git a/tests/tui_pow.c b/tests/tui_pow.c
index 249a020e5..4da7010cf 100644
--- a/tests/tui_pow.c
+++ b/tests/tui_pow.c
@@ -218,7 +218,7 @@ main (int argc, char *argv[])
int nt;
nt = randlimb () & INT_MAX;
mpfr_random (x);
- rnd = randlimb () % 4;
+ rnd = RND_RAND ();
check1 (x, prec, nt, rnd);
}
}
diff --git a/uceil_log2.c b/uceil_log2.c
index ab3bcd8ab..5d1090e0b 100644
--- a/uceil_log2.c
+++ b/uceil_log2.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
/* returns ceil(log(d)/log(2)) if d > 0,
diff --git a/ui_div.c b/ui_div.c
index 3a45d0aea..7c84704ec 100644
--- a/ui_div.c
+++ b/ui_div.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/ui_pow.c b/ui_pow.c
index 0d04c5b22..878de5878 100644
--- a/ui_pow.c
+++ b/ui_pow.c
@@ -21,9 +21,7 @@ MA 02111-1307, USA. */
#include <limits.h>
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/ui_pow_ui.c b/ui_pow_ui.c
index c8954e927..f9c20f8e9 100644
--- a/ui_pow_ui.c
+++ b/ui_pow_ui.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
int
diff --git a/ui_sub.c b/ui_sub.c
index c5bd379f8..27361d030 100644
--- a/ui_sub.c
+++ b/ui_sub.c
@@ -19,10 +19,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/urandomb.c b/urandomb.c
index 55b1a06ca..789f4ffdc 100644
--- a/urandomb.c
+++ b/urandomb.c
@@ -22,10 +22,8 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "longlong.h"
-#include "mpfr.h"
+
+#define MPFR_NEED_LONGLONG_H
#include "mpfr-impl.h"
int
diff --git a/version.c b/version.c
index 47bf0294b..8e87234b1 100644
--- a/version.c
+++ b/version.c
@@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"
const char *
diff --git a/volatile.c b/volatile.c
index d01b97c3d..c5c0c91c9 100644
--- a/volatile.c
+++ b/volatile.c
@@ -23,9 +23,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-#include "gmp.h"
-#include "gmp-impl.h"
-#include "mpfr.h"
+
#include "mpfr-impl.h"