[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bignum branch
From: |
Tom Tromey |
Subject: |
Re: bignum branch |
Date: |
Tue, 07 Aug 2018 18:25:16 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) |
>>>>> "Andy" == Andy Moreton <address@hidden> writes:
Andy> This should use mpz_size.
[...]
Andy> Use a loop with mpz_getlimbn or mpz_limbs_read to do this with the API.
Andy> mpz_roinit_n may be useful instead, using the low level APIs.
Andy> See (info "(gmp) Integer Special Functions").
What do you think of this version?
I tested it by hacking a bignum defconst into subr.el and then
re-building.
Tom
diff --git a/src/alloc.c b/src/alloc.c
index 512fdadfb2..edfb87e5cd 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5535,6 +5535,34 @@ make_pure_float (double num)
return new;
}
+/* Value is a bignum object with value VALUE allocated from pure
+ space. */
+
+static Lisp_Object
+make_pure_bignum (struct Lisp_Bignum *value)
+{
+ Lisp_Object new;
+ size_t i, nlimbs = mpz_size (value->value);
+ size_t nbytes = nlimbs * sizeof (mp_limb_t);
+ mp_limb_t *pure_limbs;
+ mp_size_t new_size;
+
+ struct Lisp_Bignum *b = pure_alloc (sizeof (struct Lisp_Bignum), Lisp_Misc);
+ b->type = Lisp_Misc_Bignum;
+
+ pure_limbs = pure_alloc (nbytes, -1);
+ for (i = 0; i < nlimbs; ++i)
+ pure_limbs[i] = mpz_getlimbn (value->value, i);
+
+ new_size = nlimbs;
+ if (mpz_sgn (value->value) < 0)
+ new_size = -new_size;
+
+ mpz_roinit_n (b->value, pure_limbs, new_size);
+
+ XSETMISC (new, b);
+ return new;
+}
/* Return a vector with room for LEN Lisp_Objects allocated from
pure space. */
@@ -5676,6 +5704,8 @@ purecopy (Lisp_Object obj)
/* Don't hash-cons it. */
return obj;
}
+ else if (BIGNUMP (obj))
+ obj = make_pure_bignum (XBIGNUM (obj));
else
{
AUTO_STRING (fmt, "Don't know how to purify: %S");
- Re: bignum branch, (continued)
- Re: bignum branch, Eli Zaretskii, 2018/08/04
- Re: bignum branch, Andy Moreton, 2018/08/04
- Re: bignum branch, Tom Tromey, 2018/08/04
- Re: bignum branch, Robert Pluim, 2018/08/06
- Re: bignum branch, Tom Tromey, 2018/08/06
- Re: bignum branch, Andy Moreton, 2018/08/07
- Re: bignum branch,
Tom Tromey <=
- Re: bignum branch, Tom Tromey, 2018/08/04
Re: bignum branch, Tom Tromey, 2018/08/03
- Re: bignum branch, Andy Moreton, 2018/08/03
- Re: bignum branch, Eli Zaretskii, 2018/08/04
- Re: bignum branch, Andy Moreton, 2018/08/05
- Re: bignum branch, Eli Zaretskii, 2018/08/05
- Re: bignum branch, Andy Moreton, 2018/08/06
- Re: bignum branch, Tom Tromey, 2018/08/06
- Re: bignum branch, Paul Eggert, 2018/08/06
- Re: bignum branch, Tom Tromey, 2018/08/06