[Gmp-commit] /var/hg/gmp: Provide alternative code, make default.

mercurial at gmplib.org mercurial at gmplib.org
Sat Aug 15 19:21:37 UTC 2015


details:   /var/hg/gmp/rev/451c0f77758f
changeset: 16767:451c0f77758f
user:      Torbjorn Granlund <torbjorng at google.com>
date:      Sat Aug 15 21:08:15 2015 +0200
description:
Provide alternative code, make default.

diffstat:

 mpn/generic/mullo_basecase.c |  51 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 45 insertions(+), 6 deletions(-)

diffs (74 lines):

diff -r e5a96e5eb06d -r 451c0f77758f mpn/generic/mullo_basecase.c
--- a/mpn/generic/mullo_basecase.c	Fri Aug 14 17:38:58 2015 +0200
+++ b/mpn/generic/mullo_basecase.c	Sat Aug 15 21:08:15 2015 +0200
@@ -5,7 +5,7 @@
    SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES.
 
 
-Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+Copyright (C) 2000, 2002, 2004, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -36,10 +36,14 @@
 #include "gmp.h"
 #include "gmp-impl.h"
 
-/*
-  FIXME: Should use mpn_addmul_2 (and higher).
-*/
+/* FIXME: Should optionally use mpn_mul_2/mpn_addmul_2.  */
 
+#ifndef MULLO_VARIANT
+#define MULLO_VARIANT 2
+#endif
+
+
+#if MULLO_VARIANT == 1
 void
 mpn_mullo_basecase (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n)
 {
@@ -47,6 +51,41 @@
 
   mpn_mul_1 (rp, up, n, vp[0]);
 
-  for (i = 1; i < n; i++)
-    mpn_addmul_1 (rp + i, up, n - i, vp[i]);
+  for (i = n - 1; i > 0; i--)
+    {
+      vp++;
+      rp++;
+      mpn_addmul_1 (rp, up, i, vp[0]);
+    }
 }
+#endif
+
+
+#if MULLO_VARIANT == 2
+void
+mpn_mullo_basecase (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n)
+{
+  mp_limb_t h;
+
+  h = up[0] * vp[n - 1];
+
+  if (n != 1)
+    {
+      mp_size_t i;
+      mp_limb_t v0;
+
+      v0 = *vp++;
+      h += up[n - 1] * v0 + mpn_mul_1 (rp, up, n - 1, v0);
+      rp++;
+
+      for (i = n - 2; i > 0; i--)
+	{
+	  v0 = *vp++;
+	  h += up[i] * v0 + mpn_addmul_1 (rp, up, i, v0);
+	  rp++;
+	}
+    }
+
+  rp[0] = h;
+}
+#endif


More information about the gmp-commit mailing list