[Gmp-commit] /var/hg/gmp: 4 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Mon Mar 19 22:44:04 CET 2012


details:   /var/hg/gmp/rev/50fc5b908a27
changeset: 14767:50fc5b908a27
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Mar 19 22:31:42 2012 +0100
description:
Whitespace cleanup.

details:   /var/hg/gmp/rev/21165dd240fb
changeset: 14768:21165dd240fb
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Mar 19 22:34:06 2012 +0100
description:
mpz/oddfac_1.c: Improve ASSERTs.

details:   /var/hg/gmp/rev/9a9449dd9937
changeset: 14769:9a9449dd9937
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Mar 19 22:42:48 2012 +0100
description:
gen-fac_ui.c: Generate more constants (possible mini-mpz_root).

details:   /var/hg/gmp/rev/38b5f7f759cc
changeset: 14770:38b5f7f759cc
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Mar 19 22:43:38 2012 +0100
description:
longlong.h (_PROTO): Remove.

diffstat:

 ChangeLog      |   7 ++++++
 gen-fac_ui.c   |  59 +++++++++++++++++++++++++++++++++++++++++++++------------
 gmp-h.in       |   4 +-
 longlong.h     |  26 ++++++++----------------
 mpz/oddfac_1.c |   3 +-
 5 files changed, 65 insertions(+), 34 deletions(-)

diffs (244 lines):

diff -r 8fa4b082723b -r 38b5f7f759cc ChangeLog
--- a/ChangeLog	Mon Mar 19 00:06:51 2012 +0100
+++ b/ChangeLog	Mon Mar 19 22:43:38 2012 +0100
@@ -1,3 +1,10 @@
+2012-03-19 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/oddfac_1.c: Improve ASSERTs.
+	* gen-fac_ui.c: Generate more constants (possible mini-mpz_root). 
+
+	* longlong.h (_PROTO): Remove.
+
 2012-03-18  Torbjorn Granlund  <tege at gmplib.org>
 
 	* longlong.h (count_trailing_zeros): Write better pure C default
diff -r 8fa4b082723b -r 38b5f7f759cc gen-fac_ui.c
--- a/gen-fac_ui.c	Mon Mar 19 00:06:51 2012 +0100
+++ b/gen-fac_ui.c	Mon Mar 19 22:43:38 2012 +0100
@@ -23,21 +23,37 @@
 #include "bootstrap.c"
 
 
-/* sets x=y*(y+2)*(y+4)*....*(y+2*(z-1))	*/
+/* x=floor(y^(1/z)) */
 void
-odd_products (mpz_t x, mpz_t y, int z)
+mpz_root (mpz_t x, mpz_t y, unsigned long z)
 {
-  mpz_t t;
+  mpz_t t, u, v;
 
-  mpz_init_set (t, y);
-  mpz_set_ui (x, 1);
-  for (; z != 0; z--)
+  if (mpz_cmp_ui (y, 1) <= 0)
     {
-      mpz_mul (x, x, t);
-      mpz_add_ui (t, t, 2);
+      mpz_set (x, y);
+      return;
     }
+  mpz_init (t);
+  mpz_init (v);
+  mpz_init_set_ui (u, 1);
+  mpz_mul_2exp (u, u, mpz_sizeinbase (y, 2) / z + 1);
+  do
+    {
+      mpz_pow_ui (t, u, z - 1);
+      mpz_tdiv_q (t, y, t);
+      mpz_mul_ui (v, u, z - 1);
+      mpz_add (t, t, v);
+      mpz_tdiv_q_ui (t, t, z);
+      if (mpz_cmp (t, u) >= 0)
+	break;
+      mpz_set (u, t);
+    }
+  while (1);
+  mpz_set (x, u);
+  mpz_clear (u);
+  mpz_clear (v);
   mpz_clear (t);
-  return;
 }
 
 /* returns 0 on success		*/
@@ -58,9 +74,9 @@
   printf
     ("/* This table is 0!,1!,2!,3!,...,n! where n! has <= GMP_NUMB_BITS bits */\n");
   printf
-    ("#define ONE_LIMB_FACTORIAL_TABLE CNST_LIMB(0x1),CNST_LIMB(0x1),CNST_LIMB(0x2");
-  mpz_init_set_ui (x, 2);
-  for (b = 3;; b++)
+    ("#define ONE_LIMB_FACTORIAL_TABLE CNST_LIMB(0x1),CNST_LIMB(0x1");
+  mpz_init_set_ui (x, 1);
+  for (b = 2;; b++)
     {
       mpz_mul_ui (x, x, b);	/* so b!=a       */
       if (mpz_sizeinbase (x, 2) > numb)
@@ -103,6 +119,23 @@
     }
   printf (")\n");
 
+  printf
+    ("\n/* This table x_1, x_2,... contains values s.t. x_n^n has <= GMP_NUMB_BITS bits */\n");
+  printf
+    ("#define NTH_ROOT_NUMB_MASK_TABLE (GMP_NUMB_MASK");
+  for (b = 2;b <= 8; b++)
+    {
+      mpz_set_ui (x, 1);
+      mpz_mul_2exp (x, x, numb);
+      mpz_sub_ui (x, x, 1);
+      mpz_root (x, x, b);
+      if (mpz_sizeinbase (x, 2) < 4)
+	break;
+      printf ("),CNST_LIMB(0x");
+      mpz_out_str (stdout, 16, x);
+    }
+  printf (")\n");
+
 #if 0
   mpz_set_ui (x, 1);
   mpz_mul_2exp (x, x, limb + 1);	/* x=2^(limb+1)        */
@@ -174,7 +207,7 @@
   limb_bits = atoi (argv[1]);
   nail_bits = atoi (argv[2]);
   numb_bits = limb_bits - nail_bits;
-  if (limb_bits < 0 || nail_bits < 0 || numb_bits < 0)
+  if (limb_bits < 2 || nail_bits < 0 || numb_bits < 1)
     {
       fprintf (stderr, "Invalid limb/nail bits %d,%d\n", limb_bits,
 	       nail_bits);
diff -r 8fa4b082723b -r 38b5f7f759cc gmp-h.in
--- a/gmp-h.in	Mon Mar 19 00:06:51 2012 +0100
+++ b/gmp-h.in	Mon Mar 19 22:43:38 2012 +0100
@@ -998,7 +998,7 @@
 __GMP_DECLSPEC int mpz_root (mpz_ptr, mpz_srcptr, unsigned long int);
 
 #define mpz_rootrem __gmpz_rootrem
-__GMP_DECLSPEC void mpz_rootrem (mpz_ptr,mpz_ptr, mpz_srcptr, unsigned long int);
+__GMP_DECLSPEC void mpz_rootrem (mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int);
 
 #define mpz_rrandomb __gmpz_rrandomb
 __GMP_DECLSPEC void mpz_rrandomb (mpz_ptr, gmp_randstate_t, mp_bitcnt_t);
@@ -1562,7 +1562,7 @@
 
 #define mpn_sub __MPN(sub)
 #if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub)
-__GMP_DECLSPEC mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t);
+__GMP_DECLSPEC mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
 #endif
 
 #define mpn_sub_1 __MPN(sub_1)
diff -r 8fa4b082723b -r 38b5f7f759cc longlong.h
--- a/longlong.h	Mon Mar 19 00:06:51 2012 +0100
+++ b/longlong.h	Mon Mar 19 22:43:38 2012 +0100
@@ -51,14 +51,6 @@
 #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, multiplier, multiplicand) multiplies two
@@ -258,9 +250,9 @@
 
 #if ! defined (count_leading_zeros) && ! defined (LONGLONG_STANDALONE)
 #if HAVE_ATTRIBUTE_CONST
-long __MPN(count_leading_zeros) _PROTO ((UDItype)) __attribute__ ((const));
+long __MPN(count_leading_zeros) (UDItype) __attribute__ ((const));
 #else
-long __MPN(count_leading_zeros) _PROTO ((UDItype));
+long __MPN(count_leading_zeros) (UDItype);
 #endif
 #define count_leading_zeros(count, x) \
   ((count) = __MPN(count_leading_zeros) (x))
@@ -272,7 +264,7 @@
 #define UDIV_PREINV_ALWAYS  1
 #define UDIV_NEEDS_NORMALIZATION 1
 #define UDIV_TIME 220
-long __MPN(count_leading_zeros) _PROTO ((UDItype));
+long __MPN(count_leading_zeros) (UDItype);
 #define count_leading_zeros(count, x) \
   ((count) = _leadz ((UWtype) (x)))
 #if defined (_CRAYIEEE)		/* I.e., Cray T90/ieee, T3D, and T3E */
@@ -509,7 +501,7 @@
     (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d));			\
     (r) = __r;								\
   } while (0)
-extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype *, UWtype, UWtype, UWtype));
+extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, UWtype);
 #define UDIV_TIME 200
 #endif /* LONGLONG_STANDALONE */
 #endif
@@ -1700,7 +1692,7 @@
     (q) = __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d));			\
     (r) = __r;								\
   } while (0)
-extern UWtype __MPN(udiv_qrnnd) _PROTO ((UWtype *, UWtype, UWtype, UWtype));
+extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, UWtype);
 #ifndef UDIV_TIME
 #define UDIV_TIME 140
 #endif
@@ -1826,7 +1818,7 @@
    hppa. */
 
 #define mpn_umul_ppmm  __MPN(umul_ppmm)
-extern UWtype mpn_umul_ppmm _PROTO ((UWtype *, UWtype, UWtype));
+extern UWtype mpn_umul_ppmm (UWtype *, UWtype, UWtype);
 
 #if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm  \
   && ! defined (LONGLONG_STANDALONE)
@@ -1839,7 +1831,7 @@
 #endif
 
 #define mpn_umul_ppmm_r  __MPN(umul_ppmm_r)
-extern UWtype mpn_umul_ppmm_r _PROTO ((UWtype, UWtype, UWtype *));
+extern UWtype mpn_umul_ppmm_r (UWtype, UWtype, UWtype *);
 
 #if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm_r	\
   && ! defined (LONGLONG_STANDALONE)
@@ -1852,7 +1844,7 @@
 #endif
 
 #define mpn_udiv_qrnnd  __MPN(udiv_qrnnd)
-extern UWtype mpn_udiv_qrnnd _PROTO ((UWtype *, UWtype, UWtype, UWtype));
+extern UWtype mpn_udiv_qrnnd (UWtype *, UWtype, UWtype, UWtype);
 
 #if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd	\
   && ! defined (LONGLONG_STANDALONE)
@@ -1866,7 +1858,7 @@
 #endif
 
 #define mpn_udiv_qrnnd_r  __MPN(udiv_qrnnd_r)
-extern UWtype mpn_udiv_qrnnd_r _PROTO ((UWtype, UWtype, UWtype, UWtype *));
+extern UWtype mpn_udiv_qrnnd_r (UWtype, UWtype, UWtype, UWtype *);
 
 #if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd_r	\
   && ! defined (LONGLONG_STANDALONE)
diff -r 8fa4b082723b -r 38b5f7f759cc mpz/oddfac_1.c
--- a/mpz/oddfac_1.c	Mon Mar 19 00:06:51 2012 +0100
+++ b/mpz/oddfac_1.c	Mon Mar 19 22:43:38 2012 +0100
@@ -499,7 +499,7 @@
 {
   static const mp_limb_t tablef[] = { ONE_LIMB_ODD_FACTORIAL_TABLE };
 
-  ASSERT (flag == 0 || (n >= numberof (tablef) && ABOVE_THRESHOLD (n, FAC_DSC_THRESHOLD)));
+  ASSERT (flag == 0 || (flag == 1 && n >= numberof (tablef) && ABOVE_THRESHOLD (n, FAC_DSC_THRESHOLD)));
 
   if (n < numberof (tablef))
     {
@@ -594,7 +594,6 @@
 	  MPZ_TMP_INIT (mswing, size);
 	  /* Put the sieve on the second half, it will be overwritten by the last mswing. */
 	  sieve = PTR (mswing) + size / 2 + 1;
-	  ASSERT ((SIZ (mswing) = 0) || ALLOC (mswing) == size);
 
 	  size = (bitwise_primesieve (sieve, n - 1) + 1) / log_n_max (n) + 1;
 


More information about the gmp-commit mailing list