[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bignum branch

From: Tom Tromey
Subject: Re: bignum branch
Date: Sat, 04 Aug 2018 11:24:56 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux)

Andy> Please check this works for you, and feel free to commit it to the
Andy> bignum branch.

Hi.  Today I found out about the mpz_import function, which would make
the slow case of uintmax_t conversion more robust.  I was wondering if
you could try the appended?  I can't readily try it since I don't think
this code path is ever used on my machine.


diff --git a/src/alloc.c b/src/alloc.c
index 367bb73fc1..c9c3cfb496 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3874,12 +3874,12 @@ mpz_set_uintmax_slow (mpz_t result, uintmax_t v)
   /* If long is larger then a faster path is taken.  */
   eassert (sizeof (uintmax_t) > sizeof (unsigned long));
-  /* This restriction could be lifted if needed.  */
-  eassert (sizeof (uintmax_t) <= 2 * sizeof (unsigned long));
-  mpz_set_ui (result, v >> (CHAR_BIT * sizeof (unsigned long)));
-  mpz_mul_2exp (result, result, CHAR_BIT * sizeof (unsigned long));
-  mpz_add_ui (result, result, v & -1ul);
+  /* COUNT = 1 means just a single word of the given size.  ORDER = -1
+     is arbitrary since there's only a single word.  ENDIAN = 0 means
+     use the native endian-ness.  NAILS = 0 means use the whole
+     word.  */
+  mpz_import (result, 1, -1, sizeof (uintmax_t), 0, 0, &v);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]