[Gmp-commit] /var/hg/gmp: Make use of mpn_add_n_sub_n in main transform loops.

mercurial at gmplib.org mercurial at gmplib.org
Sun Dec 9 19:28:32 UTC 2018


details:   /var/hg/gmp/rev/9a958f8b67e4
changeset: 17726:9a958f8b67e4
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sun Dec 09 20:28:18 2018 +0100
description:
Make use of mpn_add_n_sub_n in main transform loops.

* mpn/generic/mul_fft.c (mpn_fft_add_sub_modF): New function.
(mpn_fft_fft, mpn_fft_fftinv): Use it.

diffstat:

 mpn/generic/mul_fft.c |  32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diffs (81 lines):

diff -r ad2fba4b602d -r 9a958f8b67e4 mpn/generic/mul_fft.c
--- a/mpn/generic/mul_fft.c	Sat Dec 08 12:03:14 2018 +0100
+++ b/mpn/generic/mul_fft.c	Sun Dec 09 20:28:18 2018 +0100
@@ -6,7 +6,7 @@
    SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
    GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
-Copyright 1998-2010, 2012, 2013 Free Software Foundation, Inc.
+Copyright 1998-2010, 2012, 2013, 2018 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -288,6 +288,26 @@
     }
 }
 
+#if HAVE_NATIVE_mpn_add_n_sub_n
+static inline void
+mpn_fft_add_sub_modF (mp_ptr A0, mp_ptr Ai, mp_srcptr tp, mp_size_t n)
+{
+  mp_limb_t cyas, c, x;
+
+  cyas = mpn_add_n_sub_n (A0, Ai, A0, tp, n);
+
+  c = A0[n] - tp[n] - (cyas & 1);
+  x = (-c) & -((c & GMP_LIMB_HIGHBIT) != 0);
+  Ai[n] = x + c;
+  MPN_INCR_U (Ai, n + 1, x);
+
+  c = A0[n] + tp[n] + (cyas >> 1);
+  x = (c - 1) & -(c != 0);
+  A0[n] = c - x;
+  MPN_DECR_U (A0, n + 1, x);
+}
+
+#else /* ! HAVE_NATIVE_mpn_add_n_sub_n  */
 
 /* r <- a+b mod 2^(n*GMP_NUMB_BITS)+1.
    Assumes a and b are semi-normalized.
@@ -350,6 +370,7 @@
     }
 #endif
 }
+#endif /* HAVE_NATIVE_mpn_add_n_sub_n */
 
 /* input: A[0] ... A[inc*(K-1)] are residues mod 2^N+1 where
 	  N=n*GMP_NUMB_BITS, and 2^omega is a primitive root mod 2^N+1
@@ -388,8 +409,12 @@
 	  /* Ap[inc] <- Ap[0] + Ap[inc] * 2^(lk[1] * omega)
 	     Ap[0]   <- Ap[0] + Ap[inc] * 2^(lk[0] * omega) */
 	  mpn_fft_mul_2exp_modF (tp, Ap[inc], lk[0] * omega, n);
+#if HAVE_NATIVE_mpn_add_n_sub_n
+	  mpn_fft_add_sub_modF (Ap[0], Ap[inc], tp, n);
+#else
 	  mpn_fft_sub_modF (Ap[inc], Ap[0], tp, n);
 	  mpn_fft_add_modF (Ap[0],   Ap[0], tp, n);
+#endif
 	}
     }
 }
@@ -575,8 +600,12 @@
 	  /* Ap[K2] <- Ap[0] + Ap[K2] * 2^((j + K2) * omega)
 	     Ap[0]  <- Ap[0] + Ap[K2] * 2^(j * omega) */
 	  mpn_fft_mul_2exp_modF (tp, Ap[K2], j * omega, n);
+#if HAVE_NATIVE_mpn_add_n_sub_n
+	  mpn_fft_add_sub_modF (Ap[0], Ap[K2], tp, n);
+#else
 	  mpn_fft_sub_modF (Ap[K2], Ap[0], tp, n);
 	  mpn_fft_add_modF (Ap[0],  Ap[0], tp, n);
+#endif
 	}
     }
 }
@@ -965,7 +994,6 @@
   oldcc = cc;
 #if HAVE_NATIVE_mpn_add_n_sub_n
   c2 = mpn_add_n_sub_n (pad_op + l, pad_op, pad_op, pad_op + l, l);
-  /* c2 & 1 is the borrow, c2 & 2 is the carry */
   cc += c2 >> 1; /* carry out from high <- low + high */
   c2 = c2 & 1; /* borrow out from low <- low - high */
 #else


More information about the gmp-commit mailing list