[gmp-ecm] 68/77: Imported Upstream version 6.4.2

Jerome Benoit calculus-guest at moszumanska.debian.org
Sat Jun 6 12:33:55 UTC 2015


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

calculus-guest pushed a commit to branch master
in repository gmp-ecm.

commit d5d3adacd99ddb53c363115e6e9583aa7a392c3f
Author: Laurent Fousse <laurent at komite.net>
Date:   Sat Mar 24 21:02:12 2012 -0700

    Imported Upstream version 6.4.2
---
 ChangeLog                             | 321 ++++++++++++++++++++++++++++++++++
 Fgw.c                                 |  41 ++---
 INSTALL-ecm                           |   6 +-
 Makefile.am                           |   7 +-
 Makefile.in                           |  58 +-----
 NEWS                                  |   7 +
 auxarith.c                            |  39 ++---
 auxi.c                                |  34 ++--
 auxlib.c                              |  30 ++--
 b1_ainc.c                             |  33 ++--
 batch.c                               | 185 ++++++++++++--------
 bestd.c                               |  30 ++--
 build.vc10/bench_mulredc/.svn/entries |   2 +-
 build.vc10/bench_mulredc/Makefile     |  14 +-
 build.vc10/config.h                   |   2 +-
 build.vc10/ecm/ecm.vcxproj            |   1 -
 build.vc10/ecm/ecm.vcxproj.filters    |   3 -
 candi.c                               |  27 ++-
 champions.h                           |   2 +-
 configure                             |  22 +--
 configure.in                          |   2 +-
 ecm-ecm.h                             |  34 ++--
 ecm-gmp.h                             |   2 +-
 ecm-impl.h                            |  40 +++--
 ecm-params.h                          |   2 +-
 ecm-params.h.athlon64                 |   2 +-
 ecm-params.h.core2                    |  28 +--
 ecm-params.h.corei5                   |  16 +-
 ecm.c                                 |  31 ++--
 ecm.h                                 |  37 ++--
 ecm2.c                                |  30 ++--
 ecm_ntt.c                             |  36 ++--
 ecmfactor.c                           |  33 ++--
 ecmfactor2.c                          | 132 --------------
 ellparam_batch.c                      |  21 +++
 eval.c                                |  33 ++--
 factor.c                              |  30 ++--
 getprime.c                            |  30 ++--
 ks-multiply.c                         |  30 ++--
 listz.c                               |  30 ++--
 lucas.c                               |  40 ++---
 main.c                                |  68 ++-----
 median.c                              |  31 ++--
 memory.c                              |   4 +-
 mpmod.c                               |  64 +++----
 mpmod.h                               |  29 ++-
 mpzspm.c                              |  36 ++--
 mpzspv.c                              |  96 ++++++----
 mul_fft.c                             |  26 +--
 mul_lo.c                              |  29 ++-
 ntt_gfp.c                             |  34 ++--
 pm1.c                                 |  31 ++--
 pm1fs2.c                              |  40 ++---
 polyeval.c                            |  30 ++--
 powerpc64/mulredc.m4                  |   2 +-
 powerpc64/mulredc1.asm                |   2 +-
 powerpc64/mulredc10.asm               |   2 +-
 powerpc64/mulredc11.asm               |   2 +-
 powerpc64/mulredc12.asm               |   2 +-
 powerpc64/mulredc13.asm               |   2 +-
 powerpc64/mulredc14.asm               |   2 +-
 powerpc64/mulredc15.asm               |   2 +-
 powerpc64/mulredc16.asm               |   2 +-
 powerpc64/mulredc17.asm               |   2 +-
 powerpc64/mulredc18.asm               |   2 +-
 powerpc64/mulredc19.asm               |   2 +-
 powerpc64/mulredc2.asm                |   2 +-
 powerpc64/mulredc20.asm               |   2 +-
 powerpc64/mulredc3.asm                |   2 +-
 powerpc64/mulredc4.asm                |   2 +-
 powerpc64/mulredc5.asm                |   2 +-
 powerpc64/mulredc6.asm                |   2 +-
 powerpc64/mulredc7.asm                |   2 +-
 powerpc64/mulredc8.asm                |   2 +-
 powerpc64/mulredc9.asm                |   2 +-
 powerpc64/mulredc_1_2.m4              |   2 +-
 powerpc64/redc.asm                    |   2 +-
 pp1.c                                 |  41 +++--
 random.c                              |  44 ++---
 resume.c                              |  28 +--
 rho.c                                 |  30 ++--
 schoen_strass.c                       |  30 ++--
 sets_long.c                           |  38 ++--
 sp.c                                  |  34 ++--
 sp.h                                  |  45 ++---
 spm.c                                 |  60 +++++--
 spv.c                                 |  34 ++--
 stage2.c                              |  30 ++--
 test.ecm                              | 118 ++++++-------
 test.pm1                              |  28 +--
 test.pp1                              |  30 ++--
 toomcook.c                            |  36 ++--
 trial.c                               |  62 -------
 tune.c                                |  31 ++--
 94 files changed, 1473 insertions(+), 1313 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7971b56..531e1f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,325 @@
 ------------------------------------------------------------------------
+r1878 | zimmerma | 2012-03-19 10:11:57 +0100 (Mon, 19 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/ecm-params.h.athlon64
+   M /trunk/ecm-params.h.core2
+   M /trunk/ecm-params.h.corei5
+
+updated default tuning parameters
+
+------------------------------------------------------------------------
+r1877 | bouvierc | 2012-03-18 22:31:30 +0100 (Sun, 18 Mar 2012) | 2 lines
+Changed paths:
+   D /trunk/gpu/gpu_ecm_cc13
+
+Remove old gpu code.
+
+------------------------------------------------------------------------
+r1876 | brian_gladman | 2012-03-17 22:42:08 +0100 (Sat, 17 Mar 2012) | 1 line
+Changed paths:
+   M /trunk/build.vc10/ecm/ecm.vcxproj
+   M /trunk/build.vc10/ecm/ecm.vcxproj.filters
+
+remove trial.c from VC++ build
+------------------------------------------------------------------------
+r1875 | zimmerma | 2012-03-17 10:36:43 +0100 (Sat, 17 Mar 2012) | 3 lines
+Changed paths:
+   M /trunk/NEWS
+   M /trunk/mpzspm.c
+   M /trunk/mpzspv.c
+   M /trunk/sp.h
+   M /trunk/spm.c
+
+implement new LSB reduction of residues mod small primes in mpzspv.c,
+yields significant speedup
+
+------------------------------------------------------------------------
+r1874 | zimmerma | 2012-03-17 08:08:46 +0100 (Sat, 17 Mar 2012) | 3 lines
+Changed paths:
+   M /trunk/batch.c
+   M /trunk/ellparam_batch.c
+
+[batch.c] fixed copyright years and typo
+[ellparam_batch.c] fixed copyright years
+
+------------------------------------------------------------------------
+r1873 | bouvierc | 2012-03-16 18:38:41 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/batch.c
+   M /trunk/ellparam_batch.c
+
+Wrong names in the Copyright.
+
+------------------------------------------------------------------------
+r1872 | zimmerma | 2012-03-16 18:35:39 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   D /trunk/gpu/getprime.c
+   D /trunk/gpu/getprime.h
+   D /trunk/gpu/makefile
+   D /trunk/gpu/modular_arithmetic.c
+   D /trunk/gpu/modular_arithmetic.h
+   D /trunk/gpu/prototype.c
+   D /trunk/gpu/prototype.h
+   D /trunk/gpu/stage1-c.c
+   D /trunk/gpu/stage1.c
+
+removed obsolete files
+
+------------------------------------------------------------------------
+r1871 | bouvierc | 2012-03-16 18:08:34 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/batch.c
+   M /trunk/ellparam_batch.c
+   M /trunk/main.c
+
+Add licence in batch.c and ellparam_batch.c
+
+------------------------------------------------------------------------
+r1867 | zimmerma | 2012-03-16 17:03:40 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/Fgw.c
+   M /trunk/Makefile.am
+   M /trunk/NEWS
+   M /trunk/auxarith.c
+   M /trunk/auxi.c
+   M /trunk/auxlib.c
+   M /trunk/b1_ainc.c
+   M /trunk/bestd.c
+   M /trunk/build.vc10/config.h
+   M /trunk/candi.c
+   M /trunk/configure.in
+   D /trunk/countsmooth.c
+   M /trunk/ecm-ecm.h
+   M /trunk/ecm-gmp.h
+   M /trunk/ecm-impl.h
+   M /trunk/ecm.c
+   M /trunk/ecm.h
+   M /trunk/ecm2.c
+   M /trunk/ecm_ntt.c
+   M /trunk/ecmfactor.c
+   M /trunk/eval.c
+   M /trunk/factor.c
+   M /trunk/getprime.c
+   M /trunk/gpu/getprime.c
+   M /trunk/gpu/modular_arithmetic.c
+   M /trunk/gpu/prototype.c
+   M /trunk/gpu/stage1-c.c
+   M /trunk/gpu/stage1.c
+   M /trunk/ks-multiply.c
+   M /trunk/listz.c
+   M /trunk/lucas.c
+   M /trunk/main.c
+   M /trunk/median.c
+   M /trunk/memory.c
+   M /trunk/mpmod.c
+   M /trunk/mpmod.h
+   M /trunk/mpzspm.c
+   M /trunk/mpzspv.c
+   M /trunk/mul_fft.c
+   M /trunk/mul_lo.c
+   A /trunk/nodist/rho.gp (from /trunk/rho.gp:1864)
+   M /trunk/ntt_gfp.c
+   M /trunk/pm1.c
+   M /trunk/pm1fs2.c
+   M /trunk/polyeval.c
+   M /trunk/powerpc64/mulredc.m4
+   M /trunk/powerpc64/mulredc_1_2.m4
+   M /trunk/powerpc64/redc.asm
+   M /trunk/pp1.c
+   M /trunk/random.c
+   M /trunk/resume.c
+   M /trunk/rho.c
+   D /trunk/rho.gp
+   D /trunk/runecm2.c
+   M /trunk/schoen_strass.c
+   M /trunk/sets_long.c
+   M /trunk/sp.c
+   M /trunk/sp.h
+   M /trunk/spm.c
+   M /trunk/spv.c
+   M /trunk/stage2.c
+   M /trunk/test.ecm
+   M /trunk/test.pm1
+   M /trunk/test.pp1
+   M /trunk/testlong.pp1
+   M /trunk/toomcook.c
+   M /trunk/tune.c
+
+updated the copyright headers to GPL 3 and LGPL 3
+
+------------------------------------------------------------------------
+r1866 | zimmerma | 2012-03-16 16:05:59 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   A /trunk/nodist/countsmooth.c (from /trunk/countsmooth.c:1864)
+   A /trunk/nodist/runecm2.c (from /trunk/runecm2.c:1864)
+
+moved countsmooth.c and runecm2.c to nodist
+
+------------------------------------------------------------------------
+r1865 | zimmerma | 2012-03-16 16:04:58 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   A /trunk/nodist
+
+[nodist] new directory for non-distributed files
+
+------------------------------------------------------------------------
+r1864 | bouvierc | 2012-03-16 14:50:33 +0100 (Fri, 16 Mar 2012) | 3 lines
+Changed paths:
+   M /trunk/gpu/gpu_ecm/Makefile
+   M /trunk/gpu/gpu_ecm/utils.h
+
+Forgot to commit the new Makefile!
+Now include also directly ecm-ecm.h in gpu/gpu_ecm/utils.h
+
+------------------------------------------------------------------------
+r1863 | bouvierc | 2012-03-16 14:37:12 +0100 (Fri, 16 Mar 2012) | 7 lines
+Changed paths:
+   M /trunk/batch.c
+   M /trunk/ecm-impl.h
+   M /trunk/gpu/gpu_ecm/main.c
+   M /trunk/gpu/gpu_ecm/utils.h
+   M /trunk/random.c
+
+Rewriting Makefile of GPUECM to separate libecm file from ecm-ecm file.
+[Makefile] Separate file from libecm. Goal: linking directly libecm.
+[batch.c] Now only include ecm-impl.h 
+[random.c] No outputf in GPUECM
+[main.c] change #define to avoid conflicts
+
+
+------------------------------------------------------------------------
+r1862 | zimmerma | 2012-03-16 10:21:32 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   D /trunk/ecmfactor2.c
+
+[ecmfactor2.c] removed unmaintained program
+
+------------------------------------------------------------------------
+r1861 | zimmerma | 2012-03-16 10:16:14 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   D /trunk/bestdaux.c
+
+[bestdaux.c] removed unused file
+
+------------------------------------------------------------------------
+r1860 | zimmerma | 2012-03-16 10:05:05 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   D /trunk/trial.c
+
+[trial.c] removed unmaintained and untested file
+
+------------------------------------------------------------------------
+r1859 | zimmerma | 2012-03-16 09:39:46 +0100 (Fri, 16 Mar 2012) | 4 lines
+Changed paths:
+   M /trunk/Makefile.am
+   M /trunk/mpmod.c
+   M /trunk/test.ecm
+
+[test.ecm] added one test
+[mpmod.c] added an ASSERT
+[Makefile.am] missing tab
+
+------------------------------------------------------------------------
+r1858 | zimmerma | 2012-03-16 08:51:11 +0100 (Fri, 16 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/tune.c
+
+[tune.c] removed trailing blank
+
+------------------------------------------------------------------------
+r1857 | zimmerma | 2012-03-16 08:13:22 +0100 (Fri, 16 Mar 2012) | 4 lines
+Changed paths:
+   M /trunk/Makefile.am
+   M /trunk/test.pm1
+   M /trunk/test.pp1
+
+[test.pp1] added one test and removed blank line at the end
+[test.pm1] removed blank line at the end
+[Makefile.am] added blank line between tests
+
+------------------------------------------------------------------------
+r1856 | bouvierc | 2012-03-15 19:05:05 +0100 (Thu, 15 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/batch.c
+
+Forgot to remove unused variables.
+
+------------------------------------------------------------------------
+r1855 | zimmerma | 2012-03-15 19:00:20 +0100 (Thu, 15 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/mpmod.c
+
+[mpmod.c] fixed wrong patch in r1851
+
+------------------------------------------------------------------------
+r1854 | bouvierc | 2012-03-15 16:01:21 +0100 (Thu, 15 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/gpu/gpu_ecm/cudakernel.cu
+
+Changes in Cuda_Dbl_mod
+
+------------------------------------------------------------------------
+r1853 | bouvierc | 2012-03-15 13:29:24 +0100 (Thu, 15 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/gpu/gpu_ecm/cudakernel.cu
+
+Rewrite Normalize function.
+
+------------------------------------------------------------------------
+r1852 | bouvierc | 2012-03-15 13:27:47 +0100 (Thu, 15 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/batch.c
+
+Rewrite dup_add_batch2 with 6 residues (like dup_add_batch1)
+
+------------------------------------------------------------------------
+r1851 | zimmerma | 2012-03-15 12:09:28 +0100 (Thu, 15 Mar 2012) | 5 lines
+Changed paths:
+   M /trunk/batch.c
+   M /trunk/mpmod.c
+
+[mpmod.c] fixed bug in ecm_redc_n (found on gcc45 and gcc61),
+	  probably a new release 6.4.2 is needed
+[batch.c] reduced number of auxiliary variables from 5 to 2 in dup_add_batch1
+	  (remains to do the same in dup_add_batch2)
+
+------------------------------------------------------------------------
+r1850 | zimmerma | 2012-03-15 08:08:05 +0100 (Thu, 15 Mar 2012) | 4 lines
+Changed paths:
+   M /trunk/NEWS
+   M /trunk/build.vc10/config.h
+   M /trunk/configure.in
+   M /trunk/main.c
+   M /trunk/test.ecm
+
+[configure.in,build.vc10/config.h] bump version to 7.0-dev
+[main.c] make batch=1 mode the default one for ECM
+[test.ecm] added -batch=0 where needed
+
+------------------------------------------------------------------------
+r1847 | zimmerma | 2012-03-14 23:19:47 +0100 (Wed, 14 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/mpzspv.c
+
+[mpzspv.c] added note about possible improvement in mpzspv_from_mpzv_slow()
+
+------------------------------------------------------------------------
+r1846 | zimmerma | 2012-03-14 20:38:17 +0100 (Wed, 14 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/README.dev
+
+[README.dev] added tag for 6.4.1 release
+
+------------------------------------------------------------------------
+r1844 | zimmerma | 2012-03-14 18:29:22 +0100 (Wed, 14 Mar 2012) | 2 lines
+Changed paths:
+   M /trunk/ChangeLog
+   M /trunk/build.vc10/config.h
+   M /trunk/configure.in
+
+This will be the 6.4.1 release (if all final tests pass)
+
+------------------------------------------------------------------------
 r1842 | zimmerma | 2012-03-14 18:25:52 +0100 (Wed, 14 Mar 2012) | 5 lines
 Changed paths:
    M /trunk/configure.in
diff --git a/Fgw.c b/Fgw.c
index 18d4062..52cff89 100644
--- a/Fgw.c
+++ b/Fgw.c
@@ -1,26 +1,27 @@
-/* 
-  Interface code for George Woltman's gwnum library
+/* Interface code for George Woltman's gwnum library
   
-  Copyright 2004, 2005, 2006, 2008, 2011 Paul Zimmermann and Alexander Kruppa.
+Copyright 2004, 2005, 2006, 2008, 2011, 2012 Paul Zimmermann, Alexander Kruppa,
+David Cleaver.
   
-  Contains code based on the GWNUM library, 
-    copyright 2002-2005 George Woltman, Just For Fun Software, Inc.
+Contains code based on the GWNUM library, 
+copyright 2002-2005 George Woltman, Just For Fun Software, Inc.
   
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/INSTALL-ecm b/INSTALL-ecm
index 9510cf6..b3dd730 100644
--- a/INSTALL-ecm
+++ b/INSTALL-ecm
@@ -181,8 +181,8 @@ Step-by-step instructions, courtesy of Jes Hansen:
    cd ~
 
 7) You are back in your home directory. Now type
-   tar -xvzf ecm-6.4.1.tar.gz
-   cd ecm-6.4.1
+   tar -xvzf ecm-x.y.z.tar.gz
+   cd ecm-x.y.z
    ./configure --with-gmp=/usr/local
    make
 
@@ -197,7 +197,7 @@ In case of a problem, report it to us, with:
 
 - the versions of GMP-ECM and GMP used (first output line), for example:
   
-  GMP-ECM 6.4.1 [configured with GMP 5.0.4, --enable-asm-redc] [P+1]
+  GMP-ECM x.y.z [configured with GMP u.v.w, --enable-asm-redc] [P+1]
 
 - the detailed input enabling us to reproduce the problem, for example:
 
diff --git a/Makefile.am b/Makefile.am
index a2829a1..23ec82f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,14 +43,14 @@ libecm_la_LDFLAGS = '-version-info 0:0:0'
 libecm_la_LIBADD = $(MULREDCLIBRARY)
 
 bin_PROGRAMS = ecm
-noinst_PROGRAMS = tune ecmfactor ecmfactor2 bench_mulredc
+noinst_PROGRAMS = tune ecmfactor bench_mulredc
 # Most binaries want to link libecm.la, and the ones which don't will
 # have their own _LDADD which overrides the default LDADD here
 LDADD = libecm.la $(GMPLIB)
 
 ecm_CPPFLAGS = -DOUTSIDE_LIBECM
 ecm_CFLAGS = $(OPENMP_CFLAGS)
-ecm_SOURCES = auxi.c b1_ainc.c candi.c eval.c random.c main.c trial.c \
+ecm_SOURCES = auxi.c b1_ainc.c candi.c eval.c random.c main.c \
               resume.c getprime.c champions.h
 
 tune_SOURCES = mpmod.c tune.c mul_lo.c listz.c auxlib.c ks-multiply.c \
@@ -61,7 +61,6 @@ tune_CPPFLAGS = -DTUNE $(MULREDCINCPATH)
 tune_LDADD = $(MULREDCLIBRARY) $(GMPLIB)
 
 ecmfactor_CFLAGS = $(OPENMP_CFLAGS)
-ecmfactor2_CFLAGS = $(OPENMP_CFLAGS)
 
 rho_SOURCES = rho.c
 rho_CPPFLAGS = -DTESTDRIVE
@@ -115,7 +114,9 @@ ecm-params:	tune$(EXEEXT)
 
 check: ecm$(EXEEXT)
 	$(srcdir)/test.pp1 ./ecm$(EXEEXT)
+	echo ""
 	$(srcdir)/test.pm1 ./ecm$(EXEEXT)
+	echo ""
 	$(srcdir)/test.ecm ./ecm$(EXEEXT)
 
 longcheck: ecm$(EXEEXT)
diff --git a/Makefile.in b/Makefile.in
index a6e4cfd..a0ad9fd 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -41,7 +41,7 @@ EXTRA_PROGRAMS = rho$(EXEEXT) batch$(EXEEXT) $(am__EXEEXT_1) \
 @ENABLE_ASM_REDC_TRUE at am__append_1 = bench_mulredc test_mulredc
 @ENABLE_ASM_REDC_FALSE at am__append_2 = bench_mulredc
 bin_PROGRAMS = ecm$(EXEEXT)
-noinst_PROGRAMS = tune$(EXEEXT) ecmfactor$(EXEEXT) ecmfactor2$(EXEEXT) \
+noinst_PROGRAMS = tune$(EXEEXT) ecmfactor$(EXEEXT) \
 	bench_mulredc$(EXEEXT)
 @MEMORY_DEBUG_TRUE at am__append_3 = memory.c
 @MEMORY_DEBUG_TRUE at am__append_4 = memory.c
@@ -134,8 +134,7 @@ bench_mulredc_OBJECTS = bench_mulredc-bench_mulredc.$(OBJEXT)
 @ENABLE_ASM_REDC_TRUE@	$(am__DEPENDENCIES_1)
 am_ecm_OBJECTS = ecm-auxi.$(OBJEXT) ecm-b1_ainc.$(OBJEXT) \
 	ecm-candi.$(OBJEXT) ecm-eval.$(OBJEXT) ecm-random.$(OBJEXT) \
-	ecm-main.$(OBJEXT) ecm-trial.$(OBJEXT) ecm-resume.$(OBJEXT) \
-	ecm-getprime.$(OBJEXT)
+	ecm-main.$(OBJEXT) ecm-resume.$(OBJEXT) ecm-getprime.$(OBJEXT)
 ecm_OBJECTS = $(am_ecm_OBJECTS)
 ecm_LDADD = $(LDADD)
 ecm_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
@@ -148,13 +147,6 @@ ecmfactor_DEPENDENCIES = libecm.la $(am__DEPENDENCIES_1)
 ecmfactor_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(ecmfactor_CFLAGS) \
 	$(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-ecmfactor2_SOURCES = ecmfactor2.c
-ecmfactor2_OBJECTS = ecmfactor2-ecmfactor2.$(OBJEXT)
-ecmfactor2_LDADD = $(LDADD)
-ecmfactor2_DEPENDENCIES = libecm.la $(am__DEPENDENCIES_1)
-ecmfactor2_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(ecmfactor2_CFLAGS) \
-	$(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
 am_rho_OBJECTS = rho-rho.$(OBJEXT)
 rho_OBJECTS = $(am_rho_OBJECTS)
 rho_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
@@ -193,11 +185,11 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
 	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
 	$(LDFLAGS) -o $@
 SOURCES = $(libecm_la_SOURCES) $(batch_SOURCES) bench_mulredc.c \
-	$(ecm_SOURCES) ecmfactor.c ecmfactor2.c $(rho_SOURCES) \
-	test_mulredc.c $(tune_SOURCES)
+	$(ecm_SOURCES) ecmfactor.c $(rho_SOURCES) test_mulredc.c \
+	$(tune_SOURCES)
 DIST_SOURCES = $(am__libecm_la_SOURCES_DIST) $(batch_SOURCES) \
-	bench_mulredc.c $(ecm_SOURCES) ecmfactor.c ecmfactor2.c \
-	$(rho_SOURCES) test_mulredc.c $(am__tune_SOURCES_DIST)
+	bench_mulredc.c $(ecm_SOURCES) ecmfactor.c $(rho_SOURCES) \
+	test_mulredc.c $(am__tune_SOURCES_DIST)
 RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
 	html-recursive info-recursive install-data-recursive \
 	install-dvi-recursive install-exec-recursive \
@@ -413,7 +405,7 @@ libecm_la_LIBADD = $(MULREDCLIBRARY)
 LDADD = libecm.la $(GMPLIB)
 ecm_CPPFLAGS = -DOUTSIDE_LIBECM
 ecm_CFLAGS = $(OPENMP_CFLAGS)
-ecm_SOURCES = auxi.c b1_ainc.c candi.c eval.c random.c main.c trial.c \
+ecm_SOURCES = auxi.c b1_ainc.c candi.c eval.c random.c main.c \
               resume.c getprime.c champions.h
 
 tune_SOURCES = mpmod.c tune.c mul_lo.c listz.c auxlib.c ks-multiply.c \
@@ -423,7 +415,6 @@ tune_SOURCES = mpmod.c tune.c mul_lo.c listz.c auxlib.c ks-multiply.c \
 tune_CPPFLAGS = -DTUNE $(MULREDCINCPATH)
 tune_LDADD = $(MULREDCLIBRARY) $(GMPLIB)
 ecmfactor_CFLAGS = $(OPENMP_CFLAGS)
-ecmfactor2_CFLAGS = $(OPENMP_CFLAGS)
 rho_SOURCES = rho.c
 rho_CPPFLAGS = -DTESTDRIVE
 rho_LDADD = -lprimegen $(GMPLIB) $(GSL_LD_FLAGS)
@@ -604,9 +595,6 @@ ecm$(EXEEXT): $(ecm_OBJECTS) $(ecm_DEPENDENCIES)
 ecmfactor$(EXEEXT): $(ecmfactor_OBJECTS) $(ecmfactor_DEPENDENCIES) 
 	@rm -f ecmfactor$(EXEEXT)
 	$(ecmfactor_LINK) $(ecmfactor_OBJECTS) $(ecmfactor_LDADD) $(LIBS)
-ecmfactor2$(EXEEXT): $(ecmfactor2_OBJECTS) $(ecmfactor2_DEPENDENCIES) 
-	@rm -f ecmfactor2$(EXEEXT)
-	$(ecmfactor2_LINK) $(ecmfactor2_OBJECTS) $(ecmfactor2_LDADD) $(LIBS)
 rho$(EXEEXT): $(rho_OBJECTS) $(rho_DEPENDENCIES) 
 	@rm -f rho$(EXEEXT)
 	$(LINK) $(rho_OBJECTS) $(rho_LDADD) $(LIBS)
@@ -633,9 +621,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ecm-main.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ecm-random.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ecm-resume.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ecm-trial.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ecmfactor-ecmfactor.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ecmfactor2-ecmfactor2.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libecm_la-Fgw.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libecm_la-auxarith.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libecm_la-auxlib.Plo at am__quote@
@@ -1059,20 +1045,6 @@ ecm-main.obj: main.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ecm_CPPFLAGS) $(CPPFLAGS) $(ecm_CFLAGS) $(CFLAGS) -c -o ecm-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
 
-ecm-trial.o: trial.c
- at am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ecm_CPPFLAGS) $(CPPFLAGS) $(ecm_CFLAGS) $(CFLAGS) -MT ecm-trial.o -MD -MP -MF $(DEPDIR)/ecm-trial.Tpo -c -o ecm-trial.o `test -f 'trial.c' || echo '$(srcdir)/'`trial.c
- at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/ecm-trial.Tpo $(DEPDIR)/ecm-trial.Po
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='trial.c' object='ecm-trial.o' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ecm_CPPFLAGS) $(CPPFLAGS) $(ecm_CFLAGS) $(CFLAGS) -c -o ecm-trial.o `test -f 'trial.c' || echo '$(srcdir)/'`trial.c
-
-ecm-trial.obj: trial.c
- at am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ecm_CPPFLAGS) $(CPPFLAGS) $(ecm_CFLAGS) $(CFLAGS) -MT ecm-trial.obj -MD -MP -MF $(DEPDIR)/ecm-trial.Tpo -c -o ecm-trial.obj `if test -f 'trial.c'; then $(CYGPATH_W) 'trial.c'; else $(CYGPATH_W) '$(srcdir)/trial.c'; fi`
- at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/ecm-trial.Tpo $(DEPDIR)/ecm-trial.Po
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='trial.c' object='ecm-trial.obj' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ecm_CPPFLAGS) $(CPPFLAGS) $(ecm_CFLAGS) $(CFLAGS) -c -o ecm-trial.obj `if test -f 'trial.c'; then $(CYGPATH_W) 'trial.c'; else $(CYGPATH_W) '$(srcdir)/trial.c'; fi`
-
 ecm-resume.o: resume.c
 @am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(ecm_CPPFLAGS) $(CPPFLAGS) $(ecm_CFLAGS) $(CFLAGS) -MT ecm-resume.o -MD -MP -MF $(DEPDIR)/ecm-resume.Tpo -c -o ecm-resume.o `test -f 'resume.c' || echo '$(srcdir)/'`resume.c
 @am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/ecm-resume.Tpo $(DEPDIR)/ecm-resume.Po
@@ -1115,20 +1087,6 @@ ecmfactor-ecmfactor.obj: ecmfactor.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ecmfactor_CFLAGS) $(CFLAGS) -c -o ecmfactor-ecmfactor.obj `if test -f 'ecmfactor.c'; then $(CYGPATH_W) 'ecmfactor.c'; else $(CYGPATH_W) '$(srcdir)/ecmfactor.c'; fi`
 
-ecmfactor2-ecmfactor2.o: ecmfactor2.c
- at am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ecmfactor2_CFLAGS) $(CFLAGS) -MT ecmfactor2-ecmfactor2.o -MD -MP -MF $(DEPDIR)/ecmfactor2-ecmfactor2.Tpo -c -o ecmfactor2-ecmfactor2.o `test -f 'ecmfactor2.c' || echo '$(srcdir)/'`ecmfactor2.c
- at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/ecmfactor2-ecmfactor2.Tpo $(DEPDIR)/ecmfactor2-ecmfactor2.Po
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='ecmfactor2.c' object='ecmfactor2-ecmfactor2.o' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ecmfactor2_CFLAGS) $(CFLAGS) -c -o ecmfactor2-ecmfactor2.o `test -f 'ecmfactor2.c' || echo '$(srcdir)/'`ecmfactor2.c
-
-ecmfactor2-ecmfactor2.obj: ecmfactor2.c
- at am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ecmfactor2_CFLAGS) $(CFLAGS) -MT ecmfactor2-ecmfactor2.obj -MD -MP -MF $(DEPDIR)/ecmfactor2-ecmfactor2.Tpo -c -o ecmfactor2-ecmfactor2.obj `if test -f 'ecmfactor2.c'; then $(CYGPATH_W) 'ecmfactor2.c'; else $(CYGPATH_W) '$(srcdir)/ecmfactor2.c'; fi`
- at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/ecmfactor2-ecmfactor2.Tpo $(DEPDIR)/ecmfactor2-ecmfactor2.Po
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='ecmfactor2.c' object='ecmfactor2-ecmfactor2.obj' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ecmfactor2_CFLAGS) $(CFLAGS) -c -o ecmfactor2-ecmfactor2.obj `if test -f 'ecmfactor2.c'; then $(CYGPATH_W) 'ecmfactor2.c'; else $(CYGPATH_W) '$(srcdir)/ecmfactor2.c'; fi`
-
 rho-rho.o: rho.c
 @am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(rho_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT rho-rho.o -MD -MP -MF $(DEPDIR)/rho-rho.Tpo -c -o rho-rho.o `test -f 'rho.c' || echo '$(srcdir)/'`rho.c
 @am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/rho-rho.Tpo $(DEPDIR)/rho-rho.Po
@@ -1998,7 +1956,9 @@ ecm-params:	tune$(EXEEXT)
 
 check: ecm$(EXEEXT)
 	$(srcdir)/test.pp1 ./ecm$(EXEEXT)
+	echo ""
 	$(srcdir)/test.pm1 ./ecm$(EXEEXT)
+	echo ""
 	$(srcdir)/test.ecm ./ecm$(EXEEXT)
 
 longcheck: ecm$(EXEEXT)
diff --git a/NEWS b/NEWS
index a53e45d..98da634 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+Changes between ecm-6.4.1 and ecm-6.4.2:
+* Corrected the copyright headers
+* Reduced memory usage in stage 1 with -batch={1,2} mode.
+* Fixed bug in modular reduction (could occur only for numbers larger than
+  386 digits on 64-bit computers and 193 digits on 32-bit computers).
+* Speedup in stage 2 with the NTT default mode
+
 Changes between ecm-6.4 and ecm-6.4.1:
 * GMP-ECM is now distributed under the GPL version 3 or later for the binary,
   and under the LGPL version 3 or later for the library
diff --git a/auxarith.c b/auxarith.c
index 31e4fcb..10fe2e4 100644
--- a/auxarith.c
+++ b/auxarith.c
@@ -1,25 +1,24 @@
 /* Auxiliary arithmetic routines on unsigned long ints for the ecm library.
 
-  Copyright 2001, 2002, 2003, 2004, 2005, 2007 Paul Zimmermann and 
-  Alexander Kruppa.
-
-  This file is part of the ECM Library.
-
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008 Paul Zimmermann and 
+Alexander Kruppa.
+
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "config.h"
 #include "ecm-impl.h"
diff --git a/auxi.c b/auxi.c
index 1908b7a..6239502 100644
--- a/auxi.c
+++ b/auxi.c
@@ -1,22 +1,22 @@
 /* Auxiliary functions for GMP-ECM.
 
-  Copyright 2002, 2003, 2004, 2005, 2007 Paul Zimmermann, Alexander Kruppa, Laurent Fousse, Jim Fougeron.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2011, 2012 Paul Zimmermann,
+Alexander Kruppa, Laurent Fousse, Jim Fougeron, Cyril Bouvier.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <gmp.h>
 #include "ecm-ecm.h"
diff --git a/auxlib.c b/auxlib.c
index 02a79ec..1ecb182 100644
--- a/auxlib.c
+++ b/auxlib.c
@@ -1,24 +1,24 @@
 /* Auxiliary routines for the ecm library.
 
-  Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011 Paul Zimmermann,
+Alexander Kruppa.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 /* need stdio.h and stdarg.h for gmp.h to declare gmp_vfprintf */
 #include <stdio.h>
diff --git a/b1_ainc.c b/b1_ainc.c
index ca3e10b..4e983eb 100644
--- a/b1_ainc.c
+++ b/b1_ainc.c
@@ -1,22 +1,21 @@
 /* Code to compute "Automatic calculated" B1 incrementation
 
-  Copyright 2003, 2005 Jim Fougeron, Paul Zimmermann.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+Copyright 2003, 2005, 2006 Jim Fougeron, Paul Zimmermann.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "ecm-ecm.h"
 #include <math.h>
diff --git a/batch.c b/batch.c
index 6dfcf10..dd06f8e 100644
--- a/batch.c
+++ b/batch.c
@@ -1,3 +1,25 @@
+/* batch.c - Implement batch mode for step 1 of ECM
+ 
+Copyright 2011, 2012 Cyril Bouvier, Paul Zimmermann and David Cleaver.
+ 
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+
 /* ECM stage 1 in batch mode, for initial point (x:z) with small coordinates,
    such that x and z fit into a mp_limb_t.
    For example we can start with (x=2:y=1) with the curve by^2 = x^3 + ax^2 + x
@@ -7,13 +29,7 @@
    Y^2 = X^3 + a/b*X^2 + 1/b^2*X.
 */
 
-#ifdef GPUECM
-#include <stdlib.h>
-#include "ecm-ecm.h"
-#else
 #include "ecm-impl.h"
-#endif
-
 
 #define MAX_HEIGHT 32
 
@@ -159,7 +175,8 @@ mpresn_print (mpres_t x, mpmod_t n)
    assume (x2:z2) - (x1:z1) = (2:1)
    Uses 4 modular multiplies and 4 modular squarings.
    Inputs are x1, z1, x2, z2, d, n.
-   Auxiliary variables: q, t, u, v, w.
+   Use two auxiliary variables: t, w (it seems using one only is not possible
+   if all mpresn_mul and mpresn_sqr calls don't overlap input and output).
 
    In the batch 1 mode, we pass d_prime such that the actual d is d_prime/beta.
    Since beta is a square, if d_prime is a square (on 64-bit machines),
@@ -168,62 +185,88 @@ mpresn_print (mpres_t x, mpmod_t n)
 */
 static void
 dup_add_batch1 (mpres_t x1, mpres_t z1, mpres_t x2, mpres_t z2,
-         mpres_t q, mpres_t t, mpres_t u, mpres_t v, mpres_t w,
-         mp_limb_t d_prime, mpmod_t n)
+                mpres_t t, mpres_t w, mp_limb_t d_prime, mpmod_t n)
 {
-  mpresn_addsub (w, u, x1, z1, n); /* w = x1+/-z1 */
-  mpresn_addsub (t, v, x2, z2, n); /* t = x2+/-z2 */
-
-  mpresn_mul (t, t, u, n); /* t = (x1-z1)(x2+z2) */
-  mpresn_mul (v, v, w, n); /* v = (x2-z2)(x1+z1) */
-  mpresn_sqr (w, w, n);    /* w = (x1+z1)^2 */
-  mpresn_sqr (u, u, n);    /* u = (x1-z1)^2 */
-
-  mpresn_mul (x1, u, w, n); /* xdup = (x1+z1)^2 * (x1-z1)^2 */
-
-  mpresn_sub (w, w, u, n);   /* w = (x1+z1)^2 - (x1-z1)^2 */
+  /* active: x1 z1 x2 z2 */
+  mpresn_addsub (w, z1, x1, z1, n); /* w = x1+z1, z1 = x1-z1 */
+  /* active: w z1 x2 z2 */
+  mpresn_addsub (x1, x2, x2, z2, n); /* x1 = x2+z2, x2 = x2-z2 */
+  /* active: w z1 x1 x2 */
+
+  mpresn_mul (z2, w, x2, n); /* w = (x1+z1)(x2-z2) */
+  /* active: w z1 x1 z2 */
+  mpresn_mul (x2, z1, x1, n); /* x2 = (x1-z1)(x2+z2) */
+  /* active: w z1 x2 z2 */
+  mpresn_sqr (t, z1, n);    /* t = (x1-z1)^2 */
+  /* active: w t x2 z2 */
+  mpresn_sqr (z1, w, n);    /* z1 = (x1+z1)^2 */
+  /* active: z1 t x2 z2 */
+
+  mpresn_mul (x1, z1, t, n); /* xdup = (x1+z1)^2 * (x1-z1)^2 */
+  /* active: x1 z1 t x2 z2 */
+
+  mpresn_sub (w, z1, t, n);   /* w = (x1+z1)^2 - (x1-z1)^2 */
+  /* active: x1 w t x2 z2 */
+
+  mpresn_mul_1 (z1, w, d_prime, n); /* z1 = d * ((x1+z1)^2 - (x1-z1)^2) */
+  /* active: x1 z1 w t x2 z2 */
+
+  mpresn_add (t, t, z1, n);  /* t = (x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2) */
+  /* active: x1 w t x2 z2 */
+  mpresn_mul (z1, w, t, n); /* zdup = w * [(x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2)] */
+  /* active: x1 z1 x2 z2 */
+
+  mpresn_addsub (w, z2, x2, z2, n);
+  /* active: x1 z1 w z2 */
 
-  mpresn_mul_1 (q, w, d_prime, n); /* q = d * ((x1+z1)^2 - (x1-z1)^2) */
-
-  mpresn_add (u, u, q, n);  /* u = (x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2) */
-  mpresn_mul (z1, w, u, n); /* zdup = w * [(x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2)] */
-
-  mpresn_add (w, v, t, n);
-  mpresn_sub (v, v, t, n);
-
-  mpresn_sqr (v, v, n);
   mpresn_sqr (x2, w, n);
-  mpresn_add (z2, v, v, n);
+  /* active: x1 z1 x2 z2 */
+  mpresn_sqr (w, z2, n);
+  /* active: x1 z1 x2 w */
+  mpresn_add (z2, w, w, n);
 }
 
 static void
 dup_add_batch2 (mpres_t x1, mpres_t z1, mpres_t x2, mpres_t z2,
-         mpres_t q, mpres_t t, mpres_t u, mpres_t v, mpres_t w,
-         mpres_t d, mpmod_t n)
+                mpres_t t, mpres_t w, mpres_t d, mpmod_t n)
 {
-  mpresn_addsub (w, u, x1, z1, n); /* w = x1+/-z1 */
-  mpresn_addsub (t, v, x2, z2, n); /* t = x2+/-z2 */
-
-  mpresn_mul (t, t, u, n); /* t = (x1-z1)(x2+z2) */
-  mpresn_mul (v, v, w, n); /* v = (x2-z2)(x1+z1) */
-  mpresn_sqr (w, w, n);    /* w = (x1+z1)^2 */
-  mpresn_sqr (u, u, n);    /* u = (x1-z1)^2 */
+  /* active: x1 z1 x2 z2 */
+  mpresn_addsub (w, z1, x1, z1, n); /* w = x1+z1, z1 = x1-z1 */
+  /* active: w z1 x2 z2 */
+  mpresn_addsub (x1, x2, x2, z2, n); /* x1 = x2+z2, x2 = x2-z2 */
+  /* active: w z1 x1 x2 */
+
+  mpresn_mul (z2, w, x2, n); /* w = (x1+z1)(x2-z2) */
+  /* active: w z1 x1 z2 */
+  mpresn_mul (x2, z1, x1, n); /* x2 = (x1-z1)(x2+z2) */
+  /* active: w z1 x2 z2 */
+  mpresn_sqr (t, z1, n);    /* t = (x1-z1)^2 */
+  /* active: w t x2 z2 */
+  mpresn_sqr (z1, w, n);    /* z1 = (x1+z1)^2 */
+  /* active: z1 t x2 z2 */
+
+  mpresn_mul (x1, z1, t, n); /* xdup = (x1+z1)^2 * (x1-z1)^2 */
+  /* active: x1 z1 t x2 z2 */
+
+  mpresn_sub (w, z1, t, n);   /* w = (x1+z1)^2 - (x1-z1)^2 */
+  /* active: x1 w t x2 z2 */
+
+  mpresn_mul (z1, w, d, n); /* z1 = d * ((x1+z1)^2 - (x1-z1)^2) */
+  /* active: x1 z1 w t x2 z2 */
+
+  mpresn_add (t, t, z1, n);  /* t = (x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2) */
+  /* active: x1 w t x2 z2 */
+  mpresn_mul (z1, w, t, n); /* zdup = w * [(x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2)] */
+  /* active: x1 z1 x2 z2 */
+
+  mpresn_addsub (w, z2, x2, z2, n);
+  /* active: x1 z1 w z2 */
 
-  mpresn_mul (x1, u, w, n); /* xdup = (x1+z1)^2 * (x1-z1)^2 */
-
-  mpresn_sub (w, w, u, n);   /* w = (x1+z1)^2 - (x1-z1)^2 */
-
-  mpresn_mul (q, w, d, n); /* q = d * ((x1+z1)^2 - (x1-z1)^2) */
-
-  mpresn_add (u, u, q, n);  /* u = (x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2) */
-  mpresn_mul (z1, w, u, n); /* zdup = w * [(x1-z1)^2 - d* ((x1+z1)^2 - (x1-z1)^2)] */
-
-  mpresn_add (w, v, t, n);
-  mpresn_sub (v, v, t, n);
-
-  mpresn_sqr (v, v, n);
   mpresn_sqr (x2, w, n);
-  mpresn_add (z2, v, v, n);
+  /* active: x1 z1 x2 z2 */
+  mpresn_sqr (w, z2, n);
+  /* active: x1 z1 x2 w */
+  mpresn_add (z2, w, w, n);
 }
 
 
@@ -253,7 +296,7 @@ ecm_stage1_batch (mpz_t f, mpres_t x, mpres_t A, mpmod_t n, double B1,
 
   mpres_t x1, z1, x2, z2;
   unsigned long i;
-  mpres_t q, t, u, v, w;
+  mpres_t t, u;
   int ret = ECM_NO_FACTOR_FOUND;
 
   MEMORY_TAG;
@@ -265,17 +308,14 @@ ecm_stage1_batch (mpz_t f, mpres_t x, mpres_t A, mpmod_t n, double B1,
   MEMORY_TAG;
   mpres_init (z2, n);
   MEMORY_TAG;
-  mpres_init (q, n);
-  MEMORY_TAG;
   mpres_init (t, n);
   MEMORY_TAG;
   mpres_init (u, n);
-  MEMORY_TAG;
-  mpres_init (v, n);
-  MEMORY_TAG;
-  mpres_init (w, n);
-  MEMORY_TAG;
-  mpres_init (d_2, n);
+  if (batch == 2)
+    {
+      MEMORY_TAG;
+      mpres_init (d_2, n);
+    }
   MEMORY_UNTAG;
 
   /* initialize P */
@@ -330,8 +370,6 @@ ecm_stage1_batch (mpz_t f, mpres_t x, mpres_t A, mpmod_t n, double B1,
   mpresn_pad (z1, n);
   mpresn_pad (x2, n);
   mpresn_pad (z2, n);
-  if (batch == 2)
-    mpresn_pad (d_2, n);
 
   /* now perform the double-and-add ladder */
   if (batch == 1)
@@ -340,22 +378,23 @@ ecm_stage1_batch (mpz_t f, mpres_t x, mpres_t A, mpmod_t n, double B1,
         {
           if (mpz_tstbit (s, i) == 0) /* (j,j+1) -> (2j,2j+1) */
             /* P2 <- P1+P2    P1 <- 2*P1 */
-            dup_add_batch1 (x1, z1, x2, z2, q, t, u, v , w, d_1, n);
+            dup_add_batch1 (x1, z1, x2, z2, t, u, d_1, n);
           else /* (j,j+1) -> (2j+1,2j+2) */
               /* P1 <- P1+P2     P2 <- 2*P2 */
-            dup_add_batch1 (x2, z2, x1, z1, q, t, u, v, w, d_1, n);
+            dup_add_batch1 (x2, z2, x1, z1, t, u, d_1, n);
         }
     }
-  else
+  else /* batch = 2 */
     {
+      mpresn_pad (d_2, n);
       for (i = mpz_sizeinbase (s, 2) - 1; i-- > 0;)
         {
           if (mpz_tstbit (s, i) == 0) /* (j,j+1) -> (2j,2j+1) */
             /* P2 <- P1+P2    P1 <- 2*P1 */
-            dup_add_batch2 (x1, z1, x2, z2, q, t, u, v , w, d_2, n);
+            dup_add_batch2 (x1, z1, x2, z2, t, u, d_2, n);
           else /* (j,j+1) -> (2j+1,2j+2) */
               /* P1 <- P1+P2     P2 <- 2*P2 */
-            dup_add_batch2 (x2, z2, x1, z1, q, t, u, v, w, d_2, n);
+            dup_add_batch2 (x2, z2, x1, z1, t, u, d_2, n);
         }
     }
 
@@ -375,12 +414,12 @@ ecm_stage1_batch (mpz_t f, mpres_t x, mpres_t A, mpmod_t n, double B1,
   mpz_clear (z1);
   mpz_clear (x2);
   mpz_clear (z2);
-  mpz_clear (q);
   mpz_clear (t);
   mpz_clear (u);
-  mpz_clear (v);
-  mpz_clear (w);
-  mpz_clear (d_2);
+  if (batch == 2)
+    {
+      mpz_clear (d_2);
+    }
 
   return ret;
 }
diff --git a/bestd.c b/bestd.c
index b80b09f..e48fbb3 100644
--- a/bestd.c
+++ b/bestd.c
@@ -1,24 +1,24 @@
 /* Choice of best parameters for stage 2.
 
-  Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010 Paul Zimmermann,
+Alexander Kruppa, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <gmp.h>
diff --git a/build.vc10/bench_mulredc/.svn/entries b/build.vc10/bench_mulredc/.svn/entries
index 95884d2..d17bb92 100644
--- a/build.vc10/bench_mulredc/.svn/entries
+++ b/build.vc10/bench_mulredc/.svn/entries
@@ -1,7 +1,7 @@
 10
 
 dir
-1842
+1882
 svn+ssh://zimmerma@scm.gforge.inria.fr/svn/ecm/trunk/build.vc10/bench_mulredc
 svn+ssh://zimmerma@scm.gforge.inria.fr/svn/ecm
 
diff --git a/build.vc10/bench_mulredc/Makefile b/build.vc10/bench_mulredc/Makefile
index 304f039..7ffd7e4 100644
--- a/build.vc10/bench_mulredc/Makefile
+++ b/build.vc10/bench_mulredc/Makefile
@@ -61,11 +61,11 @@ AWK = gawk
 CC = gcc -std=gnu99
 CCAS = gcc -std=gnu99
 CCASDEPMODE = depmode=gcc3
-CCASFLAGS = -O2 -pedantic -m64 -mtune=amdfam10 -march=amdfam10
+CCASFLAGS = -O2 -m64 -march=k8 -mtune=k8
 CCDEPMODE = depmode=gcc3
-CFLAGS = -W -Wall -Wundef -O2 -pedantic -m64 -mtune=amdfam10 -march=amdfam10
+CFLAGS = -W -Wall -Wundef -pedantic -O2 -m64 -march=k8 -mtune=k8
 CPP = gcc -std=gnu99 -E
-CPPFLAGS = -I/users/caramel/logiciels/gmp-5.0.4/x86_64/include -I/users/caramel/logiciels/gmp-5.0.4/x86_64/include
+CPPFLAGS = -I/users/caramel/logiciels/mpir-2.5.1/x86_64/include -I/users/caramel/logiciels/mpir-2.5.1/x86_64/include
 CYGPATH_W = echo
 DEFS = -DHAVE_CONFIG_H
 DEPDIR = .deps
@@ -78,7 +78,7 @@ ECHO_T =
 EGREP = /bin/grep -E
 EXEEXT = 
 FGREP = /bin/grep -F
-GMPLIB = /users/caramel/logiciels/gmp-5.0.4/x86_64/lib/libgmp.a
+GMPLIB = /users/caramel/logiciels/mpir-2.5.1/x86_64/lib/libgmp.a
 GREP = /bin/grep
 GSL_LD_FLAGS = 
 INSTALL = /usr/bin/install -c
@@ -108,10 +108,10 @@ OTOOL64 =
 PACKAGE = ecm
 PACKAGE_BUGREPORT = ecm-discuss at lists.gforge.inria.fr
 PACKAGE_NAME = ecm
-PACKAGE_STRING = ecm 6.4.1
+PACKAGE_STRING = ecm 6.4.2
 PACKAGE_TARNAME = ecm
 PACKAGE_URL = 
-PACKAGE_VERSION = 6.4.1
+PACKAGE_VERSION = 6.4.2
 PATH_SEPARATOR = :
 POW_LIB = 
 RANLIB = ranlib
@@ -120,7 +120,7 @@ SET_MAKE =
 SHELL = /bin/bash
 STRIP = strip
 VALGRIND = valgrind -q --error-exitcode=1
-VERSION = 6.4.1
+VERSION = 6.4.2
 XSLDIR = /usr/share/sgml/docbook/xsl-stylesheets-1.68.1-1.1
 XSLTPROC = 
 abs_builddir = /users/caramel/zimmerma/svn/ecm/build.vc10/bench_mulredc
diff --git a/build.vc10/config.h b/build.vc10/config.h
index 23a4c01..e7cf173 100644
--- a/build.vc10/config.h
+++ b/build.vc10/config.h
@@ -1,6 +1,6 @@
 /* config.h.in.  Generated from configure.in by autoheader.  */
 
-#define VERSION "6.4.1"
+#define VERSION "6.4.2"
 
 #define VERSION_GPU "gpu_ecm-win"
 
diff --git a/build.vc10/ecm/ecm.vcxproj b/build.vc10/ecm/ecm.vcxproj
index 0305e23..7fa5d4e 100644
--- a/build.vc10/ecm/ecm.vcxproj
+++ b/build.vc10/ecm/ecm.vcxproj
@@ -211,7 +211,6 @@
     <ClCompile Include="..\..\main.c" />
     <ClCompile Include="..\..\random.c" />
     <ClCompile Include="..\..\resume.c" />
-    <ClCompile Include="..\..\trial.c" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\champions.h" />
diff --git a/build.vc10/ecm/ecm.vcxproj.filters b/build.vc10/ecm/ecm.vcxproj.filters
index 866be5b..8706613 100644
--- a/build.vc10/ecm/ecm.vcxproj.filters
+++ b/build.vc10/ecm/ecm.vcxproj.filters
@@ -35,9 +35,6 @@
     <ClCompile Include="..\..\resume.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\trial.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\config.h">
diff --git a/candi.c b/candi.c
index a203926..d7b2315 100644
--- a/candi.c
+++ b/candi.c
@@ -1,23 +1,22 @@
 /* Encapsulated candidate.  This candidate should have been a C++ class, but
    since we are using straight C for this project, I guess I can deal with it.
 
-  Copyright 2003, 2004, 2005 Jim Fougeron, Paul Zimmermann.
+Copyright 2003, 2004, 2005, 2006 Jim Fougeron, Paul Zimmermann.
 
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
 
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/champions.h b/champions.h
index ed77846..36b0f53 100644
--- a/champions.h
+++ b/champions.h
@@ -11,4 +11,4 @@ static char *champion_url[3] =
  "http://www.loria.fr/~zimmerma/records/Pminus1.html",
  "http://www.loria.fr/~zimmerma/records/Pplus1.html"};
 /* minimal number of digits to enter the champions table for ECM, P-1, P+1 */
-static unsigned int champion_digits[3] = { 67, 53, 48 };
+static unsigned int champion_digits[3] = { 68, 53, 48 };
diff --git a/configure b/configure
index 4b2a399..37ecb6c 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for ecm 6.4.1.
+# Generated by GNU Autoconf 2.68 for ecm 6.4.2.
 #
 # Report bugs to <ecm-discuss at lists.gforge.inria.fr>.
 #
@@ -570,8 +570,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='ecm'
 PACKAGE_TARNAME='ecm'
-PACKAGE_VERSION='6.4.1'
-PACKAGE_STRING='ecm 6.4.1'
+PACKAGE_VERSION='6.4.2'
+PACKAGE_STRING='ecm 6.4.2'
 PACKAGE_BUGREPORT='ecm-discuss at lists.gforge.inria.fr'
 PACKAGE_URL=''
 
@@ -1324,7 +1324,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures ecm 6.4.1 to adapt to many kinds of systems.
+\`configure' configures ecm 6.4.2 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1394,7 +1394,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of ecm 6.4.1:";;
+     short | recursive ) echo "Configuration of ecm 6.4.2:";;
    esac
   cat <<\_ACEOF
 
@@ -1514,7 +1514,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-ecm configure 6.4.1
+ecm configure 6.4.2
 generated by GNU Autoconf 2.68
 
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -2064,7 +2064,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by ecm $as_me 6.4.1, which was
+It was created by ecm $as_me 6.4.2, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   $ $0 $@
@@ -2888,7 +2888,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='ecm'
- VERSION='6.4.1'
+ VERSION='6.4.2'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2950,7 +2950,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE=ecm
- VERSION=6.4.1
+ VERSION=6.4.2
 
 
 cat >>confdefs.h <<_ACEOF
@@ -14956,7 +14956,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by ecm $as_me 6.4.1, which was
+This file was extended by ecm $as_me 6.4.2, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -15026,7 +15026,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-ecm config.status 6.4.1
+ecm config.status 6.4.2
 configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
diff --git a/configure.in b/configure.in
index 1a35379..f8d7137 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-m4_define([ECM_VERSION], [6.4.1])
+m4_define([ECM_VERSION], [6.4.2])
 
 AC_PREREQ([2.57])
 AC_INIT([ecm], ECM_VERSION, [ecm-discuss at lists.gforge.inria.fr])
diff --git a/ecm-ecm.h b/ecm-ecm.h
index e1c4500..016fbce 100644
--- a/ecm-ecm.h
+++ b/ecm-ecm.h
@@ -1,22 +1,22 @@
 /* ecm-ecm.h - private header file for GMP-ECM.
 
-  Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012 Paul Zimmermann, Alexander Kruppa and Cyril Bouvier.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #ifndef _ECM_ECM_H
 #define _ECM_ECM_H 1
diff --git a/ecm-gmp.h b/ecm-gmp.h
index f059791..e7bc0f2 100644
--- a/ecm-gmp.h
+++ b/ecm-gmp.h
@@ -7,7 +7,7 @@ This file contains modified code from the GNU MP Library.
 
 The GNU MP Library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or (at your
+the Free Software Foundation; either version 3 of the License, or (at your
 option) any later version.
 
 The GNU MP Library is distributed in the hope that it will be useful, but
diff --git a/ecm-impl.h b/ecm-impl.h
index 76d1f97..5b1e5a3 100644
--- a/ecm-impl.h
+++ b/ecm-impl.h
@@ -1,22 +1,24 @@
 /* ecm-impl.h - header file for libecm
  
-  Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012 Paul Zimmermann, Alexander Kruppa and Cyril Bouvier.
  
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
- 
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
- 
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #ifndef _ECM_IMPL_H
 #define _ECM_IMPL_H 1
@@ -763,13 +765,19 @@ int  mpn_fft_best_k (mp_size_t, int);
 mp_size_t mpn_fft_next_size (mp_size_t, int);
 
 /* batch.c */
+#define compute_s  __ECM(compute_s )
 void compute_s (mpz_t, unsigned long);
+#define write_s_in_file __ECM(write_s_in_file)
 int write_s_in_file (char *, mpz_t);
+#define read_s_from_file  __ECM(read_s_from_file)
 void read_s_from_file (mpz_t, char *); 
+#define ecm_stage1_batch  __ECM(ecm_stage1_batch)
 int ecm_stage1_batch (mpz_t, mpres_t, mpres_t, mpmod_t, double, double *, 
                                                                 int,  mpz_t);
 
 /* ellparam_batch.c */
+#define get_curve_from_ell_parametrization \
+                                      __ECM(get_curve_from_ell_parametrization )
 int get_curve_from_ell_parametrization (mpz_t, mpres_t, mpz_t, mpmod_t);
 
 /* sets_long.c */
diff --git a/ecm-params.h b/ecm-params.h
index 12531b1..2037f65 100644
--- a/ecm-params.h
+++ b/ecm-params.h
@@ -20,7 +20,7 @@
 #else /* tuning parameters for MPIR, tuned with MPIR 2.5.1 */
 
 /* 0:mulredc 1:mul+redc_1 2:mul+redc_2 3:mul+redc_n */
-#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1}
+#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
 /* 0:mulredc 1:sqr+redc_1 2:sqr+redc_2 3:sqr+redc_n */
 #define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
 #define MPZMOD_THRESHOLD 21
diff --git a/ecm-params.h.athlon64 b/ecm-params.h.athlon64
index 12531b1..2037f65 100644
--- a/ecm-params.h.athlon64
+++ b/ecm-params.h.athlon64
@@ -20,7 +20,7 @@
 #else /* tuning parameters for MPIR, tuned with MPIR 2.5.1 */
 
 /* 0:mulredc 1:mul+redc_1 2:mul+redc_2 3:mul+redc_n */
-#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1}
+#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
 /* 0:mulredc 1:sqr+redc_1 2:sqr+redc_2 3:sqr+redc_n */
 #define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
 #define MPZMOD_THRESHOLD 21
diff --git a/ecm-params.h.core2 b/ecm-params.h.core2
index f06f101..c8dadd8 100644
--- a/ecm-params.h.core2
+++ b/ecm-params.h.core2
@@ -1,37 +1,37 @@
-/* produced on coing.loria.fr (Intel(R) Core(TM)2 Duo CPU U9600 @ 1.60GHz) */
+/* produced on pasta.loria.fr (Intel(R) Core(TM)2 CPU 6700  @ 2.66GHz) */
 
 #ifndef HAVE_MPIR /* tuning parameters for GMP, tuned for GMP 5.0.4 */
 
 /* 0:mulredc 1:mul+redc_1 2:mul+redc_2 3:mul+redc_n */
-#define TUNE_MULREDC_TABLE {0,0,0,0,0,1,0,0,0,0,0,0,2,0,0,0,0,0,2,0,2}
+#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0}
 /* 0:mulredc 1:sqr+redc_1 2:sqr+redc_2 3:sqr+redc_n */
-#define TUNE_SQRREDC_TABLE {0,0,0,0,0,1,1,0,2,1,1,2,2,2,2,2,2,2,2,2,2}
+#define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,0,2,0,2,0,2,1,1,1,1,2,2,1,2,2}
 #define MPZMOD_THRESHOLD 21
 #define REDC_THRESHOLD 512
-#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 10, 9, 11, 11, 12, 13, 14, 12, 13, 14, 16, 16, 17, 18, 19}
+#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 8, 8, 9, 10, 12, 11, 12, 13, 12, 12, 14, 16, 16, 16, 18, 18, 18}
 #define NTT_GFP_TWIDDLE_DIF_BREAKOVER 17
 #define NTT_GFP_TWIDDLE_DIT_BREAKOVER 17
-#define MUL_NTT_THRESHOLD 512
-#define PREREVERTDIVISION_NTT_THRESHOLD 16
+#define MUL_NTT_THRESHOLD 256
+#define PREREVERTDIVISION_NTT_THRESHOLD 8
 #define POLYINVERT_NTT_THRESHOLD 128
 #define POLYEVALT_NTT_THRESHOLD 256
-#define MPZSPV_NORMALISE_STRIDE 512
+#define MPZSPV_NORMALISE_STRIDE 128
 
 #else /* tuning parameters for MPIR, tuned for MPIR 2.5.1 */
 
 /* 0:mulredc 1:mul+redc_1 2:mul+redc_2 3:mul+redc_n */
-#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
+#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0}
 /* 0:mulredc 1:sqr+redc_1 2:sqr+redc_2 3:sqr+redc_n */
-#define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1}
-#define MPZMOD_THRESHOLD 33
+#define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,0,0,1,1,2,2,1,1,1,1,1,1,2,1,2}
+#define MPZMOD_THRESHOLD 21
 #define REDC_THRESHOLD 512
-#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 1, 1, 1, 1, 0, 0, 6, 6, 7, 7, 7, 9, 9, 10, 11, 12, 13, 12, 12, 13, 12, 13, 14, 20, 16, 20, 20, 20, 20, 20}
+#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 1, 1, 1, 1, 1, 0, 6, 6, 7, 8, 9, 9, 11, 10, 10, 11, 12, 13, 14, 14, 11, 13, 18, 18, 14, 20, 16, 18, 18, 20}
 #define NTT_GFP_TWIDDLE_DIF_BREAKOVER 17
 #define NTT_GFP_TWIDDLE_DIT_BREAKOVER 17
-#define MUL_NTT_THRESHOLD 8192
+#define MUL_NTT_THRESHOLD 256
 #define PREREVERTDIVISION_NTT_THRESHOLD 16
-#define POLYINVERT_NTT_THRESHOLD 512
+#define POLYINVERT_NTT_THRESHOLD 128
 #define POLYEVALT_NTT_THRESHOLD 256
-#define MPZSPV_NORMALISE_STRIDE 512
+#define MPZSPV_NORMALISE_STRIDE 32
 
 #endif
diff --git a/ecm-params.h.corei5 b/ecm-params.h.corei5
index 11f8ae2..55955c9 100644
--- a/ecm-params.h.corei5
+++ b/ecm-params.h.corei5
@@ -3,35 +3,35 @@
 #ifndef HAVE_MPIR /* tuning parameters for GMP, tuned for GMP 5.0.4 */
 
 /* 0:mulredc 1:mul+redc_1 2:mul+redc_2 3:mul+redc_n */
-#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}
 /* 0:mulredc 1:sqr+redc_1 2:sqr+redc_2 3:sqr+redc_n */
 #define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1}
 #define MPZMOD_THRESHOLD 21
 #define REDC_THRESHOLD 512
-#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 1, 1, 10, 11, 11, 12, 11, 12, 13, 13, 13, 15, 15, 14, 15, 16, 17, 18, 19}
+#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 13, 13, 13, 14, 14, 15, 16, 16, 17, 20, 22}
 #define NTT_GFP_TWIDDLE_DIF_BREAKOVER 17
 #define NTT_GFP_TWIDDLE_DIT_BREAKOVER 17
 #define MUL_NTT_THRESHOLD 256
 #define PREREVERTDIVISION_NTT_THRESHOLD 8
 #define POLYINVERT_NTT_THRESHOLD 128
 #define POLYEVALT_NTT_THRESHOLD 128
-#define MPZSPV_NORMALISE_STRIDE 256
+#define MPZSPV_NORMALISE_STRIDE 512
 
 #else /* tuning parameters for MPIR, tuned for MPIR 2.5.1 */
 
 /* 0:mulredc 1:mul+redc_1 2:mul+redc_2 3:mul+redc_n */
-#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1}
+#define TUNE_MULREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,2,2}
 /* 0:mulredc 1:sqr+redc_1 2:sqr+redc_2 3:sqr+redc_n */
-#define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1}
+#define TUNE_SQRREDC_TABLE {0,0,0,0,0,0,0,0,0,0,0,2,2,1,2,2,2,2,2,2,2}
 #define MPZMOD_THRESHOLD 21
 #define REDC_THRESHOLD 512
-#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 13, 1, 14, 14, 15, 17, 17, 17, 22}
+#define MPN_MUL_LO_THRESHOLD_TABLE {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 12, 13, 14, 15, 14, 16, 18, 18, 20, 18, 20}
 #define NTT_GFP_TWIDDLE_DIF_BREAKOVER 17
 #define NTT_GFP_TWIDDLE_DIT_BREAKOVER 17
-#define MUL_NTT_THRESHOLD 512
+#define MUL_NTT_THRESHOLD 256
 #define PREREVERTDIVISION_NTT_THRESHOLD 16
 #define POLYINVERT_NTT_THRESHOLD 128
 #define POLYEVALT_NTT_THRESHOLD 256
-#define MPZSPV_NORMALISE_STRIDE 128
+#define MPZSPV_NORMALISE_STRIDE 256
 
 #endif
diff --git a/ecm.c b/ecm.c
index 2eae3bc..d6f5e3f 100644
--- a/ecm.c
+++ b/ecm.c
@@ -1,25 +1,24 @@
 /* Elliptic Curve Method: toplevel and stage 1 routines.
 
-  Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
-  Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012 Paul Zimmermann, Alexander Kruppa, Cyril Bouvier, David Cleaver.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/ecm.h b/ecm.h
index fe669cc..1f71d1e 100644
--- a/ecm.h
+++ b/ecm.h
@@ -1,25 +1,24 @@
 /* ecm.h - public interface for libecm.
  
-  Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-  Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+Paul Zimmermann, Alexander Kruppa, David Cleaver, Cyril Bouvier.
  
-  This file is part of the ECM Library.
-
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #ifndef _ECM_H
 #define _ECM_H 1
diff --git a/ecm2.c b/ecm2.c
index 526859a..0e70bbd 100644
--- a/ecm2.c
+++ b/ecm2.c
@@ -1,24 +1,24 @@
 /* Elliptic Curve Method implementation: stage 2 routines.
 
-  Copyright 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Paul Zimmermann,
+Alexander Kruppa, Pierrick Gaudry, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdlib.h>
 #include <math.h>
diff --git a/ecm_ntt.c b/ecm_ntt.c
index 79e4795..7265fdd 100644
--- a/ecm_ntt.c
+++ b/ecm_ntt.c
@@ -1,24 +1,24 @@
 /* ecm_ntt.c - high level poly functions to interface between ecm and sp
 
-  Copyright 2005 Dave Newman.
+Copyright 2005, 2006, 2007, 2008, 2009, 2011, 2012 Dave Newman,
+Paul Zimmermann, Alexander Kruppa.
 
-  This file is part of the ECM Library.
-  
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/ecmfactor.c b/ecmfactor.c
index 68540f0..f2f7c7a 100644
--- a/ecmfactor.c
+++ b/ecmfactor.c
@@ -1,22 +1,21 @@
 /* ecmfactor.c - example of use of libecm.a.
 
-  Copyright 2005 Paul Zimmermann.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+Copyright 2005, 2006 Paul Zimmermann, Dave Newman.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/ecmfactor2.c b/ecmfactor2.c
deleted file mode 100644
index 79c0252..0000000
--- a/ecmfactor2.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/* ecmfactor2.c - example of use of libecm.a with HECM.
-
-  Copyright 2008 Paul Zimmermann.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <gmp.h> /* GMP header file */
-#include "ecm.h" /* ecm header file */
-
-/* wrapper for GMP-ECM stage2 for a curve in Weierstrass form
-
-   y^2 = x^2 + A * x + B
-
-   where B is implicitly defined by y^2 - (x^2 + A * x) mod n.
-*/
-int
-ecmfactor2 (mpz_t f, mpz_t n, mpz_t A, mpz_t x, mpz_t y, mpz_t B2)
-{
-  ecm_params q;
-  int res;
-
-  gmp_printf ("Performing one curve with B2=%Zd\n", B2);
-
-  ecm_init (q);
-
-  q->sigma_is_A = -1; /* indicates that we give a curve in Weierstrass form */
-  mpz_set (q->sigma, A);
-  mpz_set (q->x, x);
-  mpz_set (q->go, y);
-  mpz_set (q->B2, B2);
-
-  res = ecm_factor (f, n, 0.0, q);
-
-  ecm_clear (q);
-
-  return res;
-}
-
-int
-main (int argc, char *argv[])
-{
-  mpz_t n, f, A, x, y, B2;
-  int res;
-
-  if (argc != 6)
-    {
-      fprintf (stderr, "Usage: ecmfactor2 <number> <A> <x> <y> <B2>\n");
-      /* example: n=100000000000000000039 A=97286259809299325273
-         x=53919461457074783540 y=67664780906038509384 B2=10000000 */
-      exit (1);
-    }
-
-  mpz_init (n);
-  /* read number on command line */
-  if (mpz_set_str (n, argv[1], 10))
-    {
-      fprintf (stderr, "Invalid number: %s\n", argv[1]);
-      exit (1);
-    }
-
-  /* read A */
-  mpz_init (A);
-  if (mpz_set_str (A, argv[2], 10))
-    {
-      fprintf (stderr, "Invalid A: %s\n", argv[2]);
-      exit (1);
-    }
-
-  /* read x */
-  mpz_init (x);
-  if (mpz_set_str (x, argv[3], 10))
-    {
-      fprintf (stderr, "Invalid x: %s\n", argv[3]);
-      exit (1);
-    }
-
-  /* read y */
-  mpz_init (y);
-  if (mpz_set_str (y, argv[4], 10))
-    {
-      fprintf (stderr, "Invalid y: %s\n", argv[4]);
-      exit (1);
-    }
-
-  /* read stage 2 bound B2 */
-  mpz_init (B2);
-  if (mpz_set_str (B2, argv[5], 10))
-    {
-      fprintf (stderr, "Invalid B2: %s\n", argv[5]);
-      exit (1);
-    }
-
-  mpz_init (f); /* for potential factor */
-
-  res = ecmfactor2 (f, n, A, x, y, B2);
-
-  if (res > 0)
-    {
-      printf ("found factor in step %u: ", res);
-      mpz_out_str (stdout, 10, f);
-      printf ("\n");
-    }
-  else if (res == ECM_NO_FACTOR_FOUND)
-    printf ("found no factor\n");
-  else
-    printf ("error\n");
-
-  mpz_clear (f);
-  mpz_clear (n);
-  mpz_clear (A);
-  mpz_clear (x);
-  mpz_clear (y);
-  mpz_clear (B2);
-
-  return 0;
-}
diff --git a/ellparam_batch.c b/ellparam_batch.c
index 16ca06e..07d784d 100644
--- a/ellparam_batch.c
+++ b/ellparam_batch.c
@@ -1,3 +1,24 @@
+/* ellparam_batch.c - Parametrization for batch mode 2
+ 
+Copyright 2012 Cyril Bouvier.
+ 
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
+
 #include "ecm-gmp.h"
 #include "ecm-impl.h"
 
diff --git a/eval.c b/eval.c
index 6bb861d..48e26a8 100644
--- a/eval.c
+++ b/eval.c
@@ -1,22 +1,21 @@
 /* Simple expression parser for GMP-ECM.
 
-  Copyright 2003, 2004, 2005 Jim Fougeron, Paul Zimmermann and Alexander Kruppa.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2012 Jim Fougeron, Paul Zimmermann and Alexander Kruppa.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/factor.c b/factor.c
index dbf0810..628bbfe 100644
--- a/factor.c
+++ b/factor.c
@@ -1,24 +1,24 @@
 /* factor.c - public interface for libecm.
 
-  Copyright 2005, 2006, 2007, 2009, 2011 Paul Zimmermann and Alexander Kruppa.
+Copyright 2005, 2006, 2007, 2009, 2011 Paul Zimmermann, Alexander Kruppa,
+David Cleaver, Cyril Bouvier.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <math.h>
diff --git a/getprime.c b/getprime.c
index 5188711..ec115de 100644
--- a/getprime.c
+++ b/getprime.c
@@ -1,24 +1,24 @@
 /* Dynamic Eratosthenes sieve.
 
-  Copyright 2001, 2002, 2003, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2012
+Paul Zimmermann, Alexander Kruppa, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <math.h>
 #include <stdlib.h>
diff --git a/ks-multiply.c b/ks-multiply.c
index 5c5465b..f5682d9 100644
--- a/ks-multiply.c
+++ b/ks-multiply.c
@@ -1,24 +1,24 @@
 /* Polynomial multiplication using GMP's integer multiplication code
 
-  Copyright 2004, 2005 Dave Newman, Paul Zimmermann.
+Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010 Dave Newman,
+Paul Zimmermann, Alexander Kruppa.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdlib.h>
 #include "ecm-gmp.h" /* for MPZ_REALLOC and MPN_COPY */
diff --git a/listz.c b/listz.c
index 8c28839..480e9a8 100644
--- a/listz.c
+++ b/listz.c
@@ -1,24 +1,24 @@
 /* Arithmetic on lists of residues modulo n.
 
-  Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2012
+Paul Zimmermann and Alexander Kruppa.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdlib.h>
 #include "ecm-impl.h"
diff --git a/lucas.c b/lucas.c
index c47a0f5..eed4bd5 100644
--- a/lucas.c
+++ b/lucas.c
@@ -1,32 +1,32 @@
 /* Auxiliary functions to evaluate Lucas sequences.
 
-  Copyright 2002, 2003, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2002, 2003, 2005, 2006, 2008, 2011, 2012
+Paul Zimmermann, Alexander Kruppa, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
-  References:
+/* References:
 
-  A p+1 Method of Factoring, H. C. Williams, Mathematics of Computation,
-  volume 39, number 159, pages 225-234, 1982.
+A p+1 Method of Factoring, H. C. Williams, Mathematics of Computation,
+volume 39, number 159, pages 225-234, 1982.
 
-  Evaluating recurrences of form X_{m+n} = f(X_m, X_n, X_{m-n}) via
-  Lucas chains, Peter L. Montgomery, December 1983, revised January 1992.
-*/
+Evaluating recurrences of form X_{m+n} = f(X_m, X_n, X_{m-n}) via
+Lucas chains, Peter L. Montgomery, December 1983, revised January 1992. */
 
 #include "ecm-impl.h"
 
diff --git a/main.c b/main.c
index 5937c79..8a2ee76 100644
--- a/main.c
+++ b/main.c
@@ -1,22 +1,23 @@
-/* GMP-ECM -- Integer factorization with ECM and Pollard 'P-1' methods.
+/* GMP-ECM -- Integer factorization with ECM, P-1 and P+1 methods.
 
-  Copyright 2001, 2002, 2003, 2004, 2005, 2011 Jim Fougeron, Laurent Fousse, Alexander Kruppa, Paul Zimmermann.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+2012 Jim Fougeron, Laurent Fousse, Alexander Kruppa, Paul Zimmermann, Cyril
+Bouvier.
 
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
 
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1353,43 +1354,6 @@ BreadthFirstDoAgain:;
 	  FREE (s, n.ndigits + 1);
 	}
 
-      if ((!breadthfirst && cnt == count) || 
-          (breadthfirst && 1 == breadthfirst_cnt))
-	{
-	  int SomeFactor;
-	  /*  Note, if a factors are found, then n will be adjusted "down" */
-	  SomeFactor = trial_factor (&n, maxtrialdiv, deep);
-	  if (SomeFactor)
-	    {
-	      /* should we increase factors found for trivials ??? */
-	      trial_factor_found = 1;
-	      factsfound += SomeFactor;
-	      if (n.isPrp)
-	        {
-		  printf ("Probable prime cofactor ");
-		  if (n.cpExpr && !decimal_cofactor)
-		    printf ("%s", n.cpExpr);
-		  else
-		    mpz_out_str (stdout, 10, n.n);
-		  printf (" has %u digits\n", n.ndigits);
-		  /* Nothing left to do with this number, so simply continue. */
-		  cnt = 0; /* no more curve to perform */
-		  fflush (stdout);
-		  continue;
-		}
-	      fflush (stdout);
-	      if (!deep)
-		{
-		  /* Note, if we are not in deep mode, then there is no need 
-		     to continue if a factor was found */
-  		  factor_is_prime = 1;
-  		  mpz_set_ui (f,1);
-		  goto OutputFactorStuff;
-		}
-
-	    }
-        }
-
       factor_is_prime = 0;
 
       cnt --; /* one more curve performed */
diff --git a/median.c b/median.c
index 6533784..c5b0a9a 100644
--- a/median.c
+++ b/median.c
@@ -1,25 +1,26 @@
 /* Median/middle product.
 
-  Copyright 2003, 2004, 2005 Laurent Fousse, Paul Zimmermann, Alexander Kruppa.
+Copyright 2003, 2004, 2005, 2006, 2007, 2008 Laurent Fousse, Paul Zimmermann,
+Alexander Kruppa, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
-References: 
+/* Reference:
 [1] Tellegen's Principle into Practice, by A. Bostan, G. Lecerf and E. Schost,
 Proc. of ISSAC'03, Philadelphia, 2003.
 */
diff --git a/memory.c b/memory.c
index 655e8ac..c21065a 100644
--- a/memory.c
+++ b/memory.c
@@ -1,12 +1,12 @@
 /* Memory allocation used during tests.
 
-Copyright 2001, 2002 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
 
 This file was copied from the GNU MP Library.
 
 The GNU MP Library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or (at your
+the Free Software Foundation; either version 3 of the License, or (at your
 option) any later version.
 
 The GNU MP Library is distributed in the hope that it will be useful, but
diff --git a/mpmod.c b/mpmod.c
index 98163a9..576c7f0 100644
--- a/mpmod.c
+++ b/mpmod.c
@@ -1,24 +1,24 @@
 /* Modular multiplication.
 
-  Copyright 2002, 2003, 2004, 2005, 2011, 2012 Paul Zimmermann, Alexander Kruppa and Cyril Bouvier.
+Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
+Paul Zimmermann, Alexander Kruppa and Cyril Bouvier.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -225,8 +225,7 @@ base2mod_2 (mpres_t R, const mpres_t S, mp_size_t n, mpz_t modulus)
 
 /* subquadratic REDC, at mpn level.
    {orig,n} is the original modulus.
-   {aux,n} is the auxiliary modulus.
-   Requires xn = 2n or 2n-1 and ABSIZ(orig_modulus)=ABSIZ(aux_modulus)=n.
+   Requires xn = 2n or 2n-1 and ABSIZ(orig_modulus)=n.
  */
 static void
 ecm_redc_n (mp_ptr rp, mp_srcptr x0p, mp_size_t xn,
@@ -234,9 +233,11 @@ ecm_redc_n (mp_ptr rp, mp_srcptr x0p, mp_size_t xn,
 {
   mp_ptr tp, up, xp;
   mp_size_t nn = n + n;
-  mp_limb_t cy;
+  mp_limb_t cy, cin;
   TMP_DECL(marker);
 
+  ASSERT((xn == 2 * n) || (xn == 2 * n - 1));
+
   TMP_MARK(marker);
   up = TMP_ALLOC_LIMBS(nn + nn);
   if (xn < nn)
@@ -258,18 +259,16 @@ ecm_redc_n (mp_ptr rp, mp_srcptr x0p, mp_size_t xn,
      either 0, or a carry out. If xp[n-1] <> 0 or tp[n-1] <> 0, 
      then there is a carry. We use a binary OR, which sets the zero flag
      if and only if both operands are zero. */
+  cin = (mp_limb_t) ((xp[n - 1] | tp[n - 1]) ? 1 : 0);
 #ifdef HAVE___GMPN_ADD_NC
-  cy = __gmpn_add_nc (rp, tp + n, xp + n, n, 
-                      (mp_limb_t) ((xp[n - 1] | tp[n - 1]) ? 1 : 0));
+  cy = __gmpn_add_nc (rp, tp + n, xp + n, n, cin);
 #else
   cy = mpn_add_n (rp, tp + n, xp + n, n);
-  cy += mpn_add_1 (rp, rp, n, (mp_limb_t) ((xp[n - 1] | tp[n - 1]) ? 1 : 0));
+  cy += mpn_add_1 (rp, rp, n, cin);
 #endif
-  /* when N < B^n/4, we don't need to perform this last reduction,
-     if we allow residues in [0, 2N).
-     See for example the slides from David Harvey at Sage Days 35
-     (http://wiki.sagemath.org/SageFlintDays/slides) */
-  if (orig[n-1] >> (GMP_NUMB_BITS - 2) && (cy || mpn_cmp (rp, orig, n) > 0))
+  /* since we add at most N-1 to the upper half of {x0p,2n},
+     one adjustment is enough */
+  if (cy)
     cy -= mpn_sub_n (rp, rp, orig, n);
   ASSERT (cy == 0);
   TMP_FREE(marker);
@@ -741,7 +740,8 @@ ecm_sqrredc_basecase_n (mp_ptr rp, mp_srcptr s1p,
 /* R <- S1 * S2 mod modulus
    i.e. R <- S1*S2/r^nn mod n, where n has nn limbs, and r=2^GMP_NUMB_BITS.
    Same as ecm_redc_basecase previous, but combined with mul
-   Neither input argument must be in modulus->temp1 */
+   Neither input argument must be in modulus->temp1
+*/
 static void 
 ecm_mulredc_basecase (mpres_t R, const mpres_t S1, const mpres_t S2, 
                       mpmod_t modulus)
@@ -1920,9 +1920,7 @@ void
 mpres_set_z (mpres_t R, const mpz_t S, mpmod_t modulus)
 {
   if (modulus->repr == ECM_MOD_MPZ || modulus->repr == ECM_MOD_BASE2)
-    {
-      mpz_mod (R, S, modulus->orig_modulus);
-    }
+    mpz_mod (R, S, modulus->orig_modulus);
   else if (modulus->repr == ECM_MOD_MODMULN)
     {
       mpz_mod (modulus->temp2, S, modulus->orig_modulus);
@@ -2319,7 +2317,9 @@ mpresn_sub (mpres_t R, const mpres_t S1, const mpres_t S2, mpmod_t modulus)
     }
 }
 
-/* (R, T) <- (S1 + S2, S1 - S2) */
+/* (R, T) <- (S1 + S2, S1 - S2)
+   Assume R differs from both S1 and S2.
+ */
 void
 mpresn_addsub (mpres_t R, mpres_t T,
                const mpres_t S1, const mpres_t S2, mpmod_t modulus)
@@ -2331,6 +2331,8 @@ mpresn_addsub (mpres_t R, mpres_t T,
   mp_size_t n = ABSIZ(modulus->orig_modulus);
   ATTRIBUTE_UNUSED mp_limb_t cy;
 
+  ASSERT (R != S1);
+  ASSERT (R != S2);
   ASSERT (SIZ(S1) == n || -SIZ(S1) == n);
   ASSERT (SIZ(S2) == n || -SIZ(S2) == n);
 
diff --git a/mpmod.h b/mpmod.h
index ad98e76..11b262c 100644
--- a/mpmod.h
+++ b/mpmod.h
@@ -1,24 +1,23 @@
 /* Header for modular multiplication.
 
-  Copyright 2012 Paul Zimmermann.
+Copyright 2012 Paul Zimmermann.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #define MPMOD_MULREDC 0    /* assembly combined mulredc */
 #define MPMOD_MUL_REDC1 1  /* mpn_mul_n or mpn_sqr followed by mpn_redc_1 */
diff --git a/mpzspm.c b/mpzspm.c
index 8337cf1..9e8ff9d 100644
--- a/mpzspm.c
+++ b/mpzspm.c
@@ -1,23 +1,23 @@
 /* mpzspm.c - "mpz small prime moduli" - pick a set of small primes large
    enough to represent a mpzv
 
-  Copyright 2005, 2008, 2010 Dave Newman, Jason Papadopoulos, Paul Zimmermann.
-
-  The SP Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The SP Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the SP Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+Copyright 2005, 2006, 2007, 2008, 2009, 2010 Dave Newman, Jason Papadopoulos,
+Paul Zimmermann, Alexander Kruppa.
+
+The SP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The SP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the SP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA. */
 
 #include <stdio.h> /* for printf */
 #include <stdlib.h>
@@ -227,7 +227,7 @@ mpzspm_init (spv_size_t max_len, mpz_t modulus)
 	  goto error_clear_mpzspm_spm;
 	}
       
-      mpzspm->spm[mpzspm->sp_num] = spm_init (max_len, p);
+      mpzspm->spm[mpzspm->sp_num] = spm_init (max_len, p, mpz_size (modulus));
       if (mpzspm->spm[mpzspm->sp_num] == NULL)
         {
           outputf (OUTPUT_ERROR, "Out of memory in mpzspm_init()\n");
diff --git a/mpzspv.c b/mpzspv.c
index 21ec5c5..96b018e 100644
--- a/mpzspv.c
+++ b/mpzspv.c
@@ -1,24 +1,23 @@
 /* mpzspv.c - "mpz small prime polynomial" functions for arithmetic on mpzv's
    reduced modulo a mpzspm
 
-  Copyright 2005, 2008, 2010 Dave Newman, Jason Papadopoulos, Alexander Kruppa
-                             and Paul Zimmermann.
-
-  The SP Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The SP Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the SP Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Dave Newman,
+Jason Papadopoulos, Alexander Kruppa, Paul Zimmermann.
+
+The SP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The SP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the SP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA. */
 
 #include <stdio.h> /* for stderr */
 #include <stdlib.h>
@@ -175,27 +174,35 @@ mpzspv_reverse (mpzspv_t x, spv_size_t offset, spv_size_t len, mpzspm_t mpzspm)
     }
 }
 
-#if 0
-/* Return {xp, xn} / B^(xn-1) mod d where B = 2^GMP_NUMB_LIMB.
-   Assume d < B - 1 */
+/* Return {xp, xn} mod p.
+   Assume 2p < B where B = 2^GMP_NUMB_LIMB.
+   We first compute {xp, xn} / B^n mod p using Montgomery reduction,
+   where the number N to factor has n limbs.
+   Then we multiply by B^(n+1) mod p (precomputed) and divide by B mod p.
+   Assume invm = -1/p mod B and Bpow = B^n mod p */
 static mp_limb_t
-ecm_bdiv_r_1 (mp_ptr xp, mp_size_t xn, mp_limb_t d)
+ecm_mod_1 (mp_ptr xp, mp_size_t xn, mp_limb_t p, mp_size_t n,
+           mp_limb_t invm, mp_limb_t Bpow)
 {
-  mp_limb_t di, q, cy, hi, lo, x0, x1;
+  mp_limb_t q, cy, hi, lo, x0, x1;
 
   if (xn == 0)
     return 0;
-  __gmpn_binvert (&di, &d, 1, &x0); /* di = 1/d mod B */
-  di = -di;                         /* -1/d mod B */
+
+  /* the code below assumes xn <= n+1, thus we call mpn_mod_1 otherwise,
+     but this should never (or rarely) happen */
+  if (xn > n + 1)
+    return mpn_mod_1 (xp, xn, p);
+
   x0 = xp[0];
   cy = (mp_limb_t) 0;
-  while (xn > 1)
+  while (n-- > 0)
     {
       /* Invariant: cy is the input carry on xp[1], x0 is xp[0] */
-      x1 = xp[1];
-      q = x0 * di; /* q = -x0/d mod B */
-      umul_ppmm (hi, lo, q, d); /* hi*B + lo = -x0 mod B */
-      /* Add hi*B + lo to x1*B + x0. Since d <= B-2 we have
+      x1 = (xn > 1) ? xp[1] : 0;
+      q = x0 * invm; /* q = -x0/p mod B */
+      umul_ppmm (hi, lo, q, p); /* hi*B + lo = -x0 mod B */
+      /* Add hi*B + lo to x1*B + x0. Since p <= B-2 we have
          hi*B + lo <= (B-1)(B-2) = B^2-3B+2, thus hi <= B-3 */
       hi += cy + (lo != 0); /* cannot overflow */
       x0 = x1 + hi;
@@ -204,12 +211,18 @@ ecm_bdiv_r_1 (mp_ptr xp, mp_size_t xn, mp_limb_t d)
       xp ++;
     }
   if (cy != 0)
-    x0 -= d;
-  while (x0 >= d)
-    x0 -= d;
-  return x0;
+    x0 -= p;
+  /* now x0 = {xp, xn} / B^n mod p */
+  umul_ppmm (x1, x0, x0, Bpow);
+  /* since Bpow < p, x1 <= p-1 */
+  q = x0 * invm;
+  umul_ppmm (hi, lo, q, p);
+  /* hi <= p-1 thus hi+x1+1 < 2p-1 < B */
+  hi = hi + x1 + (lo != 0);
+  while (hi >= p)
+    hi -= p;
+  return hi;
 }
-#endif
 
 /* convert mpzvi to CRT representation, naive version */
 static void
@@ -218,6 +231,7 @@ mpzspv_from_mpzv_slow (mpzspv_t x, const spv_size_t offset, mpz_t mpzvi,
 {
   const unsigned int sp_num = mpzspm->sp_num;
   unsigned int j;
+  mp_size_t n = mpz_size (mpzspm->modulus);
 
   /* GMP's comments on mpn_preinv_mod_1:
    *
@@ -233,10 +247,18 @@ mpzspv_from_mpzv_slow (mpzspv_t x, const spv_size_t offset, mpz_t mpzvi,
      floor(2^128/(4*sp))-2^64 = floor(2^126/sp)-2^64.
      On 32-bit it is floor(2^62/sp) where sp has 31 bits, and mpn_preinv_mod_1
      needs floor(2^64/(2*sp))-2^32 = floor(2^63/sp)-2^32. */
+
+  /* Note: we could improve this as follows. Assume the number N to factor has
+     n limbs. Instead of computing v mod p by reducing v by the high limbs,
+     we first compute v/B^(n-1) mod p by reducing v by the low limbs, then
+     deduce v mod p using a precomputed value of B^(n-1) mod p.
+     The reduction v/B is done by using a precomputed k = 1/B mod p,
+     thus v1*B+v0 = (v1+k*v0)*B and so on. */
   
   for (j = 0; j < sp_num; j++)
-    x[j][offset] = mpn_mod_1 (PTR(mpzvi), SIZ(mpzvi),
-                              (mp_limb_t) mpzspm->spm[j]->sp);
+    x[j][offset] = ecm_mod_1 (PTR(mpzvi), SIZ(mpzvi),
+                              (mp_limb_t) mpzspm->spm[j]->sp, n,
+                              mpzspm->spm[j]->invm, mpzspm->spm[j]->Bpow);
   /* The typecast to mp_limb_t assumes that mp_limb_t is at least
      as wide as sp_t */
 }
diff --git a/mul_fft.c b/mul_fft.c
index 0c10353..f7d6ee3 100644
--- a/mul_fft.c
+++ b/mul_fft.c
@@ -1,26 +1,26 @@
 /* An implementation in GMP of Scho"nhage's fast multiplication algorithm
-  modulo 2^N+1, by Paul Zimmermann, INRIA Lorraine, February 1998.
+   modulo 2^N+1, by Paul Zimmermann, INRIA Lorraine, February 1998.
 
-   Revised July 2002 and January 2003, Paul Zimmermann.
-   Further revised by Pierrick Gaudry, Paul Zimmermann, and Torbjorn Granlund,
-   March/April and November/December 2006, and also by Alexander Kruppa in
-   December 2006.
+Revised July 2002 and January 2003, Paul Zimmermann.
+Further revised by Pierrick Gaudry, Paul Zimmermann, and Torbjorn Granlund,
+March/April and November/December 2006, and also by Alexander Kruppa in
+December 2006.
 
-   Revised December 2007 for inclusion into GMP-ECM.
+Revised December 2007 for inclusion into GMP-ECM.
 
-   THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND THE FUNCTIONS HAVE
-   MUTABLE INTERFACES.  IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED
-   INTERFACES.  IT IS ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN
-   A FUTURE GNU MP RELEASE.
+THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND THE FUNCTIONS HAVE
+MUTABLE INTERFACES.  IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED
+INTERFACES.  IT IS ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN
+A FUTURE GNU MP RELEASE.
 
-Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
-Foundation, Inc.
+Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+2009, 2010, 2011 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
 The GNU MP Library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or (at your
+the Free Software Foundation; either version 3 of the License, or (at your
 option) any later version.
 
 The GNU MP Library is distributed in the hope that it will be useful, but
diff --git a/mul_lo.c b/mul_lo.c
index 87c985d..bfd40bf 100644
--- a/mul_lo.c
+++ b/mul_lo.c
@@ -1,24 +1,23 @@
 /* Low-half short product (quadratic and Mulders' algorithms).
 
-  Copyright 2003, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2003, 2005, 2006 Paul Zimmermann, Alexander Kruppa, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "ecm-impl.h"
 
diff --git a/ntt_gfp.c b/ntt_gfp.c
index 73d689a..5109256 100644
--- a/ntt_gfp.c
+++ b/ntt_gfp.c
@@ -1,22 +1,22 @@
 /* ntt_gfp.c - low-level radix-2 dif/dit ntt routines over GF(p)
    
-  Copyright 2005, 2008 Dave Newman and Jason Papadopoulos.
-
-  The SP Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The SP Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the SP Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+Copyright 2005, 2006, 2007, 2008, 2009 Dave Newman, Jason Papadopoulos,
+Brian Gladman, Alexander Kruppa, Paul Zimmermann.
+
+The SP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The SP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the SP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA. */
 
 #include "sp.h"
 #include "ecm-impl.h"
diff --git a/pm1.c b/pm1.c
index 6967aab..eef972f 100644
--- a/pm1.c
+++ b/pm1.c
@@ -1,25 +1,24 @@
 /* Pollard 'P-1' algorithm.
 
-  Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-  Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+Paul Zimmermann and Alexander Kruppa.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <math.h>
 #include <stdlib.h>
diff --git a/pm1fs2.c b/pm1fs2.c
index 0d13fe1..c855f1a 100644
--- a/pm1fs2.c
+++ b/pm1fs2.c
@@ -1,29 +1,27 @@
-/* 
-  Implementation of fast stage 2 for P-1 and P+1 as described in
-  "Improved Stage 2 to $P\pm{}1$ Factoring Algorithms" by
-  Peter L. Montgomery and Alexander Kruppa, ANTS 2008 (8th Algorithmic 
-  Number Theory Symposium).
+/* Implementation of fast stage 2 for P-1 and P+1 as described in
+   "Improved Stage 2 to $P\pm{}1$ Factoring Algorithms" by
+   Peter L. Montgomery and Alexander Kruppa, ANTS 2008 (8th Algorithmic 
+   Number Theory Symposium).
    
-  Copyright 2007, 2008 Alexander Kruppa.
-  NTT functions are based on code Copyright 2005 Dave Newman.
+Copyright 2007, 2008, 2009, 2010, 2011, 2012 Alexander Kruppa, Paul Zimmermann.
+NTT functions are based on code Copyright 2005 Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "config.h"
 #include <stdio.h>
diff --git a/polyeval.c b/polyeval.c
index af5d717..3be6353 100644
--- a/polyeval.c
+++ b/polyeval.c
@@ -1,24 +1,24 @@
 /* Implements algorithm polyeval and remainder tree using middle product.
 
-  Copyright 2003, 2004, 2005 Laurent Fousse, Alexander Kruppa, Paul Zimmermann.
+Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Laurent Fousse,
+Alexander Kruppa, Paul Zimmermann.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdlib.h>
 #include <string.h> /* for strlen */
diff --git a/powerpc64/mulredc.m4 b/powerpc64/mulredc.m4
index d7c1e52..7dfc7e7 100755
--- a/powerpc64/mulredc.m4
+++ b/powerpc64/mulredc.m4
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc1.asm b/powerpc64/mulredc1.asm
index 9dcc967..6b44128 100644
--- a/powerpc64/mulredc1.asm
+++ b/powerpc64/mulredc1.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc10.asm b/powerpc64/mulredc10.asm
index 6eda1ec..148c8e6 100644
--- a/powerpc64/mulredc10.asm
+++ b/powerpc64/mulredc10.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc11.asm b/powerpc64/mulredc11.asm
index 6c349b0..836b690 100644
--- a/powerpc64/mulredc11.asm
+++ b/powerpc64/mulredc11.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc12.asm b/powerpc64/mulredc12.asm
index a8e79d2..3415d5b 100644
--- a/powerpc64/mulredc12.asm
+++ b/powerpc64/mulredc12.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc13.asm b/powerpc64/mulredc13.asm
index 04f75d6..d95cae4 100644
--- a/powerpc64/mulredc13.asm
+++ b/powerpc64/mulredc13.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc14.asm b/powerpc64/mulredc14.asm
index 6166626..19f8074 100644
--- a/powerpc64/mulredc14.asm
+++ b/powerpc64/mulredc14.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc15.asm b/powerpc64/mulredc15.asm
index 2e821c6..2ebfba2 100644
--- a/powerpc64/mulredc15.asm
+++ b/powerpc64/mulredc15.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc16.asm b/powerpc64/mulredc16.asm
index daa0793..3e054f9 100644
--- a/powerpc64/mulredc16.asm
+++ b/powerpc64/mulredc16.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc17.asm b/powerpc64/mulredc17.asm
index b348df6..868c228 100644
--- a/powerpc64/mulredc17.asm
+++ b/powerpc64/mulredc17.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc18.asm b/powerpc64/mulredc18.asm
index fadc369..1a4fa0e 100644
--- a/powerpc64/mulredc18.asm
+++ b/powerpc64/mulredc18.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc19.asm b/powerpc64/mulredc19.asm
index b950362..42a6eae 100644
--- a/powerpc64/mulredc19.asm
+++ b/powerpc64/mulredc19.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc2.asm b/powerpc64/mulredc2.asm
index b2b6f40..342803c 100644
--- a/powerpc64/mulredc2.asm
+++ b/powerpc64/mulredc2.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc20.asm b/powerpc64/mulredc20.asm
index ed7e667..a123a94 100644
--- a/powerpc64/mulredc20.asm
+++ b/powerpc64/mulredc20.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc3.asm b/powerpc64/mulredc3.asm
index 68c142d..69bac6b 100644
--- a/powerpc64/mulredc3.asm
+++ b/powerpc64/mulredc3.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc4.asm b/powerpc64/mulredc4.asm
index 786bb46..0a2f89f 100644
--- a/powerpc64/mulredc4.asm
+++ b/powerpc64/mulredc4.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc5.asm b/powerpc64/mulredc5.asm
index 2353035..dfc24d4 100644
--- a/powerpc64/mulredc5.asm
+++ b/powerpc64/mulredc5.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc6.asm b/powerpc64/mulredc6.asm
index f175f22..df49998 100644
--- a/powerpc64/mulredc6.asm
+++ b/powerpc64/mulredc6.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc7.asm b/powerpc64/mulredc7.asm
index 53eb814..f035d3b 100644
--- a/powerpc64/mulredc7.asm
+++ b/powerpc64/mulredc7.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc8.asm b/powerpc64/mulredc8.asm
index 4d8f274..b52ddcb 100644
--- a/powerpc64/mulredc8.asm
+++ b/powerpc64/mulredc8.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc9.asm b/powerpc64/mulredc9.asm
index 63e3c1c..089a5b2 100644
--- a/powerpc64/mulredc9.asm
+++ b/powerpc64/mulredc9.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/mulredc_1_2.m4 b/powerpc64/mulredc_1_2.m4
index 76b91a3..432020b 100755
--- a/powerpc64/mulredc_1_2.m4
+++ b/powerpc64/mulredc_1_2.m4
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl 
 dnl   The ECM Library is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU Lesser General Public License as published by
-dnl   the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl   the Free Software Foundation; either version 3 of the License, or (at your
 dnl   option) any later version.
 dnl 
 dnl   The ECM Library is distributed in the hope that it will be useful, but
diff --git a/powerpc64/redc.asm b/powerpc64/redc.asm
index 62cbc0b..1147574 100755
--- a/powerpc64/redc.asm
+++ b/powerpc64/redc.asm
@@ -5,7 +5,7 @@ dnl   This file is part of the ECM Library.
 dnl
 dnl  The ECM Library is free software; you can redistribute it and/or modify
 dnl  it under the terms of the GNU Lesser General Public License as published by
-dnl  the Free Software Foundation; either version 2.1 of the License, or (at your
+dnl  the Free Software Foundation; either version 3 of the License, or (at your
 dnl  option) any later version.
 dnl
 dnl  The ECM Library is distributed in the hope that it will be useful, but
diff --git a/pp1.c b/pp1.c
index 9ff26e3..8484780 100644
--- a/pp1.c
+++ b/pp1.c
@@ -1,33 +1,32 @@
 /* The 'P+1' algorithm.
 
-  Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008
-  Paul Zimmermann and Alexander Kruppa.
+Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
+Paul Zimmermann and Alexander Kruppa.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
-  References:
+/* References:
 
-  A p+1 Method of Factoring, H. C. Williams, Mathematics of Computation,
-  volume 39, number 159, pages 225-234, 1982.
+A p+1 Method of Factoring, H. C. Williams, Mathematics of Computation,
+volume 39, number 159, pages 225-234, 1982.
 
-  Evaluating recurrences of form X_{m+n} = f(X_m, X_n, X_{m-n}) via
-  Lucas chains, Peter L. Montgomery, December 1983, revised January 1992.
-*/
+Evaluating recurrences of form X_{m+n} = f(X_m, X_n, X_{m-n}) via
+Lucas chains, Peter L. Montgomery, December 1983, revised January 1992. */
 
 #include <math.h>
 #include <stdlib.h>
diff --git a/random.c b/random.c
index bb033d4..d980af1 100644
--- a/random.c
+++ b/random.c
@@ -1,24 +1,23 @@
 /* Random initialization for P-1 and P+1.
 
-  Copyright 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2005, 2006, 2008 Paul Zimmermann, Alexander Kruppa, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -113,14 +112,16 @@ get_random_ui (void)
       CryptReleaseContext (Prov, 0);
       if (r)
         {
-#ifndef OUTSIDE_LIBECM /* warning: outputf is not exported from libecm */
+/* warning: outputf is not exported from libecm */
+#if !defined (OUTSIDE_LIBECM) && !defined(GPUECM)
           outputf (OUTPUT_DEVVERBOSE, "Got seed for RNG from CryptGenRandom\n");
 #endif
           return rnd;
         }
     }
   
-#ifndef OUTSIDE_LIBECM /* warning: outputf is not exported from libecm */
+/* warning: outputf is not exported from libecm */
+#if !defined (OUTSIDE_LIBECM) && !defined(GPUECM)
   outputf (OUTPUT_DEVVERBOSE, "Got seed for RNG from GetSystemTime\n");
 #endif
 
@@ -147,7 +148,8 @@ get_random_ui (void)
     {
       if (fread (&t, sizeof (unsigned int), 1, rndfd) == 1)
         {
-#ifndef OUTSIDE_LIBECM /* warning: outputf is not exported from libecm */
+/* warning: outputf is not exported from libecm */
+#if !defined (OUTSIDE_LIBECM) && !defined(GPUECM)
           outputf (OUTPUT_DEVVERBOSE, "Got seed for RNG from /dev/urandom\n");
 #endif
           fclose (rndfd);
@@ -159,14 +161,16 @@ get_random_ui (void)
 #ifdef HAVE_GETTIMEOFDAY
   if (gettimeofday (&tv, NULL) == 0)
     {
-#ifndef OUTSIDE_LIBECM
+/* warning: outputf is not exported from libecm */
+#if !defined (OUTSIDE_LIBECM) && !defined(GPUECM)
       outputf (OUTPUT_DEVVERBOSE, "Got seed for RNG from gettimeofday()\n");
 #endif
       return tv.tv_sec + tv.tv_usec;
     }
 #endif
 
-#ifndef OUTSIDE_LIBECM
+/* warning: outputf is not exported from libecm */
+#if !defined (OUTSIDE_LIBECM) && !defined(GPUECM)
   outputf (OUTPUT_DEVVERBOSE, "Got seed for RNG from time()+getpid()\n");
 #endif
 
diff --git a/resume.c b/resume.c
index 141208b..e544fe6 100644
--- a/resume.c
+++ b/resume.c
@@ -1,22 +1,22 @@
 /* Functions for reading a writing resume file lines.
 
-  Copyright 2001, 2002, 2003 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2010, 2011, 2012
+Paul Zimmermann, Alexander Kruppa and Cyril Bouvier.
 
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
 
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/rho.c b/rho.c
index ebfcb46..bf855d3 100644
--- a/rho.c
+++ b/rho.c
@@ -1,24 +1,24 @@
 /* Dickman's rho function (to compute probability of success of ecm).
 
-  Copyright 2004, 2005, 2007, 2008 Alexander Kruppa.
+Copyright 2004, 2005, 2006, 2008, 2009, 2010, 2011 Alexander Kruppa,
+Paul Zimmermann.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "config.h"
 #if defined(TESTDRIVE)
diff --git a/schoen_strass.c b/schoen_strass.c
index f7af7ae..4a63d7d 100644
--- a/schoen_strass.c
+++ b/schoen_strass.c
@@ -1,24 +1,24 @@
 /* Arithmetic modulo Fermat numbers.
 
-  Copyright 2004, 2005 Alexander Kruppa.
+Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Alexander Kruppa,
+Paul Zimmermann
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h> /* for abs if assertions enabled */
diff --git a/sets_long.c b/sets_long.c
index 5f05341..23aedcb 100644
--- a/sets_long.c
+++ b/sets_long.c
@@ -1,28 +1,26 @@
-/* 
-  Functions for sets of long ints, to factor (Z/NZ)* into a set of sums
-  as described in section 5 of "Improved Stage 2 to $P\pm{}1$ Factoring 
-  Algorithms" by Peter L. Montgomery and Alexander Kruppa, ANTS 2008
-  (8th Algorithmic Number Theory Symposium).
+/* Functions for sets of long ints, to factor (Z/NZ)* into a set of sums
+   as described in section 5 of "Improved Stage 2 to $P\pm{}1$ Factoring 
+   Algorithms" by Peter L. Montgomery and Alexander Kruppa, ANTS 2008
+   (8th Algorithmic Number Theory Symposium).
   
-  Copyright 2007, 2008 Alexander Kruppa.
+Copyright 2007, 2008, 2009, 2012 Alexander Kruppa, Paul Zimmermann.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "config.h"
 #include "ecm-impl.h"
diff --git a/sp.c b/sp.c
index dc8c5be..3f244f3 100644
--- a/sp.c
+++ b/sp.c
@@ -1,22 +1,22 @@
 /* sp.c - "small prime" functions that don't need to be inlined
 
-  Copyright 2005, 2008 Dave Newman and Jason Papadopoulos.
-
-  The SP Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The SP Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the SP Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+Copyright 2005, 2006, 2007, 2008, 2009, 2010 Dave Newman, Jason Papadopoulos,
+Alexander Kruppa, Paul Zimmermann.
+
+The SP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The SP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the SP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA. */
 
 #include <stdio.h> /* for stderr */
 #include <stdlib.h>
diff --git a/sp.h b/sp.h
index 4778fb7..31498bd 100644
--- a/sp.h
+++ b/sp.h
@@ -1,26 +1,27 @@
 /* sp.h - header file for the sp library
 
-  Copyright 2005, 2008, 2010, 2011, 2012 Dave Newman, Jason Papadopoulos and
-                             Paul Zimmermann.
-  Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
-  2004, 2005, 2010 Free Software Foundation, Inc. (for parts from gmp-impl.h).
+Copyright 2005, 2006, 2007, 2008, 2010, 2011, 2012 Dave Newman, Jason
+Papadopoulos, Paul Zimmermann, Brian Gladman, Alexander Kruppa.
 
-  This file is part of the SP library.
+Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
+2004, 2005, 2010 Free Software Foundation, Inc. (for parts from gmp-impl.h).
+
+This file is part of the SP library.
   
-  The SP Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The SP Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the SP Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
+The SP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The SP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the SP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA.
 */
 
 #ifndef _SP_H
@@ -148,6 +149,8 @@ typedef struct
 {
   sp_t sp;		/* value of the sp */
   sp_t mul_c;		/* constant used for reduction mod sp */
+  sp_t invm;            /* -1/sp mod 2^GMP_NUMB_BITS */
+  sp_t Bpow;            /* B^(n+1) mod sp where the input N has n limbs */
   sp_t prim_root;
   sp_t inv_prim_root;
   sp_nttdata_t nttdata;
@@ -455,7 +458,7 @@ sp_pow (sp_t x, sp_t a, sp_t m, sp_t d)
     }
 }
 
-/* 1/x mod p */
+/* 1/x mod p where d is p->mul_c */
 #define sp_inv(x,p,d) sp_pow (x, (p) - 2, p, d)
 
 /* x / 2 mod m */
@@ -466,7 +469,7 @@ int sp_prime (sp_t);
 
 /* spm */
 
-spm_t spm_init (spv_size_t, sp_t);
+spm_t spm_init (spv_size_t, sp_t, mp_size_t);
 void spm_clear (spm_t);
 
 /* spv */
diff --git a/spm.c b/spm.c
index b0e1d0d..5100a74 100644
--- a/spm.c
+++ b/spm.c
@@ -1,23 +1,23 @@
 /* spm.c - "small prime modulus" functions to precompute an inverse and a
    primitive root for a small prime
 
-  Copyright 2005, 2008 Dave Newman and Jason Papadopoulos.
-
-  The SP Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The SP Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the SP Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+Copyright 2005, 2006, 2008, 2009, 2010, 2012 Dave Newman, Jason Papadopoulos,
+Paul Zimmermann, Alexander Kruppa.
+
+The SP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The SP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the SP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA. */
 
 #include <stdlib.h>
 #include "sp.h"
@@ -90,9 +90,11 @@ nttdata_clear(sp_nttdata_t data)
 }
 
 /* Compute some constants, including a primitive n'th root of unity. 
-   Returns NULL in case of error. */
+   Returns NULL in case of error.
+   k is the number of limbs of the number to factor
+*/
 spm_t
-spm_init (spv_size_t n, sp_t sp)
+spm_init (spv_size_t n, sp_t sp, mp_size_t k)
 {
   sp_t a, b, bd, sc;
   spv_size_t q, nc, ntt_power;
@@ -105,6 +107,26 @@ spm_init (spv_size_t n, sp_t sp)
   spm->sp = sp;
   sp_reciprocal (spm->mul_c, sp);
 
+  /* compute spm->invm = -1/p mod B where B = 2^GMP_NUMB_BITS */
+  a = sp_pow (2, GMP_NUMB_BITS, sp, spm->mul_c); /* a = B mod p */
+  a = sp_inv (a, sp, spm->mul_c);                /* a = 1/B mod p */
+  /* a = 1/B mod p thus B*a - 1 = invm*p */
+  a --;
+  b = GMP_NUMB_MASK;
+#if SP_NUMB_BITS == W_TYPE_SIZE - 2
+  a = (a << 2) + (b >> (GMP_NUMB_BITS - 2));
+  b = (b << 2) & GMP_NUMB_MASK;
+  udiv_qrnnd (bd, sc, a, b, sp << 2);
+#else
+  a = (a << 1) + (b >> (GMP_NUMB_BITS - 1));
+  b = (b << 1) & GMP_NUMB_MASK;
+  udiv_qrnnd (bd, sc, a, b, sp << 1);
+#endif
+  spm->invm = bd;
+
+  /* compute spm->Bpow = B^(k+1) mod p */
+  spm->Bpow = sp_pow (2, GMP_NUMB_BITS * (k + 1), sp, spm->mul_c);
+
   /* find an $n$-th primitive root $a$ of unity $(mod sp)$. */
 
   /* Construct a $b$ whose order $(mod sp)$ is equal to $n$.
diff --git a/spv.c b/spv.c
index 224c62f..079337d 100644
--- a/spv.c
+++ b/spv.c
@@ -1,23 +1,23 @@
 /* spv.c - "small prime vector" functions for arithmetic on vectors of
    residues modulo a single small prime
 
-  Copyright 2005, 2008 Dave Newman and Jason Papadopoulos.
-
-  The SP Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The SP Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the SP Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+Copyright 2005, 2006, 2007, 2008, 2009 Dave Newman, Jason Papadopoulos,
+Brian Gladman, Alexander Kruppa, Paul Zimmermann.
+
+The SP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The SP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the SP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA. */
 
 #include <string.h> /* for memset */
 #include "sp.h"
diff --git a/stage2.c b/stage2.c
index 26273a7..60dd403 100644
--- a/stage2.c
+++ b/stage2.c
@@ -1,25 +1,25 @@
 /* Common stage 2 for ECM, P-1 and P+1 (improved standard continuation
    with subquadratic polynomial arithmetic).
 
-  Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
+Paul Zimmermann, Alexander Kruppa, Dave Newman.
 
-  This file is part of the ECM Library.
+This file is part of the ECM Library.
 
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "config.h"
 #include <stdio.h>
diff --git a/test.ecm b/test.ecm
index 9399d0f..c48ac88 100755
--- a/test.ecm
+++ b/test.ecm
@@ -2,22 +2,24 @@
 
 # test file for ECM
 #
-# Copyright 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011 Jim Fougeron, Alexander Kruppa, Dave Newman, Paul Zimmermann.
+# Copyright 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011, 2012
+# Jim Fougeron, Alexander Kruppa, Dave Newman, Paul Zimmermann, Cyril Bouvier,
+# David Cleaver.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at your
 # option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# 
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; see the file COPYING.  If not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-# MA 02110-1301, USA.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING.  If not, see
+# http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
 ECM="$1"
 
@@ -41,112 +43,102 @@ checkcode () {
 # 10     Composite factor found, cofactor is a probable prime
 # 14     Probable prime factor found, cofactor is a probable prime
 
+BATCH0=""
+
 # try primes < d in stage 2. Curve with sigma=7, mod 30210181 has order
 # 2^4 * 3^3 * 29 * 2411
-echo 2050449353925555290706354283 | $ECM -sigma 7 -k 1 30 0-1e6; checkcode $? 14
+echo 2050449353925555290706354283 | $ECM $BATCH0 -sigma 7 -k 1 30 0-1e6; checkcode $? 14
 
 # check the -treefile option
-echo 2050449353925555290706354283 | $ECM -treefile tree -sigma 7 -k 1 30 0-1e6; checkcode $? 14
+echo 2050449353925555290706354283 | $ECM $BATCH0 -treefile tree -sigma 7 -k 1 30 0-1e6; checkcode $? 14
 
 # Check a stage 2 of length 1. g1=1822795201 g2=968809 g3=567947
-echo 212252637915375215854013140804296246361 | $ECM -sigma 781683988 -go 550232165123 63421 1822795201-1822795201; checkcode $? 8
+echo 212252637915375215854013140804296246361 | $ECM $BATCH0 -sigma 781683988 -go 550232165123 63421 1822795201-1822795201; checkcode $? 8
 
 # tests from Torbjo"rn Granlund
-echo 137703491 | $ECM -sigma 6 84 1000; checkcode $? 8
+echo 137703491 | $ECM $BATCH0 -sigma 6 84 1000; checkcode $? 8
 
-echo 3533000986701102061387017352606588294716061 | $ECM -sigma 1621 191 225; checkcode $? 14
+echo 3533000986701102061387017352606588294716061 | $ECM $BATCH0 -sigma 1621 191 225; checkcode $? 14
 
-echo 145152979917007299777325725119 | $ECM -sigma 711387948 924 117751; checkcode $? 14
+echo 145152979917007299777325725119 | $ECM $BATCH0 -sigma 711387948 924 117751; checkcode $? 14
 
 # Test a few base 2 numbers. These tests are fairly quick.
 
 # Test a 2^n-1 number, factor found in stage 1. Order mod 33554520197234177
 # with sigma=262763035 is 2^3*3*5*47*59*241*601*743*937
 
-echo "2^919-1" | $ECM -sigma 262763035 937 1; checkcode $? 6
+echo "2^919-1" | $ECM $BATCH0 -sigma 262763035 937 1; checkcode $? 6
 
 # Test a 2^n-1 number, factor found in stage 2. Order mod 33554520197234177
 # with sigma=1691973485 is 2^6*3*11*29*59*73*263*283*1709
 
-echo "2^919-1" | $ECM -sigma 1691973485 283 1709; checkcode $? 6
+echo "2^919-1" | $ECM $BATCH0 -sigma 1691973485 283 1709; checkcode $? 6
 
 # Test a 2^n+1 number, factor found in stage 1. Order mod 24651922299337
 # with sigma=2301432245 is 2^3*3^3*5^2*7^2*17*67*157*521
-echo "(2^1033+1)/3" | $ECM -sigma 2301432245 521 1; checkcode $? 6
+echo "(2^1033+1)/3" | $ECM $BATCH0 -sigma 2301432245 521 1; checkcode $? 6
 
 # Test a 2^n+1 number, factor found in stage 2. Order mod 24651922299337
 # with sigma=2394040080 is 2^2*3^2*13*19*53*127*223*1847
-echo "(2^1033+1)/3" | $ECM -sigma 2301432245 223 1847; checkcode $? 6
+echo "(2^1033+1)/3" | $ECM $BATCH0 -sigma 2301432245 223 1847; checkcode $? 6
 
 # Test another 2^n+1 number, with a larger known factor divided out.
 # Factor found in stage 1, order mod 114584129081 with sigma=2399424618
 # is 2^9*3^2*5^2*7^2*53*383
-echo "(2^1063+1)/3/26210488518118323164267329859" | $ECM -sigma 2399424618 383 1 ; checkcode $? 6
+echo "(2^1063+1)/3/26210488518118323164267329859" | $ECM $BATCH0 -sigma 2399424618 383 1 ; checkcode $? 6
 
 # Like last one, but factor found in stage 2
-echo "(2^1063+1)/3/26210488518118323164267329859" | $ECM -sigma 2399424618 71 500; checkcode $? 6
+echo "(2^1063+1)/3/26210488518118323164267329859" | $ECM $BATCH0 -sigma 2399424618 71 500; checkcode $? 6
 
-echo 242668358425701966181147598421249782519178289604307455138484425562807899 | $ECM -sigma 1417477358 28560 8e7-85507063; checkcode $? 14
+echo 242668358425701966181147598421249782519178289604307455138484425562807899 | $ECM $BATCH0 -sigma 1417477358 28560 8e7-85507063; checkcode $? 14
 
 # bug found by Jim Fougeron
-echo 3533000986701102061387017352606588294716061 | $ECM -sigma 291310394389387 191 225; checkcode $? 14
+echo 3533000986701102061387017352606588294716061 | $ECM $BATCH0 -sigma 291310394389387 191 225; checkcode $? 14
 
-echo 121279606270805899614487548491773862357 | $ECM -sigma 1931630101 120; checkcode $? 14
+echo 121279606270805899614487548491773862357 | $ECM $BATCH0 -sigma 1931630101 120; checkcode $? 14
 
-echo 291310394389387 | $ECM -power 3 -sigma 40 2000; checkcode $? 8
+echo 291310394389387 | $ECM $BATCH0 -power 3 -sigma 40 2000; checkcode $? 8
 
-echo 3533000986701102061387017352606588294716061 | $ECM -sigma 3547 167 211; checkcode $? 14
+echo 3533000986701102061387017352606588294716061 | $ECM $BATCH0 -sigma 3547 167 211; checkcode $? 14
 
 # test -go option
-echo 449590253344339769860648131841615148645295989319968106906219761704350259884936939123964073775456979170209297434164627098624602597663490109944575251386017 | $ECM -sigma 63844855 -go 172969 61843 20658299; checkcode $? 14
-
-echo 17061648125571273329563156588435816942778260706938821014533 | $ECM -sigma 585928442 174000; checkcode $? 14
+echo 449590253344339769860648131841615148645295989319968106906219761704350259884936939123964073775456979170209297434164627098624602597663490109944575251386017 | $ECM $BATCH0 -sigma 63844855 -go 172969 61843 20658299; checkcode $? 14
 
-echo 89101594496537524661600025466303491594098940711325290746374420963129505171895306244425914080753573576861992127359576789001 | $ECM -sigma 877655087 -go 325001 157721 1032299; checkcode $? 14
+echo 17061648125571273329563156588435816942778260706938821014533 | $ECM $BATCH0 -sigma 585928442 174000; checkcode $? 14
 
-echo 5394204444759808120647321820789847518754252780933425517607611172590240019087317088600360602042567541009369753816111824690753627535877960715703346991252857 | $ECM -sigma 805816989 -go 345551 149827; checkcode $? 6
+echo 89101594496537524661600025466303491594098940711325290746374420963129505171895306244425914080753573576861992127359576789001 | $ECM $BATCH0 -sigma 877655087 -go 325001 157721 1032299; checkcode $? 14
 
-echo 3923385745693995079670229419275984584311007321932374190635656246740175165573932140787529348954892963218868359081838772941945556717 | $ECM -sigma 876329474 141667 150814537; checkcode $? 14
+echo 5394204444759808120647321820789847518754252780933425517607611172590240019087317088600360602042567541009369753816111824690753627535877960715703346991252857 | $ECM $BATCH0 -sigma 805816989 -go 345551 149827; checkcode $? 6
 
-echo 124539923134619429718018353168641490719788526741873602224103589351798060075728544650990190016536810151633233676972068237330360238752628542584228856301923448951 | $ECM -sigma 1604840403 -go "1260317*1179109*661883" 96097 24289207; checkcode $? 14
+echo 3923385745693995079670229419275984584311007321932374190635656246740175165573932140787529348954892963218868359081838772941945556717 | $ECM $BATCH0 -sigma 876329474 141667 150814537; checkcode $? 14
 
-# for ecm3, g1=4043946241 divides 484984500^120-17923^120
-# doesn't work with Dickson(60), commented since may be not reproducible
-#echo 5735013127104523546495917836490637235369 | $ECM -power 60 -k 2 -A 3848610099745584498259560038340842096471 -x0 2527419713481530878734189429997880136878 330000 500000000; checkcode $? 8
-
-# g1=1805746381 divides 1577240280^12-349^12, doesn't work with Dickson
-# warning: depends on the value of d chosen in stage 2
-# works with -k 2 (d=92820), -k 3 (d=78540)
-#echo 17833653493084084667826559287841287911473 | $ECM -power 6 -k 2 -A 7423036368129288563912180723909655170075 -x0 9011819881065862648414808987718432766274 389797 16e8; checkcode $? 8
-
-# g1=1822795201 divides 185550750^30-25009^30, doesn't work with Dickson
-#echo 212252637915375215854013140804296246361 | $ECM -power 15 -k 2 -sigma 781683988 1000000; checkcode $? 8
+echo 124539923134619429718018353168641490719788526741873602224103589351798060075728544650990190016536810151633233676972068237330360238752628542584228856301923448951 | $ECM $BATCH0 -sigma 1604840403 -go "1260317*1179109*661883" 96097 24289207; checkcode $? 14
 
 # p49 found by Sean Irvine
-echo 4983070578699621345648758795946786489699447158923341167929707152021191319057138908604417894224244096909460401007237133698775496719078793168004317119431646035122982915288481052088094940158965731422616671 | $ECM -sigma 909010734 122861 176711; checkcode $? 6
+echo 4983070578699621345648758795946786489699447158923341167929707152021191319057138908604417894224244096909460401007237133698775496719078793168004317119431646035122982915288481052088094940158965731422616671 | $ECM $BATCH0 -sigma 909010734 122861 176711; checkcode $? 6
 
 # bug in ecm-5.0 (overflow in fin_diff_coeff)
-echo 1408323592065265621229603282020508687 | $ECM -sigma 1549542516 -go 2169539 531571 29973883000-29973884000; checkcode $? 8
+echo 1408323592065265621229603282020508687 | $ECM $BATCH0 -sigma 1549542516 -go 2169539 531571 29973883000-29973884000; checkcode $? 8
 
 # bug in ecm 5.0 and 5.0.1 (factor found for c110 input, not with p58)
-echo 3213162276640339413566047915418064969550383692549981333701 | $ECM -sigma 2735675386 -go 1615843 408997 33631583; checkcode $? 8
+echo 3213162276640339413566047915418064969550383692549981333701 | $ECM $BATCH0 -sigma 2735675386 -go 1615843 408997 33631583; checkcode $? 8
 
-echo 39614081257132168796771975177 | $ECM -sigma 480 1e6; checkcode $? 8
+echo 39614081257132168796771975177 | $ECM $BATCH0 -sigma 480 1e6; checkcode $? 8
 
-echo 10000286586958753753 | $ECM -sigma 3956738175 1e6; checkcode $? 8
+echo 10000286586958753753 | $ECM $BATCH0 -sigma 3956738175 1e6; checkcode $? 8
 
-echo 49672383630046506169472128421 | $ECM -sigma 2687434659 166669 86778487; checkcode $? 8
+echo 49672383630046506169472128421 | $ECM $BATCH0 -sigma 2687434659 166669 86778487; checkcode $? 8
 
-echo 216259730493575791390589173296092767511 | $ECM -sigma 214659179 1124423 20477641; checkcode $? 8
+echo 216259730493575791390589173296092767511 | $ECM $BATCH0 -sigma 214659179 1124423 20477641; checkcode $? 8
 
 # bug reported by Allan Steel on 14 March 2006
-echo 49367108402201032092269771894422156977426293789852367266303146912244441959559870316184237 | $ECM -sigma 6 5000; checkcode $? 0
+echo 49367108402201032092269771894422156977426293789852367266303146912244441959559870316184237 | $ECM $BATCH0 -sigma 6 5000; checkcode $? 0
 
 # A test with a larger input number to test modular arithmetic routines not
 # in mulredc*.asm. This input has 1363 bits so it has 22 64 bit words 
 # (43 32 bit words) and cannot use mulredc which handles only up to 20 limbs
 
-echo "10090030271*10^400+696212088699" | $ECM -sigma 3923937547 1e3 1e6; checkcode $? 14
+echo "10090030271*10^400+696212088699" | $ECM $BATCH0 -sigma 3923937547 1e3 1e6; checkcode $? 14
 
 # To test batch mode 1
 # the following test works both on 32- and 64-bit machines
@@ -192,14 +184,18 @@ echo 4294967291 | $ECM -batch -A 17 1000
 checkcode $? 8
 
 # this example would fail with the old Fgw.c when using gwnum (fixed by David Cleaver, r1734)
-echo "((173^173+1)/174)/471462511391940575680645418941" | $ECM -sigma 12345 20000
+echo "((173^173+1)/174)/471462511391940575680645418941" | $ECM $BATCH0 -sigma 12345 20000
 checkcode $? 0
 
+# this test was failing on gcc45.fsffrance.org with 6.4.1
+echo "((173^173+1)/174)/471462511391940575680645418941+122" | $ECM $BATCH0 -sigma 77 20000
+checkcode $? 6
+
 # the following tests should work on machines which have uint64_t or where
 # unsigned long long has 64 bits (exercises patch from David Cleaver, r1575)
 echo "NOTE: NEXT 3 TESTS WILL FAIL ON SOME 32BIT MACHINES, THIS IS EXPECTED."
-echo 10000000000000000000000000000000000000121 | $ECM -sigma 61 -go 1195504287780095287 2950307;  checkcode $? 8
-echo 10000000000000000000000000000000000000121 | $ECM -sigma 266 -go 218187387944803649 9405629;  checkcode $? 8
-echo 10000000000000000000000000000000000000121 | $ECM -sigma 291 -go 5994496018878137 4372759;  checkcode $? 8
+echo 10000000000000000000000000000000000000121 | $ECM $BATCH0 -sigma 61 -go 1195504287780095287 2950307;  checkcode $? 8
+echo 10000000000000000000000000000000000000121 | $ECM $BATCH0 -sigma 266 -go 218187387944803649 9405629;  checkcode $? 8
+echo 10000000000000000000000000000000000000121 | $ECM $BATCH0 -sigma 291 -go 5994496018878137 4372759;  checkcode $? 8
 
 echo "All ECM tests are ok."
diff --git a/test.pm1 b/test.pm1
index 84011f9..c9bb245 100755
--- a/test.pm1
+++ b/test.pm1
@@ -2,22 +2,23 @@
 
 # test file for P-1 method
 #
-# Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Paul Zimmermann, Alexander Kruppa and Dave Newman.
+# Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012
+# Paul Zimmermann, Alexander Kruppa, Dave Newman, Jim Fougeron.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at your
 # option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# 
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; see the file COPYING.  If not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-# MA 02110-1301, USA.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING.  If not, see
+# http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
 PM1="$1 -pm1"
 
@@ -99,4 +100,3 @@ echo "10090030271*10^400+696212088699" | $PM1 2e3 2e6; checkcode $? 14
 echo "2^(64*2)-1" | $PM1 -redc -x0 -1 2 1; checkcode $? 8
 
 echo "All P-1 tests are ok."
-echo ""
diff --git a/test.pp1 b/test.pp1
index 4628502..80ef58b 100755
--- a/test.pp1
+++ b/test.pp1
@@ -1,22 +1,23 @@
 #!/bin/sh
 # test file for P+1 method
 #
-# Copyright 2002, 2003, 2005, 2006, 2007, 2008, 2009 Jim Fougeron, Alexander Kruppa, Dave Newman and Paul Zimmermann.
+# Copyright 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2012 Jim Fougeron,
+# Alexander Kruppa, Dave Newman and Paul Zimmermann.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at your
 # option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# 
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; see the file COPYING.  If not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-# MA 02110-1301, USA.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING.  If not, see
+# http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
 PP1="$1 -pp1"
 
@@ -120,5 +121,6 @@ echo "6054018161*10^400+417727253109" | $PP1 -x0 4 2e3 2e6; checkcode $? 14
 
 echo 154618728587 | $PP1 -x0 3 -go 36 4294957296-4294967295 1; checkcode $? 8
 
+echo 18446744073709551337 | $PP1 -pp1 -x0 2 70823 714487; checkcode $? 8
+
 echo "All P+1 tests are ok."
-echo ""
diff --git a/toomcook.c b/toomcook.c
index d4660bc..44fe2c1 100644
--- a/toomcook.c
+++ b/toomcook.c
@@ -1,25 +1,25 @@
 /* Implementation of the Toom-Cook 3-way and 4-way algorithms for 
    polynomial convolution products. 
   
-  Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa.
+Copyright 2001, 2002, 2003, 2004, 2005, 2006 Paul Zimmermann, Alexander Kruppa
+and Dave Newman.
   
-  This file is part of the ECM Library.
-
-  The ECM Library is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or (at your
-  option) any later version.
-
-  The ECM Library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with the ECM Library; see the file COPYING.LIB.  If not, write to
-  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-  MA 02110-1301, USA.
-*/
+This file is part of the ECM Library.
+
+The ECM Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The ECM Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the ECM Library; see the file COPYING.LIB.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include "ecm-impl.h"
 
diff --git a/trial.c b/trial.c
deleted file mode 100644
index d98ccbf..0000000
--- a/trial.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* A Very Simple trial division module
-
-  Copyright 2003, 2004, 2005 Jim Fougeron, Paul Zimmermann.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
-
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
-
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
-
-#include <stdio.h>
-#include <math.h> /* log */
-#include "ecm-ecm.h"
-
-/* Does trial division of n by the primes 1 < p <= maxfact.
-   Returns the number of factors found (counting multiplicity) */
-
-int
-trial_factor (mpcandi_t *n, double maxfact, int deep)
-{
-  unsigned long factors = 0, exponent;
-  double p;
-
-  if (mpz_sgn (n->n) == 0)
-    return 0;
-
-  getprime_clear ();  /* free the prime tables, and reinitialize */
-  /* brain dead trial factor'r but it works */
-  for (p = 2.0; p <= maxfact; p = getprime ())
-    {
-      for (exponent = 0; mpcandi_t_addfoundfactor_d (n, p); exponent++);
-      
-      if (exponent)
-	{
-	  printf ("********** Factor found trial div: %lu\n", (unsigned long) p);
-	  printf ("Found proven prime factor of %2lu digits: %lu",
-	    (unsigned long) (log (p) / log (10.0)) + 1, (unsigned long) p);
-	  
-	  if (exponent > 1)
-	    printf ("^%lu", exponent);
-	  printf ("\n");
-	  
-	  factors += exponent;
-	  if (!deep)
-	    /* We only want the first factor if not in "deep" mode */
-	    break;
-	}
-    }
-  getprime_clear ();  /* free the prime tables, and reinitialize */
-
-  return factors;
-}
diff --git a/tune.c b/tune.c
index 76e37db..85d1331 100644
--- a/tune.c
+++ b/tune.c
@@ -1,23 +1,22 @@
 /* Tune program for GMP-ECM.
 
-  Copyright 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Paul Zimmermann,
-  Alexander Kruppa, Dave Newman and Jason Papadopoulos.
+Copyright 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Paul Zimmermann,
+Alexander Kruppa, Dave Newman and Jason Papadopoulos.
 
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the
-  Free Software Foundation; either version 2 of the License, or (at your
-  option) any later version.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
 
-  This program is distributed in the hope that it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+more details.
 
-  You should have received a copy of the GNU General Public License along
-  with this program; see the file COPYING.  If not, write to the Free
-  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  02111-1307, USA.
-*/
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, see
+http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -26,7 +25,7 @@
 
 /* 250ms, we (probably) don't need any more precision */
 #define GRANULARITY 250
-#define MAX_LOG2_LEN 18 /* 2 * 131072 */ 
+#define MAX_LOG2_LEN 18 /* 2 * 131072 */
 #define MAX_LEN (1U << max_log2_len)
 #define MAX_LOG2_MPZSPV_NORMALISE_STRIDE (MIN (12, max_log2_len))
 #define M_str "95209938255048826235189575712705128366296557149606415206280987204268594538412191641776798249266895999715600261737863698825644292938050707507901970225804581"

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



More information about the debian-science-commits mailing list