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

mercurial at gmplib.org mercurial at gmplib.org
Sun Jun 8 18:27:52 UTC 2014


details:   /var/hg/gmp/rev/af66055a6b75
changeset: 16427:af66055a6b75
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jun 08 18:02:27 2014 +0200
description:
(main): Don't use TMP_SALLOC_LIMBS.

details:   /var/hg/gmp/rev/fb77ef399dfa
changeset: 16428:fb77ef399dfa
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jun 08 19:45:25 2014 +0200
description:
Update TMP markup according to last change.

details:   /var/hg/gmp/rev/b288c63bf856
changeset: 16429:b288c63bf856
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jun 08 19:49:06 2014 +0200
description:
Don't call mpn_sqr_basecase since it fails for non-cryptographic sizes for some obsolete CPUs.

details:   /var/hg/gmp/rev/12b1443791d8
changeset: 16430:12b1443791d8
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jun 08 19:52:36 2014 +0200
description:
Replace many TMP_SALLOC invocations by a single TMP_ALLOC.

details:   /var/hg/gmp/rev/c8d3f0321946
changeset: 16431:c8d3f0321946
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jun 08 19:53:40 2014 +0200
description:
Remove own squaring code, instead use mpn_mul_basecase.

details:   /var/hg/gmp/rev/d3c144da1fb0
changeset: 16432:d3c144da1fb0
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jun 08 20:27:00 2014 +0200
description:
(TMP_ALLOC): Decrease limit to about half.

details:   /var/hg/gmp/rev/9e6d79072c16
changeset: 16433:9e6d79072c16
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jun 08 20:27:15 2014 +0200
description:
ChangeLog

diffstat:

 ChangeLog                |  20 +++++++++++++--
 gmp-impl.h               |   3 +-
 mpn/generic/sec_powm.c   |  60 ++++++++----------------------------------------
 mpn/generic/sec_sqr.c    |  31 ++++++++++++++++++++++++-
 mpn/generic/toom42_mul.c |  17 +++++++------
 mpn/generic/toom53_mul.c |  25 ++++++++++---------
 tests/mpn/logic.c        |  10 ++++----
 7 files changed, 86 insertions(+), 80 deletions(-)

diffs (truncated from 312 to 300 lines):

diff -r 7592f149cc3a -r 9e6d79072c16 ChangeLog
--- a/ChangeLog	Sun Jun 08 17:13:48 2014 +0200
+++ b/ChangeLog	Sun Jun 08 20:27:15 2014 +0200
@@ -1,6 +1,20 @@
 2014-06-08  Torbjörn Granlund  <tege at gmplib.org>
 
-	* mpn/generic/dcpi1_div_q.c: Avoid TMP_SALLOC_LIMB.
+	* gmp-impl.h (TMP_ALLOC): Decrease limit to about half.
+
+	* mpn/generic/toom53_mul.c: Replace many TMP_SALLOC invocations
+	by a single TMP_ALLOC.
+	* mpn/generic/toom42_mul.c: Likewise.
+
+	* mpn/generic/sec_sqr.c: Don't unconditionally call mpn_sqr_basecase
+	since it fails for non-cryptographic sizes for some obsolete CPUs.
+
+	* mpn/generic/sec_powm.c: Remove own squaring code, instead use
+	mpn_mul_basecase.
+
+	* tests/mpn/logic.c (main): Don't use TMP_SALLOC_LIMBS.
+
+	* mpn/generic/dcpi1_div_q.c: Avoid TMP_SALLOC_LIMBS.
 	* mpn/generic/dcpi1_div_qr.c: Likewise.
 
 2014-06-08 Marco Bodrato <bodrato at mail.dm.unipi.it>
@@ -9,8 +23,8 @@
 
 2014-06-06  Torbjörn Granlund  <tege at gmplib.org>
 
-	* mpn/generic/mul.c: Swap some TMP_SALLOC_LIMB for TMP_ALLOC_LIMB
-	and some TMP_ALLOC_LIMB for TMP_SALLOC_LIMB.
+	* mpn/generic/mul.c: Swap some TMP_SALLOC_LIMBS for TMP_ALLOC_LIMBS
+	and some TMP_ALLOC_LIMBS for TMP_SALLOC_LIMBS.
 
 2014-05-31 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
diff -r 7592f149cc3a -r 9e6d79072c16 gmp-impl.h
--- a/gmp-impl.h	Sun Jun 08 17:13:48 2014 +0200
+++ b/gmp-impl.h	Sun Jun 08 20:27:15 2014 +0200
@@ -374,8 +374,9 @@
 #define TMP_MARK		__tmp_marker = 0
 #define TMP_SALLOC(n)		alloca(n)
 #define TMP_BALLOC(n)		__gmp_tmp_reentrant_alloc (&__tmp_marker, n)
+/* The peculiar stack allocation limit here is chosen for efficient asm.  */
 #define TMP_ALLOC(n)							\
-  (LIKELY ((n) < 65536) ? TMP_SALLOC(n) : TMP_BALLOC(n))
+  (LIKELY ((n) <= 0x7f00) ? TMP_SALLOC(n) : TMP_BALLOC(n))
 #define TMP_SFREE
 #define TMP_FREE							\
   do {									\
diff -r 7592f149cc3a -r 9e6d79072c16 mpn/generic/sec_powm.c
--- a/mpn/generic/sec_powm.c	Sun Jun 08 17:13:48 2014 +0200
+++ b/mpn/generic/sec_powm.c	Sun Jun 08 20:27:15 2014 +0200
@@ -3,7 +3,7 @@
 
    Contributed to the GNU project by Torbjörn Granlund.
 
-Copyright 2007-2009, 2011, 2012, 2013 Free Software Foundation, Inc.
+Copyright 2007-2009, 2011-2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -112,7 +112,7 @@
 #ifdef TUNE_SQR_TOOM2_MAX
 /* We slightly abuse TUNE_SQR_TOOM2_MAX here.  If it is set for an assembly
    mpn_sqr_basecase, it comes from SQR_TOOM2_THRESHOLD_MAX in the assembly
-   file.  An assembly mpn_sqr_basecase that does not define it, should allow
+   file.  An assembly mpn_sqr_basecase that does not define it should allow
    any size.  */
 #define SQR_BASECASE_LIM  SQR_TOOM2_THRESHOLD
 #endif
@@ -130,54 +130,14 @@
    size.  */
 #define mpn_local_sqr(rp,up,n,tp) mpn_sqr_basecase(rp,up,n)
 #else
-/* Define our own squaring function, which uses mpn_sqr_basecase for its
-   allowed sizes, but its own code for larger sizes.  */
-static void
-mpn_local_sqr (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_ptr tp)
-{
-  mp_size_t i;
-
-  ASSERT (n >= 1);
-  ASSERT (! MPN_OVERLAP_P (rp, 2*n, up, n));
-
-  if (BELOW_THRESHOLD (n, SQR_BASECASE_LIM))
-    {
-      mpn_sqr_basecase (rp, up, n);
-      return;
-    }
-
-  {
-    mp_limb_t ul, lpl;
-    ul = up[0];
-    umul_ppmm (rp[1], lpl, ul, ul << GMP_NAIL_BITS);
-    rp[0] = lpl >> GMP_NAIL_BITS;
-  }
-  if (n > 1)
-    {
-      mp_limb_t cy;
-
-      cy = mpn_mul_1 (tp, up + 1, n - 1, up[0]);
-      tp[n - 1] = cy;
-      for (i = 2; i < n; i++)
-	{
-	  mp_limb_t cy;
-	  cy = mpn_addmul_1 (tp + 2 * i - 2, up + i, n - i, up[i - 1]);
-	  tp[n + i - 2] = cy;
-	}
-      MPN_SQR_DIAGONAL (rp + 2, up + 1, n - 1);
-
-      {
-	mp_limb_t cy;
-#if HAVE_NATIVE_mpn_addlsh1_n
-	cy = mpn_addlsh1_n (rp + 1, rp + 1, tp, 2 * n - 2);
-#else
-	cy = mpn_lshift (tp, tp, 2 * n - 2, 1);
-	cy += mpn_add_n (rp + 1, rp + 1, tp, 2 * n - 2);
-#endif
-	rp[2 * n - 1] += cy;
-      }
-    }
-}
+/* Else use mpn_sqr_basecase for its allowed sizes, else mpn_mul_basecase.  */
+#define mpn_local_sqr(rp,up,n,tp) \
+  do {									\
+    if (BELOW_THRESHOLD (n, SQR_BASECASE_LIM))				\
+      mpn_sqr_basecase (rp, up, n);					\
+    else								\
+      mpn_mul_basecase(rp, up, n, up, n);				\
+  } while (0)
 #endif
 
 #define getbit(p,bi) \
diff -r 7592f149cc3a -r 9e6d79072c16 mpn/generic/sec_sqr.c
--- a/mpn/generic/sec_sqr.c	Sun Jun 08 17:13:48 2014 +0200
+++ b/mpn/generic/sec_sqr.c	Sun Jun 08 20:27:15 2014 +0200
@@ -2,7 +2,7 @@
 
    Contributed to the GNU project by Torbjörn Granlund.
 
-Copyright 2013 Free Software Foundation, Inc.
+Copyright 2013, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -33,12 +33,41 @@
 #include "gmp.h"
 #include "gmp-impl.h"
 
+#if ! HAVE_NATIVE_mpn_sqr_basecase
+/* The limit of the generic code is SQR_TOOM2_THRESHOLD.  */
+#define SQR_BASECASE_LIM  SQR_TOOM2_THRESHOLD
+#endif
+
+#if HAVE_NATIVE_mpn_sqr_basecase
+#ifdef TUNE_SQR_TOOM2_MAX
+/* We slightly abuse TUNE_SQR_TOOM2_MAX here.  If it is set for an assembly
+   mpn_sqr_basecase, it comes from SQR_TOOM2_THRESHOLD_MAX in the assembly
+   file.  An assembly mpn_sqr_basecase that does not define it should allow
+   any size.  */
+#define SQR_BASECASE_LIM  SQR_TOOM2_THRESHOLD
+#endif
+#endif
+
+#ifdef WANT_FAT_BINARY
+/* For fat builds, we use SQR_TOOM2_THRESHOLD which will expand to a read from
+   __gmpn_cpuvec.  Perhaps any possible sqr_basecase.asm allow any size, and we
+   limit the use unnecessarily.  We cannot tell, so play it safe.  FIXME.  */
+#define SQR_BASECASE_LIM  SQR_TOOM2_THRESHOLD
+#endif
+
 void
 mpn_sec_sqr (mp_ptr rp,
 	     mp_srcptr ap, mp_size_t an,
 	     mp_ptr tp)
 {
+#ifndef SQR_BASECASE_LIM
+/* If SQR_BASECASE_LIM is now not defined, use mpn_sqr_basecase for any operand
+   size.  */
   mpn_sqr_basecase (rp, ap, an);
+#else
+/* Else use mpn_sqr_basecase for its allowed sizes, else mpn_mul_basecase.  */
+  mpn_mul_basecase (rp, ap, an, ap, an);
+#endif
 }
 
 mp_size_t
diff -r 7592f149cc3a -r 9e6d79072c16 mpn/generic/toom42_mul.c
--- a/mpn/generic/toom42_mul.c	Sun Jun 08 17:13:48 2014 +0200
+++ b/mpn/generic/toom42_mul.c	Sun Jun 08 20:27:15 2014 +0200
@@ -11,7 +11,7 @@
    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2006-2008, 2012 Free Software Foundation, Inc.
+Copyright 2006-2008, 2012, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -75,6 +75,7 @@
   mp_ptr a0_a2;
   mp_ptr as1, asm1, as2;
   mp_ptr bs1, bsm1, bs2;
+  mp_ptr tmp;
   TMP_DECL;
 
 #define a0  ap
@@ -94,13 +95,13 @@
 
   TMP_MARK;
 
-  as1 = TMP_SALLOC_LIMBS (n + 1);
-  asm1 = TMP_SALLOC_LIMBS (n + 1);
-  as2 = TMP_SALLOC_LIMBS (n + 1);
-
-  bs1 = TMP_SALLOC_LIMBS (n + 1);
-  bsm1 = TMP_SALLOC_LIMBS (n);
-  bs2 = TMP_SALLOC_LIMBS (n + 1);
+  tmp = TMP_ALLOC_LIMBS (10 * (n + 1));
+  as1  = tmp; tmp += n + 1;
+  asm1 = tmp; tmp += n + 1;
+  as2  = tmp; tmp += n + 1;
+  bs1  = tmp; tmp += n + 1;
+  bsm1 = tmp; tmp += n;
+  bs2  = tmp; tmp += n + 1;
 
   a0_a2 = pp;
 
diff -r 7592f149cc3a -r 9e6d79072c16 mpn/generic/toom53_mul.c
--- a/mpn/generic/toom53_mul.c	Sun Jun 08 17:13:48 2014 +0200
+++ b/mpn/generic/toom53_mul.c	Sun Jun 08 20:27:15 2014 +0200
@@ -10,7 +10,7 @@
    SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 2006-2008, 2012 Free Software Foundation, Inc.
+Copyright 2006-2008, 2012, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -70,6 +70,7 @@
   mp_ptr gp;
   mp_ptr as1, asm1, as2, asm2, ash;
   mp_ptr bs1, bsm1, bs2, bsm2, bsh;
+  mp_ptr tmp;
   enum toom7_flags flags;
   TMP_DECL;
 
@@ -92,17 +93,17 @@
 
   TMP_MARK;
 
-  as1  = TMP_SALLOC_LIMBS (n + 1);
-  asm1 = TMP_SALLOC_LIMBS (n + 1);
-  as2  = TMP_SALLOC_LIMBS (n + 1);
-  asm2 = TMP_SALLOC_LIMBS (n + 1);
-  ash  = TMP_SALLOC_LIMBS (n + 1);
-
-  bs1  = TMP_SALLOC_LIMBS (n + 1);
-  bsm1 = TMP_SALLOC_LIMBS (n + 1);
-  bs2  = TMP_SALLOC_LIMBS (n + 1);
-  bsm2 = TMP_SALLOC_LIMBS (n + 1);
-  bsh  = TMP_SALLOC_LIMBS (n + 1);
+  tmp = TMP_ALLOC_LIMBS (10 * (n + 1));
+  as1  = tmp; tmp += n + 1;
+  asm1 = tmp; tmp += n + 1;
+  as2  = tmp; tmp += n + 1;
+  asm2 = tmp; tmp += n + 1;
+  ash  = tmp; tmp += n + 1;
+  bs1  = tmp; tmp += n + 1;
+  bsm1 = tmp; tmp += n + 1;
+  bs2  = tmp; tmp += n + 1;
+  bsm2 = tmp; tmp += n + 1;
+  bsh  = tmp; tmp += n + 1;
 
   gp = pp;
 
diff -r 7592f149cc3a -r 9e6d79072c16 tests/mpn/logic.c
--- a/tests/mpn/logic.c	Sun Jun 08 17:13:48 2014 +0200
+++ b/tests/mpn/logic.c	Sun Jun 08 20:27:15 2014 +0200
@@ -62,8 +62,8 @@
   mp_size_t max_n, n, i;
   gmp_randstate_ptr rands;
   long test, reps = 1000;
-  TMP_SDECL;
-  TMP_SMARK;
+  TMP_DECL;
+  TMP_MARK;
 
   tests_start ();
   TESTS_REPS (reps, argv, argc);
@@ -74,8 +74,8 @@
 
   max_n = 100;
 
-  rp = TMP_SALLOC_LIMBS (1 + max_n * 8 / GMP_LIMB_BITS);
-  refp = TMP_SALLOC_LIMBS (1 + max_n * 8 / GMP_LIMB_BITS);
+  rp = TMP_ALLOC_LIMBS (1 + max_n * 8 / GMP_LIMB_BITS);
+  refp = TMP_ALLOC_LIMBS (1 + max_n * 8 / GMP_LIMB_BITS);


More information about the gmp-commit mailing list