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

mercurial at gmplib.org mercurial at gmplib.org
Wed Sep 18 21:52:23 UTC 2019


details:   /var/hg/gmp/rev/f60f1fdb58a5
changeset: 17915:f60f1fdb58a5
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Wed Sep 18 23:41:32 2019 +0200
description:
(div1, div2): Rearrange things to allow for asm.

details:   /var/hg/gmp/rev/5f7e18091afd
changeset: 17916:5f7e18091afd
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Wed Sep 18 23:43:08 2019 +0200
description:
(div2): Avoid out-of-specs shift.

details:   /var/hg/gmp/rev/e30b4dd078a6
changeset: 17917:e30b4dd078a6
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Wed Sep 18 23:50:26 2019 +0200
description:
(div2): Use same variable naming in all variants.

details:   /var/hg/gmp/rev/33f3a1eafa88
changeset: 17918:33f3a1eafa88
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Wed Sep 18 23:50:51 2019 +0200
description:
ChangeLog

diffstat:

 ChangeLog           |  12 ++++++++++++
 mpn/generic/hgcd2.c |  52 +++++++++++++++++++++++++++-------------------------
 2 files changed, 39 insertions(+), 25 deletions(-)

diffs (124 lines):

diff -r f044264e2fe9 -r 33f3a1eafa88 ChangeLog
--- a/ChangeLog	Mon Sep 16 22:18:22 2019 +0200
+++ b/ChangeLog	Wed Sep 18 23:50:51 2019 +0200
@@ -1,3 +1,9 @@
+2019-09-18  Torbjörn Granlund  <tg at gmplib.org>
+
+	* mpn/generic/hgcd2.c (div1, div2): Rearrange things to allow for asm.
+	(div2): Avoid out-of-specs shift.
+	(div2): Use same variable naming in all variants.
+
 2019-09-16  Niels Möller  <nisse at lysator.liu.se>
 
 	* mpn/generic/hgcd2.c (HGCD2_DIV2_METHOD): New define.
@@ -10,6 +16,12 @@
 	version. A bitwise division, relying on fast count_leading_zeros,
 	and with fewer branches than the previous code.
 
+2019-09-15  Torbjörn Granlund  <tg at gmplib.org>
+
+	* acinclude.m4 (GMP_ASM_X86_ADX): Remove unused.
+
+	* configure.ac (x86): Amend last change.
+
 2019-09-14  Niels Möller  <nisse at lysator.liu.se>
 
 	* mpn/generic/hgcd2.c (HGCD2_DIV1_METHOD): Rename, and change
diff -r f044264e2fe9 -r 33f3a1eafa88 mpn/generic/hgcd2.c
--- a/mpn/generic/hgcd2.c	Mon Sep 16 22:18:22 2019 +0200
+++ b/mpn/generic/hgcd2.c	Wed Sep 18 23:50:51 2019 +0200
@@ -48,18 +48,14 @@
 #error Nails not implemented
 #endif
 
-/* Single-limb division optimized for small quotients. Returned value
-   holds d0 = r, d1 = q */
-static inline mp_double_limb_t
-div1 (mp_limb_t n0, mp_limb_t d0);
+#if HAVE_NATIVE_mpn_div_11
 
-/* Two-limb division optimized for small quotients.  */
-static mp_limb_t
-div2 (mp_ptr rp,
-      mp_limb_t n1, mp_limb_t n0,
-      mp_limb_t d1, mp_limb_t d0);
+#define div1 mpn_div_11
+/* Single-limb division optimized for small quotients.
+   Returned value holds d0 = r, d1 = q. */
+mp_double_limb_t div1 (mp_limb_t, mp_limb_t);
 
-#if HGCD2_DIV1_METHOD == 1
+#elif HGCD2_DIV1_METHOD == 1
 
 static inline mp_double_limb_t
 div1 (mp_limb_t n0, mp_limb_t d0)
@@ -148,7 +144,13 @@
 #error Unknown HGCD2_DIV1_METHOD
 #endif
 
-#if HGCD2_DIV2_METHOD == 1
+#if HAVE_NATIVE_mpn_div_22
+
+#define div2 mpn_div_22
+/* Two-limb division optimized for small quotients.  */
+mp_limb_t div2 (mp_ptr, mp_limb_t, mp_limb_t, mp_limb_t, mp_limb_t);
+
+#elif HGCD2_DIV2_METHOD == 1
 
 static mp_limb_t
 div2 (mp_ptr rp,
@@ -209,40 +211,40 @@
 /* Bit-wise div2. Relies on fast count_leading_zeros. */
 static mp_limb_t
 div2 (mp_ptr rp,
-      mp_limb_t nh, mp_limb_t nl,
-      mp_limb_t dh, mp_limb_t dl)
+      mp_limb_t n1, mp_limb_t n0,
+      mp_limb_t d1, mp_limb_t d0)
 {
   mp_limb_t q = 0;
   int ncnt;
   int dcnt;
 
-  count_leading_zeros (ncnt, nh);
-  count_leading_zeros (dcnt, dh);
+  count_leading_zeros (ncnt, n1);
+  count_leading_zeros (dcnt, d1);
   dcnt -= ncnt;
 
-  dh = (dh << dcnt) + (-(dcnt > 0) & (dl >> (GMP_LIMB_BITS - dcnt)));
-  dl <<= dcnt;
+  d1 = (d1 << dcnt) + (d0 >> 1 >> (GMP_LIMB_BITS - 1 - dcnt));
+  d0 <<= dcnt;
 
   do
     {
       mp_limb_t mask;
       q <<= 1;
-      if (UNLIKELY (nh == dh))
-	mask = -(nl >= dl);
+      if (UNLIKELY (n1 == d1))
+	mask = -(n0 >= d0);
       else
-	mask = -(nh > dh);
+	mask = -(n1 > d1);
 
       q -= mask;
 
-      sub_ddmmss (nh, nl, nh, nl, mask & dh, mask & dl);
+      sub_ddmmss (n1, n0, n1, n0, mask & d1, mask & d0);
 
-      dl = (dh << (GMP_LIMB_BITS - 1)) | (dl >> 1);
-      dh = dh >> 1;
+      d0 = (d1 << (GMP_LIMB_BITS - 1)) | (d0 >> 1);
+      d1 = d1 >> 1;
     }
   while (dcnt--);
 
-  rp[0] = nl;
-  rp[1] = nh;
+  rp[0] = n0;
+  rp[1] = n1;
 
   return q;
 }


More information about the gmp-commit mailing list