mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-02-04 14:40:38 -08:00
bignum: replace references to gmp limbs with ecl macros
GMP_LIMB_BITS -> ECL_BIGNUM_LIMB_BITS mp_limb_t -> ecl_limb_t
This commit is contained in:
parent
a826e65af0
commit
ceae17c1bb
4 changed files with 24 additions and 22 deletions
|
|
@ -37,7 +37,7 @@ _hash_eql(cl_hashkey h, cl_object x)
|
|||
case t_bignum:
|
||||
return hash_string(h, (unsigned char*)ECL_BIGNUM_LIMBS(x),
|
||||
labs(ECL_BIGNUM_SIZE(x)) *
|
||||
sizeof(mp_limb_t));
|
||||
sizeof(ecl_limb_t));
|
||||
case t_ratio:
|
||||
h = _hash_eql(h, x->ratio.num);
|
||||
return _hash_eql(h, x->ratio.den);
|
||||
|
|
@ -244,7 +244,7 @@ _hash_equalp(int depth, cl_hashkey h, cl_object x)
|
|||
/* FIXME! We should be more precise here! */
|
||||
return hash_string(h, (unsigned char*)ecl_bignum(x)->_mp_d,
|
||||
abs(ecl_bignum(x)->_mp_size) *
|
||||
sizeof(mp_limb_t));
|
||||
sizeof(ecl_limb_t));
|
||||
case t_ratio:
|
||||
h = _hash_equalp(0, h, x->ratio.num);
|
||||
return _hash_equalp(0, h, x->ratio.den);
|
||||
|
|
|
|||
|
|
@ -100,17 +100,17 @@ generate_double(cl_object state)
|
|||
return (generate_int64(state) >> 11) * (1.0 / 9007199254740991.0);
|
||||
}
|
||||
|
||||
static mp_limb_t
|
||||
static ecl_limb_t
|
||||
generate_limb(cl_object state)
|
||||
{
|
||||
#if GMP_LIMB_BITS <= 32
|
||||
#if ECL_BIGNUM_LIMB_BITS <= 32
|
||||
return generate_int64(state);
|
||||
#else
|
||||
# if GMP_LIMB_BITS <= 64
|
||||
# if ECL_BIGNUM_LIMB_BITS <= 64
|
||||
return generate_int64(state);
|
||||
# else
|
||||
# if GMP_LIMB_BITS <= 128
|
||||
mp_limb_t high = generate_int64(state);
|
||||
# if ECL_BIGNUM_LIMB_BITS <= 128
|
||||
ecl_limb_t high = generate_int64(state);
|
||||
return (high << 64) | generate_int64(state);
|
||||
# endif
|
||||
# endif
|
||||
|
|
@ -180,21 +180,21 @@ generate_double(cl_object state)
|
|||
return generate_int32(state) * (1.0 / 4294967296.0);
|
||||
}
|
||||
|
||||
static mp_limb_t
|
||||
static ecl_limb_t
|
||||
generate_limb(cl_object state)
|
||||
{
|
||||
#if GMP_LIMB_BITS <= 32
|
||||
#if ECL_BIGNUM_LIMB_BITS <= 32
|
||||
return generate_int32(state);
|
||||
#else
|
||||
# if GMP_LIMB_BITS <= 64
|
||||
mp_limb_t high = generate_int32(state);
|
||||
# if ECL_BIGNUM_LIMB_BITS <= 64
|
||||
ecl_limb_t high = generate_int32(state);
|
||||
return (high << 32) | generate_int32(state);
|
||||
# else
|
||||
# if GMP_LIMB_BITS <= 128
|
||||
mp_limb_t word0 = generate_int32(state);
|
||||
mp_limb_t word1 = generate_int32(state);
|
||||
mp_limb_t word2 = generate_int32(state);
|
||||
mp_limb_t word3 = generate_int32(state);
|
||||
# if ECL_BIGNUM_LIMB_BITS <= 128
|
||||
ecl_limb_t word0 = generate_int32(state);
|
||||
ecl_limb_t word1 = generate_int32(state);
|
||||
ecl_limb_t word2 = generate_int32(state);
|
||||
ecl_limb_t word3 = generate_int32(state);
|
||||
return (word3 << 96) | (word3 << 64) | (word1 << 32) || word0;
|
||||
# endif
|
||||
# endif
|
||||
|
|
@ -233,8 +233,7 @@ random_integer(cl_object limit, cl_object state)
|
|||
bit_length = ECL_FIXNUM_BITS;
|
||||
buffer = ecl_ash(ecl_make_fixnum(1), bit_length);
|
||||
for (bit_length = mpz_size(ecl_bignum(buffer)); bit_length; ) {
|
||||
ECL_BIGNUM_LIMBS(buffer)[--bit_length] =
|
||||
generate_limb(state);
|
||||
ECL_BIGNUM_LIMBS(buffer)[--bit_length] = generate_limb(state);
|
||||
}
|
||||
return cl_mod(buffer, limit);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/* number.h -- GMP interface. */
|
||||
/* number.h -- INTEGER interface. */
|
||||
#ifndef ECL_NUMBER_H
|
||||
#define ECL_NUMBER_H
|
||||
|
||||
|
|
@ -27,9 +27,10 @@ extern "C" {
|
|||
name##aux.value->_mp_d = name##data, \
|
||||
(cl_object)(&name##aux))
|
||||
|
||||
#define ECL_BIGNUM_DIM(x) (ecl_bignum(x)->_mp_alloc) /* number of allocated limbs */
|
||||
#define ECL_BIGNUM_SIZE(x) (ecl_bignum(x)->_mp_size) /* number of limbs in use times sign of the bignum */
|
||||
#define ECL_BIGNUM_LIMBS(x) (ecl_bignum(x)->_mp_d) /* pointer to array of allocated limbs */
|
||||
#define ECL_BIGNUM_LIMB_BITS GMP_LIMB_BITS
|
||||
#define ECL_BIGNUM_DIM(x) (ecl_bignum(x)->_mp_alloc) /* number of allocated limbs */
|
||||
#define ECL_BIGNUM_SIZE(x) (ecl_bignum(x)->_mp_size) /* number of limbs in use times sign of the bignum */
|
||||
#define ECL_BIGNUM_LIMBS(x) (ecl_bignum(x)->_mp_d) /* pointer to array of allocated limbs */
|
||||
|
||||
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 op);
|
||||
|
|
|
|||
|
|
@ -212,6 +212,8 @@ struct ecl_long_float {
|
|||
#define ecl_long_float(o) ((o)->longfloat.value)
|
||||
|
||||
typedef mpz_t big_num_t;
|
||||
typedef mp_limb_t ecl_limb_t;
|
||||
|
||||
struct ecl_bignum {
|
||||
_ECL_HDR;
|
||||
big_num_t value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue