Changeset 26e030 in git


Ignore:
Timestamp:
Jul 6, 2009, 4:52:01 PM (14 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
Children:
cf5d3081011bf7a0104bade9c3eaf9da21c588d7
Parents:
e6d2f67d59d8d9127eab2943d2bf0c78e249d180
Message:
*hannes: update to 5.5.1


git-svn-id: file:///usr/local/Singular/svn/trunk@11949 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
ntl
Files:
5 added
49 edited

Legend:

Unmodified
Added
Removed
  • ntl/README

    re6d2f67 r26e030  
    1 NTL  -- a library for doing numbery theory --  version 5.4.2
    2 Release date: 2008.03.05
     1NTL  -- a library for doing numbery theory --  version 5.5
     2Release date: 2009.04.08
    33
    44Author: Victor Shoup (victor@shoup.net)
     
    1919The latest version of NTL is available at http://www.shoup.net.
    2020
    21 The sources have been modified for Singular-3-0-4
     21The sources have been modified for Singular-3-1-0
    2222- for errors blame singular@mathematik.uni-kl.de,
    2323not Victor Shoup (victor@shoup.net)
  • ntl/doc/ZZ.txt

    re6d2f67 r26e030  
    221221// adjusted according to the signs of a and b.
    222222
    223 // Uses a variant of Lehmer's algorithm (see Knuth, The Art of Computer
    224 // Programming, vol. 2).
    225 
    226 
     223// The implementation may or may not Euclid's algorithm,
     224// but the coefficients a and t are always computed as if
     225// it did.
    227226
    228227
  • ntl/doc/config.txt

    re6d2f67 r26e030  
    2323CXXFLAGS=$(CFLAGS)   # C++ compilation flags (by default, same as CFLAGS)
    2424
    25 PREFIX=/usr/local    # Directory in which to install NTL library components
     25DEF_PREFIX=/usr/local # Default software directory
     26PREFIX=$(DEF_PREFIX) # Directory in which to install NTL library components
     27SHARED=off           # Generate a shared library (as well as static)
    2628
    2729NTL_STD_CXX=on       # ISO Mode switch
     
    3032                     #   long integer package
    3133
    32 GMP_PREFIX=undefined # Directory in which GMP components have been installed
     34GMP_PREFIX=$(DEF_PREFIX) # Directory in which GMP components are installed
     35
     36NTL_GF2X_LIB=off     # Switch to enable the use of the gf2x package
     37                     #   for faster arithmetic over GF(2)[X]
     38
     39GF2X_PREFIX=$(DEF_PREFIX) # Directory in which gf2x components are installed
    3340
    3441
     
    7784
    7885
     86
    7987########## Installation path:
    8088
    81 PREFIX=/usr/local
     89DEF_PREFIX=/usr/local
     90
     91# Default software directory
     92
     93PREFIX=$(DEF_PREFIX)
    8294
    8395# Set this to the directory in which you want NTL components to be
     
    8597# files are copied into $(PREFIX)/include/NTL, the library itself is
    8698# copied to $(PREFIX)/lib/libntl.a, and the documentation files
    87 # are copied into $(PREFIX)/doc/NTL.
     99# are copied into $(PREFIX)/share/doc/NTL.
    88100# Unless you have root permissions when running 'make install',
    89101# you will have to override the default PREFIX value with the
     
    92104# library components are installed, set the variables
    93105# INCLUDEDIR, LIBDIR, and DOCDIR (see below).
     106
     107########## Shared library switch:
     108
     109SHARED=off
     110
     111# Set this to 'on' if you want to generate a shared library, in addition to
     112# a static library.   Shared libraries have many advantages, but
     113# unfortunately, their use is rather less portable than that of good,
     114# old-fashioned static libraries.  If you set SHARED=on, then the makefile
     115# attempts to make use of the GNU libtool program, which is meant to work
     116# around these portability issues.  You may also want to set the
     117# configuration variable LIBTOOL (see below), to point to another version of
     118# libtool.  For example, on Mac OSX, the built-in command libtool is not
     119# actually the GNU libtool program; in this case, you will want to set
     120# LIBTOOL=glibtool.  On other systems, it may be necssary to downlaod and
     121# install a fresh copy of the libtool program (which can be obtained from
     122# http://www.gnu.org/software/libtool). Note that if SHARED=on, then
     123# in addition to using the libtool program, the makefile relies on
     124# features specific to GNU make.
     125
     126
    94127
    95128########## ISO mode switch:
     
    129162
    130163
    131 GMP_PREFIX=undefined
     164GMP_PREFIX=$(DEF_PREFIX)
    132165
    133166# If GMP was installed in a standard system directory, e.g., /usr/local,
     
    141174
    142175
     176########## GF2X variables:
     177
     178NTL_GF2X_LIB=off
     179
     180# Set to 'on' if you want to use the gf2x library for faster
     181# arithmetic over GF(2)[X] (the NTL class GF2X).
     182
     183# If you set this flag, please note the following.
     184# If you have installed gf2x in a standard "system" location, this is
     185# all you have to do.  Otherwise, if gf2x is built, but not installed
     186# in a standard place, you have to set the variable GF2X_PREFIX.
     187
     188
     189GF2X_PREFIX=$(DEF_PREFIX)
     190
     191# If gf2x was installed in a standard system directory, e.g., /usr/local,
     192# then do not set this variable.
     193# Otherwise, if you want to use gf2x and gf2x was installed in
     194# a directory <gf2x_prefix>, then set GF2X_PREFIX=<gf2x_prefix>.
     195# This works if the directory <gf2x_prefix>/include contains gf2x.h
     196# and <gf2x_prefix>/lib contains libgf2x.a. 
     197# For finer-grained control, set the variables GF2X_INCDIR and GF2X_LIBDIR
     198# instead (see below).
     199
     200
     201
    143202########### Examples:
    144203
     
    179238
    180239
     240# If you want to use both GMP and the gf2x library:
     241
     242   ./configure NTL_GMP_LIP=on NTL_GF2X_LIB=on
    181243
    182244
     
    184246
    185247   ./configure NTL_GMP_LIP=on NTL_STD_CXX=off
     248
    186249
    187250
     
    200263LDLIBS_CXX=$(LDLIBS)
    201264CPPFLAGS=
     265LIBTOOL=libtool
    202266
    203267LIBDIR=$(PREFIX)/lib
    204268INCLUDEDIR=$(PREFIX)/include
    205 DOCDIR=$(PREFIX)/include
     269DOCDIR=$(PREFIX)/share/doc
     270
    206271
    207272NTL_PSTD_NNS=off
     
    232297
    233298NTL_GMP_HACK=off
    234 GMP_INCDIR=undefined
    235 GMP_LIBDIR=undefined
     299GMP_INCDIR=$(GMP_PREFIX)/include
     300GMP_LIBDIR=$(GMP_PREFIX)/lib
     301
     302GF2X_INCDIR=$(GF2X_PREFIX)/include
     303GF2X_LIBDIR=$(GF2X_PREFIX)/lib
     304
    236305
    237306
     
    274343LDLIBS=-lm
    275344
     345# libraries for linking C programs
     346
     347
     348
     349LDLIBS_CXX=$(LDLIBS)
     350
    276351# libraries for linking C++ programs
    277352
    278353
    279354
    280 LDLIBS_CXX=$(LDLIBS)
    281 
    282 # libraries for linking C++ programs
    283 
    284 
    285 
    286355CPPFLAGS=
    287356
    288357# arguments for the C preprocessor
    289358
    290 
    291 
    292 ########### Details of the compilation process:
     359LIBTOOL=libtool
     360
     361# the libtool command -- only needed if SHARED=on
     362
     363
     364
     365########### Details of the compilation process (when SHARED=off)
     366
    293367
    294368# When a C file foo.c is compiled:
     
    305379      -o foo foo.c $(LDLIBS_CXX)
    306380
    307 # When the library ntl.a is built:
     381# When the library ntl.a is built
    308382   $(AR) $(ARFLAGS) ntl.a [ object files ]...
    309383   $(RANLIB) ntl.a
     
    311385
    312386
     387
    313388########### Further installation variables:
    314389
    315390LIBDIR=$(PREFIX)/lib
    316391INCLUDEDIR=$(PREFIX)/include
    317 DOCDIR=$(PREFIX)/doc
     392DOCDIR=$(PREFIX)/share/doc
    318393# Where to install NTL.
    319394# Execution of 'make install' copies header files into $(INCLUDEDIR)/NTL,
    320395# copies the library itself to $(LIBDIR)/libntl.a, and copies the
    321396# documentation files into $(DOCDIR)/NTL.
     397
    322398
    323399
     
    568644# If you set this flag, you may have to set GMP_PREFIX as well.
    569645
    570 
    571 
    572 
    573 GMP_INCDIR=undefined
    574 
    575 # Set to -I<directory containing gmp.h> if using GMP and GMP
    576 # is not installed in a standard system directory.
    577 
    578 
    579 
    580 GMP_LIBDIR=undefined
    581 # Set to -L<directory containing libgmp.a> if using GMP and GMP
    582 # is not installed in a standard system directory.
    583 
    584 # You do not need to define GMP_INCDIR or GMP_LIBDIR, if either
    585 #   - you are not compiling NTL with GMP,
    586 #   - you are compiling NTL with GMP, and GMP has been installed in
    587 #     a standard system ocataion (e.g., /usr/local), or
    588 #   - you are compiling NTL with GMP, GMP has been installed in
    589 #     <gmp_prefix>, and you set GMP_PREFIX=<gmp_prefix>.
    590 
     646GMP_INCDIR=$(GMP_PREFIX)/include
     647# directory containing gmp.h
     648
     649GMP_LIBDIR=$(GMP_PREFIX)/lib
     650# directory containing libgmp.a
     651
     652
     653####### More gf2x options:
     654
     655GF2X_INCDIR=$(GF2X_PREFIX)/include
     656# directory containing gf2x.h
     657
     658GF2X_LIBDIR=$(GF2X_PREFIX)/lib
     659# directory containing libgf2x.a
     660
  • ntl/doc/copying.txt

    re6d2f67 r26e030  
    33
    44NTL -- A Library for Doing Number Theory
    5 Copyright (C) 1996-2007  Victor Shoup
     5Copyright (C) 1996-2009  Victor Shoup
    66
    77The most recent version of NTL is available at http://www.shoup.net
  • ntl/doc/tools.txt

    re6d2f67 r26e030  
    3131// print an error message and call abort
    3232
     33extern void (*ErrorCallback)();
     34// A pointer (initially NULL) to a callback function.
     35// This function will be called by the Error function,
     36// as well as other functions, before calling abort().
     37// Note that the callback function is expected to have
     38// C++ linkage, as it is called directly by a C++ function,
     39// even though the latter function may be called from a
     40// C function.
     41
    3342long IsWhiteSpace(long c);
    3443// returns 1 if c is "wite space" (as defined by isspace is the
     
    4352// like NTL's, that raise an error if an input item is
    4453// ill-formed or missing. 
     54
     55long IsEOFChar(long c);
     56// test if c == EOF
    4557
    4658
  • ntl/doc/tour-changes.html

    re6d2f67 r26e030  
    1717</p>
    1818</h1>
     19
     20<p> <hr> <p>
     21<h3>
     222009.05.05: Changes between NTL 5.5 and 5.5.1
     23</h3>
     24
     25<ul>
     26<li> If using GMP (via either <tt>NTL_GMP_LIP</tt>
     27or <tt>NTL_GMP_HACK</tt>), then the new version (4.3.0) of
     28GMP implements the <tt>XGCD</tt> functionality differently,
     29so that the coefficients do not always agree with those returned by
     30the classical extended Euclidean algorithm.
     31This version of NTL corrects the coefficients, so that the
     32"classical" coefficients are always produced, regardless
     33of GMP's implementation.
     34This version of NTL also works
     35around a bug in GMP 4.3.0's <tt>XGCD</tt> code
     36(although that bug should be fixed in GMP 4.3.1).
     37
     38<li>
     39The <tt>configure</tt> script has been slightly modified:
     40there is a new configuration variable <tt>DEF_PREFIX</tt>,
     41whose value can be used to set <tt>PREFIX</tt>, <tt>GMP_PREFIX</tt>,
     42and <tt>GF2X_PREFIX</tt> in one stroke.
     43Also, the (somewhat esoteric) <tt>configure</tt> variables
     44<tt>GMP_LIBDIR</tt>, <tt>GMP_INCDIR</tt>,
     45<tt>GF2X_LIBDIR</tt>, and <tt>GF2X_INCDIR</tt>
     46have slightly different meanings now.
     47
     48</ul>
     49</h3>
     50
     51<p> <hr> <p>
     52<h3>
     532009.04.08: Changes between NTL 5.4.2 and 5.5
     54</h3>
     55
     56<ul>
     57<li>
     58Added the ability to generate a <i>shared</i> library
     59(with help from Tim Abbott). <a href="tour-unix.html#shared">Details.</a>
     60
     61<li>
     62Fixed some standardization issues
     63(with help from Tim Abbot):
     64default location of installed documentation files now conforms
     65to standards; use of <tt>EOF</tt> now conforms to standards.
     66
     67<li>
     68Added a callback mechanism to NTL's error reporting function.
     69See <tt>ErrorCallback</tt> in <a href="tools.txt">tools.txt</a>.
     70
     71<li>
     72Added support for the <tt>gf2x</tt> library for speeding up
     73arithmetic in <tt>GF2X</tt> (with help from Emmanuel Thom&eacute;).
     74<a href="tour-gf2x.html">Details.</a>
     75
     76<li>
     77In conjuction with the above, I also changed the
     78<tt>GF2X</tt> so that it works better with very large polynomials:
     79large blocks of memory are released, recursive HalfGCD algorithms
     80are used for large polynomials.
     81
     82
     83<li>
     84Fixed a bug in <tt>void TraceMod(zz_p&amp; x, const zz_pX&amp; a, const zz_pXModulus&amp; F)</tt> (reported by Luca De Feo).
     85
     86<li>
     87Fixed a performance issue in various versions of <tt>SetCoeff</tt>
     88(reported by Luca De Feo).
     89
     90<li>
     91Fixed the declaration of  <tt>mat_zz_p transpose(const mat_zz_p&amp; a)</tt>
     92(reported by Benoit Lacelle).
     93</ul>
     94
    1995
    2096<p> <hr> <p>
  • ntl/doc/tour-ex1.html

    re6d2f67 r26e030  
    7272When compiling NTL in traditional mode, this expands
    7373to the empty string.
     74More details <a href="tour-stdcxx.html">here</a>.
    7475
    7576<p> <hr> <p>
  • ntl/doc/tour-gmp.html

    re6d2f67 r26e030  
    1010<a href="tour-impl.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
    1111 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a>
    12 <a href="tour-time.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
     12<a href="tour-gf2x.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
    1313</center>
    1414
     
    2323GMP is the GNU Multi-Precision library.
    2424You can get more information about it, as well as the latest version
    25 from <a href="http://www.swox.com/gmp">here.</a>
     25from <a href="http://gmplib.org">here.</a>
    2626
    2727<p>
     
    8787<p>
    8888
    89 Download GMP from <a href="http://www.swox.com/gmp">here.</a>
     89Download GMP from <a href="http://gmplib.org">here.</a>
    9090You will get a file <tt>gmp-XXX.tar.gz</tt>.
    9191<p>
     
    9595   % tar xf gmp-XXX.tar
    9696   % cd gmp-XXX
    97    % ./configure --disable-shared --prefix=$HOME/sw
     97   % ./configure --prefix=$HOME/sw
    9898   % make
    9999   % make check
    100100   % make install
    101101</pre>
    102 This will build, test, and install GMP in $HOME/sw.
     102This will build, test, and install GMP in <tt>$HOME/sw</tt>.
    103103Of course, change $HOME/sw to whatever you want (the default is
    104104<tt>/usr/local</tt>).
    105105You will find the GMP header files in <tt>$HOME/sw/include</tt>
    106 and the compiled binary in <tt>$HOME/sw/lib/libgmp.a</tt>.
    107 
    108 <p>
    109 The option <tt>--disable-shared</tt> is optional.
    110 It disables the creation of shared libraries,
    111 which simplifies things just a bit (in particular, this documentation).
    112 Shared libraries have their advantages, but the use of
    113 such libraries seems to vary a bit across different Unix flavors.
    114 
    115 
    116 <p>
    117 Executing <tt>make uninstall</tt> undoes the <tt>make install</tt>.
    118 <p>
    119 Executing <tt>make distclean</tt> removes everything
    120 created by <tt>configure</tt> and <tt>make</tt>.
     106and the compiled binaries in <tt>$HOME/sw/lib</tt>.
     107
     108<p>
     109You can also supply the option
     110<tt>--disable-shared</tt> to the <tt>configure</tt> script,
     111if you only want static libraries.
     112However, if you ultimately want to build NTL as a shared
     113library, then you must also buld GMP as a shared library.
     114
     115<p>
     116You must ensure that NTL and GMP have the same
     117<a href="tour-unix.html#abi">ABI</a>.
     118Usually, GMP's configure script will automatically
     119choose a 64-bit ABI if available.
     120
    121121
    122122<p>
     
    138138   % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on  GMP_PREFIX=$HOME/sw
    139139</pre>
     140You can write this more simply as
     141<pre>
     142   % ./configure DEF_PREFIX=$HOME/sw NTL_GMP_LIP=on
     143</pre>
     144Here, <tt>DEF_PREFIX</tt> is a variable that is used
     145to specify the location of all software,
     146and it defaults to <tt>/usr/local</tt>.
     147
    140148
    141149<p>
     
    163171<p>
    164172Instead of passing arguments to the configure script,
    165 you can also just edit the <tt>config.h</tt> and makefile by hand.
     173you can also just edit the <tt>config.h</tt> and <tt>makefile</tt> by hand.
    166174The documentation in these files should be self-explanatory.
     175
    167176
    168177<p>
    169178When compiling programs that use NTL with GMP,
    170179you need to link with the GMP library.
    171 If GMP is not installed as above in
     180If GMP is installed as above in
    172181<tt>$HOME/sw</tt>, rather than in a standard system directory,
    173182 this just means adding
     
    177186Note that <tt>-lgmp</tt> must come <i>after</i> <tt>-lntl</tt>
    178187on the command line.
     188Finally, if NTL and GF2X are installed as
     189shared libraries, then you don't even need <tt>-lgmp</tt>.
     190
    179191
    180192<p>
     
    202214The programming interface to the long integer package
    203215completely hides implementation details.
     216
     217
    204218
    205219
     
    359373<a href="tour-impl.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
    360374 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a>
    361 <a href="tour-time.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
     375<a href="tour-gf2x.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
    362376</center>
     377
    363378
    364379
  • ntl/doc/tour-impl.html

    re6d2f67 r26e030  
    190190
    191191<p>
     192It is also generally assumed that the compiler does not
     193do too much "regrouping" of arithmetic expressions involving
     194floating point.
     195Most compilers respect the implied grouping of floating point
     196computations, and NTL goes out of its way to make its
     197intentions clear: instead of <tt>x = (a + b) + c</tt>,
     198if the grouping is truly important, this is written
     199as <tt>t = a + b; x = t + c</tt>.
     200Current standards do not allow, and most implementations will not
     201perform, any regrouping of this, e.g., <tt>x = a + (b + c)</tt>,
     202since in floating point, addition and subtraction are not
     203associative.
     204
     205<p>
     206Unfortunately, some compilers do not do this correctly,
     207unless you tell them.
     208With Intel's C compiler <tt>icc</tt>, for example,
     209you should compile NTL with the flag <tt>-fp-model source</tt>
     210to enforce strict adherence to floating point standards.
     211Also, you should be wary of compiling using an optimization
     212level higher than the default <tt>-O2</tt> --
     213this may break some floating point assumptions (and maybe
     214some other assumptions as well).
     215
     216
     217
     218<p>
    192219One big problem with the IEEE standard is that it allows intermediate
    193220quantities to be computed in a higher precision than the standard
  • ntl/doc/tour-intro.html

    re6d2f67 r26e030  
    8787<a href="tour-gmp.html">GMP (the GNU Multi-Precision library)</a>
    8888for enhanced performance.
     89NTL can also be used in conjunction with the
     90<a href="tour-gf2x.html"><tt>gf2x</tt></a> library for faster
     91arithmetic of large degree polynomials over <i>GF(2)</i>.
    8992
    9093
  • ntl/doc/tour-modules.html

    re6d2f67 r26e030  
    5555<p>
    5656
    57 However, if you compiled NTL in traditional (non-ISO mode),
     57However, if you compiled NTL in
     58<a href="tour-stdcxx.html">traditional (non-ISO mode)</a>,
    5859then <tt>&lt;NTL/tools.h&gt;</tt>
    5960includes the traditional (pre-ISO) headers
  • ntl/doc/tour-time.html

    re6d2f67 r26e030  
    88
    99<center>
    10 <a href="tour-gmp.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
     10<a href="tour-gf2x.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
    1111 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a>
    1212<a href="tour-roadmap.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
     
    406406<p>
    407407
     408
    408409<center>
    409 <a href="tour-gmp.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
     410<a href="tour-gf2x.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
    410411 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a>
    411412<a href="tour-roadmap.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
  • ntl/doc/tour-unix.html

    re6d2f67 r26e030  
    2121
    2222This procedure should work on most Unix or Unix-like platorms
    23 (including MAC OSX, and Windows with Cygwin tools).
     23(including Mac OSX, and Windows with Cygwin tools).
    2424
    2525<p>
     
    5151You will find the NTL header files in <tt>$HOME/sw/include/NTL</tt>
    5252 and the compiled binary
    53 in <tt>$HOME/sw/lib/libntl.a</tt>.
     53in <tt>$HOME/sw/lib/libntl.a</tt>
     54(this is a <i>static</i> library -- if you want a <i>shared</i>
     55library, <a href="#shared">see below</a>).
    5456<p>
    5557If you really are interested in high-performace, you will
     
    5759using  GMP (the GNU Multi-Precision package).
    5860If GMP has already been installed in a standard
    59 system library, like <tt>/usr/local</tt>, then invoke <tt>configure</tt>
     61place, like <tt>/usr/local</tt>, then invoke <tt>configure</tt>
    6062above as
    6163<pre>
     
    6365</pre>
    6466and if GMP is installed somewhere else, say <tt>$HOME/sw</tt>, then
     67either
    6568<pre>
    6669   % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw
    6770</pre>
     71or, more simply,
     72<pre>
     73   % ./configure DEF_PREFIX=$HOME/sw NTL_GMP_LIP=on
     74</pre>
    6875does the job.
     76Here, <tt>DEF_PREFIX</tt> is a variable that is used
     77to specify the location of all software,
     78and it defaults to <tt>/usr/local</tt>.
    6979<a href="tour-gmp.html">This page</a> provides more
    7080details.
     81
     82<p>
     83If you want very high-performance for polynomial arithmetic
     84over <i>GF(2)</i>, you may want to consider using the <tt>gf2x</tt> library.
     85To do this, <tt>gf2x</tt> must already be installed somewhere.
     86In addition, you should invoke <tt>configure</tt>
     87with the option <tt>NTL_GF2X_LIB=on</tt>.
     88If <tt>gf2x</tt> is installed in a standard location, this is
     89all you need to do;
     90otherwise, if <tt>gf2x</tt> is installed, say, in <tt>$HOME/sw</tt>,
     91then you also need to pass the option <tt>GF2X_PREFIX=$HOME/sw</tt>.
     92<a href="tour-gf2x.html">This page</a> provides more details.
     93
     94
    7195
    7296
     
    78102The following should work:
    79103<pre>
    80    % g++ -I$HOME/sw/include -L$HOME/sw/lib foo.c -o foo -lntl -lm
     104   % g++  -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl -lm
    81105</pre>
    82106If you are using GMP, then:
    83107<pre>
    84    % g++ -I$HOME/sw/include -L$HOME/sw/lib foo.c -o foo -lntl -lgmp -lm
    85 </pre>
     108   % g++ -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl -lgmp  -lm
     109</pre>
     110If you are using GMP and <tt>gf2x</tt>, then
     111<pre>
     112   % g++  -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl -lgmp -lgf2x  -lm
     113</pre>
     114
    86115
    87116<p>
     
    145174<p>
    146175<pre>
    147    CC=gcc               # The C compiler
    148    CXX=g++              # The C++ compiler
    149    CFLAGS=-O2           # C complilation flags
    150    CXXFLAGS=$(CFLAGS)   # C++ compilation flags (by default, same as CFLAGS)
    151 
    152    PREFIX=/usr/local    # Directory in which to install NTL library components
    153 
    154    NTL_STD_CXX=on       # ISO Mode switch
    155 
    156    NTL_GMP_LIP=off      # Switch 'on' to enable the use of GMP as the primary
    157                         # long integer package
    158 
    159    GMP_PREFIX=none      # Directory in which GMP components have been installed
     176CC=gcc               # The C compiler
     177CXX=g++              # The C++ compiler
     178CFLAGS=-O2           # C complilation flags
     179CXXFLAGS=$(CFLAGS)   # C++ compilation flags (by default, same as CFLAGS)
     180
     181DEF_PREFIX=/usr/local # Default software directory
     182PREFIX=$(DEF_PREFIX) # Directory in which to install NTL library components
     183SHARED=off           # Generate a shared library (as well as static)
     184
     185NTL_STD_CXX=on       # ISO Mode switch
     186
     187NTL_GMP_LIP=off      # Switch to enable the use of GMP as primary
     188                     #   long integer package
     189
     190GMP_PREFIX=$(DEF_PREFIX) # Directory in which GMP components are installed
     191
     192NTL_GF2X_LIB=off     # Switch to enable the use of the gf2x package
     193                     #   for faster arithmetic over GF(2)[X]
     194
     195GF2X_PREFIX=$(DEF_PREFIX) # Directory in which gf2x components are installed
    160196</pre>
    161197
     
    205241</pre>
    206242Go <a href="tour-gmp.html">here</a> for complete details.
     243
     244
     245<p>
     246<li>
     247If <a href="tour-gf2x.html"><tt>gf2x</tt></a> 
     248is installed in a standard system directory, and you want to use it
     249to obtain better performance for polynomial arithemtic over <i>GF(2)</i>,
     250run:
     251<pre>
     252   % ./configure NTL_GF2X_LIB=on
     253</pre>
     254If <tt>gf2x</tt> was installed in
     255 <tt>$HOME/sw</tt>,
     256run:
     257<pre>
     258   % ./configure NTL_GF2X_LIB=on GF2X_PREFIX=$HOME/sw
     259</pre>
     260Go <a href="tour-gf2x.html">here</a> for complete details.
    207261
    208262<p>
     
    360414The file <tt>ntl.a</tt> is copied to <tt>&lt;prefix&gt;/lib/libntl.a</tt>.
    361415The files <tt>../doc/*</tt> are copied into
    362 <tt>&lt;prefix&gt;/doc/NTL</tt>.
     416<tt>&lt;prefix&gt;/share/doc/NTL</tt>.
    363417
    364418<p>
     
    386440execute
    387441<pre>
    388    g++ -I&lt;prefix&gt;/include -L&lt;prefix&gt;/lib foo.c -o foo -lntl -lm
     442   g++  -I&lt;prefix&gt;/include foo.c -o foo  -L&lt;prefix&gt;/lib -lntl -lm
    389443</pre>
    390444This compiles <tt>foo.c</tt> as a <tt>C++</tt> program
     
    393447If you built NTL using <a href="tour-gmp.html">GMP</a>, execute:
    394448<pre>
    395    g++ -I&lt;prefix&gt;/include -L&lt;prefix&gt;/lib -L&lt;gmp_prefix&gt;/lib  foo.c -lntl -lgmp -lm
     449   g++  -I&lt;prefix&gt;/include foo.c -o foo  -L&lt;prefix&gt;/lib -lntl  -L&lt;gmp_prefix&gt;/lib -lgmp -lm
    396450</pre>
    397451<p>
     
    402456flags altogether.
    403457<p>
     458Similarly, if you built NTL using <a href="tour-gf2x.html"><tt>gf2x</tt></a>,
     459you should include flags
     460<pre>
     461   -L&lt;gf2x_prefix&gt;/lib -lgf2x
     462</pre>
     463on the command line.
     464<p>
    404465This works even if you are not working in the directory
    405466in which you built NTL.
     
    408469   make foo
    409470</pre>
     471
     472<p>
     473<h2>
     474<a name="shared">
     475Building a Shared Library
     476</a>
     477</h2>
     478<p>
     479
     480
     481By default, the above installation procedure builds
     482a <i>static</i> library only.
     483Static libraries are nice because the procedures for building
     484and using them are nearly identical across various flavors
     485of Unix.
     486However, static libraries have their drawbacks, and sometimes
     487it is desirable to build a <i>shared</i> library.
     488This can be done (in theory) by simply passing <tt>SHARED=on</tt> to
     489NTL's <tt>configure</tt>.
     490
     491<p>
     492If you set <tt>SHARED=on</tt>, then behind the scenes,
     493the procedure used by the <tt>makefile</tt> changes a bit.
     494In particular, the magical GNU program <tt>libtool</tt> is used
     495to deal with all idiosyncracies of shared libraries.
     496You may need to set the
     497configuration variable <tt>LIBTOOL</tt>, to point to another version of
     498<tt>libtool</tt>. 
     499For example, on <i>Mac OSX</i>, the built-in command called <tt>libtool</tt>
     500is not
     501actually the GNU <tt>libtool</tt> program;
     502in this case, you will want to set
     503<tt>LIBTOOL=glibtool</tt>. 
     504On other systems, it may be necssary to downlaod and
     505install a fresh copy of the libtool program (which can be obtained from
     506<a href="http://www.gnu.org/software/libtool">here</a>).
     507Note that if <tt>SHARED=on</tt>, then
     508in addition to using the <tt>libtool</tt> program, the <tt>makefile</tt>
     509relies on
     510features specific to GNU make.
     511
     512<p>
     513Note that if you want to build NTL as a shared library,
     514then if you use them, GMP and <tt>gf2x</tt> must also
     515be built and installed as shared libraries.
     516Also note that to use a shared library version of NTL,
     517you may have to do something special, like set a special
     518shell variable:  the output generated by the <tt>libtool</tt>
     519program during <tt>make install</tt> should give specific
     520instructions.
     521In addition, if NTL is built as a shared library, then
     522you typically do not have to include <tt>-lgmp</tt> (if using GMP),
     523or <tt>-lgf2x</tt> (if using <tt>gf2x</tt>), or corresponding
     524<tt>-L</tt> flags, or <tt>-lm</tt> 
     525on
     526the command line when compiling programs that use NTL.
     527
     528
     529<p>
     530<h2>
     531<a name="abi">
     53232-bit and 64-bit ABIs
     533</a>
     534</h2>
     535<p>
     536
     537
     538An ABI (Application Binary Interface) defines the sizes of various
     539<tt>C</tt> data types.
     540Typically, with a 32-bit ABI, int's and long's are 32 bits,
     541while on a 64-bit ABI, int's are 32 bits and long's are 64 bits.
     542Some platforms
     543support both 64-bit and 32-bit ABI's;
     544typically in such settings, the 64-bit ABI will yield much better
     545performance, while the 32-bit ABI is available for backward compatibility.
     546In addition, the 64-bit ABI may <i>not</i> be the default:
     547if you are using <tt>gcc</tt>, you need to pass the <tt>-m64</tt>
     548flag to the compiler to get the 64-bit ABI.
     549
     550<p>
     551When compiling NTL, you may want to try running <tt>configure</tt>
     552with <tt>CFLAGS="-O2 -m64"</tt> to force a 64-bit ABI -- this
     553may yield a very marked performance improvement.
     554
     555<p>
     556If you are using NTL with either the GMP or <tt>gf2x</tt> libraries,
     557then these must be built with the same ABI as NTL.
     558The installation script for GMP will typically select the 64-bit ABI
     559automatically if it is available.
     560The installation script for <tt>gf2x</tt> may need some hints.
     561
     562<p>
     563When compiling programs that use NTL, you must also ensure that
     564the program is compiled with the same ABI as NTL.
     565Again, if you want a 64-bit ABI, then just pass the flag <tt>-m64</tt>
     566to the compiler.
     567
     568
     569
    410570
    411571
  • ntl/doc/tour.html

    re6d2f67 r26e030  
    7474
    7575<li>
     76<a href="tour-gf2x.html">
     77Using NTL with the <tt>gf2x</tt> library
     78</a>
     79
     80<li>
    7681<a href="tour-time.html">
    7782Some Performance Data
  • ntl/include/NTL/GF2X.h

    re6d2f67 r26e030  
    9999inline long operator!=(GF2 a, const GF2X& b) { return !(a == b); }
    100100inline long operator!=(long a, const GF2X& b) { return !(a == b); }
     101
     102
    101103
    102104
     
    184186
    185187void mul(GF2X& c, const GF2X& a, const GF2X& b);
     188void OldMul(GF2X& c, const GF2X& a, const GF2X& b);
    186189
    187190void mul(GF2X& x, const GF2X& a, GF2 b);
     
    471474   { GF2X x; GCD(x, a, b); NTL_OPT_RETURN(GF2X, x); }
    472475
     476void OldGCD(GF2X& d, const GF2X& a, const GF2X& b);
     477
     478
    473479void XGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b);
     480
     481void OldXGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b);
     482
    474483   
    475484void diff(GF2X& c, const GF2X& a);
     
    586595void MinPolyInternal(GF2X& h, const GF2X& x, long m);
    587596
     597void OldMinPolyInternal(GF2X& h, const GF2X& x, long m);
     598
     599
    588600
    589601struct GF2XTransMultiplier {
  • ntl/include/NTL/WordVector.h

    re6d2f67 r26e030  
    5151#endif
    5252
     53// controls release functionality
     54
     55#define NTL_RELEASE_THRESH (10000)
     56// #define NTL_RELEASE_THRESH (0)
     57
    5358
    5459class WordVector { 
     
    6974   ~WordVector(); 
    7075   void kill();
     76
     77   void release() { if (MaxLength() > NTL_RELEASE_THRESH) kill(); }
     78   // this conditinally kills the vector, if its size is excessive
    7179
    7280   void DoSetLength(long n);
  • ntl/include/NTL/ctools.h

    re6d2f67 r26e030  
    259259
    260260double _ntl_ldexp(double x, long e);
     261
     262void _ntl_abort(void);
     263/* This is the routine called by NTL to abort a program in case of error. */
     264
     265void _ntl_abort_cxx_callback(void);
     266/* This is a C++ function (implemented in tools.c) that is
     267   used to implement the callback mechanism.  The issue here
     268   is that I don't want a C function to call a C++ function
     269   via a function pointer.  This could potentially be problematic. */
     270
     271   
    261272   
    262273#if (defined(__cplusplus) && !defined(NTL_CXX_ONLY))
  • ntl/include/NTL/def_config.h

    re6d2f67 r26e030  
    125125 * This can result in significantly faster code on some platforms.
    126126 * It requires that the GMP package (version >= 3.1) has already been
    127  * installed.  You will also have to set the variables GMP_INCDIR,
    128  * GMP_LIBDIR, and GMP_LIB in the makefile (these are set automatically
     127 * installed.  You will also have to set the variables GMP_OPT_INCDIR,
     128 * GMP_OPT_LIBDIR, GMP_OPT_LIB in the makefile (these are set automatically
    129129 * by the confiuration script when you pass the flag NTL_GMP_LIP=on
    130130 * to that script.
     
    138138 *   rm *.o; make setup3; make ntl.a
    139139 * You may also have to edit the makefile to modify the variables
    140  * GMP_INCDIR, GMP_LIBDIR, and GMP_LIB.
     140 * GMP_OPT_INCDIR, GMP_OPT_LIBDIR, and GMP_OPT_LIB.
    141141 */
    142142
     
    148148 * This can result in significantly faster code on some platforms.
    149149 * It requires that the GMP package (version >= 2.0.2) has already been
    150  * installed.  You will also have to set the variables GMP_INCDIR,
    151  * GMP_LIBDIR, and GMP_LIB in the makefile (these are set automatically
     150 * installed.  You will also have to set the variables GMP_OPT_INCDIR,
     151 * GMP_OPT_LIBDIR, GMP_OPT_LIB in the makefile (these are set automatically
    152152 * by the confiuration script when you pass the flag NTL_GMP_HACK=on
    153153 * to that script.
     
    160160 *   rm lip.o; make setup3; make ntl.a
    161161 * You may also have to edit the makefile to modify the variables
    162  * GMP_INCDIR, GMP_LIBDIR, and GMP_LIB.
    163  *
    164  */
    165 
    166 #endif
    167 
     162 * GMP_OPT_INCDIR, GMP_OPT_LIBDIR, and GMP_OPT_LIB.
     163 *
     164 */
     165
     166#endif
     167
     168#if 0
     169#define NTL_GF2X_LIB
     170
     171/*
     172 * Use this flag if you want to use the gf2x library for
     173 * faster GF2X arithmetic.
     174 * This can result in significantly faster code, especially
     175 * when working with polynomials of huge degree.
     176 * You will also have to set the variables GF2X_OPT_INCDIR,
     177 * GF2X_OPT_LIBDIR, GF2X_OPT_LIB in the makefile (these are set automatically
     178 * by the confiuration script when you pass the flag NTL_GF2X_LIB=on
     179 * to that script.
     180 *
     181 * To re-build after changing this flag:
     182 *   rm GF2X.o; GF2X1.o; make ntl.a
     183 * You may also have to edit the makefile to modify the variables
     184 * GF2X_OPT_INCDIR, GF2X_OPT_LIBDIR, and GF2X_OPT_LIB.
     185 */
     186
     187#endif
    168188
    169189#if 0
  • ntl/include/NTL/mat_lzz_p.h

    re6d2f67 r26e030  
    8181// functional variant of determinant
    8282
    83 inline mat_zz_p transpose(mat_zz_p& a)
     83inline mat_zz_p transpose(const mat_zz_p& a)
    8484   { mat_zz_p x; transpose(x, a); NTL_OPT_RETURN(mat_zz_p, x); }
    8585
  • ntl/include/NTL/new.h

    re6d2f67 r26e030  
    1313#include <new>
    1414
    15 #define NTL_NEW_OP ::new //(std::nothrow)
     15#define NTL_NEW_OP new (std::nothrow)
    1616
    1717
  • ntl/include/NTL/tools.h

    re6d2f67 r26e030  
    117117
    118118
    119 
    120119NTL_OPEN_NNS
     120
     121extern void (*ErrorCallback)();
    121122
    122123struct INIT_SIZE_STRUCT { };
  • ntl/include/NTL/version.h

    re6d2f67 r26e030  
    33#define NTL_version__H
    44
    5 #define NTL_VERSION "5.4.2"
     5#define NTL_VERSION "5.5.1"
    66
    77#define NTL_MAJOR_VERSION  (5)
    8 #define NTL_MINOR_VERSION  (4)
    9 #define NTL_REVISION       (2)
     8#define NTL_MINOR_VERSION  (5)
     9#define NTL_REVISION       (1)
    1010
    1111#endif
  • ntl/src/DIRNAME

    re6d2f67 r26e030  
    1 ntl-5.4.2
     1ntl-5.5.1
  • ntl/src/DispSettings.c

    re6d2f67 r26e030  
    4343#ifdef NTL_GMP_HACK
    4444   cout << "NTL_GMP_HACK\n";
     45#endif
     46
     47#ifdef NTL_GF2X_LIB
     48   cout << "NTL_GF2X_LIB\n";
    4549#endif
    4650
  • ntl/src/DoConfig

    re6d2f67 r26e030  
    77
    88'WIZARD'  => 'on',
     9'SHARED'  => 'off',
    910
    1011);
     
    1920'ARFLAGS'     => 'ruv',
    2021'RANLIB'      => 'ranlib',
     22'LIBTOOL'     => 'libtool',
     23
    2124'LDFLAGS'     => '',
    2225'LDFLAGS_CXX' => '$(LDFLAGS)',
     
    2427'LDLIBS_CXX'  => '$(LDLIBS)',
    2528'CPPFLAGS'    => '',
    26 'PREFIX'      => '/usr/local',
     29
     30'DEF_PREFIX'  => '/usr/local',
     31
     32'PREFIX'      => '$(DEF_PREFIX)',
    2733'LIBDIR'      => '$(PREFIX)/lib',
    2834'INCLUDEDIR'  => '$(PREFIX)/include',
    29 'DOCDIR'      => '$(PREFIX)/doc',
    30 
    31 'GMP_PREFIX'  => undef,
    32 'GMP_INCDIR'  => undef,
    33 'GMP_LIBDIR'  => undef,
     35'DOCDIR'      => '$(PREFIX)/share/doc',
     36
     37'GMP_PREFIX'  => '$(DEF_PREFIX)',
     38'GMP_INCDIR'  => '$(GMP_PREFIX)/include',
     39'GMP_LIBDIR'  => '$(GMP_PREFIX)/lib',
     40
     41'GF2X_PREFIX'  => '$(DEF_PREFIX)',
     42'GF2X_INCDIR'  => '$(GF2X_PREFIX)/include',
     43'GF2X_LIBDIR'  => '$(GF2X_PREFIX)/lib',
    3444
    3545);
     
    4656'NTL_GMP_LIP'           => 'off',
    4757'NTL_GMP_HACK'          => 'off',
     58'NTL_GF2X_LIB'          => 'off',
    4859'NTL_CXX_ONLY'          => 'off',
    4960'NTL_X86_FIX'           => 'off',
     
    106117}
    107118
    108 
    109 
    110 # some special logic to set GMP_INCDIR, GMP_LIBDIR, and GMP_LIB.
    111 # note that GMP_PREFIX is not really a variable in the makefile template
     119# some special MakeVal values that are determined by SHARED
     120
     121if ($MakeFlag{'SHARED'} eq 'off') {
     122
     123   $MakeVal{'LSTAT'} = '';
     124   $MakeVal{'LSHAR'} = '# ';
     125
     126} else {
     127
     128   # sanity check for libtool
     129
     130   print("***** checking for libtool *****\n");
     131   if (system("$MakeVal{'LIBTOOL'} --version")) {
     132      die "Error: bad libtool ($MakeVal{'LIBTOOL'}) -- try glibtool?";
     133   }
     134   print("***** libtool OK *****\n\n");
     135
     136   $MakeVal{'LSTAT'} = '# ';
     137   $MakeVal{'LSHAR'} = '';
     138
     139}
     140
     141# a special MakeVal value that is determined by NTL_GMP_LIP
     142# and NTL_GMP_HACK
     143
    112144
    113145if ($ConfigFlag{'NTL_GMP_LIP'} eq 'on' || $ConfigFlag{'NTL_GMP_HACK'} eq 'on') {
    114 
    115    if (defined($MakeVal{'GMP_PREFIX'})) {
    116       if (!defined($MakeVal{'GMP_INCDIR'})) {
    117          $MakeVal{'GMP_INCDIR'} = "-I$MakeVal{'GMP_PREFIX'}/include";
    118       }
    119 
    120       if (!defined($MakeVal{'GMP_LIBDIR'})) {
    121          $MakeVal{'GMP_LIBDIR'} = "-L$MakeVal{'GMP_PREFIX'}/lib";
    122       }
    123    }
    124    else {
    125       if (!defined($MakeVal{'GMP_INCDIR'})) {
    126          $MakeVal{'GMP_INCDIR'} = '';
    127       }
    128 
    129       if (!defined($MakeVal{'GMP_LIBDIR'})) {
    130          $MakeVal{'GMP_LIBDIR'} = '';
    131       }
    132    }
    133    
    134    $MakeVal{'GMP_LIB'} = '-lgmp';
     146   $MakeVal{'GMP'} = '';
    135147}
    136148else {
    137 
    138    $MakeVal{'GMP_INCDIR'} = '';
    139    $MakeVal{'GMP_LIBDIR'} = '';
    140    $MakeVal{'GMP_LIB'} = '';
    141 
    142 }
    143 
     149   $MakeVal{'GMP'} = '# ';
     150}
     151
     152# a special MakeVal value that is determined by NTL_GF2X_LIB
     153
     154
     155if ($ConfigFlag{'NTL_GF2X_LIB'} eq 'on') {
     156   $MakeVal{'GF2X'} = '';
     157}
     158else {
     159   $MakeVal{'GF2X'} = '# ';
     160}
    144161
    145162
  • ntl/src/GF2X.c

    re6d2f67 r26e030  
    44
    55#include <NTL/new.h>
     6#include <stdio.h>
     7
     8#if (defined(NTL_WIZARD_HACK) && defined(NTL_GF2X_LIB))
     9#undef NTL_GF2X_LIB
     10#endif
     11
     12#ifdef NTL_GF2X_LIB
     13#include <gf2x.h>
     14#endif
    615
    716NTL_START_IMPL
     
    696705
    697706
     707#ifdef NTL_GF2X_LIB
     708
     709
    698710void mul(GF2X& c, const GF2X& a, const GF2X& b)
     711{
     712   long sa = a.xrep.length();
     713   long sb = b.xrep.length();
     714
     715   if (sa <= 0 || sb <= 0) {
     716      clear(c);
     717      return;
     718   }
     719 
     720   _ntl_ulong a0 = a.xrep[0];
     721   _ntl_ulong b0 = b.xrep[0];
     722
     723   if (sb == 1 && b0 == 1) {
     724      c = a;
     725      return;
     726   }
     727
     728   if (sa == 1 && a0 == 1) {
     729      c = b;
     730      return;
     731   }
     732
     733   if (&a == &b) {
     734      sqr(c, a);
     735      return;
     736   }
     737
     738   if (sa == 1 && sb == 1) {
     739      // special case...
     740      _ntl_ulong v[2];
     741      if (!(a0 >> NTL_BITS_PER_LONG/2))
     742         mul_half(v, b0, a0);
     743      else if (!(b0 >> NTL_BITS_PER_LONG/2))
     744         mul_half(v, a0, b0);
     745      else
     746         mul1(v, a0, b0);
     747
     748      if (v[1]) {
     749         c.xrep.SetLength(2);
     750         _ntl_ulong *cp = &c.xrep[0];
     751         cp[0] = v[0];
     752         cp[1] = v[1];
     753      }
     754      else {
     755         c.xrep.SetLength(1);
     756         _ntl_ulong *cp = &c.xrep[0];
     757         cp[0] = v[0];
     758      }
     759      return;
     760   }
     761
     762   if (sa == 2 && sb == 2) {
     763      // special case...
     764      _ntl_ulong v[4];
     765      mul2(v, &a.xrep[0], &b.xrep[0]);
     766      if (v[3]) {
     767         c.xrep.SetLength(4);
     768         _ntl_ulong *cp = &c.xrep[0];
     769         cp[0] = v[0];
     770         cp[1] = v[1];
     771         cp[2] = v[2];
     772         cp[3] = v[3];
     773      }
     774      else {
     775         c.xrep.SetLength(3);
     776         _ntl_ulong *cp = &c.xrep[0];
     777         cp[0] = v[0];
     778         cp[1] = v[1];
     779         cp[2] = v[2];
     780      }
     781      return;
     782   }
     783
     784   // another special case:  one of the two inputs
     785   // has length 1 (or less).
     786
     787   if (sa == 1) {
     788      c.xrep.SetLength(sb + 1);
     789      _ntl_ulong *cp = c.xrep.elts();
     790      const _ntl_ulong *bp = b.xrep.elts();
     791
     792      if (a0 >> (NTL_BITS_PER_LONG-NTL_BB_MUL1_BITS+1))
     793         Mul1(cp, bp, sb, a0);
     794      else
     795         Mul1_short(cp, bp, sb, a0);
     796
     797
     798      c.normalize();
     799      return;
     800   }
     801
     802   if (sb == 1) {
     803      c.xrep.SetLength(sa + 1);
     804      _ntl_ulong *cp = c.xrep.elts();
     805      const _ntl_ulong *ap = a.xrep.elts();
     806
     807
     808      if (b0 >> (NTL_BITS_PER_LONG-NTL_BB_MUL1_BITS+1))
     809         Mul1(cp, ap, sa, b0);
     810      else
     811         Mul1_short(cp, ap, sa, b0);
     812
     813      c.normalize();
     814      return;
     815   }
     816
     817   // finally: the general case
     818
     819
     820   WordVector mem;
     821
     822   const _ntl_ulong *ap = a.xrep.elts(), *bp = b.xrep.elts();
     823   _ntl_ulong *cp;
     824
     825
     826   long sc = sa + sb;
     827   long in_mem = 0;
     828
     829   if (&a == &c || &b == &c) {
     830      mem.SetLength(sc);
     831      cp = mem.elts();
     832      in_mem = 1;
     833   }
     834   else {
     835      c.xrep.SetLength(sc);
     836      cp = c.xrep.elts();
     837   }
     838
     839   gf2x_mul(cp, ap, sa, bp, sb);
     840
     841   if (in_mem) {
     842      c.xrep = mem;
     843   }
     844
     845   c.normalize();
     846   mem.release();
     847}
     848#else
     849void OldMul(GF2X& c, const GF2X& a, const GF2X& b)
     850{
     851   mul(c, a, b);
     852}
     853#endif
     854
     855
     856
     857#ifdef NTL_GF2X_LIB
     858void OldMul(GF2X& c, const GF2X& a, const GF2X& b)
     859#else
     860void mul(GF2X& c, const GF2X& a, const GF2X& b)
     861#endif
    699862{
    700863   long sa = a.xrep.length();
     
    11021265
    11031266   c.normalize();
    1104 }
    1105 
     1267
     1268   mem.release();
     1269   stk.release();
     1270   vec.release();
     1271}
    11061272
    11071273
  • ntl/src/GF2X1.c

    re6d2f67 r26e030  
    66#include <NTL/new.h>
    77
     8#if (defined(NTL_WIZARD_HACK) && defined(NTL_GF2X_LIB))
     9#undef NTL_GF2X_LIB
     10#endif
     11
     12
     13// some crossover points...choice depends
     14// if we are using the gf2x lib or not
     15
     16#ifdef NTL_GF2X_LIB
     17
     18#define NTL_GF2X_GCD_CROSSOVER (400L*NTL_BITS_PER_LONG)
     19#define NTL_GF2X_HalfGCD_CROSSOVER (6L*NTL_BITS_PER_LONG)
     20#define NTL_GF2X_BERMASS_CROSSOVER (200L*NTL_BITS_PER_LONG)
     21
     22#else
     23
     24#define NTL_GF2X_GCD_CROSSOVER (900L*NTL_BITS_PER_LONG)
     25#define NTL_GF2X_HalfGCD_CROSSOVER (6L*NTL_BITS_PER_LONG)
     26#define NTL_GF2X_BERMASS_CROSSOVER (450L*NTL_BITS_PER_LONG)
     27
     28#endif
     29
     30
    831NTL_START_IMPL
    932
     
    2346
    2447~GF2XRegisterType()
    25 { GF2XRegisterTop--; }
     48{ xrep->xrep.release(); 
     49  GF2XRegisterTop--; }
    2650
    2751operator GF2X& () { return *xrep; }
     
    134158   }
    135159   r.normalize();
     160
     161   GF2X_rembuf.release();
     162   for (i = 0; i <= min(dq, NTL_BITS_PER_LONG-1); i++) {
     163      WordVector& st = stab[((_ntl_ulong)(posb+i))%NTL_BITS_PER_LONG].xrep;
     164      st.release();
     165   }
    136166}
    137167
     
    220250   }
    221251   r.normalize();
     252
     253   GF2X_rembuf.release();
     254   for (i = 0; i <= min(da-db, NTL_BITS_PER_LONG-1); i++) {
     255      WordVector& st = stab[((_ntl_ulong)(posb+i))%NTL_BITS_PER_LONG].xrep;
     256      st.release();
     257   }
    222258}
    223259
     
    912948   long bdiff3 = (n-k3) - wdiff3*NTL_BITS_PER_LONG;
    913949
    914    static GF2X r;
     950   GF2XRegister(r);
    915951   r = a;
    916952
     
    13621398      r.normalize();
    13631399   }
     1400
     1401   GF2X_rembuf.release();
    13641402}
    13651403
     
    15181556      r.normalize();
    15191557   }
     1558
     1559   GF2X_rembuf.release();
    15201560}
    15211561
     
    16491689      }
    16501690   }
     1691
     1692   GF2X_rembuf.release();
    16511693}
    16521694
     
    20652107
    20662108
    2067 void GCD(GF2X& d, const GF2X& a, const GF2X& b)
     2109void OldGCD(GF2X& d, const GF2X& a, const GF2X& b)
    20682110{
    20692111   long sa = a.xrep.length();
     
    22902332
    22912333
    2292 void XGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b)
     2334void OldXGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b)
    22932335{
    22942336   long sa = a.xrep.length();
     
    23472389   long sf = f.xrep.length();
    23482390
    2349    if (sa >= 10 && 2*sf > 3*sa) {
     2391   if ((sa >= 10 && 2*sf > 3*sa) ||
     2392       sf > NTL_GF2X_GCD_CROSSOVER/NTL_BITS_PER_LONG) {
    23502393      GF2XRegister(t);
    23512394
     
    28632906
    28642907
    2865 void MinPolyInternal(GF2X& h, const GF2X& x, long m)
     2908void OldMinPolyInternal(GF2X& h, const GF2X& x, long m)
    28662909{
    28672910   GF2X a, b, r, s;
     
    32183261
    32193262
     3263
     3264// New versions of GCD, XGCD, and MinPolyInternal
     3265// and support routines
     3266
     3267class _NTL_GF2XMatrix {
     3268private:
     3269
     3270   _NTL_GF2XMatrix(const _NTL_GF2XMatrix&);  // disable
     3271   GF2X elts[2][2];
     3272
     3273public:
     3274
     3275   _NTL_GF2XMatrix() { }
     3276   ~_NTL_GF2XMatrix() { }
     3277
     3278   void operator=(const _NTL_GF2XMatrix&);
     3279   GF2X& operator() (long i, long j) { return elts[i][j]; }
     3280   const GF2X& operator() (long i, long j) const { return elts[i][j]; }
     3281};
     3282
     3283
     3284void _NTL_GF2XMatrix::operator=(const _NTL_GF2XMatrix& M)
     3285{
     3286   elts[0][0] = M.elts[0][0];
     3287   elts[0][1] = M.elts[0][1];
     3288   elts[1][0] = M.elts[1][0];
     3289   elts[1][1] = M.elts[1][1];
     3290}
     3291
     3292
     3293static
     3294void mul(GF2X& U, GF2X& V, const _NTL_GF2XMatrix& M)
     3295// (U, V)^T = M*(U, V)^T
     3296{
     3297   GF2X t1, t2, t3;
     3298
     3299   mul(t1, M(0,0), U);
     3300   mul(t2, M(0,1), V);
     3301   add(t3, t1, t2);
     3302   mul(t1, M(1,0), U);
     3303   mul(t2, M(1,1), V);
     3304   add(V, t1, t2);
     3305   U = t3;
     3306}
     3307
     3308
     3309static
     3310void mul(_NTL_GF2XMatrix& A, _NTL_GF2XMatrix& B, _NTL_GF2XMatrix& C)
     3311// A = B*C, B and C are destroyed
     3312{
     3313   GF2X t1, t2;
     3314
     3315   mul(t1, B(0,0), C(0,0));
     3316   mul(t2, B(0,1), C(1,0));
     3317   add(A(0,0), t1, t2);
     3318
     3319   mul(t1, B(1,0), C(0,0));
     3320   mul(t2, B(1,1), C(1,0));
     3321   add(A(1,0), t1, t2);
     3322
     3323   mul(t1, B(0,0), C(0,1));
     3324   mul(t2, B(0,1), C(1,1));
     3325   add(A(0,1), t1, t2);
     3326
     3327   mul(t1, B(1,0), C(0,1));
     3328   mul(t2, B(1,1), C(1,1));
     3329   add(A(1,1), t1, t2);
     3330
     3331   long i, j;
     3332   for (i = 0; i < 2; i++) {
     3333      for (j = 0; j < 2; j++) {
     3334          B(i,j).kill();
     3335          C(i,j).kill();
     3336      }
     3337   }
     3338}
     3339
     3340static
     3341void IterHalfGCD(_NTL_GF2XMatrix& M_out, GF2X& U, GF2X& V, long d_red)
     3342{
     3343   M_out(0,0).SetMaxLength(d_red);
     3344   M_out(0,1).SetMaxLength(d_red);
     3345   M_out(1,0).SetMaxLength(d_red);
     3346   M_out(1,1).SetMaxLength(d_red);
     3347
     3348   set(M_out(0,0));   clear(M_out(0,1));
     3349   clear(M_out(1,0)); set(M_out(1,1));
     3350
     3351   long goal = deg(U) - d_red;
     3352
     3353   if (deg(V) <= goal)
     3354      return;
     3355
     3356   GF2X Q, t(INIT_SIZE, d_red);
     3357
     3358   while (deg(V) > goal) {
     3359      DivRem(Q, U, U, V);
     3360      swap(U, V);
     3361
     3362      mul(t, Q, M_out(1,0));
     3363      sub(t, M_out(0,0), t);
     3364      M_out(0,0) = M_out(1,0);
     3365      M_out(1,0) = t;
     3366
     3367      mul(t, Q, M_out(1,1));
     3368      sub(t, M_out(0,1), t);
     3369      M_out(0,1) = M_out(1,1);
     3370      M_out(1,1) = t;
     3371   }
     3372}
     3373
     3374
     3375
     3376static
     3377void HalfGCD(_NTL_GF2XMatrix& M_out, const GF2X& U, const GF2X& V, long d_red)
     3378{
     3379   if (IsZero(V) || deg(V) <= deg(U) - d_red) {
     3380      set(M_out(0,0));   clear(M_out(0,1));
     3381      clear(M_out(1,0)); set(M_out(1,1));
     3382
     3383      return;
     3384   }
     3385
     3386
     3387   long n = deg(U) - 2*d_red + 2;
     3388   if (n < 0) n = 0;
     3389
     3390   GF2X U1, V1;
     3391
     3392   RightShift(U1, U, n);
     3393   RightShift(V1, V, n);
     3394
     3395   if (d_red <= NTL_GF2X_HalfGCD_CROSSOVER) {
     3396      IterHalfGCD(M_out, U1, V1, d_red);
     3397      return;
     3398   }
     3399
     3400   long d1 = (d_red + 1)/2;
     3401   if (d1 < 1) d1 = 1;
     3402   if (d1 >= d_red) d1 = d_red - 1;
     3403
     3404   _NTL_GF2XMatrix M1;
     3405
     3406   HalfGCD(M1, U1, V1, d1);
     3407   mul(U1, V1, M1);
     3408
     3409
     3410   long d2 = deg(V1) - deg(U) + n + d_red;
     3411
     3412   if (IsZero(V1) || d2 <= 0) {
     3413      M_out = M1;
     3414      return;
     3415   }
     3416
     3417
     3418   GF2X Q;
     3419   _NTL_GF2XMatrix M2;
     3420
     3421   DivRem(Q, U1, U1, V1);
     3422   swap(U1, V1);
     3423
     3424   HalfGCD(M2, U1, V1, d2);
     3425
     3426   GF2X t(INIT_SIZE, deg(M1(1,1))+deg(Q)+1);
     3427
     3428   mul(t, Q, M1(1,0));
     3429   sub(t, M1(0,0), t);
     3430   swap(M1(0,0), M1(1,0));
     3431   swap(M1(1,0), t);
     3432
     3433   t.kill();
     3434
     3435   t.SetMaxLength(deg(M1(1,1))+deg(Q)+1);
     3436
     3437   mul(t, Q, M1(1,1));
     3438   sub(t, M1(0,1), t);
     3439   swap(M1(0,1), M1(1,1));
     3440   swap(M1(1,1), t);
     3441
     3442   t.kill();
     3443
     3444   mul(M_out, M2, M1);
     3445}
     3446
     3447static
     3448void HalfGCD(GF2X& U, GF2X& V)
     3449{
     3450   long d_red = (deg(U)+1)/2;
     3451
     3452   if (IsZero(V) || deg(V) <= deg(U) - d_red) {
     3453      return;
     3454   }
     3455
     3456   long du = deg(U);
     3457
     3458
     3459   long d1 = (d_red + 1)/2;
     3460   if (d1 < 1) d1 = 1;
     3461   if (d1 >= d_red) d1 = d_red - 1;
     3462
     3463   _NTL_GF2XMatrix M1;
     3464
     3465   HalfGCD(M1, U, V, d1);
     3466   mul(U, V, M1);
     3467
     3468   long d2 = deg(V) - du + d_red;
     3469
     3470   if (IsZero(V) || d2 <= 0) {
     3471      return;
     3472   }
     3473
     3474   M1(0,0).kill();
     3475   M1(0,1).kill();
     3476   M1(1,0).kill();
     3477   M1(1,1).kill();
     3478
     3479
     3480   GF2X Q;
     3481
     3482   DivRem(Q, U, U, V);
     3483   swap(U, V);
     3484
     3485   HalfGCD(M1, U, V, d2);
     3486
     3487   mul(U, V, M1);
     3488}
     3489
     3490
     3491void GCD(GF2X& d, const GF2X& u, const GF2X& v)
     3492{
     3493   long su = u.xrep.length();
     3494   long sv = v.xrep.length();
     3495
     3496   if (su <= NTL_GF2X_GCD_CROSSOVER/NTL_BITS_PER_LONG &&
     3497       sv <= NTL_GF2X_GCD_CROSSOVER/NTL_BITS_PER_LONG) {
     3498      OldGCD(d, u, v);
     3499      return;
     3500   }
     3501   
     3502   GF2X u1, v1;
     3503
     3504   u1 = u;
     3505   v1 = v;
     3506
     3507   long du1 = deg(u1);
     3508   long dv1 = deg(v1);
     3509
     3510   if (du1 == dv1) {
     3511      if (IsZero(u1)) {
     3512         clear(d);
     3513         return;
     3514      }
     3515
     3516      rem(v1, v1, u1);
     3517   }
     3518   else if (du1 < dv1) {
     3519      swap(u1, v1);
     3520      du1 = dv1;
     3521   }
     3522
     3523   // deg(u1) > deg(v1)
     3524
     3525   while (du1 >= NTL_GF2X_GCD_CROSSOVER && !IsZero(v1)) {
     3526      HalfGCD(u1, v1);
     3527
     3528      if (!IsZero(v1)) {
     3529         rem(u1, u1, v1);
     3530         swap(u1, v1);
     3531      }
     3532
     3533      du1 = deg(u1);
     3534   }
     3535
     3536   OldGCD(d, u1, v1);
     3537}
     3538
     3539static
     3540void XHalfGCD(_NTL_GF2XMatrix& M_out, GF2X& U, GF2X& V, long d_red)
     3541{
     3542   if (IsZero(V) || deg(V) <= deg(U) - d_red) {
     3543      set(M_out(0,0));   clear(M_out(0,1));
     3544      clear(M_out(1,0)); set(M_out(1,1));
     3545
     3546      return;
     3547   }
     3548
     3549   long du = deg(U);
     3550
     3551   if (d_red <= NTL_GF2X_HalfGCD_CROSSOVER) {
     3552      IterHalfGCD(M_out, U, V, d_red);
     3553      return;
     3554   }
     3555
     3556   long d1 = (d_red + 1)/2;
     3557   if (d1 < 1) d1 = 1;
     3558   if (d1 >= d_red) d1 = d_red - 1;
     3559
     3560   _NTL_GF2XMatrix M1;
     3561
     3562   HalfGCD(M1, U, V, d1);
     3563   mul(U, V, M1);
     3564
     3565   long d2 = deg(V) - du + d_red;
     3566
     3567   if (IsZero(V) || d2 <= 0) {
     3568      M_out = M1;
     3569      return;
     3570   }
     3571
     3572
     3573   GF2X Q;
     3574   _NTL_GF2XMatrix M2;
     3575
     3576   DivRem(Q, U, U, V);
     3577   swap(U, V);
     3578
     3579   XHalfGCD(M2, U, V, d2);
     3580
     3581
     3582   GF2X t(INIT_SIZE, deg(M1(1,1))+deg(Q)+1);
     3583
     3584   mul(t, Q, M1(1,0));
     3585   sub(t, M1(0,0), t);
     3586   swap(M1(0,0), M1(1,0));
     3587   swap(M1(1,0), t);
     3588
     3589   t.kill();
     3590
     3591   t.SetMaxLength(deg(M1(1,1))+deg(Q)+1);
     3592
     3593   mul(t, Q, M1(1,1));
     3594   sub(t, M1(0,1), t);
     3595   swap(M1(0,1), M1(1,1));
     3596   swap(M1(1,1), t);
     3597
     3598   t.kill();
     3599
     3600   mul(M_out, M2, M1);
     3601}
     3602
     3603
     3604
     3605
     3606void XGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b)
     3607{
     3608   // GF2 w;
     3609
     3610   long sa = a.xrep.length();
     3611   long sb = b.xrep.length();
     3612
     3613   if (sa <= NTL_GF2X_GCD_CROSSOVER/NTL_BITS_PER_LONG &&
     3614       sb <= NTL_GF2X_GCD_CROSSOVER/NTL_BITS_PER_LONG) {
     3615      OldXGCD(d, s, t, a, b);
     3616      return;
     3617   }
     3618
     3619   GF2X U, V, Q;
     3620
     3621   U = a;
     3622   V = b;
     3623
     3624   long flag = 0;
     3625
     3626   if (deg(U) == deg(V)) {
     3627      DivRem(Q, U, U, V);
     3628      swap(U, V);
     3629      flag = 1;
     3630   }
     3631   else if (deg(U) < deg(V)) {
     3632      swap(U, V);
     3633      flag = 2;
     3634   }
     3635
     3636   _NTL_GF2XMatrix M;
     3637
     3638   XHalfGCD(M, U, V, deg(U)+1);
     3639
     3640   d = U;
     3641
     3642
     3643   if (flag == 0) {
     3644      s = M(0,0);
     3645      t = M(0,1);
     3646   }
     3647   else if (flag == 1) {
     3648      s = M(0,1);
     3649      mul(t, Q, M(0,1));
     3650      sub(t, M(0,0), t);
     3651   }
     3652   else {  /* flag == 2 */
     3653      s = M(0,1);
     3654      t = M(0,0);
     3655   }
     3656
     3657   // normalize
     3658
     3659   // inv(w, LeadCoeff(d));
     3660   // mul(d, d, w);
     3661   // mul(s, s, w);
     3662   // mul(t, t, w);
     3663}
     3664
     3665
     3666void MinPolyInternal(GF2X& h, const GF2X& x, long m)
     3667
     3668   if (m < NTL_GF2X_BERMASS_CROSSOVER) {
     3669      OldMinPolyInternal(h, x, m);
     3670      return;
     3671   }
     3672
     3673   GF2X a, b;
     3674   _NTL_GF2XMatrix M;
     3675     
     3676   SetCoeff(b, 2*m);
     3677   CopyReverse(a, x, 2*m-1);
     3678   HalfGCD(M, b, a, m+1);
     3679
     3680   h = M(1,1);
     3681}
     3682
     3683
     3684
    32203685NTL_END_IMPL
  • ntl/src/InitSettings.c

    re6d2f67 r26e030  
    5151#else
    5252   cout << "NTL_GMP_HACK=0\n";
     53#endif
     54
     55#ifdef NTL_GF2X_LIB
     56   cout << "NTL_GF2X_LIB=1\n";
     57#else
     58   cout << "NTL_GF2X_LIB=0\n";
    5359#endif
    5460
  • ntl/src/MakeDesc.c

    re6d2f67 r26e030  
    794794   }
    795795
     796   /*
     797    * check that ints are bigger than chars.
     798    */
     799
     800   if (bpi <= CHAR_BIT) {
     801      fprintf(stderr, "BAD NEWS: int type must be longer than char type.\n");
     802      return 1;
     803   }
    796804
    797805
  • ntl/src/QuickTest.c

    re6d2f67 r26e030  
    22#include <NTL/ZZ_pX.h>
    33#include <NTL/lzz_pX.h>
     4#include <NTL/GF2X.h>
    45
    56#include <NTL/version.h>
     
    3637
    3738
     39int GF2X_test()
     40{
     41   GF2X a, b, c, c1;
     42
     43   long n;
     44
     45#ifdef NTL_GF2X_LIB
     46   for (n = 32; n <= (1L << 18); n = n << 1) {
     47      random(a, n);
     48      random(b, n);
     49      OldMul(c, a, b);
     50      mul(c1, a, b);
     51      if (c1 != c) return 1;
     52   }
     53#endif
     54
     55   return 0;
     56}
     57
     58void GF2X_time()
     59{
     60   long n = 1000000L;
     61   long iter;
     62
     63   GF2X a, b, c;
     64
     65   double t;
     66   long i;
     67
     68   random(a, n);
     69   random(b, n);
     70
     71   mul(c, a, b);
     72
     73   iter = 0;
     74   do {
     75      iter = iter ? (2*iter) : 1;
     76      t = GetTime();
     77      for (i = 0; i < iter; i++)
     78         mul(c, a, b);
     79      t = GetTime() - t;
     80   } while (t < 0.5);
     81
     82   cerr << "time to multiply polynomials over GF(2) \n   of degree < 1000000: "
     83        << (t/iter) << "s\n";
     84
     85#ifdef NTL_GF2X_LIB
     86   OldMul(c, a, b);
     87
     88   iter = 0;
     89   do {
     90      iter = iter ? (2*iter) : 1;
     91      t = GetTime();
     92      for (i = 0; i < iter; i++)
     93         OldMul(c, a, b);
     94      t = GetTime() - t;
     95   } while (t < 0.5);
     96
     97   cerr << "   **** using old code: "  << (t/iter) << "s\n";
     98#endif
     99
     100}
    38101
    39102
     
    70133   cerr << "NTL_GMP_HACK\n";
    71134#endif
     135
     136#ifdef NTL_GF2X_LIB
     137   cerr << "NTL_GF2X_LIB\n";
     138#endif
     139
    72140
    73141#ifdef NTL_LONG_LONG_TYPE
     
    172240
    173241   if (_ntl_gmp_hack)
    174       cerr << "using GMP hack\n";
     242      cerr << "using GMP hack\n\n";
     243
     244   cerr << "running tests...";
    175245
    176246   long n, k;
     
    242312   }
    243313
    244    cerr << "test is OK\n";
     314   // Test gf2x code....
     315
     316   if (GF2X_test()) {
     317      cerr << "GF2X test failed!\n";
     318      return 1;
     319   }
     320   
     321
     322   cerr << "OK\n";
    245323
    246324   ZZ x1, x2, x3, x4;
     
    369447   cerr << "\n";
    370448
     449   GF2X_time();
     450
    371451   return 0;
    372452}
  • ntl/src/RemoveProg

    re6d2f67 r26e030  
    44   rm -f $i
    55   rm -f $i.exe
     6   rm -f .libs/$i
     7   rm -f .libs/$i.exe
    68done
     9 
     10exit 0
    711
  • ntl/src/TestScript

    re6d2f67 r26e030  
    5050./MoreFacTest < MoreFacTestIn
    5151sh RemoveProg MoreFacTest
     52
     53echo
     54echo "---------------------------------"
     55echo "making GF2XTest"
     56make GF2XTest
     57echo "running GF2XTest"
     58./GF2XTest
     59sh RemoveProg GF2XTest
    5260
    5361echo
  • ntl/src/WINDIR

    re6d2f67 r26e030  
    1 WinNTL-5_4_2
     1WinNTL-5_5_1
  • ntl/src/Wizard

    re6d2f67 r26e030  
    2121fi
    2222
    23 rm -r small
     23rm -rf small
    2424
    2525mkdir small
     
    8989
    9090
    91 
    9291cd small/src
    9392perl WizardAux
  • ntl/src/WizardAux

    re6d2f67 r26e030  
    9191'NTL_GF2X_NOINLINE'    => 0,
    9292
    93 'WIZARD_HACK'          => '#define NTL_OLD_ZZ_pX_MUL',
     93'WIZARD_HACK'          => '#define NTL_WIZARD_HACK',
    9494
    9595);
  • ntl/src/ZZX.c

    re6d2f67 r26e030  
    115115
    116116   m = deg(x);
     117
     118   if (i > m && IsZero(a)) return;
    117119
    118120   if (i > m) {
  • ntl/src/ZZ_pEX.c

    re6d2f67 r26e030  
    104104
    105105   m = deg(x);
     106
     107   if (i > m && IsZero(a)) return;
    106108
    107109   if (i > m) {
     
    143145
    144146   m = deg(x);
     147
     148   if (i > m && IsZero(a)) return;
    145149
    146150   if (i > m) {
  • ntl/src/ZZ_pX.c

    re6d2f67 r26e030  
    88
    99
    10 #ifndef NTL_OLD_ZZ_pX_MUL
     10#ifndef NTL_WIZARD_HACK
    1111
    1212#include <NTL/ZZX.h>
     
    9595
    9696   m = deg(x);
     97
     98   if (i > m && IsZero(a)) return;
    9799
    98100   if (i > m) {
     
    419421
    420422
    421 #ifndef NTL_OLD_ZZ_pX_MUL
     423#ifndef NTL_WIZARD_HACK
    422424
    423425// These crossovers are tuned for a Pentium, but hopefully
  • ntl/src/c_lip_impl.h

    re6d2f67 r26e030  
    2323   fprintf(stderr,"fatal error:\n   %s\nexit...\n",c);
    2424   fflush(stderr);
    25    abort();
     25   _ntl_abort();
    2626}
    2727
     
    3535#define NTL_GMP_SQRT_CROSS (2)
    3636#define NTL_GMP_GCD_CROSS (1)
    37 #define NTL_GMP_XGCD_CROSS (1)
    38 #define NTL_GMP_INVMOD_CROSS (1)
     37#define NTL_GMP_XGCD_CROSS (4)
     38#define NTL_GMP_INVMOD_CROSS (2)
    3939
    4040#ifdef NTL_GMP_HACK
     
    48194819                         */
    48204820
    4821                         while (_ntl_zsign(v) < 0)
    4822                                 _ntl_zadd(v, nin, &v);
    4823 
    4824                         while (_ntl_zcompare(v, nin) >= 0)
    4825                                 _ntl_zsub(v, nin, &v);
    4826 
     4821                        _ntl_zmod(v, nin, &v);
    48274822                        _ntl_zcopy(v, invv);
    48284823                        return 0;
     
    48894884   if (_ntl_gmp_hack &&
    48904885       a[0] >= NTL_GMP_XGCD_CROSS && b[0] >= NTL_GMP_XGCD_CROSS) {
     4886
     4887      static _ntl_verylong xa1 = 0, xb1 = 0, d1 = 0, b_red = 0;
     4888      static _ntl_verylong tmp1 = 0, tmp2 = 0, tmp3 = 0;
     4889
    48914890      GT_INIT
     4891
     4892     
    48924893
    48934894      lip_to_mpz(aa, gt_1);
    48944895      lip_to_mpz(bb, gt_2);
    48954896      mpz_gcdext(gt_3, gt_4, gt_5, gt_1, gt_2);
    4896       mpz_to_lip(&a, gt_3);
    4897       mpz_to_lip(&b, gt_4);
    4898       mpz_to_lip(&modcon, gt_5);
    4899       _ntl_zcopy(a, d);
    4900       _ntl_zcopy(b, xa);
    4901       _ntl_zcopy(modcon, xb);
     4897      mpz_to_lip(&d1, gt_3);
     4898      mpz_to_lip(&xa1, gt_4);
     4899      mpz_to_lip(&xb1, gt_5);
     4900
     4901      /* normalize...this ensures results agree with
     4902         classical Euclid...not very efficient... */
     4903
     4904      if (_ntl_zcompare(a, b) >= 0) {
     4905         _ntl_zdiv(a, d1, &a, 0);
     4906         _ntl_zdiv(b, d1, &b, 0);
     4907         _ntl_zdiv(xa1, b, &tmp1, &xa1);
     4908         _ntl_zlshift(xa1, 1, &tmp2);
     4909         if (anegative) _ntl_zsadd(tmp2, 1, &tmp2);
     4910         if (_ntl_zcompare(tmp2, b) > 0) {
     4911            _ntl_zsub(xa1, b, &xa1);
     4912            _ntl_zsadd(tmp1, 1, &tmp1);
     4913         }
     4914         _ntl_zmul(tmp1, a, &tmp2);
     4915         if (anegative != bnegative)
     4916            _ntl_zsub(xb1, tmp2, &xb1);
     4917         else
     4918            _ntl_zadd(xb1, tmp2, &xb1);
     4919      }
     4920      else {
     4921         _ntl_zdiv(a, d1, &a, 0);
     4922         _ntl_zdiv(b, d1, &b, 0);
     4923         _ntl_zdiv(xb1, a, &tmp1, &xb1);
     4924         _ntl_zlshift(xb1, 1, &tmp2);
     4925         if (bnegative) _ntl_zsadd(tmp2, 1, &tmp2);
     4926         if (_ntl_zcompare(tmp2, a) > 0) {
     4927            _ntl_zsub(xb1, a, &xb1);
     4928            _ntl_zsadd(tmp1, 1, &tmp1);
     4929         }
     4930         _ntl_zmul(tmp1, b, &tmp2);
     4931         if (anegative != bnegative)
     4932            _ntl_zsub(xa1, tmp2, &xa1);
     4933         else
     4934            _ntl_zadd(xa1, tmp2, &xa1);
     4935      }
     4936
     4937
     4938      /* end normalize */
     4939
     4940      _ntl_zcopy(d1, d);
     4941      _ntl_zcopy(xa1, xa);
     4942      _ntl_zcopy(xb1, xb);
    49024943      return;
    49034944   }
  • ntl/src/cfile

    re6d2f67 r26e030  
    125125 * This can result in significantly faster code on some platforms.
    126126 * It requires that the GMP package (version >= 3.1) has already been
    127  * installed.  You will also have to set the variables GMP_INCDIR,
    128  * GMP_LIBDIR, and GMP_LIB in the makefile (these are set automatically
     127 * installed.  You will also have to set the variables GMP_OPT_INCDIR,
     128 * GMP_OPT_LIBDIR, GMP_OPT_LIB in the makefile (these are set automatically
    129129 * by the confiuration script when you pass the flag NTL_GMP_LIP=on
    130130 * to that script.
     
    138138 *   rm *.o; make setup3; make ntl.a
    139139 * You may also have to edit the makefile to modify the variables
    140  * GMP_INCDIR, GMP_LIBDIR, and GMP_LIB.
     140 * GMP_OPT_INCDIR, GMP_OPT_LIBDIR, and GMP_OPT_LIB.
    141141 */
    142142
     
    148148 * This can result in significantly faster code on some platforms.
    149149 * It requires that the GMP package (version >= 2.0.2) has already been
    150  * installed.  You will also have to set the variables GMP_INCDIR,
    151  * GMP_LIBDIR, and GMP_LIB in the makefile (these are set automatically
     150 * installed.  You will also have to set the variables GMP_OPT_INCDIR,
     151 * GMP_OPT_LIBDIR, GMP_OPT_LIB in the makefile (these are set automatically
    152152 * by the confiuration script when you pass the flag NTL_GMP_HACK=on
    153153 * to that script.
     
    160160 *   rm lip.o; make setup3; make ntl.a
    161161 * You may also have to edit the makefile to modify the variables
    162  * GMP_INCDIR, GMP_LIBDIR, and GMP_LIB.
    163  *
    164  */
    165 
    166 #endif
    167 
     162 * GMP_OPT_INCDIR, GMP_OPT_LIBDIR, and GMP_OPT_LIB.
     163 *
     164 */
     165
     166#endif
     167
     168#if @{NTL_GF2X_LIB}
     169#define NTL_GF2X_LIB
     170
     171/*
     172 * Use this flag if you want to use the gf2x library for
     173 * faster GF2X arithmetic.
     174 * This can result in significantly faster code, especially
     175 * when working with polynomials of huge degree.
     176 * You will also have to set the variables GF2X_OPT_INCDIR,
     177 * GF2X_OPT_LIBDIR, GF2X_OPT_LIB in the makefile (these are set automatically
     178 * by the confiuration script when you pass the flag NTL_GF2X_LIB=on
     179 * to that script.
     180 *
     181 * To re-build after changing this flag:
     182 *   rm GF2X.o; GF2X1.o; make ntl.a
     183 * You may also have to edit the makefile to modify the variables
     184 * GF2X_OPT_INCDIR, GF2X_OPT_LIBDIR, and GF2X_OPT_LIB.
     185 */
     186
     187#endif
    168188
    169189#if @{FLAG_LONG_LONG_TYPE}
  • ntl/src/ctools.c

    re6d2f67 r26e030  
    7878
    7979
     80void _ntl_abort(void)
     81{
     82   _ntl_abort_cxx_callback();
     83   abort();
     84}
    8085
     86
     87
  • ntl/src/def_makefile

    re6d2f67 r26e030  
    2424# Some useful flags:
    2525#   -O2   --  recommended level of optimization
     26#   -m64  --  needed to get 64-bit longs on some platforms
    2627#   -g    --  debugging
    2728#   -mcpu=v8  --  needed with gcc/g++ to get the full instruction set
     
    5152
    5253LDFLAGS=
    53 # arguments for linker for C++ programs
     54# arguments for linker for C programs
    5455
    5556LDFLAGS_CXX=$(LDFLAGS)
     57# libraries for linking C++ programs
     58
     59LDLIBS=-lm
    5660# libraries for linking C programs
    57 
    58 LDLIBS=-lm
    59 # libraries for linking C++ programs
    6061
    6162LDLIBS_CXX=$(LDLIBS)
     
    6566# arguments for the C preprocessor
    6667
    67 PREFIX=/usr/local
     68LIBTOOL=libtool
     69# libtool command
     70
     71DEF_PREFIX=/usr/local
     72
     73PREFIX=$(DEF_PREFIX)
    6874LIBDIR=$(PREFIX)/lib
    6975INCLUDEDIR=$(PREFIX)/include
    70 DOCDIR=$(PREFIX)/doc
     76DOCDIR=$(PREFIX)/share/doc
    7177# where to install NTL
    7278
     
    7480#
    7581#  Second, if you want to use GMP (the GNU Multi-Precision library),
    76 #  define the variables GMP_INCDIR, GMP_LIBDIR, GMP_LIB below.
    77 #  Otherwise, leave these defined as empty.
     82#  define the variables GMP_OPT_INCDIR, GMP_OPT_LIBDIR, GMP_OPT_LIB below.
    7883#  You also will have to set either NTL_GMP_LIP or NTL_GMP_HACK
    7984#  in the config.h file.
     
    8893
    8994
    90 GMP_INCDIR=
    91 # Set to -I<directory containing gmp.h> if using GMP and GMP
    92 # is not installed in a standard system directory, empty otherwise
    93 
    94 GMP_LIBDIR=
    95 # Set to -L<directory containing libgmp.a> if using GMP and GMP
    96 # is not installed in a standard system directory, empty otherwise
    97 
    98 GMP_LIB=
    99 # Set to -lgmp if using GMP, empty otherwise
    100 
    101 ###############################################################
    102 #
    103 # Third, if you do not want to run the wizard that automagically
     95GMP_PREFIX=$(DEF_PREFIX)
     96
     97GMP_INCDIR=$(GMP_PREFIX)/include
     98# directory containing gmp.h if using GMP
     99
     100GMP_LIBDIR=$(GMP_PREFIX)/lib
     101# directory containing libgmp.a if using GMP
     102
     103GMP_OPT_INCDIR=# -I$(GMP_INCDIR) # GMP
     104GMP_OPT_LIBDIR=# -L$(GMP_LIBDIR) # GMP
     105GMP_OPT_LIB=# -lgmp # GMP
     106# uncomment these if using GMP
     107
     108
     109###############################################################
     110#
     111#  Third, if you want to use gf2x (a library for fast
     112#  multiplication over GF(2)[X]), you need to
     113#  define the variables GF2X_OPT_INCDIR, GF2X_OPT_LIBDIR, GF2X_OPT_LIB below.
     114#  You also will have to set NTL_GF2X_LIB
     115#  in the config.h file.
     116#
     117###############################################################
     118
     119GF2X_PREFIX=$(DEF_PREFIX)
     120
     121GF2X_INCDIR=$(GF2X_PREFIX)/include
     122# directory containing gf2x.h if using gf2x
     123
     124GF2X_LIBDIR=$(GF2X_PREFIX)/lib
     125# directory containing libgf2x.a
     126
     127GF2X_OPT_INCDIR=# -I$(GF2X_INCDIR) # GF2X
     128GF2X_OPT_LIBDIR=# -L$(GF2X_LIBDIR) # GF2X
     129GF2X_OPT_LIB=# -lgf2x # GF2X
     130# uncomment these if using gf2x
     131
     132
     133###############################################################
     134#
     135# Fourth, if you do not want to run the wizard that automagically
    104136# sets some performace related flags in config.h, set the flag below.
    105137#
     
    214246TS1=QuickTest.c BerlekampTest.c CanZassTest.c ZZXFacTest.c MoreFacTest.c LLLTest.c
    215247TS2=$(TS1) subset.c MatrixTest.c CharPolyTest.c RRTest.c QuadTest.c
    216 TS3=$(TS2) GF2EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c
     248TS3=$(TS2) GF2XTest.c GF2EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c
    217249
    218250TS = $(TS3)
     
    252284D16=$(D15) tour.html tour-ex1.html tour-ex2.html tour-ex3.html tour-ex4.html
    253285D17=$(D16) tour-ex5.html tour-ex6.html arrow1.gif arrow2.gif arrow3.gif
    254 D18=$(D17) tour-gmp.html config.txt version.txt
     286D18=$(D17) tour-gmp.html tour-gf2x.html tour-tips.html config.txt version.txt
    255287
    256288DOC = $(D18)
     
    262294PROG1=QuickTest BerlekampTest CanZassTest ZZXFacTest MoreFacTest LLLTest  BitMatTest
    263295PROG2=$(PROG1) MatrixTest CharPolyTest RRTest QuadTest
    264 PROG3=$(PROG2) GF2EXTest subset ZZ_pEXTest lzz_pEXTest
     296PROG3=$(PROG2) GF2XTest GF2EXTest subset ZZ_pEXTest lzz_pEXTest
    265297PROGS = $(PROG3)
    266298
     
    290322
    291323
     324
     325# 'make all' does a complete make, including all setup.
     326# It also creates the file 'all', which means you should
     327# run 'make clobber' before running 'make' or 'make all'
     328# again.
    292329
    293330all:
     
    297334        make setup4
    298335        make ntl.a
     336        touch all
    299337
    300338
     
    319357
    320358setup3:
    321         $(LINK) $(GMP_FLAG) $(GMP_INCDIR) -o gen_lip_gmp_aux gen_lip_gmp_aux.c $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS)
     359        $(LINK) $(GMP_OPT_INCDIR) -o gen_lip_gmp_aux gen_lip_gmp_aux.c $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS)
    322360        ./gen_lip_gmp_aux > lip_gmp_aux_impl.h
    323         $(LINK) $(GMP_FLAG) $(GMP_INCDIR) -o gen_gmp_aux gen_gmp_aux.c $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS)
     361        $(LINK) $(GMP_OPT_INCDIR) -o gen_gmp_aux gen_gmp_aux.c $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS)
    324362        ./gen_gmp_aux > ../include/NTL/gmp_aux.h
    325363
     
    331369
    332370ntl.a:  $(OBJ)
    333         $(AR) $(ARFLAGS) ntl.a $(OBJ)
    334         - $(RANLIB) ntl.a
     371        $(AR) $(ARFLAGS) ntl.a $(OBJ) #LSTAT
     372        - $(RANLIB) ntl.a #LSTAT
     373#       $(LIBTOOL) --mode=link $(LINK_CXX) -o libntl.la $(OBJ:.o=.lo) $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(GF2X_OPT_LIBDIR) $(GF2X_OPT_LIB) $(LDLIBS_CXX) -rpath $(LIBDIR) -version-info `cat VERSION_INFO` #LSHAR
     374
     375LCOMP= #LSTAT
     376# LCOMP=$(LIBTOOL) --mode=compile #LSHAR
    335377
    336378lip.o:  lip.c g_lip_impl.h c_lip_impl.h lip_gmp_aux_impl.h
    337         $(COMPILE) $(GMP_INCDIR) lip.c
     379        $(LCOMP) $(COMPILE) $(GMP_OPT_INCDIR) lip.c
    338380
    339381ctools.o:       ctools.c
    340         $(COMPILE) ctools.c
     382        $(LCOMP) $(COMPILE) ctools.c
    341383
    342384
    343385GetTime.o: GetTime.c
    344         $(COMPILE) GetTime.c
     386        $(LCOMP) $(COMPILE) GetTime.c
     387
    345388
    346389
    347390.c.o:
    348         $(COMPILE_CXX) $<
     391        $(LCOMP) $(COMPILE_CXX) $(GF2X_OPT_INCDIR) $<
    349392
    350393.c:
    351         $(LINK_CXX) -o $@ $< ntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     394        $(LINK_CXX) -o $@ $< ntl.a $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(GF2X_OPT_LIBDIR) $(GF2X_OPT_LIB) $(LDLIBS_CXX) #LSTAT
     395#       $(LIBTOOL) --mode=link $(LINK_CXX) -o $@ $< libntl.la #LSHAR
    352396
    353397#################################################################
     
    359403
    360404check:
     405        sh RemoveProg $(PROGS)
    361406        make QuickTest
    362407        ./QuickTest
    363         - sh RemoveProg QuickTest
     408        sh RemoveProg QuickTest
    364409        sh TestScript
    365410
     
    381426
    382427install:
    383         mkdir -p -m 755 $(LIBDIR)
    384         cp -p ntl.a $(LIBDIR)/libntl.a
    385         - chmod a+r $(LIBDIR)/libntl.a
    386428        mkdir -p -m 755 $(INCLUDEDIR)
    387         - rm -r $(INCLUDEDIR)/NTL
     429        rm -rf $(INCLUDEDIR)/NTL
    388430        mkdir -m 755 $(INCLUDEDIR)/NTL
    389431        cp -p ../include/NTL/*.h $(INCLUDEDIR)/NTL
    390432        - chmod -R a+r $(INCLUDEDIR)/NTL
    391433        mkdir -p -m 755 $(DOCDIR)
    392         - rm -r $(DOCDIR)/NTL
     434        rm -rf $(DOCDIR)/NTL
    393435        mkdir -m 755 $(DOCDIR)/NTL
    394436        cp -p ../doc/*.txt $(DOCDIR)/NTL
     
    396438        cp -p ../doc/*.gif $(DOCDIR)/NTL
    397439        - chmod -R a+r $(DOCDIR)/NTL
     440        mkdir -p -m 755 $(LIBDIR)
     441        cp -p ntl.a $(LIBDIR)/libntl.a #LSTAT
     442        - chmod a+r $(LIBDIR)/libntl.a #LSTAT
     443#       $(LIBTOOL) --mode=install cp -p libntl.la $(LIBDIR) #LSHAR
    398444
    399445
    400446uninstall:
    401         - rm $(LIBDIR)/libntl.a
    402         - rm -r $(INCLUDEDIR)/NTL
    403         - rm -r $(DOCDIR)/NTL
     447        rm -f $(LIBDIR)/libntl.a #LSTAT
     448#       $(LIBTOOL) --mode=uninstall rm -f $(LIBDIR)/libntl.la #LSHAR
     449        rm -rf $(INCLUDEDIR)/NTL
     450        rm -rf $(DOCDIR)/NTL
    404451
    405452#################################################################
     
    415462
    416463clobber:       
    417         - rm ntl.a mach_desc.h ../include/NTL/mach_desc.h  GetTime.c
    418         - rm lip_gmp_aux_impl.h ../include/NTL/gmp_aux.h
    419         - sh RemoveProg $(PROGS) MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
    420         - rm *.o
    421         - rm -r small
     464        rm -f ntl.a mach_desc.h ../include/NTL/mach_desc.h  GetTime.c
     465        rm -f lip_gmp_aux_impl.h ../include/NTL/gmp_aux.h
     466        sh RemoveProg $(PROGS) MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
     467        rm -f *.o
     468        rm -rf small
     469        rm -f cfileout mfileout
     470        rm -rf .libs *.lo libntl.la
     471        rm -f all
    422472
    423473clean:
    424         - rm *.o
    425         - sh RemoveProg MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
    426         - rm -r small
     474        sh RemoveProg MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
     475        rm -f *.o
     476        rm -rf small
     477#       - $(LIBTOOL) --mode=clean rm -f libntl.la *.lo #LSHAR
    427478
    428479#################################################################
     
    438489
    439490package:
    440         sh unixify "$(SFILES) DIRNAME WINDIR" "$(INCL)" "$(DOC)"
    441         -rm -rf `cat DIRNAME`
    442         - rm -f `cat DIRNAME`.tar
    443         - rm -f `cat DIRNAME`.tar.gz
     491        sh unixify "$(SFILES) DIRNAME WINDIR VERSION_INFO NOTES" "$(INCL)" "$(DOC)"
     492        rm -rf `cat DIRNAME`
     493        rm -f `cat DIRNAME`.tar
     494        rm -f `cat DIRNAME`.tar.gz
    444495        mv unix `cat DIRNAME`
    445496        chmod -R a+rX `cat DIRNAME`
    446497        tar -cvf `cat DIRNAME`.tar `cat DIRNAME`
    447498        gzip `cat DIRNAME`.tar
    448         - rm -rf `cat DIRNAME`
     499        rm -rf `cat DIRNAME`
    449500
    450501winpack:
    451502        sh dosify "$(SRC)" "$(INCL)" "$(DOC)" "$(TS)" "$(TD)" "$(SINC)"
    452         - rm -rf `cat WINDIR`
    453         - rm -f `cat WINDIR`.zip
     503        rm -rf `cat WINDIR`
     504        rm -f `cat WINDIR`.zip
    454505        mv dos `cat WINDIR`
    455506        chmod -R a+rX `cat WINDIR`
     
    471522WOBJ = $(WO3)
    472523
    473 
     524# wntl.a: LCOMP= #LSHAR
    474525wntl.a: $(WOBJ)
    475526        $(AR) $(ARFLAGS) wntl.a $(WOBJ)
    476527        - $(RANLIB) wntl.a
    477528
    478 
    479 
    480529MulTimeTest:
    481         $(LINK_CXX) -o MulTimeTest MulTimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB)  $(LDLIBS_CXX)
     530        $(LINK_CXX) -o MulTimeTest MulTimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB)  $(LDLIBS_CXX)
    482531
    483532PolyTimeTest:
    484         $(LINK_CXX) -o PolyTimeTest PolyTimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     533        $(LINK_CXX) -o PolyTimeTest PolyTimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS_CXX)
    485534
    486535Poly1TimeTest:
    487         $(LINK_CXX) -o Poly1TimeTest Poly1TimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     536        $(LINK_CXX) -o Poly1TimeTest Poly1TimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS_CXX)
    488537
    489538
    490539GF2XTimeTest:
    491         $(LINK_CXX) -o GF2XTimeTest GF2XTimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     540        $(LINK_CXX) -o GF2XTimeTest GF2XTimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS_CXX)
    492541
    493542InitSettings:
     
    500549
    501550
    502 ################################################################
    503 #
    504 # Notes on making a new distribution
    505 #
    506 #  - change version numbers in ../include/NTL/version.h, DIRNAME, and WINDIR
    507 #
    508 #  - if changes were made to makefile or ../include/NTL/config.h,
    509 #    make sure these changes are implemented in the template files
    510 #    mfile and cfile, and then run:
    511 #      ./configure
    512 #      cp makefile def_makefile
    513 #      cp ../include/NTL/config.h ../include/NTL/def_config.h
    514 #
    515 #  - run: 
    516 #      make package
    517 #      make winpack
    518 #
    519 ################################################################
    520 
    521 
     551
  • ntl/src/fileio.c

    re6d2f67 r26e030  
    1414
    1515   if (!s) {
    16       cerr << "open write error: " << name << "\n";
    17       abort();
     16      cerr << "open write error: " << name;
     17      Error("");
    1818   }
    1919}
     
    2424   s.open(name, ios::in);
    2525   if (!s) {
    26       cerr << "open read error: " << name << "\n";
    27       abort();
     26      cerr << "open read error: " << name;
     27      Error("");
    2828   }
    2929}
  • ntl/src/g_lip_impl.h

    re6d2f67 r26e030  
    331331
    332332
     333/* ForceNormal ensures a normalized bigint */
     334
     335static
     336void ForceNormal(_ntl_gbigint x)
     337{
     338   long sx, xneg;
     339   mp_limb_t *xdata;
     340
     341   if (!x) return;
     342   GET_SIZE_NEG(sx, xneg, x);
     343   xdata = DATA(x);
     344   STRIP(sx, xdata);
     345   if (xneg) sx = -sx;
     346   SIZE(x) = sx;
     347}
     348
    333349
    334350static
     
    337353   fprintf(stderr,"fatal error:\n   %s\nexit...\n",c);
    338354   fflush(stderr);
    339    abort();
     355   _ntl_abort();
    340356}
    341357
     
    24212437      SIZE(xa) = sxa;
    24222438
     2439      /* Thes two ForceNormal's are work-arounds for GMP bugs
     2440         in GMP 4.3.0 */
     2441      ForceNormal(d);
     2442      ForceNormal(xa);
     2443
     2444      /* now we normalize xa, so that so that xa in ( -b/2d, b/2d ],
     2445         which makes the output agree with Euclid's algorithm,
     2446         regardless of what mpn_gcdext does */
     2447
     2448      if (!ZEROP(xa)) {
     2449         _ntl_gcopy(bin, &b);
     2450         SIZE(b) = sb;
     2451         if (!ONEP(d)) {
     2452            _ntl_gdiv(b, d, &b, &tmp);
     2453            if (!ZEROP(tmp)) ghalt("internal bug in _ntl_gexteucl");
     2454         }
     2455
     2456         if (SIZE(xa) > 0) { /* xa positive */
     2457            if (_ntl_gcompare(xa, b) > 0) {
     2458               _ntl_gmod(xa, b, &xa);
     2459            }
     2460            _ntl_glshift(xa, 1, &tmp);
     2461            if (_ntl_gcompare(tmp, b) > 0) {
     2462               _ntl_gsub(xa, b, &xa);
     2463            }
     2464         }
     2465         else { /* xa negative */
     2466            SIZE(xa) = -SIZE(xa);
     2467            if (_ntl_gcompare(xa, b) > 0) {
     2468               SIZE(xa) = -SIZE(xa);
     2469               _ntl_gmod(xa, b, &xa);
     2470               _ntl_gsub(xa, b, &xa);
     2471            }
     2472            else {
     2473               SIZE(xa) = -SIZE(xa);
     2474            }
     2475            _ntl_glshift(xa, 1, &tmp);
     2476            SIZE(tmp) = -SIZE(tmp);
     2477            if (_ntl_gcompare(tmp, b) >= 0) {
     2478               _ntl_gadd(xa, b, &xa);
     2479            }
     2480         }
     2481      }
     2482
     2483      /* end normalize */
     2484   
     2485
    24232486      if (aneg) _ntl_gnegate(&xa);
    24242487
     
    24902553   SIZE(u) = su;
    24912554
     2555      /* Thes two ForceNormal's are work-arounds for GMP bugs
     2556         in GMP 4.3.0 */
     2557      ForceNormal(d);
     2558      ForceNormal(u);
     2559
     2560
    24922561   if (ONEP(d)) {
    24932562
     
    24972566       */
    24982567
    2499       while (_ntl_gsign(u) < 0) _ntl_gadd(u, nin, &u);
    2500       while (_ntl_gcompare(u, nin) >= 0) _ntl_gsub(u, nin, &u);
     2568
     2569      if (_ntl_gsign(u) < 0) {
     2570         _ntl_gadd(u, nin, &u);
     2571         if (_ntl_gsign(u) < 0) {
     2572            _ntl_gmod(u, nin, &u);
     2573         }
     2574      }
     2575      else if (_ntl_gcompare(u, nin) >= 0) {
     2576         _ntl_gsub(u, nin, &u);
     2577         if (_ntl_gcompare(u, nin) >= 0) {
     2578             _ntl_gmod(u, nin, &u);
     2579         }
     2580      }
    25012581
    25022582      _ntl_gcopy(u, invv);
  • ntl/src/lzz_pEX.c

    re6d2f67 r26e030  
    106106
    107107   m = deg(x);
     108
     109   if (i > m && IsZero(a)) return;
    108110
    109111   if (i > m) {
     
    146148
    147149   m = deg(x);
     150
     151   if (i > m && IsZero(a)) return;
    148152
    149153   if (i > m) {
  • ntl/src/lzz_pX.c

    re6d2f67 r26e030  
    7575
    7676   m = deg(x);
     77
     78   if (i > m && IsZero(a)) return;
    7779
    7880   if (i > m) {
  • ntl/src/lzz_pX1.c

    re6d2f67 r26e030  
    16241624
    16251625   if (F.tracevec.length() == 0)
    1626       TraceVec(F);
     1626      ComputeTraceVec(F);
    16271627
    16281628   InnerProduct(x, a.rep, F.tracevec);
  • ntl/src/mfile

    re6d2f67 r26e030  
    2424# Some useful flags:
    2525#   -O2   --  recommended level of optimization
     26#   -m64  --  needed to get 64-bit longs on some platforms
    2627#   -g    --  debugging
    2728#   -mcpu=v8  --  needed with gcc/g++ to get the full instruction set
     
    5152
    5253LDFLAGS=@{LDFLAGS}
    53 # arguments for linker for C++ programs
     54# arguments for linker for C programs
    5455
    5556LDFLAGS_CXX=@{LDFLAGS_CXX}
     57# libraries for linking C++ programs
     58
     59LDLIBS=@{LDLIBS}
    5660# libraries for linking C programs
    57 
    58 LDLIBS=@{LDLIBS}
    59 # libraries for linking C++ programs
    6061
    6162LDLIBS_CXX=@{LDLIBS_CXX}
     
    6465CPPFLAGS=@{CPPFLAGS}
    6566# arguments for the C preprocessor
     67
     68LIBTOOL=@{LIBTOOL}
     69# libtool command
     70
     71DEF_PREFIX=@{DEF_PREFIX}
    6672
    6773PREFIX=@{PREFIX}
     
    7480#
    7581#  Second, if you want to use GMP (the GNU Multi-Precision library),
    76 #  define the variables GMP_INCDIR, GMP_LIBDIR, GMP_LIB below.
    77 #  Otherwise, leave these defined as empty.
     82#  define the variables GMP_OPT_INCDIR, GMP_OPT_LIBDIR, GMP_OPT_LIB below.
    7883#  You also will have to set either NTL_GMP_LIP or NTL_GMP_HACK
    7984#  in the config.h file.
     
    8893
    8994
     95GMP_PREFIX=@{GMP_PREFIX}
     96
    9097GMP_INCDIR=@{GMP_INCDIR}
    91 # Set to -I<directory containing gmp.h> if using GMP and GMP
    92 # is not installed in a standard system directory, empty otherwise
     98# directory containing gmp.h if using GMP
    9399
    94100GMP_LIBDIR=@{GMP_LIBDIR}
    95 # Set to -L<directory containing libgmp.a> if using GMP and GMP
    96 # is not installed in a standard system directory, empty otherwise
    97 
    98 GMP_LIB=@{GMP_LIB}
    99 # Set to -lgmp if using GMP, empty otherwise
    100 
    101 ###############################################################
    102 #
    103 # Third, if you do not want to run the wizard that automagically
     101# directory containing libgmp.a if using GMP
     102
     103GMP_OPT_INCDIR=@{GMP}-I$(GMP_INCDIR) # GMP
     104GMP_OPT_LIBDIR=@{GMP}-L$(GMP_LIBDIR) # GMP
     105GMP_OPT_LIB=@{GMP}-lgmp # GMP
     106# uncomment these if using GMP
     107
     108
     109###############################################################
     110#
     111#  Third, if you want to use gf2x (a library for fast
     112#  multiplication over GF(2)[X]), you need to
     113#  define the variables GF2X_OPT_INCDIR, GF2X_OPT_LIBDIR, GF2X_OPT_LIB below.
     114#  You also will have to set NTL_GF2X_LIB
     115#  in the config.h file.
     116#
     117###############################################################
     118
     119GF2X_PREFIX=@{GF2X_PREFIX}
     120
     121GF2X_INCDIR=@{GF2X_INCDIR}
     122# directory containing gf2x.h if using gf2x
     123
     124GF2X_LIBDIR=@{GF2X_LIBDIR}
     125# directory containing libgf2x.a
     126
     127GF2X_OPT_INCDIR=@{GF2X}-I$(GF2X_INCDIR) # GF2X
     128GF2X_OPT_LIBDIR=@{GF2X}-L$(GF2X_LIBDIR) # GF2X
     129GF2X_OPT_LIB=@{GF2X}-lgf2x # GF2X
     130# uncomment these if using gf2x
     131
     132
     133###############################################################
     134#
     135# Fourth, if you do not want to run the wizard that automagically
    104136# sets some performace related flags in config.h, set the flag below.
    105137#
     
    214246TS1=QuickTest.c BerlekampTest.c CanZassTest.c ZZXFacTest.c MoreFacTest.c LLLTest.c
    215247TS2=$(TS1) subset.c MatrixTest.c CharPolyTest.c RRTest.c QuadTest.c
    216 TS3=$(TS2) GF2EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c
     248TS3=$(TS2) GF2XTest.c GF2EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c
    217249
    218250TS = $(TS3)
     
    252284D16=$(D15) tour.html tour-ex1.html tour-ex2.html tour-ex3.html tour-ex4.html
    253285D17=$(D16) tour-ex5.html tour-ex6.html arrow1.gif arrow2.gif arrow3.gif
    254 D18=$(D17) tour-gmp.html config.txt version.txt
     286D18=$(D17) tour-gmp.html tour-gf2x.html tour-tips.html config.txt version.txt
    255287
    256288DOC = $(D18)
     
    262294PROG1=QuickTest BerlekampTest CanZassTest ZZXFacTest MoreFacTest LLLTest  BitMatTest
    263295PROG2=$(PROG1) MatrixTest CharPolyTest RRTest QuadTest
    264 PROG3=$(PROG2) GF2EXTest subset ZZ_pEXTest lzz_pEXTest
     296PROG3=$(PROG2) GF2XTest GF2EXTest subset ZZ_pEXTest lzz_pEXTest
    265297PROGS = $(PROG3)
    266298
     
    290322
    291323
     324
     325# 'make all' does a complete make, including all setup.
     326# It also creates the file 'all', which means you should
     327# run 'make clobber' before running 'make' or 'make all'
     328# again.
    292329
    293330all:
     
    297334        make setup4
    298335        make ntl.a
     336        touch all
    299337
    300338
     
    319357
    320358setup3:
    321         $(LINK) $(GMP_FLAG) $(GMP_INCDIR) -o gen_lip_gmp_aux gen_lip_gmp_aux.c $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS)
     359        $(LINK) $(GMP_OPT_INCDIR) -o gen_lip_gmp_aux gen_lip_gmp_aux.c $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS)
    322360        ./gen_lip_gmp_aux > lip_gmp_aux_impl.h
    323         $(LINK) $(GMP_FLAG) $(GMP_INCDIR) -o gen_gmp_aux gen_gmp_aux.c $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS)
     361        $(LINK) $(GMP_OPT_INCDIR) -o gen_gmp_aux gen_gmp_aux.c $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS)
    324362        ./gen_gmp_aux > ../include/NTL/gmp_aux.h
    325363
     
    331369
    332370ntl.a:  $(OBJ)
    333         $(AR) $(ARFLAGS) ntl.a $(OBJ)
    334         - $(RANLIB) ntl.a
     371@{LSTAT}        $(AR) $(ARFLAGS) ntl.a $(OBJ) #LSTAT
     372@{LSTAT}        - $(RANLIB) ntl.a #LSTAT
     373@{LSHAR}        $(LIBTOOL) --mode=link $(LINK_CXX) -o libntl.la $(OBJ:.o=.lo) $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(GF2X_OPT_LIBDIR) $(GF2X_OPT_LIB) $(LDLIBS_CXX) -rpath $(LIBDIR) -version-info `cat VERSION_INFO` #LSHAR
     374
     375@{LSTAT}LCOMP= #LSTAT
     376@{LSHAR}LCOMP=$(LIBTOOL) --mode=compile #LSHAR
    335377
    336378lip.o:  lip.c g_lip_impl.h c_lip_impl.h lip_gmp_aux_impl.h
    337         $(COMPILE) $(GMP_INCDIR) lip.c
     379        $(LCOMP) $(COMPILE) $(GMP_OPT_INCDIR) lip.c
    338380
    339381ctools.o:       ctools.c
    340         $(COMPILE) ctools.c
     382        $(LCOMP) $(COMPILE) ctools.c
    341383
    342384
    343385GetTime.o: GetTime.c
    344         $(COMPILE) GetTime.c
     386        $(LCOMP) $(COMPILE) GetTime.c
     387
    345388
    346389
    347390.c.o:
    348         $(COMPILE_CXX) $<
     391        $(LCOMP) $(COMPILE_CXX) $(GF2X_OPT_INCDIR) $<
    349392
    350393.c:
    351         $(LINK_CXX) -o $@ $< ntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     394@{LSTAT}        $(LINK_CXX) -o $@ $< ntl.a $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(GF2X_OPT_LIBDIR) $(GF2X_OPT_LIB) $(LDLIBS_CXX) #LSTAT
     395@{LSHAR}        $(LIBTOOL) --mode=link $(LINK_CXX) -o $@ $< libntl.la #LSHAR
    352396
    353397#################################################################
     
    359403
    360404check:
     405        sh RemoveProg $(PROGS)
    361406        make QuickTest
    362407        ./QuickTest
    363         - sh RemoveProg QuickTest
     408        sh RemoveProg QuickTest
    364409        sh TestScript
    365410
     
    381426
    382427install:
    383         mkdir -p -m 755 $(LIBDIR)
    384         cp -p ntl.a $(LIBDIR)/libntl.a
    385         - chmod a+r $(LIBDIR)/libntl.a
    386428        mkdir -p -m 755 $(INCLUDEDIR)
    387         - rm -r $(INCLUDEDIR)/NTL
     429        rm -rf $(INCLUDEDIR)/NTL
    388430        mkdir -m 755 $(INCLUDEDIR)/NTL
    389431        cp -p ../include/NTL/*.h $(INCLUDEDIR)/NTL
    390432        - chmod -R a+r $(INCLUDEDIR)/NTL
    391433        mkdir -p -m 755 $(DOCDIR)
    392         - rm -r $(DOCDIR)/NTL
     434        rm -rf $(DOCDIR)/NTL
    393435        mkdir -m 755 $(DOCDIR)/NTL
    394436        cp -p ../doc/*.txt $(DOCDIR)/NTL
     
    396438        cp -p ../doc/*.gif $(DOCDIR)/NTL
    397439        - chmod -R a+r $(DOCDIR)/NTL
     440        mkdir -p -m 755 $(LIBDIR)
     441@{LSTAT}        cp -p ntl.a $(LIBDIR)/libntl.a #LSTAT
     442@{LSTAT}        - chmod a+r $(LIBDIR)/libntl.a #LSTAT
     443@{LSHAR}        $(LIBTOOL) --mode=install cp -p libntl.la $(LIBDIR) #LSHAR
    398444
    399445
    400446uninstall:
    401         - rm $(LIBDIR)/libntl.a
    402         - rm -r $(INCLUDEDIR)/NTL
    403         - rm -r $(DOCDIR)/NTL
     447@{LSTAT}        rm -f $(LIBDIR)/libntl.a #LSTAT
     448@{LSHAR}        $(LIBTOOL) --mode=uninstall rm -f $(LIBDIR)/libntl.la #LSHAR
     449        rm -rf $(INCLUDEDIR)/NTL
     450        rm -rf $(DOCDIR)/NTL
    404451
    405452#################################################################
     
    415462
    416463clobber:       
    417         - rm ntl.a mach_desc.h ../include/NTL/mach_desc.h  GetTime.c
    418         - rm lip_gmp_aux_impl.h ../include/NTL/gmp_aux.h
    419         - sh RemoveProg $(PROGS) MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
    420         - rm *.o
    421         - rm -r small
     464        rm -f ntl.a mach_desc.h ../include/NTL/mach_desc.h  GetTime.c
     465        rm -f lip_gmp_aux_impl.h ../include/NTL/gmp_aux.h
     466        sh RemoveProg $(PROGS) MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
     467        rm -f *.o
     468        rm -rf small
     469        rm -f cfileout mfileout
     470        rm -rf .libs *.lo libntl.la
     471        rm -f all
    422472
    423473clean:
    424         - rm *.o
    425         - sh RemoveProg MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
    426         - rm -r small
     474        sh RemoveProg MakeDesc TestGetTime gen_lip_gmp_aux gen_gmp_aux
     475        rm -f *.o
     476        rm -rf small
     477@{LSHAR}        - $(LIBTOOL) --mode=clean rm -f libntl.la *.lo #LSHAR
    427478
    428479#################################################################
     
    438489
    439490package:
    440         sh unixify "$(SFILES) DIRNAME WINDIR" "$(INCL)" "$(DOC)"
    441         -rm -rf `cat DIRNAME`
    442         - rm -f `cat DIRNAME`.tar
    443         - rm -f `cat DIRNAME`.tar.gz
     491        sh unixify "$(SFILES) DIRNAME WINDIR VERSION_INFO NOTES" "$(INCL)" "$(DOC)"
     492        rm -rf `cat DIRNAME`
     493        rm -f `cat DIRNAME`.tar
     494        rm -f `cat DIRNAME`.tar.gz
    444495        mv unix `cat DIRNAME`
    445496        chmod -R a+rX `cat DIRNAME`
    446497        tar -cvf `cat DIRNAME`.tar `cat DIRNAME`
    447498        gzip `cat DIRNAME`.tar
    448         - rm -rf `cat DIRNAME`
     499        rm -rf `cat DIRNAME`
    449500
    450501winpack:
    451502        sh dosify "$(SRC)" "$(INCL)" "$(DOC)" "$(TS)" "$(TD)" "$(SINC)"
    452         - rm -rf `cat WINDIR`
    453         - rm -f `cat WINDIR`.zip
     503        rm -rf `cat WINDIR`
     504        rm -f `cat WINDIR`.zip
    454505        mv dos `cat WINDIR`
    455506        chmod -R a+rX `cat WINDIR`
     
    471522WOBJ = $(WO3)
    472523
    473 
     524@{LSHAR}wntl.a: LCOMP= #LSHAR
    474525wntl.a: $(WOBJ)
    475526        $(AR) $(ARFLAGS) wntl.a $(WOBJ)
    476527        - $(RANLIB) wntl.a
    477528
    478 
    479 
    480529MulTimeTest:
    481         $(LINK_CXX) -o MulTimeTest MulTimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB)  $(LDLIBS_CXX)
     530        $(LINK_CXX) -o MulTimeTest MulTimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB)  $(LDLIBS_CXX)
    482531
    483532PolyTimeTest:
    484         $(LINK_CXX) -o PolyTimeTest PolyTimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     533        $(LINK_CXX) -o PolyTimeTest PolyTimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS_CXX)
    485534
    486535Poly1TimeTest:
    487         $(LINK_CXX) -o Poly1TimeTest Poly1TimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     536        $(LINK_CXX) -o Poly1TimeTest Poly1TimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS_CXX)
    488537
    489538
    490539GF2XTimeTest:
    491         $(LINK_CXX) -o GF2XTimeTest GF2XTimeTest.c wntl.a  $(GMP_LIBDIR) $(GMP_LIB) $(LDLIBS_CXX)
     540        $(LINK_CXX) -o GF2XTimeTest GF2XTimeTest.c wntl.a  $(GMP_OPT_LIBDIR) $(GMP_OPT_LIB) $(LDLIBS_CXX)
    492541
    493542InitSettings:
     
    500549
    501550
    502 ################################################################
    503 #
    504 # Notes on making a new distribution
    505 #
    506 #  - change version numbers in ../include/NTL/version.h, DIRNAME, and WINDIR
    507 #
    508 #  - if changes were made to makefile or ../include/NTL/config.h,
    509 #    make sure these changes are implemented in the template files
    510 #    mfile and cfile, and then run:
    511 #      ./configure
    512 #      cp makefile def_makefile
    513 #      cp ../include/NTL/config.h ../include/NTL/def_config.h
    514 #
    515 #  - run: 
    516 #      make package
    517 #      make winpack
    518 #
    519 ################################################################
    520 
    521 
     551
  • ntl/src/tools.c

    re6d2f67 r26e030  
    88#include <NTL/new.h>
    99
     10void _ntl_abort_cxx_callback(void)
     11{
     12   if (NTL_NNS ErrorCallback) (*NTL_NNS ErrorCallback)();
     13}
     14
    1015NTL_START_IMPL
    1116
     17void (*ErrorCallback)() = 0;
    1218
    1319void Error(const char *s)
    1420{
    1521   printf("%s\n", s );
    16    abort();
     22   _ntl_abort();
    1723}
    1824
Note: See TracChangeset for help on using the changeset viewer.