[Ecm-commits] r2400 - branches/6.4.4

cvs commits ecm-commits at lists.gforge.inria.fr
Wed Feb 13 17:49:57 CET 2013


Author: kruppa
Date: 2013-02-13 17:49:56 +0100 (Wed, 13 Feb 2013)
New Revision: 2400

Log:
Merge of commit r2320


Modified:
   branches/6.4.4/ecm-gmp.h
   branches/6.4.4/ecm-impl.h
   branches/6.4.4/mpmod.c
Modified: branches/6.4.4/ecm-gmp.h
===================================================================
--- branches/6.4.4/ecm-gmp.h	2013-02-13 16:42:57 UTC (rev 2399)
+++ branches/6.4.4/ecm-gmp.h	2013-02-13 16:49:56 UTC (rev 2400)
@@ -124,11 +124,11 @@
 #endif
 
 #if defined(HAVE___GMPN_REDC_1)
-  void __gmpn_redc_1 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
+  mp_limb_t __gmpn_redc_1 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
 #endif
 
 #if defined(HAVE___GMPN_REDC_2)
-  void __gmpn_redc_2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr);
+  mp_limb_t __gmpn_redc_2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr);
 #endif
 
 #if defined(HAVE___GMPN_REDC_N)

Modified: branches/6.4.4/ecm-impl.h
===================================================================
--- branches/6.4.4/ecm-impl.h	2013-02-13 16:42:57 UTC (rev 2399)
+++ branches/6.4.4/ecm-impl.h	2013-02-13 16:49:56 UTC (rev 2400)
@@ -76,6 +76,8 @@
 #define __ECM_HAVE_TOKEN_PASTE  0
 #endif
 
+#define ECM_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
+
 #ifndef __ECM
 #if __ECM_HAVE_TOKEN_PASTE
 #define __ECM(x) __ecm_##x

Modified: branches/6.4.4/mpmod.c
===================================================================
--- branches/6.4.4/mpmod.c	2013-02-13 16:42:57 UTC (rev 2399)
+++ branches/6.4.4/mpmod.c	2013-02-13 16:49:56 UTC (rev 2400)
@@ -50,6 +50,20 @@
 static void base2mod (mpres_t, const mpres_t, mpres_t, mpmod_t) ATTRIBUTE_HOT;
 static void REDC (mpres_t, const mpres_t, mpz_t, mpmod_t);
 
+/* Up from GMP 5.1.0, mpn_redc{1,2} do not subtract the modulus if needed,
+   but return the carry of the final addition */
+#if ECM_VERSION_NUM(__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR,__GNU_MP_VERSION_PATCHLEVEL) < ECM_VERSION_NUM(5,1,0)
+#define REDC1(rp,cp,np,nn,invm) __gmpn_redc_1(rp,cp,np,nn,invm)
+#define REDC2(rp,cp,np,nn,invm) __gmpn_redc_2(rp,cp,np,nn,invm)
+#else
+#define REDC1(rp,cp,np,nn,invm)                  \
+  if (__gmpn_redc_1 (rp,cp,np,nn,invm))          \
+    mpn_sub_n (rp, rp, np, nn)
+#define REDC2(rp,cp,np,nn,invm)                  \
+  if (__gmpn_redc_2 (rp,cp,np,nn,invm))          \
+    mpn_sub_n (rp, rp, np, nn)
+#endif
+
 #if 0 /* PZ: commented out, since I don't see how to use this code.
          Indeed, we need a large enough value of K to get significant
          timings; however, for small B1 a too large value of K will
@@ -316,10 +330,10 @@
                  const mp_ptr invm)
 {
 #ifdef HAVE___GMPN_REDC_2
-  __gmpn_redc_2 (rp, cp, np, nn, invm);
+  REDC2(rp, cp, np, nn, invm);
 #else /* HAVE___GMPN_REDC_2 is not defined */
 #ifdef HAVE___GMPN_REDC_1
-  __gmpn_redc_1 (rp, cp, np, nn, invm[0]);
+  REDC1(rp, cp, np, nn, invm[0]);
 #else /* neither HAVE___GMPN_REDC_2 nor HAVE___GMPN_REDC_1 is defined */
   mp_limb_t cy;
   mp_size_t j;
@@ -343,7 +357,6 @@
     }
 #endif /* HAVE___GMPN_REDC_1 */
 #endif /* HAVE___GMPN_REDC_2 */
-  /* Note: both mpn_redc_1 and mpn_redc_2 subtract N if needed */
 }
 
 /* r <- c/R^nn mod n, where n has nn limbs, and R=2^GMP_NUMB_BITS.
@@ -642,13 +655,13 @@
         case MPMOD_MUL_REDC1: /* mpn_mul_n + __gmpn_redc_1 */
 #ifdef HAVE___GMPN_REDC_1
           mpn_mul_n (tmp, s1p, s2p, nn);
-          __gmpn_redc_1 (rp, tmp, np, nn, invm[0]);
+          REDC1(rp, tmp, np, nn, invm[0]);
           break;
 #endif /* otherwise go through to the next available mode */
         case MPMOD_MUL_REDC2: /* mpn_mul_n + __gmpn_redc_2 */
 #ifdef HAVE___GMPN_REDC_2
           mpn_mul_n (tmp, s1p, s2p, nn);
-          __gmpn_redc_2 (rp, tmp, np, nn, invm);
+          REDC2(rp, tmp, np, nn, invm);
           break;
 #endif /* otherwise go through to the next available mode */
         case MPMOD_MUL_REDCN: /* mpn_mul_n + __gmpn_redc_n */
@@ -699,13 +712,13 @@
         case MPMOD_MUL_REDC1: /* mpn_sqr + __gmpn_redc_1 */
 #ifdef HAVE___GMPN_REDC_1
           mpn_sqr (tmp, s1p, nn);
-          __gmpn_redc_1 (rp, tmp, np, nn, invm[0]);
+          REDC1(rp, tmp, np, nn, invm[0]);
           break;
 #endif /* otherwise go through to the next available mode */
         case MPMOD_MUL_REDC2: /* mpn_sqr + __gmpn_redc_2 */
 #ifdef HAVE___GMPN_REDC_2
           mpn_sqr (tmp, s1p, nn);
-          __gmpn_redc_2 (rp, tmp, np, nn, invm);
+          REDC2(rp, tmp, np, nn, invm);
           break;
 #endif /* otherwise go through to the next available mode */
         case MPMOD_MUL_REDCN: /* mpn_sqr + __gmpn_redc_n */




More information about the Ecm-commits mailing list