Changeset 26e030 in git
- Timestamp:
- Jul 6, 2009, 4:52:01 PM (14 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- cf5d3081011bf7a0104bade9c3eaf9da21c588d7
- Parents:
- e6d2f67d59d8d9127eab2943d2bf0c78e249d180
- 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.22 Release date: 200 8.03.051 NTL -- a library for doing numbery theory -- version 5.5 2 Release date: 2009.04.08 3 3 4 4 Author: Victor Shoup (victor@shoup.net) … … 19 19 The latest version of NTL is available at http://www.shoup.net. 20 20 21 The sources have been modified for Singular-3- 0-421 The sources have been modified for Singular-3-1-0 22 22 - for errors blame singular@mathematik.uni-kl.de, 23 23 not Victor Shoup (victor@shoup.net) -
ntl/doc/ZZ.txt
re6d2f67 r26e030 221 221 // adjusted according to the signs of a and b. 222 222 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. 227 226 228 227 -
ntl/doc/config.txt
re6d2f67 r26e030 23 23 CXXFLAGS=$(CFLAGS) # C++ compilation flags (by default, same as CFLAGS) 24 24 25 PREFIX=/usr/local # Directory in which to install NTL library components 25 DEF_PREFIX=/usr/local # Default software directory 26 PREFIX=$(DEF_PREFIX) # Directory in which to install NTL library components 27 SHARED=off # Generate a shared library (as well as static) 26 28 27 29 NTL_STD_CXX=on # ISO Mode switch … … 30 32 # long integer package 31 33 32 GMP_PREFIX=undefined # Directory in which GMP components have been installed 34 GMP_PREFIX=$(DEF_PREFIX) # Directory in which GMP components are installed 35 36 NTL_GF2X_LIB=off # Switch to enable the use of the gf2x package 37 # for faster arithmetic over GF(2)[X] 38 39 GF2X_PREFIX=$(DEF_PREFIX) # Directory in which gf2x components are installed 33 40 34 41 … … 77 84 78 85 86 79 87 ########## Installation path: 80 88 81 PREFIX=/usr/local 89 DEF_PREFIX=/usr/local 90 91 # Default software directory 92 93 PREFIX=$(DEF_PREFIX) 82 94 83 95 # Set this to the directory in which you want NTL components to be … … 85 97 # files are copied into $(PREFIX)/include/NTL, the library itself is 86 98 # 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. 88 100 # Unless you have root permissions when running 'make install', 89 101 # you will have to override the default PREFIX value with the … … 92 104 # library components are installed, set the variables 93 105 # INCLUDEDIR, LIBDIR, and DOCDIR (see below). 106 107 ########## Shared library switch: 108 109 SHARED=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 94 127 95 128 ########## ISO mode switch: … … 129 162 130 163 131 GMP_PREFIX= undefined164 GMP_PREFIX=$(DEF_PREFIX) 132 165 133 166 # If GMP was installed in a standard system directory, e.g., /usr/local, … … 141 174 142 175 176 ########## GF2X variables: 177 178 NTL_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 189 GF2X_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 143 202 ########### Examples: 144 203 … … 179 238 180 239 240 # If you want to use both GMP and the gf2x library: 241 242 ./configure NTL_GMP_LIP=on NTL_GF2X_LIB=on 181 243 182 244 … … 184 246 185 247 ./configure NTL_GMP_LIP=on NTL_STD_CXX=off 248 186 249 187 250 … … 200 263 LDLIBS_CXX=$(LDLIBS) 201 264 CPPFLAGS= 265 LIBTOOL=libtool 202 266 203 267 LIBDIR=$(PREFIX)/lib 204 268 INCLUDEDIR=$(PREFIX)/include 205 DOCDIR=$(PREFIX)/include 269 DOCDIR=$(PREFIX)/share/doc 270 206 271 207 272 NTL_PSTD_NNS=off … … 232 297 233 298 NTL_GMP_HACK=off 234 GMP_INCDIR=undefined 235 GMP_LIBDIR=undefined 299 GMP_INCDIR=$(GMP_PREFIX)/include 300 GMP_LIBDIR=$(GMP_PREFIX)/lib 301 302 GF2X_INCDIR=$(GF2X_PREFIX)/include 303 GF2X_LIBDIR=$(GF2X_PREFIX)/lib 304 236 305 237 306 … … 274 343 LDLIBS=-lm 275 344 345 # libraries for linking C programs 346 347 348 349 LDLIBS_CXX=$(LDLIBS) 350 276 351 # libraries for linking C++ programs 277 352 278 353 279 354 280 LDLIBS_CXX=$(LDLIBS)281 282 # libraries for linking C++ programs283 284 285 286 355 CPPFLAGS= 287 356 288 357 # arguments for the C preprocessor 289 358 290 291 292 ########### Details of the compilation process: 359 LIBTOOL=libtool 360 361 # the libtool command -- only needed if SHARED=on 362 363 364 365 ########### Details of the compilation process (when SHARED=off) 366 293 367 294 368 # When a C file foo.c is compiled: … … 305 379 -o foo foo.c $(LDLIBS_CXX) 306 380 307 # When the library ntl.a is built :381 # When the library ntl.a is built 308 382 $(AR) $(ARFLAGS) ntl.a [ object files ]... 309 383 $(RANLIB) ntl.a … … 311 385 312 386 387 313 388 ########### Further installation variables: 314 389 315 390 LIBDIR=$(PREFIX)/lib 316 391 INCLUDEDIR=$(PREFIX)/include 317 DOCDIR=$(PREFIX)/ doc392 DOCDIR=$(PREFIX)/share/doc 318 393 # Where to install NTL. 319 394 # Execution of 'make install' copies header files into $(INCLUDEDIR)/NTL, 320 395 # copies the library itself to $(LIBDIR)/libntl.a, and copies the 321 396 # documentation files into $(DOCDIR)/NTL. 397 322 398 323 399 … … 568 644 # If you set this flag, you may have to set GMP_PREFIX as well. 569 645 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 646 GMP_INCDIR=$(GMP_PREFIX)/include 647 # directory containing gmp.h 648 649 GMP_LIBDIR=$(GMP_PREFIX)/lib 650 # directory containing libgmp.a 651 652 653 ####### More gf2x options: 654 655 GF2X_INCDIR=$(GF2X_PREFIX)/include 656 # directory containing gf2x.h 657 658 GF2X_LIBDIR=$(GF2X_PREFIX)/lib 659 # directory containing libgf2x.a 660 -
ntl/doc/copying.txt
re6d2f67 r26e030 3 3 4 4 NTL -- A Library for Doing Number Theory 5 Copyright (C) 1996-200 7Victor Shoup5 Copyright (C) 1996-2009 Victor Shoup 6 6 7 7 The most recent version of NTL is available at http://www.shoup.net -
ntl/doc/tools.txt
re6d2f67 r26e030 31 31 // print an error message and call abort 32 32 33 extern 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 33 42 long IsWhiteSpace(long c); 34 43 // returns 1 if c is "wite space" (as defined by isspace is the … … 43 52 // like NTL's, that raise an error if an input item is 44 53 // ill-formed or missing. 54 55 long IsEOFChar(long c); 56 // test if c == EOF 45 57 46 58 -
ntl/doc/tour-changes.html
re6d2f67 r26e030 17 17 </p> 18 18 </h1> 19 20 <p> <hr> <p> 21 <h3> 22 2009.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> 27 or <tt>NTL_GMP_HACK</tt>), then the new version (4.3.0) of 28 GMP implements the <tt>XGCD</tt> functionality differently, 29 so that the coefficients do not always agree with those returned by 30 the classical extended Euclidean algorithm. 31 This version of NTL corrects the coefficients, so that the 32 "classical" coefficients are always produced, regardless 33 of GMP's implementation. 34 This version of NTL also works 35 around 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> 39 The <tt>configure</tt> script has been slightly modified: 40 there is a new configuration variable <tt>DEF_PREFIX</tt>, 41 whose value can be used to set <tt>PREFIX</tt>, <tt>GMP_PREFIX</tt>, 42 and <tt>GF2X_PREFIX</tt> in one stroke. 43 Also, 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> 46 have slightly different meanings now. 47 48 </ul> 49 </h3> 50 51 <p> <hr> <p> 52 <h3> 53 2009.04.08: Changes between NTL 5.4.2 and 5.5 54 </h3> 55 56 <ul> 57 <li> 58 Added 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> 62 Fixed some standardization issues 63 (with help from Tim Abbot): 64 default location of installed documentation files now conforms 65 to standards; use of <tt>EOF</tt> now conforms to standards. 66 67 <li> 68 Added a callback mechanism to NTL's error reporting function. 69 See <tt>ErrorCallback</tt> in <a href="tools.txt">tools.txt</a>. 70 71 <li> 72 Added support for the <tt>gf2x</tt> library for speeding up 73 arithmetic in <tt>GF2X</tt> (with help from Emmanuel Thomé). 74 <a href="tour-gf2x.html">Details.</a> 75 76 <li> 77 In conjuction with the above, I also changed the 78 <tt>GF2X</tt> so that it works better with very large polynomials: 79 large blocks of memory are released, recursive HalfGCD algorithms 80 are used for large polynomials. 81 82 83 <li> 84 Fixed a bug in <tt>void TraceMod(zz_p& x, const zz_pX& a, const zz_pXModulus& F)</tt> (reported by Luca De Feo). 85 86 <li> 87 Fixed a performance issue in various versions of <tt>SetCoeff</tt> 88 (reported by Luca De Feo). 89 90 <li> 91 Fixed the declaration of <tt>mat_zz_p transpose(const mat_zz_p& a)</tt> 92 (reported by Benoit Lacelle). 93 </ul> 94 19 95 20 96 <p> <hr> <p> -
ntl/doc/tour-ex1.html
re6d2f67 r26e030 72 72 When compiling NTL in traditional mode, this expands 73 73 to the empty string. 74 More details <a href="tour-stdcxx.html">here</a>. 74 75 75 76 <p> <hr> <p> -
ntl/doc/tour-gmp.html
re6d2f67 r26e030 10 10 <a href="tour-impl.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a> 11 11 <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> 13 13 </center> 14 14 … … 23 23 GMP is the GNU Multi-Precision library. 24 24 You can get more information about it, as well as the latest version 25 from <a href="http:// www.swox.com/gmp">here.</a>25 from <a href="http://gmplib.org">here.</a> 26 26 27 27 <p> … … 87 87 <p> 88 88 89 Download GMP from <a href="http:// www.swox.com/gmp">here.</a>89 Download GMP from <a href="http://gmplib.org">here.</a> 90 90 You will get a file <tt>gmp-XXX.tar.gz</tt>. 91 91 <p> … … 95 95 % tar xf gmp-XXX.tar 96 96 % cd gmp-XXX 97 % ./configure -- disable-shared --prefix=$HOME/sw97 % ./configure --prefix=$HOME/sw 98 98 % make 99 99 % make check 100 100 % make install 101 101 </pre> 102 This will build, test, and install GMP in $HOME/sw.102 This will build, test, and install GMP in <tt>$HOME/sw</tt>. 103 103 Of course, change $HOME/sw to whatever you want (the default is 104 104 <tt>/usr/local</tt>). 105 105 You will find the GMP header files in <tt>$HOME/sw/include</tt> 106 and the compiled binar y 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>. 106 and the compiled binaries in <tt>$HOME/sw/lib</tt>. 107 108 <p> 109 You can also supply the option 110 <tt>--disable-shared</tt> to the <tt>configure</tt> script, 111 if you only want static libraries. 112 However, if you ultimately want to build NTL as a shared 113 library, then you must also buld GMP as a shared library. 114 115 <p> 116 You must ensure that NTL and GMP have the same 117 <a href="tour-unix.html#abi">ABI</a>. 118 Usually, GMP's configure script will automatically 119 choose a 64-bit ABI if available. 120 121 121 122 122 <p> … … 138 138 % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw 139 139 </pre> 140 You can write this more simply as 141 <pre> 142 % ./configure DEF_PREFIX=$HOME/sw NTL_GMP_LIP=on 143 </pre> 144 Here, <tt>DEF_PREFIX</tt> is a variable that is used 145 to specify the location of all software, 146 and it defaults to <tt>/usr/local</tt>. 147 140 148 141 149 <p> … … 163 171 <p> 164 172 Instead of passing arguments to the configure script, 165 you can also just edit the <tt>config.h</tt> and makefileby hand.173 you can also just edit the <tt>config.h</tt> and <tt>makefile</tt> by hand. 166 174 The documentation in these files should be self-explanatory. 175 167 176 168 177 <p> 169 178 When compiling programs that use NTL with GMP, 170 179 you need to link with the GMP library. 171 If GMP is notinstalled as above in180 If GMP is installed as above in 172 181 <tt>$HOME/sw</tt>, rather than in a standard system directory, 173 182 this just means adding … … 177 186 Note that <tt>-lgmp</tt> must come <i>after</i> <tt>-lntl</tt> 178 187 on the command line. 188 Finally, if NTL and GF2X are installed as 189 shared libraries, then you don't even need <tt>-lgmp</tt>. 190 179 191 180 192 <p> … … 202 214 The programming interface to the long integer package 203 215 completely hides implementation details. 216 217 204 218 205 219 … … 359 373 <a href="tour-impl.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a> 360 374 <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> 362 376 </center> 377 363 378 364 379 -
ntl/doc/tour-impl.html
re6d2f67 r26e030 190 190 191 191 <p> 192 It is also generally assumed that the compiler does not 193 do too much "regrouping" of arithmetic expressions involving 194 floating point. 195 Most compilers respect the implied grouping of floating point 196 computations, and NTL goes out of its way to make its 197 intentions clear: instead of <tt>x = (a + b) + c</tt>, 198 if the grouping is truly important, this is written 199 as <tt>t = a + b; x = t + c</tt>. 200 Current standards do not allow, and most implementations will not 201 perform, any regrouping of this, e.g., <tt>x = a + (b + c)</tt>, 202 since in floating point, addition and subtraction are not 203 associative. 204 205 <p> 206 Unfortunately, some compilers do not do this correctly, 207 unless you tell them. 208 With Intel's C compiler <tt>icc</tt>, for example, 209 you should compile NTL with the flag <tt>-fp-model source</tt> 210 to enforce strict adherence to floating point standards. 211 Also, you should be wary of compiling using an optimization 212 level higher than the default <tt>-O2</tt> -- 213 this may break some floating point assumptions (and maybe 214 some other assumptions as well). 215 216 217 218 <p> 192 219 One big problem with the IEEE standard is that it allows intermediate 193 220 quantities to be computed in a higher precision than the standard -
ntl/doc/tour-intro.html
re6d2f67 r26e030 87 87 <a href="tour-gmp.html">GMP (the GNU Multi-Precision library)</a> 88 88 for enhanced performance. 89 NTL can also be used in conjunction with the 90 <a href="tour-gf2x.html"><tt>gf2x</tt></a> library for faster 91 arithmetic of large degree polynomials over <i>GF(2)</i>. 89 92 90 93 -
ntl/doc/tour-modules.html
re6d2f67 r26e030 55 55 <p> 56 56 57 However, if you compiled NTL in traditional (non-ISO mode), 57 However, if you compiled NTL in 58 <a href="tour-stdcxx.html">traditional (non-ISO mode)</a>, 58 59 then <tt><NTL/tools.h></tt> 59 60 includes the traditional (pre-ISO) headers -
ntl/doc/tour-time.html
re6d2f67 r26e030 8 8 9 9 <center> 10 <a href="tour-g mp.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> 11 11 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 12 12 <a href="tour-roadmap.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a> … … 406 406 <p> 407 407 408 408 409 <center> 409 <a href="tour-g mp.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> 410 411 <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 411 412 <a href="tour-roadmap.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a> -
ntl/doc/tour-unix.html
re6d2f67 r26e030 21 21 22 22 This procedure should work on most Unix or Unix-like platorms 23 (including M ACOSX, and Windows with Cygwin tools).23 (including Mac OSX, and Windows with Cygwin tools). 24 24 25 25 <p> … … 51 51 You will find the NTL header files in <tt>$HOME/sw/include/NTL</tt> 52 52 and the compiled binary 53 in <tt>$HOME/sw/lib/libntl.a</tt>. 53 in <tt>$HOME/sw/lib/libntl.a</tt> 54 (this is a <i>static</i> library -- if you want a <i>shared</i> 55 library, <a href="#shared">see below</a>). 54 56 <p> 55 57 If you really are interested in high-performace, you will … … 57 59 using GMP (the GNU Multi-Precision package). 58 60 If GMP has already been installed in a standard 59 system library, like <tt>/usr/local</tt>, then invoke <tt>configure</tt>61 place, like <tt>/usr/local</tt>, then invoke <tt>configure</tt> 60 62 above as 61 63 <pre> … … 63 65 </pre> 64 66 and if GMP is installed somewhere else, say <tt>$HOME/sw</tt>, then 67 either 65 68 <pre> 66 69 % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw 67 70 </pre> 71 or, more simply, 72 <pre> 73 % ./configure DEF_PREFIX=$HOME/sw NTL_GMP_LIP=on 74 </pre> 68 75 does the job. 76 Here, <tt>DEF_PREFIX</tt> is a variable that is used 77 to specify the location of all software, 78 and it defaults to <tt>/usr/local</tt>. 69 79 <a href="tour-gmp.html">This page</a> provides more 70 80 details. 81 82 <p> 83 If you want very high-performance for polynomial arithmetic 84 over <i>GF(2)</i>, you may want to consider using the <tt>gf2x</tt> library. 85 To do this, <tt>gf2x</tt> must already be installed somewhere. 86 In addition, you should invoke <tt>configure</tt> 87 with the option <tt>NTL_GF2X_LIB=on</tt>. 88 If <tt>gf2x</tt> is installed in a standard location, this is 89 all you need to do; 90 otherwise, if <tt>gf2x</tt> is installed, say, in <tt>$HOME/sw</tt>, 91 then 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 71 95 72 96 … … 78 102 The following should work: 79 103 <pre> 80 % g++ -I$HOME/sw/include -L$HOME/sw/lib foo.c -o foo -lntl-lm104 % g++ -I$HOME/sw/include foo.c -o foo -L$HOME/sw/lib -lntl -lm 81 105 </pre> 82 106 If you are using GMP, then: 83 107 <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> 110 If 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 86 115 87 116 <p> … … 145 174 <p> 146 175 <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 176 CC=gcc # The C compiler 177 CXX=g++ # The C++ compiler 178 CFLAGS=-O2 # C complilation flags 179 CXXFLAGS=$(CFLAGS) # C++ compilation flags (by default, same as CFLAGS) 180 181 DEF_PREFIX=/usr/local # Default software directory 182 PREFIX=$(DEF_PREFIX) # Directory in which to install NTL library components 183 SHARED=off # Generate a shared library (as well as static) 184 185 NTL_STD_CXX=on # ISO Mode switch 186 187 NTL_GMP_LIP=off # Switch to enable the use of GMP as primary 188 # long integer package 189 190 GMP_PREFIX=$(DEF_PREFIX) # Directory in which GMP components are installed 191 192 NTL_GF2X_LIB=off # Switch to enable the use of the gf2x package 193 # for faster arithmetic over GF(2)[X] 194 195 GF2X_PREFIX=$(DEF_PREFIX) # Directory in which gf2x components are installed 160 196 </pre> 161 197 … … 205 241 </pre> 206 242 Go <a href="tour-gmp.html">here</a> for complete details. 243 244 245 <p> 246 <li> 247 If <a href="tour-gf2x.html"><tt>gf2x</tt></a> 248 is installed in a standard system directory, and you want to use it 249 to obtain better performance for polynomial arithemtic over <i>GF(2)</i>, 250 run: 251 <pre> 252 % ./configure NTL_GF2X_LIB=on 253 </pre> 254 If <tt>gf2x</tt> was installed in 255 <tt>$HOME/sw</tt>, 256 run: 257 <pre> 258 % ./configure NTL_GF2X_LIB=on GF2X_PREFIX=$HOME/sw 259 </pre> 260 Go <a href="tour-gf2x.html">here</a> for complete details. 207 261 208 262 <p> … … 360 414 The file <tt>ntl.a</tt> is copied to <tt><prefix>/lib/libntl.a</tt>. 361 415 The files <tt>../doc/*</tt> are copied into 362 <tt><prefix>/ doc/NTL</tt>.416 <tt><prefix>/share/doc/NTL</tt>. 363 417 364 418 <p> … … 386 440 execute 387 441 <pre> 388 g++ -I<prefix>/include -L<prefix>/lib foo.c -o foo -lntl-lm442 g++ -I<prefix>/include foo.c -o foo -L<prefix>/lib -lntl -lm 389 443 </pre> 390 444 This compiles <tt>foo.c</tt> as a <tt>C++</tt> program … … 393 447 If you built NTL using <a href="tour-gmp.html">GMP</a>, execute: 394 448 <pre> 395 g++ -I<prefix>/include -L<prefix>/lib -L<gmp_prefix>/lib foo.c -lntl -lgmp-lm449 g++ -I<prefix>/include foo.c -o foo -L<prefix>/lib -lntl -L<gmp_prefix>/lib -lgmp -lm 396 450 </pre> 397 451 <p> … … 402 456 flags altogether. 403 457 <p> 458 Similarly, if you built NTL using <a href="tour-gf2x.html"><tt>gf2x</tt></a>, 459 you should include flags 460 <pre> 461 -L<gf2x_prefix>/lib -lgf2x 462 </pre> 463 on the command line. 464 <p> 404 465 This works even if you are not working in the directory 405 466 in which you built NTL. … … 408 469 make foo 409 470 </pre> 471 472 <p> 473 <h2> 474 <a name="shared"> 475 Building a Shared Library 476 </a> 477 </h2> 478 <p> 479 480 481 By default, the above installation procedure builds 482 a <i>static</i> library only. 483 Static libraries are nice because the procedures for building 484 and using them are nearly identical across various flavors 485 of Unix. 486 However, static libraries have their drawbacks, and sometimes 487 it is desirable to build a <i>shared</i> library. 488 This can be done (in theory) by simply passing <tt>SHARED=on</tt> to 489 NTL's <tt>configure</tt>. 490 491 <p> 492 If you set <tt>SHARED=on</tt>, then behind the scenes, 493 the procedure used by the <tt>makefile</tt> changes a bit. 494 In particular, the magical GNU program <tt>libtool</tt> is used 495 to deal with all idiosyncracies of shared libraries. 496 You may need to set the 497 configuration variable <tt>LIBTOOL</tt>, to point to another version of 498 <tt>libtool</tt>. 499 For example, on <i>Mac OSX</i>, the built-in command called <tt>libtool</tt> 500 is not 501 actually the GNU <tt>libtool</tt> program; 502 in this case, you will want to set 503 <tt>LIBTOOL=glibtool</tt>. 504 On other systems, it may be necssary to downlaod and 505 install a fresh copy of the libtool program (which can be obtained from 506 <a href="http://www.gnu.org/software/libtool">here</a>). 507 Note that if <tt>SHARED=on</tt>, then 508 in addition to using the <tt>libtool</tt> program, the <tt>makefile</tt> 509 relies on 510 features specific to GNU make. 511 512 <p> 513 Note that if you want to build NTL as a shared library, 514 then if you use them, GMP and <tt>gf2x</tt> must also 515 be built and installed as shared libraries. 516 Also note that to use a shared library version of NTL, 517 you may have to do something special, like set a special 518 shell variable: the output generated by the <tt>libtool</tt> 519 program during <tt>make install</tt> should give specific 520 instructions. 521 In addition, if NTL is built as a shared library, then 522 you typically do not have to include <tt>-lgmp</tt> (if using GMP), 523 or <tt>-lgf2x</tt> (if using <tt>gf2x</tt>), or corresponding 524 <tt>-L</tt> flags, or <tt>-lm</tt> 525 on 526 the command line when compiling programs that use NTL. 527 528 529 <p> 530 <h2> 531 <a name="abi"> 532 32-bit and 64-bit ABIs 533 </a> 534 </h2> 535 <p> 536 537 538 An ABI (Application Binary Interface) defines the sizes of various 539 <tt>C</tt> data types. 540 Typically, with a 32-bit ABI, int's and long's are 32 bits, 541 while on a 64-bit ABI, int's are 32 bits and long's are 64 bits. 542 Some platforms 543 support both 64-bit and 32-bit ABI's; 544 typically in such settings, the 64-bit ABI will yield much better 545 performance, while the 32-bit ABI is available for backward compatibility. 546 In addition, the 64-bit ABI may <i>not</i> be the default: 547 if you are using <tt>gcc</tt>, you need to pass the <tt>-m64</tt> 548 flag to the compiler to get the 64-bit ABI. 549 550 <p> 551 When compiling NTL, you may want to try running <tt>configure</tt> 552 with <tt>CFLAGS="-O2 -m64"</tt> to force a 64-bit ABI -- this 553 may yield a very marked performance improvement. 554 555 <p> 556 If you are using NTL with either the GMP or <tt>gf2x</tt> libraries, 557 then these must be built with the same ABI as NTL. 558 The installation script for GMP will typically select the 64-bit ABI 559 automatically if it is available. 560 The installation script for <tt>gf2x</tt> may need some hints. 561 562 <p> 563 When compiling programs that use NTL, you must also ensure that 564 the program is compiled with the same ABI as NTL. 565 Again, if you want a 64-bit ABI, then just pass the flag <tt>-m64</tt> 566 to the compiler. 567 568 569 410 570 411 571 -
ntl/doc/tour.html
re6d2f67 r26e030 74 74 75 75 <li> 76 <a href="tour-gf2x.html"> 77 Using NTL with the <tt>gf2x</tt> library 78 </a> 79 80 <li> 76 81 <a href="tour-time.html"> 77 82 Some Performance Data -
ntl/include/NTL/GF2X.h
re6d2f67 r26e030 99 99 inline long operator!=(GF2 a, const GF2X& b) { return !(a == b); } 100 100 inline long operator!=(long a, const GF2X& b) { return !(a == b); } 101 102 101 103 102 104 … … 184 186 185 187 void mul(GF2X& c, const GF2X& a, const GF2X& b); 188 void OldMul(GF2X& c, const GF2X& a, const GF2X& b); 186 189 187 190 void mul(GF2X& x, const GF2X& a, GF2 b); … … 471 474 { GF2X x; GCD(x, a, b); NTL_OPT_RETURN(GF2X, x); } 472 475 476 void OldGCD(GF2X& d, const GF2X& a, const GF2X& b); 477 478 473 479 void XGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b); 480 481 void OldXGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b); 482 474 483 475 484 void diff(GF2X& c, const GF2X& a); … … 586 595 void MinPolyInternal(GF2X& h, const GF2X& x, long m); 587 596 597 void OldMinPolyInternal(GF2X& h, const GF2X& x, long m); 598 599 588 600 589 601 struct GF2XTransMultiplier { -
ntl/include/NTL/WordVector.h
re6d2f67 r26e030 51 51 #endif 52 52 53 // controls release functionality 54 55 #define NTL_RELEASE_THRESH (10000) 56 // #define NTL_RELEASE_THRESH (0) 57 53 58 54 59 class WordVector { … … 69 74 ~WordVector(); 70 75 void kill(); 76 77 void release() { if (MaxLength() > NTL_RELEASE_THRESH) kill(); } 78 // this conditinally kills the vector, if its size is excessive 71 79 72 80 void DoSetLength(long n); -
ntl/include/NTL/ctools.h
re6d2f67 r26e030 259 259 260 260 double _ntl_ldexp(double x, long e); 261 262 void _ntl_abort(void); 263 /* This is the routine called by NTL to abort a program in case of error. */ 264 265 void _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 261 272 262 273 #if (defined(__cplusplus) && !defined(NTL_CXX_ONLY)) -
ntl/include/NTL/def_config.h
re6d2f67 r26e030 125 125 * This can result in significantly faster code on some platforms. 126 126 * 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 automatically127 * 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 129 129 * by the confiuration script when you pass the flag NTL_GMP_LIP=on 130 130 * to that script. … … 138 138 * rm *.o; make setup3; make ntl.a 139 139 * 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. 141 141 */ 142 142 … … 148 148 * This can result in significantly faster code on some platforms. 149 149 * 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 automatically150 * 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 152 152 * by the confiuration script when you pass the flag NTL_GMP_HACK=on 153 153 * to that script. … … 160 160 * rm lip.o; make setup3; make ntl.a 161 161 * 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 168 188 169 189 #if 0 -
ntl/include/NTL/mat_lzz_p.h
re6d2f67 r26e030 81 81 // functional variant of determinant 82 82 83 inline mat_zz_p transpose( mat_zz_p& a)83 inline mat_zz_p transpose(const mat_zz_p& a) 84 84 { mat_zz_p x; transpose(x, a); NTL_OPT_RETURN(mat_zz_p, x); } 85 85 -
ntl/include/NTL/new.h
re6d2f67 r26e030 13 13 #include <new> 14 14 15 #define NTL_NEW_OP ::new //(std::nothrow)15 #define NTL_NEW_OP new (std::nothrow) 16 16 17 17 -
ntl/include/NTL/tools.h
re6d2f67 r26e030 117 117 118 118 119 120 119 NTL_OPEN_NNS 120 121 extern void (*ErrorCallback)(); 121 122 122 123 struct INIT_SIZE_STRUCT { }; -
ntl/include/NTL/version.h
re6d2f67 r26e030 3 3 #define NTL_version__H 4 4 5 #define NTL_VERSION "5. 4.2"5 #define NTL_VERSION "5.5.1" 6 6 7 7 #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) 10 10 11 11 #endif -
ntl/src/DIRNAME
re6d2f67 r26e030 1 ntl-5. 4.21 ntl-5.5.1 -
ntl/src/DispSettings.c
re6d2f67 r26e030 43 43 #ifdef NTL_GMP_HACK 44 44 cout << "NTL_GMP_HACK\n"; 45 #endif 46 47 #ifdef NTL_GF2X_LIB 48 cout << "NTL_GF2X_LIB\n"; 45 49 #endif 46 50 -
ntl/src/DoConfig
re6d2f67 r26e030 7 7 8 8 'WIZARD' => 'on', 9 'SHARED' => 'off', 9 10 10 11 ); … … 19 20 'ARFLAGS' => 'ruv', 20 21 'RANLIB' => 'ranlib', 22 'LIBTOOL' => 'libtool', 23 21 24 'LDFLAGS' => '', 22 25 'LDFLAGS_CXX' => '$(LDFLAGS)', … … 24 27 'LDLIBS_CXX' => '$(LDLIBS)', 25 28 'CPPFLAGS' => '', 26 'PREFIX' => '/usr/local', 29 30 'DEF_PREFIX' => '/usr/local', 31 32 'PREFIX' => '$(DEF_PREFIX)', 27 33 'LIBDIR' => '$(PREFIX)/lib', 28 34 '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', 34 44 35 45 ); … … 46 56 'NTL_GMP_LIP' => 'off', 47 57 'NTL_GMP_HACK' => 'off', 58 'NTL_GF2X_LIB' => 'off', 48 59 'NTL_CXX_ONLY' => 'off', 49 60 'NTL_X86_FIX' => 'off', … … 106 117 } 107 118 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 121 if ($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 112 144 113 145 if ($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'} = ''; 135 147 } 136 148 else { 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 155 if ($ConfigFlag{'NTL_GF2X_LIB'} eq 'on') { 156 $MakeVal{'GF2X'} = ''; 157 } 158 else { 159 $MakeVal{'GF2X'} = '# '; 160 } 144 161 145 162 -
ntl/src/GF2X.c
re6d2f67 r26e030 4 4 5 5 #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 6 15 7 16 NTL_START_IMPL … … 696 705 697 706 707 #ifdef NTL_GF2X_LIB 708 709 698 710 void 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 849 void 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 858 void OldMul(GF2X& c, const GF2X& a, const GF2X& b) 859 #else 860 void mul(GF2X& c, const GF2X& a, const GF2X& b) 861 #endif 699 862 { 700 863 long sa = a.xrep.length(); … … 1102 1265 1103 1266 c.normalize(); 1104 } 1105 1267 1268 mem.release(); 1269 stk.release(); 1270 vec.release(); 1271 } 1106 1272 1107 1273 -
ntl/src/GF2X1.c
re6d2f67 r26e030 6 6 #include <NTL/new.h> 7 7 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 8 31 NTL_START_IMPL 9 32 … … 23 46 24 47 ~GF2XRegisterType() 25 { GF2XRegisterTop--; } 48 { xrep->xrep.release(); 49 GF2XRegisterTop--; } 26 50 27 51 operator GF2X& () { return *xrep; } … … 134 158 } 135 159 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 } 136 166 } 137 167 … … 220 250 } 221 251 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 } 222 258 } 223 259 … … 912 948 long bdiff3 = (n-k3) - wdiff3*NTL_BITS_PER_LONG; 913 949 914 static GF2X r;950 GF2XRegister(r); 915 951 r = a; 916 952 … … 1362 1398 r.normalize(); 1363 1399 } 1400 1401 GF2X_rembuf.release(); 1364 1402 } 1365 1403 … … 1518 1556 r.normalize(); 1519 1557 } 1558 1559 GF2X_rembuf.release(); 1520 1560 } 1521 1561 … … 1649 1689 } 1650 1690 } 1691 1692 GF2X_rembuf.release(); 1651 1693 } 1652 1694 … … 2065 2107 2066 2108 2067 void GCD(GF2X& d, const GF2X& a, const GF2X& b)2109 void OldGCD(GF2X& d, const GF2X& a, const GF2X& b) 2068 2110 { 2069 2111 long sa = a.xrep.length(); … … 2290 2332 2291 2333 2292 void XGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b)2334 void OldXGCD(GF2X& d, GF2X& s, GF2X& t, const GF2X& a, const GF2X& b) 2293 2335 { 2294 2336 long sa = a.xrep.length(); … … 2347 2389 long sf = f.xrep.length(); 2348 2390 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) { 2350 2393 GF2XRegister(t); 2351 2394 … … 2863 2906 2864 2907 2865 void MinPolyInternal(GF2X& h, const GF2X& x, long m)2908 void OldMinPolyInternal(GF2X& h, const GF2X& x, long m) 2866 2909 { 2867 2910 GF2X a, b, r, s; … … 3218 3261 3219 3262 3263 3264 // New versions of GCD, XGCD, and MinPolyInternal 3265 // and support routines 3266 3267 class _NTL_GF2XMatrix { 3268 private: 3269 3270 _NTL_GF2XMatrix(const _NTL_GF2XMatrix&); // disable 3271 GF2X elts[2][2]; 3272 3273 public: 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 3284 void _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 3293 static 3294 void 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 3309 static 3310 void 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 3340 static 3341 void 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 3376 static 3377 void 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 3447 static 3448 void 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 3491 void 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 3539 static 3540 void 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 3606 void 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 3666 void 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 3220 3685 NTL_END_IMPL -
ntl/src/InitSettings.c
re6d2f67 r26e030 51 51 #else 52 52 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"; 53 59 #endif 54 60 -
ntl/src/MakeDesc.c
re6d2f67 r26e030 794 794 } 795 795 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 } 796 804 797 805 -
ntl/src/QuickTest.c
re6d2f67 r26e030 2 2 #include <NTL/ZZ_pX.h> 3 3 #include <NTL/lzz_pX.h> 4 #include <NTL/GF2X.h> 4 5 5 6 #include <NTL/version.h> … … 36 37 37 38 39 int 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 58 void 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 } 38 101 39 102 … … 70 133 cerr << "NTL_GMP_HACK\n"; 71 134 #endif 135 136 #ifdef NTL_GF2X_LIB 137 cerr << "NTL_GF2X_LIB\n"; 138 #endif 139 72 140 73 141 #ifdef NTL_LONG_LONG_TYPE … … 172 240 173 241 if (_ntl_gmp_hack) 174 cerr << "using GMP hack\n"; 242 cerr << "using GMP hack\n\n"; 243 244 cerr << "running tests..."; 175 245 176 246 long n, k; … … 242 312 } 243 313 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"; 245 323 246 324 ZZ x1, x2, x3, x4; … … 369 447 cerr << "\n"; 370 448 449 GF2X_time(); 450 371 451 return 0; 372 452 } -
ntl/src/RemoveProg
re6d2f67 r26e030 4 4 rm -f $i 5 5 rm -f $i.exe 6 rm -f .libs/$i 7 rm -f .libs/$i.exe 6 8 done 9 10 exit 0 7 11 -
ntl/src/TestScript
re6d2f67 r26e030 50 50 ./MoreFacTest < MoreFacTestIn 51 51 sh RemoveProg MoreFacTest 52 53 echo 54 echo "---------------------------------" 55 echo "making GF2XTest" 56 make GF2XTest 57 echo "running GF2XTest" 58 ./GF2XTest 59 sh RemoveProg GF2XTest 52 60 53 61 echo -
ntl/src/WINDIR
re6d2f67 r26e030 1 WinNTL-5_ 4_21 WinNTL-5_5_1 -
ntl/src/Wizard
re6d2f67 r26e030 21 21 fi 22 22 23 rm -r small23 rm -rf small 24 24 25 25 mkdir small … … 89 89 90 90 91 92 91 cd small/src 93 92 perl WizardAux -
ntl/src/WizardAux
re6d2f67 r26e030 91 91 'NTL_GF2X_NOINLINE' => 0, 92 92 93 'WIZARD_HACK' => '#define NTL_ OLD_ZZ_pX_MUL',93 'WIZARD_HACK' => '#define NTL_WIZARD_HACK', 94 94 95 95 ); -
ntl/src/ZZX.c
re6d2f67 r26e030 115 115 116 116 m = deg(x); 117 118 if (i > m && IsZero(a)) return; 117 119 118 120 if (i > m) { -
ntl/src/ZZ_pEX.c
re6d2f67 r26e030 104 104 105 105 m = deg(x); 106 107 if (i > m && IsZero(a)) return; 106 108 107 109 if (i > m) { … … 143 145 144 146 m = deg(x); 147 148 if (i > m && IsZero(a)) return; 145 149 146 150 if (i > m) { -
ntl/src/ZZ_pX.c
re6d2f67 r26e030 8 8 9 9 10 #ifndef NTL_ OLD_ZZ_pX_MUL10 #ifndef NTL_WIZARD_HACK 11 11 12 12 #include <NTL/ZZX.h> … … 95 95 96 96 m = deg(x); 97 98 if (i > m && IsZero(a)) return; 97 99 98 100 if (i > m) { … … 419 421 420 422 421 #ifndef NTL_ OLD_ZZ_pX_MUL423 #ifndef NTL_WIZARD_HACK 422 424 423 425 // These crossovers are tuned for a Pentium, but hopefully -
ntl/src/c_lip_impl.h
re6d2f67 r26e030 23 23 fprintf(stderr,"fatal error:\n %s\nexit...\n",c); 24 24 fflush(stderr); 25 abort();25 _ntl_abort(); 26 26 } 27 27 … … 35 35 #define NTL_GMP_SQRT_CROSS (2) 36 36 #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) 39 39 40 40 #ifdef NTL_GMP_HACK … … 4819 4819 */ 4820 4820 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); 4827 4822 _ntl_zcopy(v, invv); 4828 4823 return 0; … … 4889 4884 if (_ntl_gmp_hack && 4890 4885 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 4891 4890 GT_INIT 4891 4892 4892 4893 4893 4894 lip_to_mpz(aa, gt_1); 4894 4895 lip_to_mpz(bb, gt_2); 4895 4896 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); 4902 4943 return; 4903 4944 } -
ntl/src/cfile
re6d2f67 r26e030 125 125 * This can result in significantly faster code on some platforms. 126 126 * 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 automatically127 * 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 129 129 * by the confiuration script when you pass the flag NTL_GMP_LIP=on 130 130 * to that script. … … 138 138 * rm *.o; make setup3; make ntl.a 139 139 * 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. 141 141 */ 142 142 … … 148 148 * This can result in significantly faster code on some platforms. 149 149 * 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 automatically150 * 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 152 152 * by the confiuration script when you pass the flag NTL_GMP_HACK=on 153 153 * to that script. … … 160 160 * rm lip.o; make setup3; make ntl.a 161 161 * 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 168 188 169 189 #if @{FLAG_LONG_LONG_TYPE} -
ntl/src/ctools.c
re6d2f67 r26e030 78 78 79 79 80 void _ntl_abort(void) 81 { 82 _ntl_abort_cxx_callback(); 83 abort(); 84 } 80 85 86 87 -
ntl/src/def_makefile
re6d2f67 r26e030 24 24 # Some useful flags: 25 25 # -O2 -- recommended level of optimization 26 # -m64 -- needed to get 64-bit longs on some platforms 26 27 # -g -- debugging 27 28 # -mcpu=v8 -- needed with gcc/g++ to get the full instruction set … … 51 52 52 53 LDFLAGS= 53 # arguments for linker for C ++programs54 # arguments for linker for C programs 54 55 55 56 LDFLAGS_CXX=$(LDFLAGS) 57 # libraries for linking C++ programs 58 59 LDLIBS=-lm 56 60 # libraries for linking C programs 57 58 LDLIBS=-lm59 # libraries for linking C++ programs60 61 61 62 LDLIBS_CXX=$(LDLIBS) … … 65 66 # arguments for the C preprocessor 66 67 67 PREFIX=/usr/local 68 LIBTOOL=libtool 69 # libtool command 70 71 DEF_PREFIX=/usr/local 72 73 PREFIX=$(DEF_PREFIX) 68 74 LIBDIR=$(PREFIX)/lib 69 75 INCLUDEDIR=$(PREFIX)/include 70 DOCDIR=$(PREFIX)/ doc76 DOCDIR=$(PREFIX)/share/doc 71 77 # where to install NTL 72 78 … … 74 80 # 75 81 # 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. 78 83 # You also will have to set either NTL_GMP_LIP or NTL_GMP_HACK 79 84 # in the config.h file. … … 88 93 89 94 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 95 GMP_PREFIX=$(DEF_PREFIX) 96 97 GMP_INCDIR=$(GMP_PREFIX)/include 98 # directory containing gmp.h if using GMP 99 100 GMP_LIBDIR=$(GMP_PREFIX)/lib 101 # directory containing libgmp.a if using GMP 102 103 GMP_OPT_INCDIR=# -I$(GMP_INCDIR) # GMP 104 GMP_OPT_LIBDIR=# -L$(GMP_LIBDIR) # GMP 105 GMP_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 119 GF2X_PREFIX=$(DEF_PREFIX) 120 121 GF2X_INCDIR=$(GF2X_PREFIX)/include 122 # directory containing gf2x.h if using gf2x 123 124 GF2X_LIBDIR=$(GF2X_PREFIX)/lib 125 # directory containing libgf2x.a 126 127 GF2X_OPT_INCDIR=# -I$(GF2X_INCDIR) # GF2X 128 GF2X_OPT_LIBDIR=# -L$(GF2X_LIBDIR) # GF2X 129 GF2X_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 104 136 # sets some performace related flags in config.h, set the flag below. 105 137 # … … 214 246 TS1=QuickTest.c BerlekampTest.c CanZassTest.c ZZXFacTest.c MoreFacTest.c LLLTest.c 215 247 TS2=$(TS1) subset.c MatrixTest.c CharPolyTest.c RRTest.c QuadTest.c 216 TS3=$(TS2) GF2 EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c248 TS3=$(TS2) GF2XTest.c GF2EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c 217 249 218 250 TS = $(TS3) … … 252 284 D16=$(D15) tour.html tour-ex1.html tour-ex2.html tour-ex3.html tour-ex4.html 253 285 D17=$(D16) tour-ex5.html tour-ex6.html arrow1.gif arrow2.gif arrow3.gif 254 D18=$(D17) tour-gmp.html config.txt version.txt286 D18=$(D17) tour-gmp.html tour-gf2x.html tour-tips.html config.txt version.txt 255 287 256 288 DOC = $(D18) … … 262 294 PROG1=QuickTest BerlekampTest CanZassTest ZZXFacTest MoreFacTest LLLTest BitMatTest 263 295 PROG2=$(PROG1) MatrixTest CharPolyTest RRTest QuadTest 264 PROG3=$(PROG2) GF2 EXTest subset ZZ_pEXTest lzz_pEXTest296 PROG3=$(PROG2) GF2XTest GF2EXTest subset ZZ_pEXTest lzz_pEXTest 265 297 PROGS = $(PROG3) 266 298 … … 290 322 291 323 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. 292 329 293 330 all: … … 297 334 make setup4 298 335 make ntl.a 336 touch all 299 337 300 338 … … 319 357 320 358 setup3: 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) 322 360 ./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) 324 362 ./gen_gmp_aux > ../include/NTL/gmp_aux.h 325 363 … … 331 369 332 370 ntl.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 375 LCOMP= #LSTAT 376 # LCOMP=$(LIBTOOL) --mode=compile #LSHAR 335 377 336 378 lip.o: lip.c g_lip_impl.h c_lip_impl.h lip_gmp_aux_impl.h 337 $( COMPILE) $(GMP_INCDIR) lip.c379 $(LCOMP) $(COMPILE) $(GMP_OPT_INCDIR) lip.c 338 380 339 381 ctools.o: ctools.c 340 $( COMPILE) ctools.c382 $(LCOMP) $(COMPILE) ctools.c 341 383 342 384 343 385 GetTime.o: GetTime.c 344 $(COMPILE) GetTime.c 386 $(LCOMP) $(COMPILE) GetTime.c 387 345 388 346 389 347 390 .c.o: 348 $( COMPILE_CXX) $<391 $(LCOMP) $(COMPILE_CXX) $(GF2X_OPT_INCDIR) $< 349 392 350 393 .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 352 396 353 397 ################################################################# … … 359 403 360 404 check: 405 sh RemoveProg $(PROGS) 361 406 make QuickTest 362 407 ./QuickTest 363 -sh RemoveProg QuickTest408 sh RemoveProg QuickTest 364 409 sh TestScript 365 410 … … 381 426 382 427 install: 383 mkdir -p -m 755 $(LIBDIR)384 cp -p ntl.a $(LIBDIR)/libntl.a385 - chmod a+r $(LIBDIR)/libntl.a386 428 mkdir -p -m 755 $(INCLUDEDIR) 387 - rm -r$(INCLUDEDIR)/NTL429 rm -rf $(INCLUDEDIR)/NTL 388 430 mkdir -m 755 $(INCLUDEDIR)/NTL 389 431 cp -p ../include/NTL/*.h $(INCLUDEDIR)/NTL 390 432 - chmod -R a+r $(INCLUDEDIR)/NTL 391 433 mkdir -p -m 755 $(DOCDIR) 392 - rm -r$(DOCDIR)/NTL434 rm -rf $(DOCDIR)/NTL 393 435 mkdir -m 755 $(DOCDIR)/NTL 394 436 cp -p ../doc/*.txt $(DOCDIR)/NTL … … 396 438 cp -p ../doc/*.gif $(DOCDIR)/NTL 397 439 - 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 398 444 399 445 400 446 uninstall: 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 404 451 405 452 ################################################################# … … 415 462 416 463 clobber: 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 422 472 423 473 clean: 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 427 478 428 479 ################################################################# … … 438 489 439 490 package: 440 sh unixify "$(SFILES) DIRNAME WINDIR " "$(INCL)" "$(DOC)"441 -rm -rf `cat DIRNAME`442 -rm -f `cat DIRNAME`.tar443 -rm -f `cat DIRNAME`.tar.gz491 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 444 495 mv unix `cat DIRNAME` 445 496 chmod -R a+rX `cat DIRNAME` 446 497 tar -cvf `cat DIRNAME`.tar `cat DIRNAME` 447 498 gzip `cat DIRNAME`.tar 448 -rm -rf `cat DIRNAME`499 rm -rf `cat DIRNAME` 449 500 450 501 winpack: 451 502 sh dosify "$(SRC)" "$(INCL)" "$(DOC)" "$(TS)" "$(TD)" "$(SINC)" 452 -rm -rf `cat WINDIR`453 -rm -f `cat WINDIR`.zip503 rm -rf `cat WINDIR` 504 rm -f `cat WINDIR`.zip 454 505 mv dos `cat WINDIR` 455 506 chmod -R a+rX `cat WINDIR` … … 471 522 WOBJ = $(WO3) 472 523 473 524 # wntl.a: LCOMP= #LSHAR 474 525 wntl.a: $(WOBJ) 475 526 $(AR) $(ARFLAGS) wntl.a $(WOBJ) 476 527 - $(RANLIB) wntl.a 477 528 478 479 480 529 MulTimeTest: 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) 482 531 483 532 PolyTimeTest: 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) 485 534 486 535 Poly1TimeTest: 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) 488 537 489 538 490 539 GF2XTimeTest: 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) 492 541 493 542 InitSettings: … … 500 549 501 550 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 14 14 15 15 if (!s) { 16 cerr << "open write error: " << name << "\n";17 abort();16 cerr << "open write error: " << name; 17 Error(""); 18 18 } 19 19 } … … 24 24 s.open(name, ios::in); 25 25 if (!s) { 26 cerr << "open read error: " << name << "\n";27 abort();26 cerr << "open read error: " << name; 27 Error(""); 28 28 } 29 29 } -
ntl/src/g_lip_impl.h
re6d2f67 r26e030 331 331 332 332 333 /* ForceNormal ensures a normalized bigint */ 334 335 static 336 void 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 333 349 334 350 static … … 337 353 fprintf(stderr,"fatal error:\n %s\nexit...\n",c); 338 354 fflush(stderr); 339 abort();355 _ntl_abort(); 340 356 } 341 357 … … 2421 2437 SIZE(xa) = sxa; 2422 2438 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 2423 2486 if (aneg) _ntl_gnegate(&xa); 2424 2487 … … 2490 2553 SIZE(u) = su; 2491 2554 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 2492 2561 if (ONEP(d)) { 2493 2562 … … 2497 2566 */ 2498 2567 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 } 2501 2581 2502 2582 _ntl_gcopy(u, invv); -
ntl/src/lzz_pEX.c
re6d2f67 r26e030 106 106 107 107 m = deg(x); 108 109 if (i > m && IsZero(a)) return; 108 110 109 111 if (i > m) { … … 146 148 147 149 m = deg(x); 150 151 if (i > m && IsZero(a)) return; 148 152 149 153 if (i > m) { -
ntl/src/lzz_pX.c
re6d2f67 r26e030 75 75 76 76 m = deg(x); 77 78 if (i > m && IsZero(a)) return; 77 79 78 80 if (i > m) { -
ntl/src/lzz_pX1.c
re6d2f67 r26e030 1624 1624 1625 1625 if (F.tracevec.length() == 0) 1626 TraceVec(F);1626 ComputeTraceVec(F); 1627 1627 1628 1628 InnerProduct(x, a.rep, F.tracevec); -
ntl/src/mfile
re6d2f67 r26e030 24 24 # Some useful flags: 25 25 # -O2 -- recommended level of optimization 26 # -m64 -- needed to get 64-bit longs on some platforms 26 27 # -g -- debugging 27 28 # -mcpu=v8 -- needed with gcc/g++ to get the full instruction set … … 51 52 52 53 LDFLAGS=@{LDFLAGS} 53 # arguments for linker for C ++programs54 # arguments for linker for C programs 54 55 55 56 LDFLAGS_CXX=@{LDFLAGS_CXX} 57 # libraries for linking C++ programs 58 59 LDLIBS=@{LDLIBS} 56 60 # libraries for linking C programs 57 58 LDLIBS=@{LDLIBS}59 # libraries for linking C++ programs60 61 61 62 LDLIBS_CXX=@{LDLIBS_CXX} … … 64 65 CPPFLAGS=@{CPPFLAGS} 65 66 # arguments for the C preprocessor 67 68 LIBTOOL=@{LIBTOOL} 69 # libtool command 70 71 DEF_PREFIX=@{DEF_PREFIX} 66 72 67 73 PREFIX=@{PREFIX} … … 74 80 # 75 81 # 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. 78 83 # You also will have to set either NTL_GMP_LIP or NTL_GMP_HACK 79 84 # in the config.h file. … … 88 93 89 94 95 GMP_PREFIX=@{GMP_PREFIX} 96 90 97 GMP_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 93 99 94 100 GMP_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 103 GMP_OPT_INCDIR=@{GMP}-I$(GMP_INCDIR) # GMP 104 GMP_OPT_LIBDIR=@{GMP}-L$(GMP_LIBDIR) # GMP 105 GMP_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 119 GF2X_PREFIX=@{GF2X_PREFIX} 120 121 GF2X_INCDIR=@{GF2X_INCDIR} 122 # directory containing gf2x.h if using gf2x 123 124 GF2X_LIBDIR=@{GF2X_LIBDIR} 125 # directory containing libgf2x.a 126 127 GF2X_OPT_INCDIR=@{GF2X}-I$(GF2X_INCDIR) # GF2X 128 GF2X_OPT_LIBDIR=@{GF2X}-L$(GF2X_LIBDIR) # GF2X 129 GF2X_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 104 136 # sets some performace related flags in config.h, set the flag below. 105 137 # … … 214 246 TS1=QuickTest.c BerlekampTest.c CanZassTest.c ZZXFacTest.c MoreFacTest.c LLLTest.c 215 247 TS2=$(TS1) subset.c MatrixTest.c CharPolyTest.c RRTest.c QuadTest.c 216 TS3=$(TS2) GF2 EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c248 TS3=$(TS2) GF2XTest.c GF2EXTest.c BitMatTest.c ZZ_pEXTest.c lzz_pEXTest.c 217 249 218 250 TS = $(TS3) … … 252 284 D16=$(D15) tour.html tour-ex1.html tour-ex2.html tour-ex3.html tour-ex4.html 253 285 D17=$(D16) tour-ex5.html tour-ex6.html arrow1.gif arrow2.gif arrow3.gif 254 D18=$(D17) tour-gmp.html config.txt version.txt286 D18=$(D17) tour-gmp.html tour-gf2x.html tour-tips.html config.txt version.txt 255 287 256 288 DOC = $(D18) … … 262 294 PROG1=QuickTest BerlekampTest CanZassTest ZZXFacTest MoreFacTest LLLTest BitMatTest 263 295 PROG2=$(PROG1) MatrixTest CharPolyTest RRTest QuadTest 264 PROG3=$(PROG2) GF2 EXTest subset ZZ_pEXTest lzz_pEXTest296 PROG3=$(PROG2) GF2XTest GF2EXTest subset ZZ_pEXTest lzz_pEXTest 265 297 PROGS = $(PROG3) 266 298 … … 290 322 291 323 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. 292 329 293 330 all: … … 297 334 make setup4 298 335 make ntl.a 336 touch all 299 337 300 338 … … 319 357 320 358 setup3: 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) 322 360 ./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) 324 362 ./gen_gmp_aux > ../include/NTL/gmp_aux.h 325 363 … … 331 369 332 370 ntl.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 335 377 336 378 lip.o: lip.c g_lip_impl.h c_lip_impl.h lip_gmp_aux_impl.h 337 $( COMPILE) $(GMP_INCDIR) lip.c379 $(LCOMP) $(COMPILE) $(GMP_OPT_INCDIR) lip.c 338 380 339 381 ctools.o: ctools.c 340 $( COMPILE) ctools.c382 $(LCOMP) $(COMPILE) ctools.c 341 383 342 384 343 385 GetTime.o: GetTime.c 344 $(COMPILE) GetTime.c 386 $(LCOMP) $(COMPILE) GetTime.c 387 345 388 346 389 347 390 .c.o: 348 $( COMPILE_CXX) $<391 $(LCOMP) $(COMPILE_CXX) $(GF2X_OPT_INCDIR) $< 349 392 350 393 .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 352 396 353 397 ################################################################# … … 359 403 360 404 check: 405 sh RemoveProg $(PROGS) 361 406 make QuickTest 362 407 ./QuickTest 363 -sh RemoveProg QuickTest408 sh RemoveProg QuickTest 364 409 sh TestScript 365 410 … … 381 426 382 427 install: 383 mkdir -p -m 755 $(LIBDIR)384 cp -p ntl.a $(LIBDIR)/libntl.a385 - chmod a+r $(LIBDIR)/libntl.a386 428 mkdir -p -m 755 $(INCLUDEDIR) 387 - rm -r$(INCLUDEDIR)/NTL429 rm -rf $(INCLUDEDIR)/NTL 388 430 mkdir -m 755 $(INCLUDEDIR)/NTL 389 431 cp -p ../include/NTL/*.h $(INCLUDEDIR)/NTL 390 432 - chmod -R a+r $(INCLUDEDIR)/NTL 391 433 mkdir -p -m 755 $(DOCDIR) 392 - rm -r$(DOCDIR)/NTL434 rm -rf $(DOCDIR)/NTL 393 435 mkdir -m 755 $(DOCDIR)/NTL 394 436 cp -p ../doc/*.txt $(DOCDIR)/NTL … … 396 438 cp -p ../doc/*.gif $(DOCDIR)/NTL 397 439 - 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 398 444 399 445 400 446 uninstall: 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 404 451 405 452 ################################################################# … … 415 462 416 463 clobber: 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 422 472 423 473 clean: 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 427 478 428 479 ################################################################# … … 438 489 439 490 package: 440 sh unixify "$(SFILES) DIRNAME WINDIR " "$(INCL)" "$(DOC)"441 -rm -rf `cat DIRNAME`442 -rm -f `cat DIRNAME`.tar443 -rm -f `cat DIRNAME`.tar.gz491 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 444 495 mv unix `cat DIRNAME` 445 496 chmod -R a+rX `cat DIRNAME` 446 497 tar -cvf `cat DIRNAME`.tar `cat DIRNAME` 447 498 gzip `cat DIRNAME`.tar 448 -rm -rf `cat DIRNAME`499 rm -rf `cat DIRNAME` 449 500 450 501 winpack: 451 502 sh dosify "$(SRC)" "$(INCL)" "$(DOC)" "$(TS)" "$(TD)" "$(SINC)" 452 -rm -rf `cat WINDIR`453 -rm -f `cat WINDIR`.zip503 rm -rf `cat WINDIR` 504 rm -f `cat WINDIR`.zip 454 505 mv dos `cat WINDIR` 455 506 chmod -R a+rX `cat WINDIR` … … 471 522 WOBJ = $(WO3) 472 523 473 524 @{LSHAR}wntl.a: LCOMP= #LSHAR 474 525 wntl.a: $(WOBJ) 475 526 $(AR) $(ARFLAGS) wntl.a $(WOBJ) 476 527 - $(RANLIB) wntl.a 477 528 478 479 480 529 MulTimeTest: 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) 482 531 483 532 PolyTimeTest: 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) 485 534 486 535 Poly1TimeTest: 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) 488 537 489 538 490 539 GF2XTimeTest: 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) 492 541 493 542 InitSettings: … … 500 549 501 550 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 8 8 #include <NTL/new.h> 9 9 10 void _ntl_abort_cxx_callback(void) 11 { 12 if (NTL_NNS ErrorCallback) (*NTL_NNS ErrorCallback)(); 13 } 14 10 15 NTL_START_IMPL 11 16 17 void (*ErrorCallback)() = 0; 12 18 13 19 void Error(const char *s) 14 20 { 15 21 printf("%s\n", s ); 16 abort();22 _ntl_abort(); 17 23 } 18 24
Note: See TracChangeset
for help on using the changeset viewer.