From 9f7e11f28e0fd62f73b92c937c70b8c1e03386d0 Mon Sep 17 00:00:00 2001 From: simonm Date: Fri, 5 Jun 1998 14:37:45 +0000 Subject: [PATCH] [project @ 1998-06-05 14:37:45 by simonm] Import GMP 2.0.2 --- ghc/rts/gmp/INSTALL | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ ghc/rts/gmp/NEWS | 56 +++++++++++++++++++ ghc/rts/gmp/README | 137 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 ghc/rts/gmp/INSTALL create mode 100644 ghc/rts/gmp/NEWS create mode 100644 ghc/rts/gmp/README diff --git a/ghc/rts/gmp/INSTALL b/ghc/rts/gmp/INSTALL new file mode 100644 index 0000000..38bfaa8 --- /dev/null +++ b/ghc/rts/gmp/INSTALL @@ -0,0 +1,154 @@ +INSTALLING GMP +============== + +These instructions are only for the impatient. Others should read the install +instructions in the manual, gmp.info. Use "info -f gmp.info", or, if you +don't have info, use type "C-h i g (gmp.info)Top" in emacs. + +Here are short instructions how to install MP, and some examples that help you +get started using MP. + +First, you need to compile, and optionally install, MP. Since you're +impatient, try this: + + ./configure; make + +If that fails, or you care about the performance of MP, you need to read the +full instructions in the chapter "Installing MP", in the manual. + +Next, you need to try some small test programs, for example the ones below. + +In MP programs, all variables need to be initialized before they are assigned, +and cleared out before program flow leaves the scope in which it was declared. +Here is an example of a program that reads two numbers from the command line, +multiplies them, and prints the result to stdout. + + #include + #include /* All MP programs need to include gmp.h */ + + main (int argc, char **argv) + { + mpz_t a, b, p; + + /* Initialize variables */ + mpz_init (a); + mpz_init (b); + mpz_init (p); + + /* Assign a and b from base 10 strings in argv */ + mpz_set_str (a, argv[1], 10); + mpz_set_str (b, argv[2], 10); + + /* Multiply a and b and put the result in p */ + mpz_mul (p, a, b); + + /* Print p in base 10 */ + mpz_out_str (stdout, 10, p); + fputc ('\n', stdout); + + /* Clear out variables */ + mpz_clear (a); + mpz_clear (b); + mpz_clear (p); + exit (0); + } + + +In practice, that example would be written like this instead: + + #include + #include + + main (int argc, char **argv) + { + mpz_t a, b, p; + + /* Initialize and assign a and b from base 10 strings in argv */ + mpz_init_set_str (a, argv[1], 10); + mpz_init_set_str (b, argv[2], 10); + /* Initialize p */ + mpz_init (p); + + /* Multiply a and b and put the result in p */ + mpz_mul (p, a, b); + + /* Print p in base 10 */ + mpz_out_str (stdout, 10, p); + fputc ('\n', stdout); + + /* Since we're about to exit, no need to clear out variables */ + exit (0); + } + +Finally, you have to compile your test program, and link it with the MP +library. Assuming your working directory is still the gmp source directory, +type: + + gcc -g -I. example.c libgmp.a + + +Now try to run the example: + + a.out 98365871231256752134 319378318340103345227 + 31415926535897932384618573336104570964418 + +The functions used here all operate on the domain of signed integers. +Functions operating on that domain have names starting with "mpz_". There are +many more such functions than used in these examples. See the chapter +"Integer Functions" in the manual, for a complete list. + +There are two other main classes of functions in MP. They operate on rational +numbers and floating-point numbers, respectively. The chapters "Rational +Number Functions", and "Floating-point Functions" documents these classes. + +To run a set of tests, do "make check". This will take a while. + +To create the printable documentation from the texinfo source, type "make +dvi". This requires the "tex" command to be available in your search path. + +To install the library, do "make install". + +If you decide to use MP, It is a good idea you read at least the chapter "MP +Basics" in the manual. + + +Known Build Problems +-------------------- + +Note that GCC 2.7.2 (as well as 2.6.3) for the RS/6000 and PowerPC can not +be used to compile GMP, due to a bug in GCC. If you want to use GCC, you +need to apply the patch at the end of this file, or use a later version of +the compiler. + +If you are on a Sequent Symmetry, use GAS instead of the system's assembler +due to the latter's serious bugs. + +The system compiler on NeXT is a massacred and old gcc, even if the +compiler calls itself cc. This compiler cannot be used to build GMP. You +need to get a real gcc, and install that before you compile GMP. (NeXT +might have fixed this in newer releases of their system.) + +Please report other problems to bug-gmp@prep.ai.mit.edu. + + +Patch to apply to GCC 2.6.3 and 2.7.2: + +*** config/rs6000/rs6000.md Sun Feb 11 08:22:11 1996 +--- config/rs6000/rs6000.md.new Sun Feb 18 03:33:37 1996 +*************** +*** 920,926 **** + (set (match_operand:SI 0 "gpc_reg_operand" "=r") + (not:SI (match_dup 1)))] + "" +! "nor. %0,%2,%1" + [(set_attr "type" "compare")]) + + (define_insn "" +--- 920,926 ---- + (set (match_operand:SI 0 "gpc_reg_operand" "=r") + (not:SI (match_dup 1)))] + "" +! "nor. %0,%1,%1" + [(set_attr "type" "compare")]) + + (define_insn "" diff --git a/ghc/rts/gmp/NEWS b/ghc/rts/gmp/NEWS new file mode 100644 index 0000000..b61c840 --- /dev/null +++ b/ghc/rts/gmp/NEWS @@ -0,0 +1,56 @@ +NOTEWORTHY CHANGES IN GNU MP IN VERSION 2 + +* Division routines in the mpz class have changed. There are three classes of + functions, that rounds the quotient to -infinity, 0, and +infinity, + respectively. The first class of functions have names that begin with + mpz_fdiv (f is short for floor), the second class' names begin with mpz_tdiv + (t is short for trunc), and the third class' names begin with mpz_cdiv (c is + short for ceil). + + The old division routines beginning with mpz_m are similar to the new + mpz_fdiv, with the exception that some of the new functions return useful + values. + + The old function names can still be used. All the old functions names will + now do floor division, not trunc division as some of them used to. This was + changed to make the functions more compatible with common mathematical + practice. + + The mpz_mod and mpz_mod_ui functions now compute the mathematical mod + function. I.e., the sign of the 2nd argument is ignored. + +* The mpq assignment functions do not canonicalize their results. A new + function, mpq_canonicalize must be called by the user if the result is not + known to be canonical. +* The mpn functions are now documented. These functions are intended for + very time critical applications, or applications that need full control over + memory allocation. Note that the mpn interface is irregular and hard to + use. +* New functions for arbitrary precision floating point arithmetic. Names + begin with `mpf_'. Associated type mpf_t. +* New and improved mpz functions, including much faster GCD, fast exact + division (mpz_divexact), bit scan (mpz_scan0 and mpz_scan1), and number + theoretical functions like Jacobi (mpz_jacobi) and multiplicative inverse + (mpz_invert). +* New variable types (mpz_t and mpq_t) are available that makes syntax of + mpz and mpq calls nicer (no need for & before variables). The MP_INT and + MP_RAT types are still available for compatibility. +* Uses GNU configure. This makes it possible to choose target architecture + and CPU variant, and to compile into a separate object directory. +* Carefully optimized assembly for important inner loops. Support for DEC + Alpha, Amd 29000, HPPA 1.0 and 1.1, Intel pentium and generic x86, Intel + i960, Motorola MC68000, MC68020, MC88100, and MC88110, Motorola/IBM + PowerPC, National NS32000, IBM POWER, MIPS R3000, R4000, SPARCv7, + SuperSPARC, generic SPARCv8, and DEC VAX. Some support also for ARM, + Clipper, IBM ROMP (RT), and Pyramid AP/XP. +* Faster. Thanks to the assembler code, new algorithms, and general tuning. + In particular, the speed on machines without GCC is improved. +* Support for machines without alloca. +* Now under the LGPL. + +INCOMPATIBILITIES BETWEEN GMP 1 AND GMP 2 + +* mpq assignment functions do not canonicalize their results. +* mpz division functions round differently. +* mpz mod functions now really compute mod. +* mpz_powm and mpz_powm_ui now really use mod for reduction. diff --git a/ghc/rts/gmp/README b/ghc/rts/gmp/README new file mode 100644 index 0000000..3afa677 --- /dev/null +++ b/ghc/rts/gmp/README @@ -0,0 +1,137 @@ + THE GNU MP LIBRARY + + +GNU MP is a library for arbitrary precision arithmetic, operating on signed +integers, rational numbers, and floating point numbers. It has a rich set +of functions, and the functions have a regular interface. + +GNU MP is designed to be as fast as possible, both for small operands and for +huge operands. The speed is achieved by using fullwords as the basic +arithmetic type, by using fast algorithms, by carefully optimized assembly +code for the most common inner loops for a lots of CPUs, and by a general +emphasis on speed (instead of simplicity or elegance). + +The speed of GNU MP is believed to be faster than any other similar library. +The advantage for GNU MP increases with the operand sizes for certain +operations, since GNU MP in many cases has asymptotically faster algorithms. + + + GETTING STARTED + +First, you have to configure and compiler GNU MP. Simply typing + + ./configure; make + +will normally do a reasonable job, but will not give optimal library +execution speed. So unless you're very unpatient, please read the detailed +instructions in the file INSTALL or in gmp.texi. + +Once you have compiled the library, you should write some small example, and +make sure you can compile them. A typical compilation command is this: + + gcc -g your-file.c -I libgmp.a -lm + +If you have installed the library, you can simply do: + + gcc -g your-file.c -lgmp -lm + +The -lm is normally not needed, since only a few functions in GNU MP use the +math library. + +Here is a sample program that declares 2 variables, initializes them as +required, and sets one of them from a signed integer, and the other from a +string of digits. It then prints the product of the two numbers in base 10. + + #include + #include "gmp.h" + + main () + { + mpz_t a, b, p; + + mpz_init (a); /* initialize variables */ + mpz_init (b); + mpz_init (p); + + mpz_set_si (a, 756839); /* assign variables */ + mpz_set_str (b, "314159265358979323846", 0); + mpz_mul (p, a, b); /* generate product */ + mpz_out_str (stdout, 10, p); /* print number without newline */ + puts (""); /* print newline */ + + mpz_clear (a); /* clear out variables */ + mpz_clear (b); + mpz_clear (p); + + exit (0); + } + +This might look tedious, with all initializing and clearing. Fortunately +some of these operations can be combined, and other operations can often be +avoided. The example above would be written differently by an experienced +GNU MP user: + + #include + #include "gmp.h" + + main () + { + mpz_t b, p; + + mpz_init (p); + + mpz_init_set_str (b, "314159265358979323846", 0); + mpz_mul_ui (p, b, 756839); /* generate product */ + mpz_out_str (stdout, 10, p); /* print number without newline */ + puts (""); /* print newline */ + + exit (0); + } + + + OVERVIEW OF GNU MP + +There are five classes of functions in GNU MP. + + 1. Signed integer arithmetic functions, mpz_*. These functions are intended + to be easy to use, with their regular interface. The associated type is + `mpz_t'. + + 2. Rational arithmetic functions, mpq_*. For now, just a small set of + functions necessary for basic rational arithmetics. The associated type + is `mpq_t'. + + 3. Floating-point arithmetic functions, mpf_*. If the C type `double' + doesn't give enough precision for your application, declare your + variables as `mpf_t' instead, set the precision to any number desired, + and call the functions in the mpf class for the arithmetic operations. + + 4. Positive-integer, hard-to-use, very low overhead functions are in the + mpn_* class. No memory management is performed. The caller must ensure + enough space is available for the results. The set of functions is not + regular, nor is the calling interface. These functions accept input + arguments in the form of pairs consisting of a pointer to the least + significant word, and a integral size telling how many limbs (= words) + the pointer points to. + + Almost all calculations, in the entire package, are made by calling these + low-level functions. + + 5. Berkeley MP compatible functions. + + To use these functions, include the file "mp.h". You can test if you are + using the GNU version by testing if the symbol __GNU_MP__ is defined. + +For more information on how to use GNU MP, please refer to the documentation. +It is composed from the file gmp.texi, and can be displayed on the screen or +printed. How to do that, as well how to build the library, is described in +the INSTALL file in this directory. + + + REPORTING BUGS + +If you find a bug in the library, please make sure to tell us about it! + +Report bugs and propose modifications and enhancements to +bug-gmp@prep.ai.mit.edu. What information is needed in a good bug report is +described in the manual. -- 1.7.10.4