Removed the possibility of building ECL without bignums

This commit is contained in:
Juan Jose Garcia Ripoll 2010-11-06 16:42:39 +01:00
parent c3d234a149
commit 3b92fb53f0
16 changed files with 262 additions and 488 deletions

15
src/aclocal.m4 vendored
View file

@ -878,18 +878,17 @@ dnl Configure libatomic-ops
dnl
AC_DEFUN([ECL_LIBATOMIC_OPS],[
if test "x$ecl_threads" != "xno"; then
if mkdir atomic; then
(destdir=`${PWDCMD}`; cd atomic; CC="${CC} ${PICFLAG}" \
$srcdir/gc/libatomic*/configure --disable-shared --prefix=${destdir} \
test -d atomic || mkdir atomic
(destdir=`${PWDCMD}`; cd atomic && CC="${CC} ${PICFLAG}" \
$srcdir/gc/libatomic*/configure --disable-shared --prefix=${destdir} \
--infodir=${destdir}/doc --includedir=${destdir}/ecl --with-pic \
--libdir=${destdir} --build=${build_alias} --host=${host_alias} \
CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" CC="${CC} \
${PICFLAG}")
SUBDIRS="${SUBDIRS} atomic"
CORE_LIBS="-leclatomic ${CORE_LIBS}"
if test "${enable_shared}" = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclatomic.${LIBEXT}"
fi
SUBDIRS="${SUBDIRS} atomic"
CORE_LIBS="-leclatomic ${CORE_LIBS}"
if test "${enable_shared}" = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclatomic.${LIBEXT}"
fi
fi
])

View file

@ -267,10 +267,8 @@ ONCE_MORE:
*/
switch (t) {
case t_bignum:
#ifdef WITH_GMP
obj->big.big_dim = obj->big.big_size = 0;
obj->big.big_limbs = NULL;
#endif
break;
case t_ratio:
obj->ratio.num = OBJNULL;

View file

@ -1196,23 +1196,16 @@ si_gc_stats(cl_object enable)
GC_print_stats = (enable == @':full');
}
if (cl_core.bytes_consed == Cnil) {
#ifndef WITH_GMP
cl_core.bytes_consed = MAKE_FIXNUM(0);
cl_core.gc_counter = MAKE_FIXNUM(0);
#else
cl_core.bytes_consed = ecl_alloc_object(t_bignum);
mpz_init2(cl_core.bytes_consed->big.big_num, 128);
cl_core.gc_counter = ecl_alloc_object(t_bignum);
mpz_init2(cl_core.gc_counter->big.big_num, 128);
#endif
} else {
/* We need fresh copies of the bignums */
size1 = _ecl_big_plus_fix(cl_core.bytes_consed, 1);
size2 = _ecl_big_plus_fix(cl_core.gc_counter, 1);
#ifdef WITH_GMP
mpz_set_ui(cl_core.bytes_consed->big.big_num, 0);
mpz_set_ui(cl_core.gc_counter->big.big_num, 0);
#endif
}
@(return size1 size2 old_status)
}
@ -1227,7 +1220,6 @@ static void
gather_statistics()
{
if (cl_core.gc_stats) {
#ifdef WITH_GMP
/* Sorry, no gc stats if you do not use bignums */
#if GBC_BOEHM == 0
mpz_add_ui(cl_core.bytes_consed->big.big_num,
@ -1255,7 +1247,6 @@ gather_statistics()
mpz_add_ui(cl_core.gc_counter->big.big_num,
cl_core.gc_counter->big.big_num,
1);
#endif
}
}

View file

@ -365,6 +365,140 @@ _ecl_big_to_long_double(cl_object o)
}
#endif
static void
mpz_ior_op(cl_object out, cl_object i, cl_object j)
{
mpz_ior(out->big.big_num, i->big.big_num, j->big.big_num);
}
static void
mpz_xor_op(cl_object out, cl_object i, cl_object j)
{
mpz_xor(out->big.big_num, i->big.big_num, j->big.big_num);
}
static void
mpz_and_op(cl_object out, cl_object i, cl_object j)
{
mpz_and(out->big.big_num, i->big.big_num, j->big.big_num);
}
static void
mpz_eqv_op(cl_object out, cl_object i, cl_object j)
{
mpz_xor(out->big.big_num, i->big.big_num, j->big.big_num);
mpz_com(out->big.big_num, out->big.big_num);
}
static void
mpz_nand_op(cl_object out, cl_object i, cl_object j)
{
mpz_and(out->big.big_num, i->big.big_num, j->big.big_num);
mpz_com(out->big.big_num, out->big.big_num);
}
static void
mpz_nor_op(cl_object out, cl_object i, cl_object j)
{
mpz_ior(out->big.big_num, i->big.big_num, j->big.big_num);
mpz_com(out->big.big_num, out->big.big_num);
}
static void
mpz_andc1_op(cl_object out, cl_object i, cl_object j)
{
mpz_com(out->big.big_num, i->big.big_num);
mpz_and(out->big.big_num, out->big.big_num, j->big.big_num);
}
static void
mpz_orc1_op(cl_object out, cl_object i, cl_object j)
{
mpz_com(out->big.big_num, i->big.big_num);
mpz_ior(out->big.big_num, out->big.big_num, j->big.big_num);
}
static void
mpz_andc2_op(cl_object out, cl_object i, cl_object j)
{
/* (i & ~j) = ~((~i) | j) */
mpz_orc1_op(out, i, j);
mpz_com(out->big.big_num, out->big.big_num);
}
static void
mpz_orc2_op(cl_object out, cl_object i, cl_object j)
{
/* (i | ~j) = ~((~i) & j) */
mpz_andc1_op(out, i, j);
mpz_com(out->big.big_num, out->big.big_num);
}
static void
mpz_b_clr_op(cl_object out, cl_object i, cl_object j)
{
mpz_set_si(out->big.big_num, 0);
}
static void
mpz_b_set_op(cl_object o, cl_object i, cl_object j)
{
mpz_set_si(o->big.big_num, -1);
}
static void
mpz_b_1_op(cl_object out, cl_object i, cl_object j)
{
if (i != out)
mpz_set(out->big.big_num, i->big.big_num);
}
static void
mpz_b_2_op(cl_object out, cl_object i, cl_object j)
{
mpz_set(out->big.big_num, j->big.big_num);
}
static void
mpz_b_c1_op(cl_object out, cl_object i, cl_object j)
{
mpz_com(out->big.big_num, i->big.big_num);
}
static void
mpz_b_c2_op(cl_object out, cl_object i, cl_object j)
{
mpz_com(out->big.big_num, j->big.big_num);
}
static _ecl_big_binary_op bignum_operations[16] = {
mpz_b_clr_op,
mpz_and_op,
mpz_andc2_op,
mpz_b_1_op,
mpz_andc1_op,
mpz_b_2_op,
mpz_xor_op,
mpz_ior_op,
mpz_nor_op,
mpz_eqv_op,
mpz_b_c2_op,
mpz_orc2_op,
mpz_b_c1_op,
mpz_orc1_op,
mpz_nand_op,
mpz_b_set_op};
_ecl_big_binary_op
_ecl_big_boole_operator(int operator)
{
unlikely_if((operator < 0) || (operator >= 16)) {
ecl_internal_error("_ecl_big_boole_operator passed "
"an invalid operator");
}
return bignum_operations[operator];
}
void
init_big()
{

View file

@ -24,10 +24,8 @@ ecl_def_string_array(feature_names,static,const) = {
#ifdef ECL_IEEE_FP
ecl_def_string_array_elt("IEEE-FLOATING-POINT"),
#endif
#ifdef WITH_GMP
ecl_def_string_array_elt("COMMON-LISP"),
ecl_def_string_array_elt("ANSI-CL"),
#endif /* WITH_GMP */
#if defined(GBC_BOEHM)
ecl_def_string_array_elt("BOEHM-GC"),
#endif

View file

@ -4805,7 +4805,6 @@ ecl_off_t_to_integer(ecl_off_t offset)
output = MAKE_FIXNUM((cl_fixnum)offset);
} else {
cl_object y = _ecl_big_register0();
#ifdef WITH_GMP
if (sizeof(y->big.big_limbs[0]) == sizeof(cl_index)) {
y->big.big_limbs[0] = (cl_index)offset;
offset >>= FIXNUM_BITS;
@ -4815,9 +4814,6 @@ ecl_off_t_to_integer(ecl_off_t offset)
y->big.big_limbs[0] = offset;
y->big.big_size = 1;
}
#else
y->big.big_num = offset;
#endif
output = _ecl_big_register_normalize(y);
}
return output;
@ -4832,7 +4828,6 @@ ecl_integer_to_off_t(cl_object offset)
} else if (FIXNUMP(offset)) {
output = fixint(offset);
} else if (ECL_BIGNUMP(offset)) {
#ifdef WITH_GMP
if (sizeof(offset->big.big_limbs[0]) == sizeof(cl_index)) {
if (offset->big.big_size > 2) {
goto ERR;
@ -4848,9 +4843,6 @@ ecl_integer_to_off_t(cl_object offset)
}
output = offset->big.big_limbs[0];
}
#else
output = offset->big.big_num;
#endif
} else {
ERR: FEerror("Not a valid file offset: ~S", 1, offset);
}

View file

@ -136,7 +136,6 @@ BEGIN:
switch (type_of(x)) {
case t_bignum: {
#ifdef WITH_GMP
/* GMP may set num.alloc before actually allocating anything.
With these checks we make sure we do not move anything
we don't have to. Besides, we use big_dim as the size
@ -145,7 +144,6 @@ BEGIN:
cl_ptr limbs = (cl_ptr)x->big.big_limbs;
cl_index size = x->big.big_dim * sizeof(mp_limb_t);
if (size) mark_contblock(limbs, size);
#endif /* WITH_GMP */
break;
}
case t_ratio:

View file

@ -45,12 +45,8 @@ _hash_eql(cl_hashkey h, cl_object x)
{
switch (type_of(x)) {
case t_bignum:
#ifdef WITH_GMP
return hash_string(h, (unsigned char*)x->big.big_limbs,
labs(x->big.big_size) * sizeof(mp_limb_t));
#else /* WITH_GMP */
return hash_word(h, (cl_index)(x->big.big_num));
#endif /* WITH_GMP */
case t_ratio:
h = _hash_eql(h, x->ratio.num);
return _hash_eql(h, x->ratio.den);

View file

@ -29,264 +29,97 @@ ior_op(cl_fixnum i, cl_fixnum j)
return(i | j);
}
static void
mpz_ior_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_ior(i->big.big_num, i->big.big_num, j->big.big_num);
#else /* WITH_GMP */
i->big.big_num |= j->big.big_num;
#endif /* WITH_GMP */
}
static cl_fixnum
xor_op(cl_fixnum i, cl_fixnum j)
{
return(i ^ j);
}
static void
mpz_xor_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_xor(i->big.big_num, i->big.big_num, j->big.big_num);
#else /* WITH_GMP */
i->big.big_num ^= j->big.big_num;
#endif /* WITH_GMP */
}
static cl_fixnum
and_op(cl_fixnum i, cl_fixnum j)
{
return(i & j);
}
static void
mpz_and_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_and(i->big.big_num, i->big.big_num, j->big.big_num);
#else /* WITH_GMP */
i->big.big_num &= j->big.big_num;
#endif /* WITH_GMP */
}
static cl_fixnum
eqv_op(cl_fixnum i, cl_fixnum j)
{
return(~(i ^ j));
}
static void
mpz_eqv_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_xor(i->big.big_num, i->big.big_num, j->big.big_num);
mpz_com(i->big.big_num, i->big.big_num);
#else /* WITH_GMP */
i->big.big_num = ~(i->big.big_num ^ j->big.big_num);
#endif /* WITH_GMP */
}
static cl_fixnum
nand_op(cl_fixnum i, cl_fixnum j)
{
return(~(i & j));
}
static void
mpz_nand_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_and(i->big.big_num, i->big.big_num, j->big.big_num);
mpz_com(i->big.big_num, i->big.big_num);
#else /* WITH_GMP */
i->big.big_num = ~(i->big.big_num & j->big.big_num);
#endif /* WITH_GMP */
}
static cl_fixnum
nor_op(cl_fixnum i, cl_fixnum j)
{
return(~(i | j));
}
static void
mpz_nor_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_ior(i->big.big_num, i->big.big_num, j->big.big_num);
mpz_com(i->big.big_num, i->big.big_num);
#else /* WITH_GMP */
i->big.big_num = ~(i->big.big_num | j->big.big_num);
#endif /* WITH_GMP */
}
static cl_fixnum
andc1_op(cl_fixnum i, cl_fixnum j)
{
return((~i) & j);
}
static void
mpz_andc1_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_com(i->big.big_num, i->big.big_num);
mpz_and(i->big.big_num, i->big.big_num, j->big.big_num);
#else /* WITH_GMP */
i->big.big_num = (~i->big.big_num) & (big_num_t)j;
#endif /* WITH_GMP */
}
static cl_fixnum
andc2_op(cl_fixnum i, cl_fixnum j)
{
return(i & (~j));
}
static void mpz_orc1_op(cl_object, cl_object);
static void
mpz_andc2_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
/* (i & ~j) = ~((~i) | j) */
mpz_orc1_op(i, j);
mpz_com(i->big.big_num, i->big.big_num);
#else /* WITH_GMP */
i->big.big_num = i->big.big_num & (~j->big.big_num);
#endif /* WITH_GMP */
}
static cl_fixnum
orc1_op(cl_fixnum i, cl_fixnum j)
{
return((~i) | j);
}
static void
mpz_orc1_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_com(i->big.big_num, i->big.big_num);
mpz_ior(i->big.big_num, i->big.big_num, j->big.big_num);
#else /* WITH_GMP */
i->big.big_num = (~i->big.big_num) | j->big.big_num;
#endif /* WITH_GMP */
}
static cl_fixnum
orc2_op(cl_fixnum i, cl_fixnum j)
{
return(i | (~j));
}
static void
mpz_orc2_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
/* (i | ~j) = ~((~i) & j) */
mpz_andc1_op(i, j);
mpz_com(i->big.big_num, i->big.big_num);
#else /* WITH_GMP */
i->big.big_num = i->big.big_num | (~j->big.big_num);
#endif /* WITH_GMP */
}
static cl_fixnum
b_clr_op(cl_fixnum i, cl_fixnum j)
{
return(0);
}
static void
mpz_b_clr_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_set_si(i->big.big_num, 0);
#else /* WITH_GMP */
i->big.big_num = 0ll;
#endif /* WITH_GMP */
}
static cl_fixnum
b_set_op(cl_fixnum i, cl_fixnum j)
{
return(-1);
}
static void
mpz_b_set_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_set_si(i->big.big_num, -1);
#else /* WITH_GMP */
i->big.big_num = -1ll;
#endif /* WITH_GMP */
}
static cl_fixnum
b_1_op(cl_fixnum i, cl_fixnum j)
{
return(i);
}
static void
mpz_b_1_op(cl_object i, cl_object j)
{
}
static cl_fixnum
b_2_op(cl_fixnum i, cl_fixnum j)
{
return(j);
}
static void
mpz_b_2_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_set(i->big.big_num, j->big.big_num);
#else /* WITH_GMP */
i->big.big_num = j->big.big_num;
#endif /* WITH_GMP */
}
static cl_fixnum
b_c1_op(cl_fixnum i, cl_fixnum j)
{
return(~i);
}
static void
mpz_b_c1_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_com(i->big.big_num, i->big.big_num);
#else /* WITH_GMP */
i->big.big_num = ~i->big.big_num;
#endif /* WITH_GMP */
}
static cl_fixnum
b_c2_op(cl_fixnum i, cl_fixnum j)
{
return(~j);
}
static void
mpz_b_c2_op(cl_object i, cl_object j)
{
#ifdef WITH_GMP
mpz_com(i->big.big_num, j->big.big_num);
#else /* WITH_GMP */
i->big.big_num = ~j->big.big_num;
#endif /* WITH_GMP */
}
typedef cl_fixnum (*bit_operator)(cl_fixnum, cl_fixnum);
typedef void (*bignum_bit_operator)(cl_object, cl_object);
static bit_operator fixnum_operations[16] = {
b_clr_op,
@ -306,24 +139,6 @@ static bit_operator fixnum_operations[16] = {
nand_op,
b_set_op};
static bignum_bit_operator bignum_operations[16] = {
mpz_b_clr_op,
mpz_and_op,
mpz_andc2_op,
mpz_b_1_op,
mpz_andc1_op,
mpz_b_2_op,
mpz_xor_op,
mpz_ior_op,
mpz_nor_op,
mpz_eqv_op,
mpz_b_c2_op,
mpz_orc2_op,
mpz_b_c1_op,
mpz_orc1_op,
mpz_nand_op,
mpz_b_set_op};
static cl_object
log_op(cl_narg narg, int op, cl_va_list ARGS)
@ -355,7 +170,7 @@ ecl_boole(int op, cl_object x, cl_object y)
case t_bignum: {
cl_object x_copy = _ecl_big_register0();
_ecl_big_set_fixnum(x_copy, fix(x));
bignum_operations[op](x_copy, y);
(_ecl_big_boole_operator(op))(x_copy, x_copy, y);
return _ecl_big_register_normalize(x_copy);
}
default:
@ -364,17 +179,16 @@ ecl_boole(int op, cl_object x, cl_object y)
break;
case t_bignum: {
cl_object x_copy = _ecl_big_register0();
_ecl_big_set(x_copy, x);
switch (type_of(y)) {
case t_fixnum: {
cl_object z = _ecl_big_register1();
_ecl_big_set_fixnum(z,fix(y));
bignum_operations[op](x_copy, z);
(_ecl_big_boole_operator(op))(x_copy, x, z);
_ecl_big_register_free(z);
break;
}
case t_bignum:
bignum_operations[op](x_copy, y);
(_ecl_big_boole_operator(op))(x_copy, x, y);
break;
default:
FEwrong_type_nth_arg(@[boole], 2, y, @[integer]);
@ -407,7 +221,6 @@ count_bits(cl_object x)
break;
}
case t_bignum:
#ifdef WITH_GMP
if (_ecl_big_sign(x) >= 0)
count = mpz_popcount(x->big.big_num);
else {
@ -416,15 +229,6 @@ count_bits(cl_object x)
count = mpz_popcount(z->big.big_num);
_ecl_big_register_free(z);
}
#else /* WITH_GMP */
{
big_num_t i = x->big.big_num;
if ( i<0 )
i = ~i;
for ( count=0 ; i ; i >>= 1 )
if ( i&1 ) count++;
}
#endif /* WITH_GMP */
break;
default:
FEwrong_type_only_arg(@[logcount], x, @[integer]);
@ -461,22 +265,13 @@ ecl_ash(cl_object x, cl_fixnum w)
}
return MAKE_FIXNUM(y);
}
#ifdef WITH_GMP
mpz_div_2exp(y->big.big_num, x->big.big_num, bits);
#else /* WITH_GMP */
y->big.big_num = x->big.big_num >> bits;
#endif /* WITH_GMP */
} else {
#ifdef WITH_GMP
if (FIXNUMP(x)) {
_ecl_big_set_fixnum(y, fix(x));
x = y;
}
mpz_mul_2exp(y->big.big_num, x->big.big_num, (unsigned long)w);
#else /* WITH_GMP */
y->big.big_num = FIXNUMP(x) ? fix(x) : x->big.big_num;
y->big.big_num <<= w;
#endif /* WITH_GMP */
}
return _ecl_big_register_normalize(y);
}
@ -593,15 +388,7 @@ cl_logbitp(cl_object p, cl_object x)
i = ((y >> n) & 1);
}
} else {
#ifdef WITH_GMP
i = mpz_tstbit(x->big.big_num, n);
#else /* WITH_GMP */
if ( n >= 8*sizeof(big_num_t) ) {
i = (x->big.big_num < 0);
} else {
i = (x->big.big_num >> n) & 1;
}
#endif /* WITH_GMP */
}
} else {
assert_type_non_negative_integer(p);
@ -671,15 +458,7 @@ ecl_integer_length(cl_object x)
case t_bignum:
if (_ecl_big_sign(x) < 0)
x = cl_lognot(x);
#ifdef WITH_GMP
count = mpz_sizeinbase(x->big.big_num, 2);
#else /* WITH_GMP */
for ( i=(8*sizeof(big_num_t))-1 ; i>0 ; i-- )
if ( (x->big.big_num >> i) & 1 ) {
count = i;
break;
}
#endif /* WITH_GMP */
break;
default:
FEwrong_type_only_arg(@[integer-length], x, @[integer]);

View file

@ -128,7 +128,6 @@ generate_double(cl_object state)
#endif
#ifdef WITH_GMP
static mp_limb_t
generate_limb(cl_object state)
{
@ -149,12 +148,10 @@ generate_limb(cl_object state)
# endif
#endif
}
#endif
static cl_object
random_integer(cl_object limit, cl_object state)
{
#ifdef WITH_GMP
cl_index bit_length = ecl_integer_length(limit);
cl_object buffer;
if (bit_length <= FIXNUM_BITS)
@ -165,9 +162,6 @@ random_integer(cl_object limit, cl_object state)
generate_limb(state);
}
return cl_mod(buffer, limit);
#else
return ecl_floor1(ecl_times(x, cl_rational(ecl_make_doublefloat(d))));
#endif
}
static cl_object

View file

@ -73,14 +73,9 @@ fixint(cl_object x)
if (FIXNUMP(x))
return fix(x);
if (ECL_BIGNUMP(x)) {
#ifdef WITH_GMP
if (mpz_fits_slong_p(x->big.big_num)) {
return mpz_get_si(x->big.big_num);
}
#else /* WITH_GMP */
if ( !((cl_fixnum)x->big.big_num < x->big.big_num) )
return (cl_fixnum)x->big.big_num;
#endif /* WITH_GMP */
}
FEwrong_type_argument(@[fixnum], x);
}
@ -93,15 +88,9 @@ fixnnint(cl_object x)
if (i >= 0)
return i;
} else if (ECL_BIGNUMP(x)) {
#ifdef WITH_GMP
if (mpz_fits_ulong_p(x->big.big_num)) {
return mpz_get_ui(x->big.big_num);
}
#else /* WITH_GMP */
if ( x->big.big_num >= 0
&& !((cl_fixnum)x->big.big_num < x->big.big_num) )
return (cl_fixnum)x->big.big_num;
#endif /* WITH_GMP */
}
cl_error(9, @'simple-type-error', @':format-control',
make_constant_base_string("Not a non-negative fixnum ~S"),
@ -239,9 +228,6 @@ ecl_to_int32_t(cl_object x) {
#endif /* ecl_uint32_t */
#if defined(ecl_uint64_t) && (FIXNUM_BITS < 64)
# if !defined(WITH_GMP) || FIXNUM_BITS != 32
# error "Cannot handle ecl_uint64_t without GMP or 32/64 bits integer"
# endif
ecl_uint64_t
ecl_to_uint64_t(cl_object x) {
do {
@ -360,9 +346,6 @@ ecl_make_long_long(ecl_long_long_t i) {
return ecl_make_int64_t(i);
}
# else
# if !defined(WITH_GMP)
# error "Cannot handle ecl_ulong_long_t without GMP"
# endif
ecl_ulong_long_t
ecl_to_unsigned_long_long(cl_object x) {
do {
@ -659,7 +642,6 @@ ecl_make_complex(cl_object r, cl_object i)
return(c);
}
#ifdef WITH_GMP
static cl_object
into_bignum(cl_object bignum, cl_object integer)
{
@ -734,66 +716,50 @@ prepare_ratio_to_float(cl_object num, cl_object den, int digits, cl_fixnum *scal
scale++;
} while (1);
}
#endif /* WITH_GMP */
static float
ratio_to_float(cl_object num, cl_object den)
{
#ifdef WITH_GMP
cl_fixnum scale;
cl_object bits = prepare_ratio_to_float(num, den, FLT_MANT_DIG, &scale);
# if (FIXNUM_BITS-ECL_TAG_BITS) >= FLT_MANT_DIG
#if (FIXNUM_BITS-ECL_TAG_BITS) >= FLT_MANT_DIG
/* The output of prepare_ratio_to_float will always fit an integer */
float output = fix(bits);
# else
float output = FIXNUMP(bits)? fix(bits) : _ecl_big_to_double(bits);
# endif
return ldexpf(output, scale);
#else
return (float)(FIXNUMP(num) ? fix(num) : num->big.big_num) /
(float)(FIXNUMP(den) ? fix(den) : den->big.big_num);
float output = FIXNUMP(bits)? fix(bits) : _ecl_big_to_double(bits);
#endif
return ldexpf(output, scale);
}
static double
ratio_to_double(cl_object num, cl_object den)
{
#ifdef WITH_GMP
cl_fixnum scale;
cl_object bits = prepare_ratio_to_float(num, den, DBL_MANT_DIG, &scale);
# if (FIXNUM_BITS-ECL_TAG_BITS) >= DBL_MANT_DIG
#if (FIXNUM_BITS-ECL_TAG_BITS) >= DBL_MANT_DIG
/* The output of prepare_ratio_to_float will always fit an integer */
double output = fix(bits);
# else
double output = FIXNUMP(bits)? fix(bits) : _ecl_big_to_double(bits);
# endif
return ldexp(output, scale);
#else
return (double)(FIXNUMP(num) ? fix(num) : num->big.big_num) /
(double)(FIXNUMP(den) ? fix(den) : den->big.big_num);
double output = FIXNUMP(bits)? fix(bits) : _ecl_big_to_double(bits);
#endif
return ldexp(output, scale);
}
#ifdef ECL_LONG_FLOAT
static long double
ratio_to_long_double(cl_object num, cl_object den)
{
#ifdef WITH_GMP
cl_fixnum scale;
cl_object bits = prepare_ratio_to_float(num, den, LDBL_MANT_DIG, &scale);
# if (FIXNUM_BITS-ECL_TAG_BITS) >= LDBL_MANT_DIG
#if (FIXNUM_BITS-ECL_TAG_BITS) >= LDBL_MANT_DIG
/* The output of prepare_ratio_to_float will always fit an integer */
long double output = fix(bits);
# else
#else
long double output = FIXNUMP(bits)?
(long double)fix(bits) :
_ecl_big_to_long_double(bits);
# endif
return ldexpl(output, scale);
#else
return (long double)(FIXNUMP(num) ? fix(num) : num->big.big_num) /
(long double)(FIXNUMP(den) ? fix(den) : den->big.big_num);
#endif
return ldexpl(output, scale);
}
#endif /* ECL_LONG_FLOAT */

127
src/configure vendored
View file

@ -4908,12 +4908,11 @@ else
INFOEXT=info
fi
if test "x${with_gmp}" != "xno"; then
CPPFLAGS="$CPPFLAGS $GMP_CPPFLAGS"
LDFLAGS="$LDFLAGS $GMP_LDFLAGS"
CPPFLAGS="$CPPFLAGS $GMP_CPPFLAGS"
LDFLAGS="$LDFLAGS $GMP_LDFLAGS"
if test ${with_system_gmp} = "auto"; then
{ $as_echo "$as_me:$LINENO: checking for __gmpz_init in -lgmp" >&5
if test ${with_system_gmp} = "auto"; then
{ $as_echo "$as_me:$LINENO: checking for __gmpz_init in -lgmp" >&5
$as_echo_n "checking for __gmpz_init in -lgmp... " >&6; }
if test "${ac_cv_lib_gmp___gmpz_init+set}" = set; then
$as_echo_n "(cached) " >&6
@ -4984,11 +4983,11 @@ else
with_system_gmp=no
fi
fi
fi
ECL_GMP_HEADER=
if test "${with_system_gmp}" = "yes"; then
{ $as_echo "$as_me:$LINENO: checking for __gmpz_init in -lgmp" >&5
ECL_GMP_HEADER=
if test "${with_system_gmp}" = "yes"; then
{ $as_echo "$as_me:$LINENO: checking for __gmpz_init in -lgmp" >&5
$as_echo_n "checking for __gmpz_init in -lgmp... " >&6; }
if test "${ac_cv_lib_gmp___gmpz_init+set}" = set; then
$as_echo_n "(cached) " >&6
@ -5579,7 +5578,7 @@ if test "x$ac_cv_header_gmp_h" = x""yes; then
fi
if test "${ac_cv_header_gmp_gmp_h+set}" = set; then
if test "${ac_cv_header_gmp_gmp_h+set}" = set; then
{ $as_echo "$as_me:$LINENO: checking for gmp/gmp.h" >&5
$as_echo_n "checking for gmp/gmp.h... " >&6; }
if test "${ac_cv_header_gmp_gmp_h+set}" = set; then
@ -5711,69 +5710,55 @@ if test "x$ac_cv_header_gmp_gmp_h" = x""yes; then
fi
else
SUBDIRS="${SUBDIRS} gmp"
CORE_LIBS="-leclgmp ${CORE_LIBS}"
if test ${enable_shared} = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclgmp.${LIBEXT}"
fi
else
SUBDIRS="${SUBDIRS} gmp"
CORE_LIBS="-leclgmp ${CORE_LIBS}"
if test ${enable_shared} = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclgmp.${LIBEXT}"
fi
fi
if test "${with_gmp}" = "no" ; then
{ $as_echo "$as_me:$LINENO: Not using GMP library at all. Are you sure?" >&5
$as_echo "$as_me: Not using GMP library at all. Are you sure?" >&6;}
EXTRA_OBJS="${EXTRA_OBJS} big_ll.o"
ECL_GMP_HEADER='nofile'
else
cat >>confdefs.h <<\_ACEOF
#define WITH_GMP 1
_ACEOF
EXTRA_OBJS="${EXTRA_OBJS} big.o"
if test "${with_system_gmp}" = "no" ; then
{ $as_echo "$as_me:$LINENO: Configuring included GMP library:" >&5
EXTRA_OBJS="${EXTRA_OBJS} big.o"
if test "${with_system_gmp}" = "no" ; then
{ $as_echo "$as_me:$LINENO: Configuring included GMP library:" >&5
$as_echo "$as_me: Configuring included GMP library:" >&6;}
test -d gmp && rm -rf gmp
if test -z "$gmp_build"; then
gmp_build="${build_alias}"
fi
ECL_GMP_HEADER='ecl/gmp.h'
if test "x$ABI" = "x"; then
GMP_ABI=""
else
GMP_ABI="ABI=$ABI"
fi
if mkdir gmp; then
(destdir=`${PWDCMD}`; cd gmp; CC="${CC} ${PICFLAG}" \
$srcdir/gmp/configure --disable-shared --prefix=${destdir} \
--infodir=${destdir}/doc --includedir=${destdir}/ecl --with-pic \
--libdir=${destdir} --build=${gmp_build} --host=${host_alias} \
CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" CC="${CC} ${PICFLAG}" \
"$GMP_ABI" $with_gmp)
if test ! -f gmp/config.status; then
{ { $as_echo "$as_me:$LINENO: error: Failed to configure the GMP library." >&5
$as_echo "$as_me: error: Failed to configure the GMP library." >&2;}
{ (exit 1); exit 1; }; }
fi
fi
test -d gmp && rm -rf gmp
if test -z "$gmp_build"; then
gmp_build="${build_alias}"
fi
ECL_GMP_HEADER='ecl/gmp.h'
if test "x$ABI" = "x"; then
GMP_ABI=""
else
if test "x$ECL_GMP_HEADER" = "x"; then
{ { $as_echo "$as_me:$LINENO: error: Can not find GMP header." >&5
$as_echo "$as_me: error: Can not find GMP header." >&2;}
GMP_ABI="ABI=$ABI"
fi
if mkdir gmp; then
(destdir=`${PWDCMD}`; cd gmp; CC="${CC} ${PICFLAG}" \
$srcdir/gmp/configure --disable-shared --prefix=${destdir} \
-infodir=${destdir}/doc --includedir=${destdir}/ecl --with-pic \
--libdir=${destdir} --build=${gmp_build} --host=${host_alias} \
CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" CC="${CC} ${PICFLAG}" \
"$GMP_ABI" $with_gmp)
if test ! -f gmp/config.status; then
{ { $as_echo "$as_me:$LINENO: error: Failed to configure the GMP library." >&5
$as_echo "$as_me: error: Failed to configure the GMP library." >&2;}
{ (exit 1); exit 1; }; }
fi
fi
with_gmp="yes"
else
if test "x$ECL_GMP_HEADER" = "x"; then
{ { $as_echo "$as_me:$LINENO: error: Can not find GMP header." >&5
$as_echo "$as_me: error: Can not find GMP header." >&2;}
{ (exit 1); exit 1; }; }
fi
fi
{ $as_echo "$as_me:$LINENO: checking GMP autoconf" >&5
$as_echo_n "checking GMP autoconf... " >&6; }
{ $as_echo "$as_me:$LINENO: result: \"${with_gmp}.${with_system_gmp}.${enable_slow_config}\"" >&5
$as_echo "\"${with_gmp}.${with_system_gmp}.${enable_slow_config}\"" >&6; }
if test "${with_gmp}.${with_system_gmp}.${enable_slow_config}" = "yes.no.yes"; then
{ $as_echo "$as_me:$LINENO: result: \"${with_system_gmp}.${enable_slow_config}\"" >&5
$as_echo "\"${with_system_gmp}.${enable_slow_config}\"" >&6; }
if test "${with_system_gmp}.${enable_slow_config}" = "no.yes"; then
{ $as_echo "$as_me:$LINENO: checking Using the GMP library to guess good compiler/linker flags" >&5
$as_echo_n "checking Using the GMP library to guess good compiler/linker flags... " >&6; }
@ -14706,20 +14691,26 @@ _ACEOF
fi
{ $as_echo "$as_me:$LINENO: checking libatomics" >&5
$as_echo_n "checking libatomics... " >&6; }
if test "x$ecl_threads" != "xno"; then
if mkdir atomic; then
(destdir=`${PWDCMD}`; cd atomic; CC="${CC} ${PICFLAG}" \
$srcdir/gc/libatomic*/configure --disable-shared --prefix=${destdir} \
test -d atomic || mkdir atomic
(destdir=`${PWDCMD}`; cd atomic && CC="${CC} ${PICFLAG}" \
$srcdir/gc/libatomic*/configure --disable-shared --prefix=${destdir} \
--infodir=${destdir}/doc --includedir=${destdir}/ecl --with-pic \
--libdir=${destdir} --build=${build_alias} --host=${host_alias} \
CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" CC="${CC} \
${PICFLAG}")
SUBDIRS="${SUBDIRS} atomic"
CORE_LIBS="-leclatomic ${CORE_LIBS}"
if test "${enable_shared}" = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclatomic.${LIBEXT}"
fi
SUBDIRS="${SUBDIRS} atomic"
CORE_LIBS="-leclatomic ${CORE_LIBS}"
if test "${enable_shared}" = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclatomic.${LIBEXT}"
fi
{ $as_echo "$as_me:$LINENO: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:$LINENO: result: no" >&5
$as_echo "no" >&6; }
fi

View file

@ -349,78 +349,68 @@ dnl build flags for the library, because GMP may choose to build for 64
dnl or 32 bits executables and ECL has to be compiled / linked using precisely
dnl the same flags
dnl
if test "x${with_gmp}" != "xno"; then
CPPFLAGS="$CPPFLAGS $GMP_CPPFLAGS"
LDFLAGS="$LDFLAGS $GMP_LDFLAGS"
CPPFLAGS="$CPPFLAGS $GMP_CPPFLAGS"
LDFLAGS="$LDFLAGS $GMP_LDFLAGS"
if test ${with_system_gmp} = "auto"; then
AC_CHECK_LIB( [gmp], [__gmpz_init],
[with_system_gmp=yes], [with_system_gmp=no] )
fi
if test ${with_system_gmp} = "auto"; then
AC_CHECK_LIB( [gmp], [__gmpz_init],
[with_system_gmp=yes], [with_system_gmp=no] )
fi
ECL_GMP_HEADER=
if test "${with_system_gmp}" = "yes"; then
AC_CHECK_LIB( [gmp], [__gmpz_init],
[FASL_LIBS="${FASL_LIBS} -lgmp"],
[AC_MSG_ERROR([System gmp library requested but not found.])])
AC_CHECK_HEADER( [gmp.h], [ECL_GMP_HEADER='gmp.h'] )
AC_CHECK_HEADER( [gmp/gmp.h], [ECL_GMP_HEADER='gmp/gmp.h'] )
else
SUBDIRS="${SUBDIRS} gmp"
CORE_LIBS="-leclgmp ${CORE_LIBS}"
if test ${enable_shared} = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclgmp.${LIBEXT}"
fi
ECL_GMP_HEADER=
if test "${with_system_gmp}" = "yes"; then
AC_CHECK_LIB( [gmp], [__gmpz_init],
[FASL_LIBS="${FASL_LIBS} -lgmp"],
[AC_MSG_ERROR([System gmp library requested but not found.])])
AC_CHECK_HEADER( [gmp.h], [ECL_GMP_HEADER='gmp.h'] )
AC_CHECK_HEADER( [gmp/gmp.h], [ECL_GMP_HEADER='gmp/gmp.h'] )
else
SUBDIRS="${SUBDIRS} gmp"
CORE_LIBS="-leclgmp ${CORE_LIBS}"
if test ${enable_shared} = "no"; then
LIBRARIES="${LIBRARIES} ${LIBPREFIX}eclgmp.${LIBEXT}"
fi
fi
dnl ----------------------------------------------------------------------
dnl Configure local GMP if needed
AC_SUBST(ECL_GMP_HEADER)
if test "${with_gmp}" = "no" ; then
AC_MSG_NOTICE(Not using GMP library at all. Are you sure?)
EXTRA_OBJS="${EXTRA_OBJS} big_ll.o"
ECL_GMP_HEADER='nofile'
else
AC_DEFINE( [WITH_GMP], [1], [Use GMP for bignums] )
EXTRA_OBJS="${EXTRA_OBJS} big.o"
if test "${with_system_gmp}" = "no" ; then
AC_MSG_NOTICE(Configuring included GMP library:)
test -d gmp && rm -rf gmp
if test -z "$gmp_build"; then
gmp_build="${build_alias}"
fi
ECL_GMP_HEADER='ecl/gmp.h'
if test "x$ABI" = "x"; then
GMP_ABI=""
else
GMP_ABI="ABI=$ABI"
fi
if mkdir gmp; then
dnl Notice we need -DPIC to force the assembler to generate PIC code
(destdir=`${PWDCMD}`; cd gmp; CC="${CC} ${PICFLAG}" \
$srcdir/gmp/configure --disable-shared --prefix=${destdir} \
--infodir=${destdir}/doc --includedir=${destdir}/ecl --with-pic \
--libdir=${destdir} --build=${gmp_build} --host=${host_alias} \
CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" CC="${CC} ${PICFLAG}" \
"$GMP_ABI" $with_gmp)
if test ! -f gmp/config.status; then
AC_MSG_ERROR([Failed to configure the GMP library.])
fi
fi
EXTRA_OBJS="${EXTRA_OBJS} big.o"
if test "${with_system_gmp}" = "no" ; then
AC_MSG_NOTICE(Configuring included GMP library:)
test -d gmp && rm -rf gmp
if test -z "$gmp_build"; then
gmp_build="${build_alias}"
fi
ECL_GMP_HEADER='ecl/gmp.h'
if test "x$ABI" = "x"; then
GMP_ABI=""
else
if test "x$ECL_GMP_HEADER" = "x"; then
AC_MSG_ERROR([Can not find GMP header.])
GMP_ABI="ABI=$ABI"
fi
if mkdir gmp; then
dnl Notice we need -DPIC to force the assembler to generate PIC code
(destdir=`${PWDCMD}`; cd gmp; CC="${CC} ${PICFLAG}" \
$srcdir/gmp/configure --disable-shared --prefix=${destdir} \
-infodir=${destdir}/doc --includedir=${destdir}/ecl --with-pic \
--libdir=${destdir} --build=${gmp_build} --host=${host_alias} \
CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" CC="${CC} ${PICFLAG}" \
"$GMP_ABI" $with_gmp)
if test ! -f gmp/config.status; then
AC_MSG_ERROR([Failed to configure the GMP library.])
fi
fi
with_gmp="yes"
else
if test "x$ECL_GMP_HEADER" = "x"; then
AC_MSG_ERROR([Can not find GMP header.])
fi
fi
dnl -----------------------------------------------------------------------
dnl GMP-based search of C/C++ compiler and linker flags
AC_MSG_CHECKING([GMP autoconf])
AC_MSG_RESULT(["${with_gmp}.${with_system_gmp}.${enable_slow_config}"])
if test "${with_gmp}.${with_system_gmp}.${enable_slow_config}" = "yes.no.yes"; then
AC_MSG_RESULT(["${with_system_gmp}.${enable_slow_config}"])
if test "${with_system_gmp}.${enable_slow_config}" = "no.yes"; then
ECL_GMP_BASED_CONFIG
fi

View file

@ -54,11 +54,8 @@
/* Use GNU Multiple Precision library for bignums */
#ifndef DPP
#undef WITH_GMP
#ifdef WITH_GMP
#include "@ECL_GMP_HEADER@"
#endif
#endif
/* Userland threads? */
#undef ECL_THREADS

View file

@ -16,7 +16,7 @@
#ifndef ECL_NUMBER_H
#define ECL_NUMBER_H
#define ECL_BIG_REGISTER_SIZE 32
#ifdef WITH_GMP
#define ECL_WITH_TEMP_BIGNUM(name,n) \
mp_limb_t name##data[n]; \
volatile struct ecl_bignum name##aux; \
@ -30,6 +30,9 @@ extern ECL_API cl_object _ecl_big_set_index(cl_object x, cl_index f);
#ifdef ECL_LONG_FLOAT
extern ECL_API long double _ecl_big_to_long_double(cl_object x);
#endif
typedef void (*_ecl_big_binary_op)(cl_object out, cl_object o1, cl_object o2);
extern ECL_API _ecl_big_binary_op _ecl_big_boole_operator(int operator);
#if ECL_LONG_BITS >= FIXNUM_BITS
#define _ecl_big_set_fixnum(x, f) mpz_set_si((x)->big.big_num,(f))
#define _ecl_big_set_index(x, f) mpz_set_ui((x)->big.big_num,(f))
@ -60,39 +63,4 @@ extern ECL_API long double _ecl_big_to_long_double(cl_object x);
#define _ecl_big_tdiv_q_ui(q, x, y) mpz_tdiv_q_ui((q)->big.big_num, (x)->big.big_num, (y))
#define _ecl_big_set_d(x, d) mpz_set_d((x)->big.big_num, (d))
#else /* WITH_GMP */
#define ECL_WITH_TEMP_BIGNUM(name,n) \
volatile struct ecl_bignum name##aux; \
const cl_object name = (name##aux.big_num = 0, \
(cl_object)(&name##aux))
#define _ecl_big_set_fixnum(x,f) ((x)->big.big_num=(f))
#define _ecl_big_set_index(x,f) ((x)->big.big_num=(f))
#define _ecl_big_init2(x,size) ((x)->big.big_num=0)
#define _ecl_big_clear(x) mpz_clear((x)->big.big_num)
#define _ecl_big_set(x,y) ((x)->big.big_num = (y)->big.big_num)
extern int _ecl_big_num_t_sgn(big_num_t x);
#define _ecl_big_odd_p(x) ((int)((x)->big.big_num&1) != 0)
#define _ecl_big_even_p(x) ((int)((x)->big.big_num&1) == 0)
#define _ecl_big_zerop(x) ((x)->big.big_num == (big_num_t)0)
#define _ecl_big_sign(x) _ecl_big_num_t_sgn((x)->big.big_num)
#define _ecl_big_compare(x,y) _ecl_big_num_t_sgn((x)->big.big_num - (y)->big.big_num)
#define _ecl_big_complement(z, x) ((z)->big.big_num = -((x)->big.big_num))
#define _ecl_big_add(z, x, y) (z)->big.big_num = (x)->big.big_num+(y)->big.big_num
#define _ecl_big_sub(z, x, y) (z)->big.big_num = (x)->big.big_num-(y)->big.big_num
#define _ecl_big_mul(z, x, y) (z)->big.big_num = (x)->big.big_num*(y)->big.big_num
#define _ecl_big_add_ui(z, x, y) ((z)->big.big_num = (x)->big.big_num+(unsigned long)(y))
#define _ecl_big_sub_ui(z, x, y) ((z)->big.big_num = (x)->big.big_num-(unsigned long)(y))
#define _ecl_big_mul_ui(z, x, y) ((x)->big.big_num = (x)->big.big_num*(unsigned long)(y))
#define _ecl_big_mul_si(z, x, y) (z)->big.big_num = (x)->big.big_num*(y)
#define _ecl_big_set_ui(x, i) ((x)->big.big_num = ((big_num_t)((unsigned long int)i)))
#define _ecl_big_set_si(x, i) ((x)->big.big_num = ((big_num_t)((long int)i)))
#define _ecl_big_to_double(x) ((double)((x)->big.big_num))
#define _ecl_big_to_long(x) ((long int)((x)->big.big_num))
#define _ecl_big_to_ulong(x) ((unsigned long int)((x)->big.big_num))
#define _ecl_big_cmp_si(x, y) ((x)->big.big_num!=(y))
#define _ecl_big_tdiv_q(q, x, y) ((q)->big.big_num = (x)->big.big_num / (y)->big.big_num)
#define _ecl_big_tdiv_q_ui(q, x, y) ((q)->big.big_num = (x)->big.big_num / (y))
#define _ecl_big_set_d(x, d) ((x)->big.big_num = (big_num_t)(d))
#endif /* WITH_GMP */
#endif /* ECL_NUMBER_H */

View file

@ -215,8 +215,6 @@ struct ecl_long_float {
#define ecl_long_float(o) ((o)->longfloat.value)
#endif
#ifdef WITH_GMP
struct ecl_bignum {
HEADER;
mpz_t big_num;
@ -225,21 +223,6 @@ struct ecl_bignum {
#define big_size big_num->_mp_size
#define big_limbs big_num->_mp_d
#else /* WITH_GMP */
# ifdef ecl_long_long_t
typedef long long int big_num_t;
# else
typedef long int big_num_t; /* would it work? */
# endif /* ecl_long_long_t */
struct ecl_bignum {
HEADER;
big_num_t big_num;
};
#endif /* WITH_GMP */
struct ecl_ratio {
HEADER;
cl_object den; /* denominator, must be an integer */