[libntl] 01/07: Import ntl_6.1.0.orig.tar.gz

Julien Puydt julien.puydt at laposte.net
Fri Aug 15 08:23:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch Snark_NTL6
in repository libntl.

commit 53cb09d8670135484776c9ee2fc83b1323c88ae7
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Sun Aug 10 15:24:27 2014 +0200

    Import ntl_6.1.0.orig.tar.gz
---
 README                |  4 +--
 doc/copying.txt       |  2 +-
 doc/lzz_p.txt         | 12 +++++++
 doc/tour-changes.html | 18 ++++++++++-
 include/NTL/FFT.h     | 58 ++++++++++++++++++++++++++-------
 include/NTL/lzz_p.h   | 15 ++++++---
 include/NTL/tools.h   |  4 +++
 include/NTL/version.h |  4 +--
 src/DIRNAME           |  2 +-
 src/DoConfig          |  2 +-
 src/FFT.c             | 68 +++++++++++++++++++++++++--------------
 src/NOTES             |  7 ++--
 src/VERSION_INFO      |  2 +-
 src/WINDIR            |  2 +-
 src/ZZ_pX.c           | 12 +++----
 src/lzz_p.c           | 55 +++++++++++++++++++++++++++----
 src/lzz_pX.c          | 89 ++++++++++++++++++++++++---------------------------
 17 files changed, 240 insertions(+), 116 deletions(-)

diff --git a/README b/README
index eb6a4af..9545071 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
-NTL  -- a library for doing numbery theory --  version 6.0
-Release date: 2013.02.15
+NTL  -- a library for doing numbery theory --  version 6.1
+Release date: 2014.03.13
 
 Author: Victor Shoup (victor at shoup.net)
 
diff --git a/doc/copying.txt b/doc/copying.txt
index 4f927a2..1b1dd57 100644
--- a/doc/copying.txt
+++ b/doc/copying.txt
@@ -2,7 +2,7 @@
 COPYRIGHT NOTICE
 
 NTL -- A Library for Doing Number Theory
-Copyright (C) 1996-2013  Victor Shoup
+Copyright (C) 1996-2014  Victor Shoup
 
 The most recent version of NTL is available at http://www.shoup.net
 
diff --git a/doc/lzz_p.txt b/doc/lzz_p.txt
index 9e51d1a..228eaf3 100644
--- a/doc/lzz_p.txt
+++ b/doc/lzz_p.txt
@@ -316,6 +316,14 @@ static void zz_p::FFTInit(long i);
 // of 2 that divides p-1 gets smaller, thus placing a more severe
 // restriction on the degrees of the polynomials to be multiplied.
 
+static void zz_p::UserFFTInit(long p);
+// set the modulus to a user-provided FFT prime p. To be useful,
+// p-1 should be divisibly by a high power of 2. 
+// The function "long CalcMaxRoot(long p)" is a utility routine
+// that may be used to calculate this value. 
+// If you are going to perform arithmetic modulo a degree n polynomial, 
+// you will want CalcMaxRoot(p) >= NextPowerOfTwo(n)+1. 
+
 zz_pContext::zz_pContext(long p, long maxroot);
 // constructor for a zz_pContext with same semantics
 // as zz_p::init(p, maxroot) above.
@@ -324,4 +332,8 @@ zz_pContext::zz_pContext(INIT_FFT_TYPE, long i);
 // constructor for a zz_pContext with same semantics
 // as zz_p::FFTInit(i) above; invoke as zz_pContext(INIT_FFT, i).
 
+zz_pContext::zz_pContext(INIT_USER_FFT_TYPE, long p);
+// constructor for a zz_pContext with same semantics
+// as zz_p::UserFFTInit(p) above; invoke as zz_pContext(INIT_USER_FFT, p).
+
 
diff --git a/doc/tour-changes.html b/doc/tour-changes.html
index 5167d4c..9b90163 100644
--- a/doc/tour-changes.html
+++ b/doc/tour-changes.html
@@ -19,6 +19,22 @@ A Tour of NTL: Summary of Changes
 
 <p> <hr> <p>
 <h3>
+2014.03.13: Changes between NTL 6.0 and 6.1
+</h3>
+
+<ul>
+Added support for "user defined" FFT primes for <tt>zz_p</tt>.
+See the functions
+<pre>
+   static void zz_p::UserFFTInit(long p);
+   zz_pContext::zz_pContext(INIT_USER_FFT_TYPE, long p);
+</pre>
+in the <tt>lzz_p</tt> module.
+
+</ul>
+
+<p> <hr> <p>
+<h3>
 2013.02.15: Changes between NTL 5.5.2 and 6.0
 </h3>
 
@@ -60,7 +76,7 @@ There are many new conversions provided.
 Moreover, whenever there is a conversion from a ring <i>R</i>
 to a ring <i>S</i>, there is a corresponding, coefficiet-wise
 conversion from the polynomial ring <i>R[X]</i> to the
-polynomial ring <i>R[X]</i>.
+polynomial ring <i>S[X]</i>.
 
 <p>
 In addition, using the template mechanism, there are
diff --git a/include/NTL/FFT.h b/include/NTL/FFT.h
index 91482ae..9da1fee 100644
--- a/include/NTL/FFT.h
+++ b/include/NTL/FFT.h
@@ -63,11 +63,13 @@ struct FFTPrimeInfo {
    Vec<mulmod_precon_t> TwoInvPreconTable;
    // mulmod preconditioning data
 
+   long bigtab; // flag indicating if we use big tables for this prime
    FFTMultipliers MulTab;
    FFTMultipliers InvMulTab;
 
 };
 
+void InitFFTPrimeInfo(FFTPrimeInfo& info, long q, long w, long bigtab);
 
 #define NTL_FFT_BIGTAB_LIMIT (256)
 // big tables are only used for the first NTL_FFT_BIGTAB_LIMIT primes
@@ -75,7 +77,7 @@ struct FFTPrimeInfo {
 // the convolution as well.
 
 
-extern FFTPrimeInfo *FFTTables;
+extern FFTPrimeInfo **FFTTables;
 
 
 // legacy interface
@@ -96,19 +98,16 @@ void UseFFTPrime(long index);
 void FFT(long* A, const long* a, long k, long q, const long* root);
 // the low-level FFT routine.
 // computes a 2^k point FFT modulo q, using the table root for the roots.
-// A and a may overlap.
 
 void FFT(long* A, const long* a, long k, long q, const long* root, FFTMultipliers& tab);
 
 
 inline
-void FFTFwd(long* A, const long *a, long k, long i)
+void FFTFwd(long* A, const long *a, long k, FFTPrimeInfo& info)
 // Slightly higher level interface...using the ith FFT prime
-// A and a cannot overlap
 {
-   FFTPrimeInfo& info = FFTTables[i];
 #ifdef NTL_FFT_BIGTAB
-   if (i < NTL_FFT_BIGTAB_LIMIT)
+   if (info.bigtab)
       FFT(A, a, k, info.q, &info.RootTable[0], info.MulTab);
    else
       FFT(A, a, k, info.q, &info.RootTable[0]);
@@ -117,14 +116,18 @@ void FFTFwd(long* A, const long *a, long k, long i)
 #endif
 }
 
+inline 
+void FFTFwd(long* A, const long *a, long k, long i)
+{
+   FFTFwd(A, a, k, *FFTTables[i]);
+}
+
 inline
-void FFTRev(long* A, const long *a, long k, long i)
+void FFTRev(long* A, const long *a, long k, FFTPrimeInfo& info)
 // Slightly higher level interface...using the ith FFT prime
-// A and a cannot overlap
 {
-   FFTPrimeInfo& info = FFTTables[i];
 #ifdef NTL_FFT_BIGTAB
-   if (i < NTL_FFT_BIGTAB_LIMIT)
+   if (info.bigtab)
       FFT(A, a, k, info.q, &info.RootInvTable[0], info.InvMulTab);
    else
       FFT(A, a, k, info.q, &info.RootInvTable[0]);
@@ -134,13 +137,44 @@ void FFTRev(long* A, const long *a, long k, long i)
 }
 
 inline
-void FFTMulTwoInv(long* A, const long *a, long k, long i)
+void FFTRev(long* A, const long *a, long k, long i)
+{
+   FFTRev(A, a, k, *FFTTables[i]);
+}
+
+inline
+void FFTMulTwoInv(long* A, const long *a, long k, FFTPrimeInfo& info)
 {
-   FFTPrimeInfo& info = FFTTables[i];
    VectorMulModPrecon(1L << k, A, a, info.TwoInvTable[k], info.q, 
                       info.TwoInvPreconTable[k]);
 }
 
+inline
+void FFTMulTwoInv(long* A, const long *a, long k, long i)
+{
+   FFTMulTwoInv(A, a, k, *FFTTables[i]);
+}
+
+inline 
+void FFTRev1(long* A, const long *a, long k, FFTPrimeInfo& info)
+// FFTRev + FFTMulTwoInv
+{
+   FFTRev(A, a, k, info);
+   FFTMulTwoInv(A, A, k, info);
+}
+
+inline 
+void FFTRev1(long* A, const long *a, long k, long i)
+{
+   FFTRev1(A, a, k, *FFTTables[i]);
+}
+
+
+long IsFFTPrime(long n, long& w);
+// tests if n is an "FFT prime" and returns corresponding root
+
+
+
 
 NTL_CLOSE_NNS
 
diff --git a/include/NTL/lzz_p.h b/include/NTL/lzz_p.h
index fc19076..a8af8dd 100644
--- a/include/NTL/lzz_p.h
+++ b/include/NTL/lzz_p.h
@@ -15,7 +15,8 @@ private:
    void operator=(const zz_pInfoT&); // disabled
 public:
    zz_pInfoT(long NewP, long maxroot);
-   zz_pInfoT(long Index);
+   zz_pInfoT(INIT_FFT_TYPE, long index);
+   zz_pInfoT(INIT_USER_FFT_TYPE, long q);
    ~zz_pInfoT();
 
    long ref_count;
@@ -23,10 +24,14 @@ public:
    long p;
    double pinv;
 
-   long index;        // index >= 0 means we are directly using
-                     // an FFT prime
+   FFTPrimeInfo* p_info; // non-null means we are directly using 
+                        // an FFT prime
 
-   long PrimeCnt;     // 0 for FFT prime;  otherwise same as NumPrimes
+   long p_own;     // flag to indicate if info object is owened
+                   // by this
+
+
+   long PrimeCnt;    // 0 for FFT prime;  otherwise same as NumPrimes
                      // used for establishing crossover points
 
    long NumPrimes;
@@ -60,6 +65,7 @@ void restore() const;
 zz_pContext() { ptr = 0; }
 zz_pContext(long p, long maxroot=NTL_FFTMaxRoot);
 zz_pContext(INIT_FFT_TYPE, long index);
+zz_pContext(INIT_USER_FFT_TYPE, long q);
 
 zz_pContext(const zz_pContext&); 
 
@@ -101,6 +107,7 @@ long _zz_p__rep;
 
 static void init(long NewP, long maxroot=NTL_FFTMaxRoot);
 static void FFTInit(long index);
+static void UserFFTInit(long q);
 
 
 
diff --git a/include/NTL/tools.h b/include/NTL/tools.h
index ebd0de6..f1f09ea 100644
--- a/include/NTL/tools.h
+++ b/include/NTL/tools.h
@@ -138,6 +138,10 @@ struct INIT_FFT_STRUCT { };
 const INIT_FFT_STRUCT INIT_FFT = INIT_FFT_STRUCT();
 typedef const INIT_FFT_STRUCT& INIT_FFT_TYPE;
 
+struct INIT_USER_FFT_STRUCT { };
+const INIT_USER_FFT_STRUCT INIT_USER_FFT = INIT_USER_FFT_STRUCT();
+typedef const INIT_USER_FFT_STRUCT& INIT_USER_FFT_TYPE;
+
 
 #ifdef NTL_NO_INIT_TRANS
 #define NTL_OPT_RETURN(t, x) return x
diff --git a/include/NTL/version.h b/include/NTL/version.h
index a1595cd..6055ff5 100644
--- a/include/NTL/version.h
+++ b/include/NTL/version.h
@@ -2,10 +2,10 @@
 #ifndef NTL_version__H
 #define NTL_version__H
 
-#define NTL_VERSION "6.0.0"
+#define NTL_VERSION "6.1.0"
 
 #define NTL_MAJOR_VERSION  (6)
-#define NTL_MINOR_VERSION  (0)
+#define NTL_MINOR_VERSION  (1)
 #define NTL_REVISION       (0)
 
 #endif
diff --git a/src/DIRNAME b/src/DIRNAME
index 544ba5a..a3eb917 100644
--- a/src/DIRNAME
+++ b/src/DIRNAME
@@ -1 +1 @@
-ntl-6.0.0
+ntl-6.1.0
diff --git a/src/DoConfig b/src/DoConfig
index 2138b88..5920a3b 100644
--- a/src/DoConfig
+++ b/src/DoConfig
@@ -92,7 +92,7 @@
 
 foreach $arg (@ARGV) {
 
-   if ($arg =~ '-h|help|-help|--help') {
+   if ($arg =~ '^(-h|help|-help|--help)$') {
       system("more ../doc/config.txt");
       exit;
    }
diff --git a/src/FFT.c b/src/FFT.c
index 0ef1a22..c00bf31 100644
--- a/src/FFT.c
+++ b/src/FFT.c
@@ -7,8 +7,8 @@
 NTL_START_IMPL
 
 
-FFTPrimeInfo *FFTTables = 0;
-Vec<FFTPrimeInfo> FFTTables_store;
+FFTPrimeInfo **FFTTables = 0;
+Vec<FFTPrimeInfo*> FFTTables_store;
 
 long *FFTPrime = 0;
 Vec<long> FFTPrime_store;
@@ -27,12 +27,16 @@ long NumFFTPrimes = 0;
 
 
 
-static
 long IsFFTPrime(long n, long& w)
 {
    long  m, x, y, z;
    long j, k;
 
+
+   if (n <= 1 || n >= NTL_SP_BOUND) return 0;
+
+   if (n % 2 == 0) return 0;
+
    if (n % 3 == 0) return 0;
 
    if (n % 5 == 0) return 0;
@@ -140,31 +144,12 @@ long CalcMaxRoot(long p)
 }
 
 
-
-void UseFFTPrime(long index)
+void InitFFTPrimeInfo(FFTPrimeInfo& info, long q, long w, long bigtab)
 {
-   long numprimes = FFTTables_store.length();
-
-   if (index < 0 || index > numprimes)
-      Error("invalid FFT prime index");
-
-   if (index < numprimes) return;
-
-   // index == numprimes
-
-   long q, w;
-
-   NextFFTPrime(q, w);
-
    double qinv = 1/((double) q);
 
    long mr = CalcMaxRoot(q);
 
-   FFTTables_store.SetLength(numprimes+1);
-   FFTTables = FFTTables_store.elts();
-
-   FFTPrimeInfo& info = FFTTables[numprimes];
-
    info.q = q;
    info.qinv = qinv;
 
@@ -197,6 +182,41 @@ void UseFFTPrime(long index)
    for (j = 0; j <= mr; j++)
       tipt[j] = PrepMulModPrecon(tit[j], q, qinv);
 
+   info.bigtab = bigtab;
+}
+
+
+void UseFFTPrime(long index)
+{
+   long numprimes = FFTTables_store.length();
+
+   if (index < 0 || index > numprimes)
+      Error("invalid FFT prime index");
+
+   if (index < numprimes) return;
+
+   // index == numprimes
+
+   long q, w;
+
+   NextFFTPrime(q, w);
+
+
+   FFTTables_store.SetLength(numprimes+1);
+   FFTTables = FFTTables_store.elts();
+   FFTTables[numprimes] = NTL_NEW_OP FFTPrimeInfo();
+   if (!FFTTables[numprimes]) Error("out of memory in UseFFTPrime");
+
+   FFTPrimeInfo& info = *FFTTables[numprimes];
+
+   long bigtab = 0;
+
+#ifdef NTL_FFT_BIGTAB
+   if (index < NTL_FFT_BIGTAB_LIMIT)
+      bigtab = 1;
+#endif
+
+   InitFFTPrimeInfo(info, q, w, bigtab);
 
    // initialize data structures for the legacy inteface
 
@@ -208,7 +228,7 @@ void UseFFTPrime(long index)
 
    FFTPrimeInv_store.SetLength(NumFFTPrimes);
    FFTPrimeInv = FFTPrimeInv_store.elts();
-   FFTPrimeInv[NumFFTPrimes-1] = qinv;
+   FFTPrimeInv[NumFFTPrimes-1] = 1/((double) q);
 }
 
 
diff --git a/src/NOTES b/src/NOTES
index c861060..f45574b 100644
--- a/src/NOTES
+++ b/src/NOTES
@@ -3,8 +3,6 @@ These are basically notes to myself on preparing a new
 distribution of NTL.
 
 
-Notes on making a new distribution
-
 - change version numbers in ../include/NTL/version.h, DIRNAME, and WINDIR
 
 - change the libtool soname in VERSION_INFO. See:
@@ -15,15 +13,16 @@ http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
   make sure these changes are implemented in the template files 
   mfile and cfile, and then run:
 
-- update ../README and ../doc/copying.txt
-
 ./configure
 cp makefile def_makefile
 cp ../include/NTL/config.h ../include/NTL/def_config.h
 
+- update ../README and ../doc/copying.txt
+
 - run:  
 
 make package
 make winpack
 
 
+
diff --git a/src/VERSION_INFO b/src/VERSION_INFO
index 7e093fb..2edd6c3 100644
--- a/src/VERSION_INFO
+++ b/src/VERSION_INFO
@@ -1 +1 @@
-2:0:0
+3:0:0
diff --git a/src/WINDIR b/src/WINDIR
index 1f3e2b6..3ee9373 100644
--- a/src/WINDIR
+++ b/src/WINDIR
@@ -1 +1 @@
-WinNTL-6_0_0
+WinNTL-6_1_0
diff --git a/src/ZZ_pX.c b/src/ZZ_pX.c
index 144433a..a6a4406 100644
--- a/src/ZZ_pX.c
+++ b/src/ZZ_pX.c
@@ -1594,8 +1594,7 @@ void RevToFFTRep(FFTRep& y, const vec_ZZ_p& x,
 
    for (i = 0; i < ZZ_pInfo->NumPrimes; i++) {
       long *yp = &y.tbl[i][0];
-      FFTRev(yp, yp, k, i);
-      FFTMulTwoInv(yp, yp, k, i);
+      FFTRev1(yp, yp, k, i);
    }
 
 }
@@ -1621,8 +1620,7 @@ void FromFFTRep(ZZ_pX& x, FFTRep& y, long lo, long hi)
 
    for (i = 0; i < ZZ_pInfo->NumPrimes; i++) {
       long *yp = &y.tbl[i][0];
-      FFTRev(yp, yp, k, i);
-      FFTMulTwoInv(yp, yp, k, i);
+      FFTRev1(yp, yp, k, i);
    }
 
    hi = min(hi, n-1);
@@ -1695,8 +1693,7 @@ void NDFromFFTRep(ZZ_pX& x, const FFTRep& y, long lo, long hi, FFTRep& z)
       long *zp = &z.tbl[i][0];
       const long *yp = &y.tbl[i][0];
 
-      FFTRev(zp, yp, k, i);
-      FFTMulTwoInv(zp, zp, k, i);
+      FFTRev1(zp, yp, k, i);
    }
 
    hi = min(hi, n-1);
@@ -1740,8 +1737,7 @@ void FromFFTRep(ZZ_p* x, FFTRep& y, long lo, long hi)
 
    for (i = 0; i < ZZ_pInfo->NumPrimes; i++) {
       long *yp = &y.tbl[i][0];
-      FFTRev(yp, yp, k, i);
-      FFTMulTwoInv(yp, yp, k, i);
+      FFTRev1(yp, yp, k, i);
    }
 
    for (j = lo; j <= hi; j++) {
diff --git a/src/lzz_p.c b/src/lzz_p.c
index 4d1b46e..d378ad8 100644
--- a/src/lzz_p.c
+++ b/src/lzz_p.c
@@ -22,7 +22,8 @@ zz_pInfoT::zz_pInfoT(long NewP, long maxroot)
 
    pinv = 1/double(p);
 
-   index = -1;
+   p_info = 0;
+   p_own = 0;
 
    conv(P, p);
 
@@ -72,12 +73,10 @@ zz_pInfoT::zz_pInfoT(long NewP, long maxroot)
    }
 }
 
-zz_pInfoT::zz_pInfoT(long Index)
+zz_pInfoT::zz_pInfoT(INIT_FFT_TYPE, long index)
 {
    ref_count = 1;
 
-   index = Index;
-
    if (index < 0)
       Error("bad FFT prime index");
 
@@ -90,22 +89,55 @@ zz_pInfoT::zz_pInfoT(long Index)
    p = FFTPrime[index];
    pinv = FFTPrimeInv[index];
 
+   p_info = FFTTables[index];
+   p_own = 0;
+
    NumPrimes = 1;
    PrimeCnt = 0;
 
    MaxRoot = CalcMaxRoot(p);
 }
 
+zz_pInfoT::zz_pInfoT(INIT_USER_FFT_TYPE, long q)
+{
+   ref_count = 1;
+
+
+   long w;
+   if (!IsFFTPrime(q, w)) Error("invalid user supplied prime");
+
+   p = q;
+   pinv = 1/((double) q);
+
+   p_info = NTL_NEW_OP FFTPrimeInfo();
+   if (!p_info) Error("out of memory");
+
+   long bigtab = 0;
+#ifdef NTL_FFT_BIGTAB
+   bigtab = 1;
+#endif
+   InitFFTPrimeInfo(*p_info, q, w, bigtab); 
+
+   p_own = 1;
+
+   NumPrimes = 1;
+   PrimeCnt = 0;
+
+   MaxRoot = CalcMaxRoot(p);
+}
 
 
 
 zz_pInfoT::~zz_pInfoT()
 {
-   if (index < 0) {
+   if (!p_info) {
       free(CoeffModP);
       free(x);
       free(u);
    }
+   else {
+      if (p_own) delete p_info;
+   }
 }
 
 
@@ -152,6 +184,12 @@ void zz_p::FFTInit(long index)
    c.restore();
 }
 
+void zz_p::UserFFTInit(long q)
+{
+   zz_pContext c(INIT_USER_FFT, q);
+   c.restore();
+}
+
 zz_pContext::zz_pContext(long p, long maxroot)
 {
    ptr = NTL_NEW_OP zz_pInfoT(p, maxroot);
@@ -159,7 +197,12 @@ zz_pContext::zz_pContext(long p, long maxroot)
 
 zz_pContext::zz_pContext(INIT_FFT_TYPE, long index)
 {
-   ptr = NTL_NEW_OP zz_pInfoT(index);
+   ptr = NTL_NEW_OP zz_pInfoT(INIT_FFT, index);
+}
+
+zz_pContext::zz_pContext(INIT_USER_FFT_TYPE, long q)
+{
+   ptr = NTL_NEW_OP zz_pInfoT(INIT_USER_FFT, q);
 }
 
 zz_pContext::zz_pContext(const zz_pContext& a)
diff --git a/src/lzz_pX.c b/src/lzz_pX.c
index df05d56..75a1994 100644
--- a/src/lzz_pX.c
+++ b/src/lzz_pX.c
@@ -1572,9 +1572,9 @@ void TofftRep(fftRep& y, const zz_pX& x, long k, long lo, long hi)
 
    const zz_p *xx = x.rep.elts();
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
-   if (index >= 0) {
+   if (p_info) {
       for (j = 0; j < n; j++) {
          if (j >= m) {
             y.tbl[0][j] = 0;
@@ -1608,9 +1608,9 @@ void TofftRep(fftRep& y, const zz_pX& x, long k, long lo, long hi)
    }
    
 
-   if (index >= 0) {
+   if (p_info) {
       long *yp = &y.tbl[0][0];
-      FFTFwd(yp, yp, k, index);
+      FFTFwd(yp, yp, k, *p_info);
    } 
    else {
       for (i = 0; i < zz_pInfo->NumPrimes; i++) {
@@ -1648,11 +1648,11 @@ void RevTofftRep(fftRep& y, const vec_zz_p& x,
 
    const zz_p *xx = x.elts();
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
    offset = offset & (n-1);
 
-   if (index >= 0) {
+   if (p_info) {
       for (j = 0; j < n; j++) {
          if (j >= m) {
             y.tbl[0][offset] = 0;
@@ -1688,16 +1688,14 @@ void RevTofftRep(fftRep& y, const vec_zz_p& x,
    }
 
 
-   if (index >= 0) {
+   if (p_info) {
       long *yp = &y.tbl[0][0];
-      FFTRev(yp, yp, k, index);
-      FFTMulTwoInv(yp, yp, k, index);
+      FFTRev1(yp, yp, k, *p_info);
    }
    else {
       for (i = 0; i < zz_pInfo->NumPrimes; i++) {
          long *yp = &y.tbl[i][0];
-         FFTRev(yp, yp, k, i);
-         FFTMulTwoInv(yp, yp, k, i);
+         FFTRev1(yp, yp, k, i);
       }
    }
 }
@@ -1717,18 +1715,16 @@ void FromfftRep(zz_pX& x, fftRep& y, long lo, long hi)
    k = y.k;
    n = (1L << k);
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
-   if (index >= 0) {
+   if (p_info) {
       long *yp = &y.tbl[0][0];
-      FFTRev(yp, yp, k, index);
-      FFTMulTwoInv(yp, yp, k, index);
+      FFTRev1(yp, yp, k, *p_info);
    }
    else {
       for (i = 0; i < NumPrimes; i++) {
          long *yp = &y.tbl[i][0];
-         FFTRev(yp, yp, k, i);
-         FFTMulTwoInv(yp, yp, k, i);
+         FFTRev1(yp, yp, k, i);
       }
    }
 
@@ -1737,7 +1733,7 @@ void FromfftRep(zz_pX& x, fftRep& y, long lo, long hi)
    l = max(l, 0);
    x.rep.SetLength(l);
 
-   if (index >= 0) {
+   if (p_info) {
       zz_p *xp = x.rep.elts();
       long *yp = &y.tbl[0][0];
       for (j = 0; j < l; j++) 
@@ -1771,11 +1767,11 @@ void RevFromfftRep(vec_zz_p& x, fftRep& y, long lo, long hi)
    k = y.k;
    n = (1L << k);
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
-   if (index >= 0) {
+   if (p_info) {
       long *yp = &y.tbl[0][0];
-      FFTFwd(yp, yp, k, index);
+      FFTFwd(yp, yp, k, *p_info);
    }
    else {
       for (i = 0; i < NumPrimes; i++) {
@@ -1789,7 +1785,7 @@ void RevFromfftRep(vec_zz_p& x, fftRep& y, long lo, long hi)
    l = max(l, 0);
    x.SetLength(l);
 
-   if (index >= 0) {
+   if (p_info) {
       zz_p *xp = x.elts();
       long *yp = &y.tbl[0][0];
       for (j = 0; j < l; j++) 
@@ -1817,20 +1813,18 @@ void NDFromfftRep(zz_pX& x, const fftRep& y, long lo, long hi, fftRep& z)
 
    z.SetSize(k);
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
-   if (index >= 0) {
+   if (p_info) {
       long *zp = &z.tbl[0][0];
       const long *yp = &y.tbl[0][0];
-      FFTRev(zp, yp, k, index);
-      FFTMulTwoInv(zp, zp, k, index);
+      FFTRev1(zp, yp, k, *p_info);
    }
    else {
       for (i = 0; i < NumPrimes; i++) {
          long *zp = &z.tbl[i][0];
          const long *yp = &y.tbl[i][0];
-         FFTRev(zp, yp, k, i);
-         FFTMulTwoInv(zp, zp, k, i);
+         FFTRev1(zp, yp, k, i);
       }
    }
 
@@ -1839,7 +1833,7 @@ void NDFromfftRep(zz_pX& x, const fftRep& y, long lo, long hi, fftRep& z)
    l = max(l, 0);
    x.rep.SetLength(l);
 
-   if (index >= 0) {
+   if (p_info) {
       zz_p *xp = x.rep.elts();
       long *zp = &z.tbl[0][0];
       for (j = 0; j < l; j++) 
@@ -1878,11 +1872,11 @@ void FromfftRep(zz_p* x, fftRep& y, long lo, long hi)
    k = y.k;
    n = (1L << k);
 
-   long index = zz_pInfo->index;
-   if (index >= 0) {
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
+
+   if (p_info) {
       long *yp = &y.tbl[0][0];
-      FFTRev(yp, yp, k, index);
-      FFTMulTwoInv(yp, yp, k, index);
+      FFTRev1(yp, yp, k, *p_info);
 
       for (j = lo; j <= hi; j++) {
          if (j >= n)
@@ -1895,8 +1889,7 @@ void FromfftRep(zz_p* x, fftRep& y, long lo, long hi)
    else {
       for (i = 0; i < NumPrimes; i++) {
          long *yp = &y.tbl[i][0];
-         FFTRev(yp, yp, k, i);
-         FFTMulTwoInv(yp, yp, k, i);
+         FFTRev1(yp, yp, k, i);
       }
    
       for (j = lo; j <= hi; j++) {
@@ -1924,14 +1917,14 @@ void mul(fftRep& z, const fftRep& x, const fftRep& y)
 
    z.SetSize(k);
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
-   if (index >= 0) {
+   if (p_info) {
       long *zp = &z.tbl[0][0];
       const long *xp = &x.tbl[0][0];
       const long *yp = &y.tbl[0][0];
-      long q = FFTPrime[index];
-      double qinv = FFTPrimeInv[index];
+      long q = p_info->q;
+      double qinv = p_info->qinv;
 
       for (j = 0; j < n; j++)
          zp[j] = MulMod(xp[j], yp[j], q, qinv);
@@ -1961,13 +1954,13 @@ void sub(fftRep& z, const fftRep& x, const fftRep& y)
 
    z.SetSize(k);
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
-   if (index >= 0) {
+   if (p_info) {
       long *zp = &z.tbl[0][0];
       const long *xp = &x.tbl[0][0];
       const long *yp = &y.tbl[0][0];
-      long q = FFTPrime[index];
+      long q = p_info->q;
 
       for (j = 0; j < n; j++)
          zp[j] = SubMod(xp[j], yp[j], q);
@@ -1996,13 +1989,13 @@ void add(fftRep& z, const fftRep& x, const fftRep& y)
 
    z.SetSize(k);
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
 
-   if (index >= 0) {
+   if (p_info) {
       long *zp = &z.tbl[0][0];
       const long *xp = &x.tbl[0][0];
       const long *yp = &y.tbl[0][0];
-      long q = FFTPrime[index];
+      long q = p_info->q;
 
       for (j = 0; j < n; j++)
          zp[j] = AddMod(xp[j], yp[j], q);
@@ -2055,10 +2048,10 @@ void AddExpand(fftRep& x, const fftRep& a)
 
    if (l < k) Error("AddExpand: bad args");
 
-   long index = zz_pInfo->index;
+   FFTPrimeInfo *p_info = zz_pInfo->p_info;
    
-   if (index >= 0) {
-      long q = FFTPrime[index];
+   if (p_info) {
+      long q = p_info->q;
       const long *ap = &a.tbl[0][0];
       long *xp = &x.tbl[0][0];
       for (j = 0; j < n; j++) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/libntl.git



More information about the debian-science-commits mailing list