Remove gmp

This commit is contained in:
Brendan Shanks 2018-06-28 23:44:25 -07:00
parent 0d02f4e407
commit 7323f69920
821 changed files with 0 additions and 67167 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +0,0 @@
*Data
libgmp.PPC.nd
libgmp.carb.nd
libs

View File

@ -1,2 +0,0 @@
#include <alloca.h>

View File

@ -1,66 +0,0 @@
/* gmp-mparam.h -- Compiler/machine parameter header file.
Copyright (C) 1991, 1993, 1994, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#define BITS_PER_MP_LIMB 32
#define BYTES_PER_MP_LIMB 4
#define BITS_PER_LONGINT 32
#define BITS_PER_INT 32
#define BITS_PER_SHORTINT 16
#define BITS_PER_CHAR 8
/* These values are for the 604. Presumably, these should be considerably
different for the 603 and 750 that have much slower multiply
instructions. */
/* Generated by tuneup.c, 2000-05-26. */
#ifndef KARATSUBA_MUL_THRESHOLD
#define KARATSUBA_MUL_THRESHOLD 26 /* tuneup says 20 */
#endif
#ifndef TOOM3_MUL_THRESHOLD
#define TOOM3_MUL_THRESHOLD 228
#endif
#ifndef KARATSUBA_SQR_THRESHOLD
#define KARATSUBA_SQR_THRESHOLD 46 /* tuneup says 44 */
#endif
#ifndef TOOM3_SQR_THRESHOLD
#define TOOM3_SQR_THRESHOLD 262
#endif
#ifndef BZ_THRESHOLD
#define BZ_THRESHOLD 52
#endif
#ifndef FIB_THRESHOLD
#define FIB_THRESHOLD 86
#endif
#ifndef POWM_THRESHOLD
#define POWM_THRESHOLD 23
#endif
#ifndef GCD_ACCEL_THRESHOLD
#define GCD_ACCEL_THRESHOLD 7
#endif
#ifndef GCDEXT_THRESHOLD
#define GCDEXT_THRESHOLD 53
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,26 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define exit macosexit
#define abort macosabort
#define malloc lshmalloc
#define calloc lshcalloc
#define realloc lshrealloc
#define free lshfree
#ifdef __cplusplus
extern "C" {
#endif
void *lshmalloc(unsigned long size);
void *lshcalloc(unsigned long items, unsigned long size);
void *lshrealloc(void *addr, unsigned long size);
void lshfree(void *addr);
#ifdef __cplusplus
}
#endif
#define VERSION "3.1"

View File

@ -1,7 +0,0 @@
#ifndef mc68020
#define mc68020 1
#endif
#define ALLOCA_68K_BUG 1
#include "gmpprefix.h"

View File

@ -1,2 +0,0 @@
#include <MSLCarbonPrefix.h>
#include "gmpprefixppc.h"

View File

@ -1 +0,0 @@
#include "gmpprefix.h"

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +0,0 @@
#include <stdio.h>
#include <stdlib.h>

Binary file not shown.

Binary file not shown.

BIN
gmp/NEWS

Binary file not shown.

Binary file not shown.

View File

@ -1,92 +0,0 @@
/*
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
@TOP@
/* Define if a limb is long long. */
#undef _LONG_LONG_LIMB
/* Define if we have native implementation of function. */
#undef HAVE_NATIVE_
#undef HAVE_NATIVE_mpn_add
#undef HAVE_NATIVE_mpn_add_1
#undef HAVE_NATIVE_mpn_add_n
#undef HAVE_NATIVE_mpn_add_nc
#undef HAVE_NATIVE_mpn_addmul_1
#undef HAVE_NATIVE_mpn_addmul_1c
#undef HAVE_NATIVE_mpn_addsub_n
#undef HAVE_NATIVE_mpn_addsub_nc
#undef HAVE_NATIVE_mpn_and_n
#undef HAVE_NATIVE_mpn_andn_n
#undef HAVE_NATIVE_mpn_bdivmod
#undef HAVE_NATIVE_mpn_cmp
#undef HAVE_NATIVE_mpn_com_n
#undef HAVE_NATIVE_mpn_copyd
#undef HAVE_NATIVE_mpn_copyi
#undef HAVE_NATIVE_mpn_divexact_by3c
#undef HAVE_NATIVE_mpn_divrem
#undef HAVE_NATIVE_mpn_divrem_1
#undef HAVE_NATIVE_mpn_divrem_1c
#undef HAVE_NATIVE_mpn_divrem_2
#undef HAVE_NATIVE_mpn_divrem_newton
#undef HAVE_NATIVE_mpn_divrem_classic
#undef HAVE_NATIVE_mpn_dump
#undef HAVE_NATIVE_mpn_gcd
#undef HAVE_NATIVE_mpn_gcd_1
#undef HAVE_NATIVE_mpn_gcdext
#undef HAVE_NATIVE_mpn_get_str
#undef HAVE_NATIVE_mpn_hamdist
#undef HAVE_NATIVE_mpn_invert_limb
#undef HAVE_NATIVE_mpn_ior_n
#undef HAVE_NATIVE_mpn_iorn_n
#undef HAVE_NATIVE_mpn_lshift
#undef HAVE_NATIVE_mpn_mod_1
#undef HAVE_NATIVE_mpn_mod_1c
#undef HAVE_NATIVE_mpn_mul
#undef HAVE_NATIVE_mpn_mul_1
#undef HAVE_NATIVE_mpn_mul_1c
#undef HAVE_NATIVE_mpn_mul_basecase
#undef HAVE_NATIVE_mpn_mul_n
#undef HAVE_NATIVE_mpn_nand_n
#undef HAVE_NATIVE_mpn_nior_n
#undef HAVE_NATIVE_mpn_perfect_square_p
#undef HAVE_NATIVE_mpn_popcount
#undef HAVE_NATIVE_mpn_preinv_mod_1
#undef HAVE_NATIVE_mpn_random2
#undef HAVE_NATIVE_mpn_random
#undef HAVE_NATIVE_mpn_rawrandom
#undef HAVE_NATIVE_mpn_rshift
#undef HAVE_NATIVE_mpn_scan0
#undef HAVE_NATIVE_mpn_scan1
#undef HAVE_NATIVE_mpn_set_str
#undef HAVE_NATIVE_mpn_sqrtrem
#undef HAVE_NATIVE_mpn_sqr_basecase
#undef HAVE_NATIVE_mpn_sub
#undef HAVE_NATIVE_mpn_sub_1
#undef HAVE_NATIVE_mpn_sub_n
#undef HAVE_NATIVE_mpn_sub_nc
#undef HAVE_NATIVE_mpn_submul_1
#undef HAVE_NATIVE_mpn_submul_1c
#undef HAVE_NATIVE_mpn_udiv_w_sdiv
#undef HAVE_NATIVE_mpn_umul_ppmm
#undef HAVE_NATIVE_mpn_udiv_qrnnd
#undef HAVE_NATIVE_mpn_xor_n
#undef HAVE_NATIVE_mpn_xnor_n

Binary file not shown.

BIN
gmp/aclocal.m4 vendored

Binary file not shown.

Binary file not shown.

View File

@ -1,678 +0,0 @@
/* Copyright (C) 1989, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. */
/*$Id$*/
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
/*
ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone for the
consequences of using it or for whether it serves any particular purpose or
works at all, unless he says so in writing. Refer to the GNU General Public
License (the "GPL") for full details.
Everyone is granted permission to copy, modify and redistribute ansi2knr,
but only under the conditions described in the GPL. A copy of this license
is supposed to have been given to you along with ansi2knr so you can know
your rights and responsibilities. It should be in a file named COPYLEFT,
or, if there is no file named COPYLEFT, a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies.
We explicitly state here what we believe is already implied by the GPL: if
the ansi2knr program is distributed as a separate set of sources and a
separate executable file which are aggregated on a storage medium together
with another program, this in itself does not bring the other program under
the GPL, nor does the mere fact that such a program or the procedures for
constructing it invoke the ansi2knr executable bring any other part of the
program under the GPL.
*/
/*
* Usage:
ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]
* --filename provides the file name for the #line directive in the output,
* overriding input_file (if present).
* If no input_file is supplied, input is read from stdin.
* If no output_file is supplied, output goes to stdout.
* There are no error messages.
*
* ansi2knr recognizes function definitions by seeing a non-keyword
* identifier at the left margin, followed by a left parenthesis,
* with a right parenthesis as the last character on the line,
* and with a left brace as the first token on the following line
* (ignoring possible intervening comments), except that a line
* consisting of only
* identifier1(identifier2)
* will not be considered a function definition unless identifier2 is
* the word "void", and a line consisting of
* identifier1(identifier2, <<arbitrary>>)
* will not be considered a function definition.
* ansi2knr will recognize a multi-line header provided
* that no intervening line ends with a left or right brace or a semicolon.
* These algorithms ignore whitespace and comments, except that
* the function name must be the first thing on the line.
* The following constructs will confuse it:
* - Any other construct that starts at the left margin and
* follows the above syntax (such as a macro or function call).
* - Some macros that tinker with the syntax of function headers.
*/
/*
* The original and principal author of ansi2knr is L. Peter Deutsch
* <ghost@aladdin.com>. Other authors are noted in the change history
* that follows (in reverse chronological order):
lpd 1999-04-12 added minor fixes from Pavel Roskin
<pavel_roskin@geocities.com> for clean compilation with
gcc -W -Wall
lpd 1999-03-22 added hack to recognize lines consisting of
identifier1(identifier2, xxx) as *not* being procedures
lpd 1999-02-03 made indentation of preprocessor commands consistent
lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an
endless loop; quoted strings within an argument list
confused the parser
lpd 1999-01-24 added a check for write errors on the output,
suggested by Jim Meyering <meyering@ascend.com>
lpd 1998-11-09 added further hack to recognize identifier(void)
as being a procedure
lpd 1998-10-23 added hack to recognize lines consisting of
identifier1(identifier2) as *not* being procedures
lpd 1997-12-08 made input_file optional; only closes input and/or
output file if not stdin or stdout respectively; prints
usage message on stderr rather than stdout; adds
--filename switch (changes suggested by
<ceder@lysator.liu.se>)
lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with
compilers that don't understand void, as suggested by
Tom Lane
lpd 1996-01-15 changed to require that the first non-comment token
on the line following a function header be a left brace,
to reduce sensitivity to macros, as suggested by Tom Lane
<tgl@sss.pgh.pa.us>
lpd 1995-06-22 removed #ifndefs whose sole purpose was to define
undefined preprocessor symbols as 0; changed all #ifdefs
for configuration symbols to #ifs
lpd 1995-04-05 changed copyright notice to make it clear that
including ansi2knr in a program does not bring the entire
program under the GPL
lpd 1994-12-18 added conditionals for systems where ctype macros
don't handle 8-bit characters properly, suggested by
Francois Pinard <pinard@iro.umontreal.ca>;
removed --varargs switch (this is now the default)
lpd 1994-10-10 removed CONFIG_BROKETS conditional
lpd 1994-07-16 added some conditionals to help GNU `configure',
suggested by Francois Pinard <pinard@iro.umontreal.ca>;
properly erase prototype args in function parameters,
contributed by Jim Avera <jima@netcom.com>;
correct error in writeblanks (it shouldn't erase EOLs)
lpd 1989-xx-xx original version
*/
/* Most of the conditionals here are to make ansi2knr work with */
/* or without the GNU configure machinery. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <ctype.h>
#if HAVE_CONFIG_H
/*
For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h).
This will define HAVE_CONFIG_H and so, activate the following lines.
*/
# if STDC_HEADERS || HAVE_STRING_H
# include <string.h>
# else
# include <strings.h>
# endif
#else /* not HAVE_CONFIG_H */
/* Otherwise do it the hard way */
# ifdef BSD
# include <strings.h>
# else
# ifdef VMS
extern int strlen(), strncmp();
# else
# include <string.h>
# endif
# endif
#endif /* not HAVE_CONFIG_H */
#if STDC_HEADERS
# include <stdlib.h>
#else
/*
malloc and free should be declared in stdlib.h,
but if you've got a K&R compiler, they probably aren't.
*/
# ifdef MSDOS
# include <malloc.h>
# else
# ifdef VMS
extern char *malloc();
extern void free();
# else
extern char *malloc();
extern int free();
# endif
# endif
#endif
/* Define NULL (for *very* old compilers). */
#ifndef NULL
# define NULL (0)
#endif
/*
* The ctype macros don't always handle 8-bit characters correctly.
* Compensate for this here.
*/
#ifdef isascii
# undef HAVE_ISASCII /* just in case */
# define HAVE_ISASCII 1
#else
#endif
#if STDC_HEADERS || !HAVE_ISASCII
# define is_ascii(c) 1
#else
# define is_ascii(c) isascii(c)
#endif
#define is_space(c) (is_ascii(c) && isspace(c))
#define is_alpha(c) (is_ascii(c) && isalpha(c))
#define is_alnum(c) (is_ascii(c) && isalnum(c))
/* Scanning macros */
#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
/* Forward references */
char *skipspace();
char *scanstring();
int writeblanks();
int test1();
int convert1();
/* The main program */
int
main(argc, argv)
int argc;
char *argv[];
{ FILE *in = stdin;
FILE *out = stdout;
char *filename = 0;
char *program_name = argv[0];
char *output_name = 0;
#define bufsize 5000 /* arbitrary size */
char *buf;
char *line;
char *more;
char *usage =
"Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n";
/*
* In previous versions, ansi2knr recognized a --varargs switch.
* If this switch was supplied, ansi2knr would attempt to convert
* a ... argument to va_alist and va_dcl; if this switch was not
* supplied, ansi2knr would simply drop any such arguments.
* Now, ansi2knr always does this conversion, and we only
* check for this switch for backward compatibility.
*/
int convert_varargs = 1;
int output_error;
while ( argc > 1 && argv[1][0] == '-' ) {
if ( !strcmp(argv[1], "--varargs") ) {
convert_varargs = 1;
argc--;
argv++;
continue;
}
if ( !strcmp(argv[1], "--filename") && argc > 2 ) {
filename = argv[2];
argc -= 2;
argv += 2;
continue;
}
fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name,
argv[1]);
fprintf(stderr, usage);
exit(1);
}
switch ( argc )
{
default:
fprintf(stderr, usage);
exit(0);
case 3:
output_name = argv[2];
out = fopen(output_name, "w");
if ( out == NULL ) {
fprintf(stderr, "%s: Cannot open output file %s\n",
program_name, output_name);
exit(1);
}
/* falls through */
case 2:
in = fopen(argv[1], "r");
if ( in == NULL ) {
fprintf(stderr, "%s: Cannot open input file %s\n",
program_name, argv[1]);
exit(1);
}
if ( filename == 0 )
filename = argv[1];
/* falls through */
case 1:
break;
}
if ( filename )
fprintf(out, "#line 1 \"%s\"\n", filename);
buf = malloc(bufsize);
if ( buf == NULL )
{
fprintf(stderr, "Unable to allocate read buffer!\n");
exit(1);
}
line = buf;
while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
{
test: line += strlen(line);
switch ( test1(buf) )
{
case 2: /* a function header */
convert1(buf, out, 1, convert_varargs);
break;
case 1: /* a function */
/* Check for a { at the start of the next line. */
more = ++line;
f: if ( line >= buf + (bufsize - 1) ) /* overflow check */
goto wl;
if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
goto wl;
switch ( *skipspace(more, 1) )
{
case '{':
/* Definitely a function header. */
convert1(buf, out, 0, convert_varargs);
fputs(more, out);
break;
case 0:
/* The next line was blank or a comment: */
/* keep scanning for a non-comment. */
line += strlen(line);
goto f;
default:
/* buf isn't a function header, but */
/* more might be. */
fputs(buf, out);
strcpy(buf, more);
line = buf;
goto test;
}
break;
case -1: /* maybe the start of a function */
if ( line != buf + (bufsize - 1) ) /* overflow check */
continue;
/* falls through */
default: /* not a function */
wl: fputs(buf, out);
break;
}
line = buf;
}
if ( line != buf )
fputs(buf, out);
free(buf);
if ( output_name ) {
output_error = ferror(out);
output_error |= fclose(out);
} else { /* out == stdout */
fflush(out);
output_error = ferror(out);
}
if ( output_error ) {
fprintf(stderr, "%s: error writing to %s\n", program_name,
(output_name ? output_name : "stdout"));
exit(1);
}
if ( in != stdin )
fclose(in);
return 0;
}
/* Skip over whitespace and comments, in either direction. */
char *
skipspace(p, dir)
register char *p;
register int dir; /* 1 for forward, -1 for backward */
{ for ( ; ; )
{ while ( is_space(*p) )
p += dir;
if ( !(*p == '/' && p[dir] == '*') )
break;
p += dir; p += dir;
while ( !(*p == '*' && p[dir] == '/') )
{ if ( *p == 0 )
return p; /* multi-line comment?? */
p += dir;
}
p += dir; p += dir;
}
return p;
}
/* Scan over a quoted string, in either direction. */
char *
scanstring(p, dir)
register char *p;
register int dir;
{
for (p += dir; ; p += dir)
if (*p == '"' && p[-dir] != '\\')
return p + dir;
}
/*
* Write blanks over part of a string.
* Don't overwrite end-of-line characters.
*/
int
writeblanks(start, end)
char *start;
char *end;
{ char *p;
for ( p = start; p < end; p++ )
if ( *p != '\r' && *p != '\n' )
*p = ' ';
return 0;
}
/*
* Test whether the string in buf is a function definition.
* The string may contain and/or end with a newline.
* Return as follows:
* 0 - definitely not a function definition;
* 1 - definitely a function definition;
* 2 - definitely a function prototype (NOT USED);
* -1 - may be the beginning of a function definition,
* append another line and look again.
* The reason we don't attempt to convert function prototypes is that
* Ghostscript's declaration-generating macros look too much like
* prototypes, and confuse the algorithms.
*/
int
test1(buf)
char *buf;
{ register char *p = buf;
char *bend;
char *endfn;
int contin;
if ( !isidfirstchar(*p) )
return 0; /* no name at left margin */
bend = skipspace(buf + strlen(buf) - 1, -1);
switch ( *bend )
{
case ';': contin = 0 /*2*/; break;
case ')': contin = 1; break;
case '{': return 0; /* not a function */
case '}': return 0; /* not a function */
default: contin = -1;
}
while ( isidchar(*p) )
p++;
endfn = p;
p = skipspace(p, 1);
if ( *p++ != '(' )
return 0; /* not a function */
p = skipspace(p, 1);
if ( *p == ')' )
return 0; /* no parameters */
/* Check that the apparent function name isn't a keyword. */
/* We only need to check for keywords that could be followed */
/* by a left parenthesis (which, unfortunately, is most of them). */
{ static char *words[] =
{ "asm", "auto", "case", "char", "const", "double",
"extern", "float", "for", "if", "int", "long",
"register", "return", "short", "signed", "sizeof",
"static", "switch", "typedef", "unsigned",
"void", "volatile", "while", 0
};
char **key = words;
char *kp;
unsigned len = endfn - buf;
while ( (kp = *key) != 0 )
{ if ( strlen(kp) == len && !strncmp(kp, buf, len) )
return 0; /* name is a keyword */
key++;
}
}
{
char *id = p;
int len;
/*
* Check for identifier1(identifier2) and not
* identifier1(void), or identifier1(identifier2, xxxx).
*/
while ( isidchar(*p) )
p++;
len = p - id;
p = skipspace(p, 1);
if (*p == ',' ||
(*p == ')' && (len != 4 || strncmp(id, "void", 4)))
)
return 0; /* not a function */
}
/*
* If the last significant character was a ), we need to count
* parentheses, because it might be part of a formal parameter
* that is a procedure.
*/
if (contin > 0) {
int level = 0;
for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1))
level += (*p == '(' ? 1 : *p == ')' ? -1 : 0);
if (level > 0)
contin = -1;
}
return contin;
}
/* Convert a recognized function definition or header to K&R syntax. */
int
convert1(buf, out, header, convert_varargs)
char *buf;
FILE *out;
int header; /* Boolean */
int convert_varargs; /* Boolean */
{ char *endfn;
register char *p;
/*
* The breaks table contains pointers to the beginning and end
* of each argument.
*/
char **breaks;
unsigned num_breaks = 2; /* for testing */
char **btop;
char **bp;
char **ap;
char *vararg = 0;
/* Pre-ANSI implementations don't agree on whether strchr */
/* is called strchr or index, so we open-code it here. */
for ( endfn = buf; *(endfn++) != '('; )
;
top: p = endfn;
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
if ( breaks == NULL )
{ /* Couldn't allocate break table, give up */
fprintf(stderr, "Unable to allocate break table!\n");
fputs(buf, out);
return -1;
}
btop = breaks + num_breaks * 2 - 2;
bp = breaks;
/* Parse the argument list */
do
{ int level = 0;
char *lp = NULL;
char *rp = NULL;
char *end = NULL;
if ( bp >= btop )
{ /* Filled up break table. */
/* Allocate a bigger one and start over. */
free((char *)breaks);
num_breaks <<= 1;
goto top;
}
*bp++ = p;
/* Find the end of the argument */
for ( ; end == NULL; p++ )
{ switch(*p)
{
case ',':
if ( !level ) end = p;
break;
case '(':
if ( !level ) lp = p;
level++;
break;
case ')':
if ( --level < 0 ) end = p;
else rp = p;
break;
case '/':
if (p[1] == '*')
p = skipspace(p, 1) - 1;
break;
case '"':
p = scanstring(p, 1) - 1;
break;
default:
;
}
}
/* Erase any embedded prototype parameters. */
if ( lp && rp )
writeblanks(lp + 1, rp);
p--; /* back up over terminator */
/* Find the name being declared. */
/* This is complicated because of procedure and */
/* array modifiers. */
for ( ; ; )
{ p = skipspace(p - 1, -1);
switch ( *p )
{
case ']': /* skip array dimension(s) */
case ')': /* skip procedure args OR name */
{ int level = 1;
while ( level )
switch ( *--p )
{
case ']': case ')':
level++;
break;
case '[': case '(':
level--;
break;
case '/':
if (p > buf && p[-1] == '*')
p = skipspace(p, -1) + 1;
break;
case '"':
p = scanstring(p, -1) + 1;
break;
default: ;
}
}
if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
{ /* We found the name being declared */
while ( !isidfirstchar(*p) )
p = skipspace(p, 1) + 1;
goto found;
}
break;
default:
goto found;
}
}
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
{ if ( convert_varargs )
{ *bp++ = "va_alist";
vararg = p-2;
}
else
{ p++;
if ( bp == breaks + 1 ) /* sole argument */
writeblanks(breaks[0], p);
else
writeblanks(bp[-1] - 1, p);
bp--;
}
}
else
{ while ( isidchar(*p) ) p--;
*bp++ = p+1;
}
p = end;
}
while ( *p++ == ',' );
*bp = p;
/* Make a special check for 'void' arglist */
if ( bp == breaks+2 )
{ p = skipspace(breaks[0], 1);
if ( !strncmp(p, "void", 4) )
{ p = skipspace(p+4, 1);
if ( p == breaks[2] - 1 )
{ bp = breaks; /* yup, pretend arglist is empty */
writeblanks(breaks[0], p + 1);
}
}
}
/* Put out the function name and left parenthesis. */
p = buf;
while ( p != endfn ) putc(*p, out), p++;
/* Put out the declaration. */
if ( header )
{ fputs(");", out);
for ( p = breaks[0]; *p; p++ )
if ( *p == '\r' || *p == '\n' )
putc(*p, out);
}
else
{ for ( ap = breaks+1; ap < bp; ap += 2 )
{ p = *ap;
while ( isidchar(*p) )
putc(*p, out), p++;
if ( ap < bp - 1 )
fputs(", ", out);
}
fputs(") ", out);
/* Put out the argument declarations */
for ( ap = breaks+2; ap <= bp; ap += 2 )
(*ap)[-1] = ';';
if ( vararg != 0 )
{ *vararg = 0;
fputs(breaks[0], out); /* any prior args */
fputs("va_dcl", out); /* the final arg */
fputs(bp[0], out);
}
else
fputs(breaks[0], out);
}
free((char *)breaks);
return 0;
}

View File

@ -1,52 +0,0 @@
/* GMP assertion failure handler. */
/*
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
int
#if __STDC__
__gmp_assert_fail (const char *filename, int linenum,
const char *expr)
#else
__gmp_assert_fail (filename, linenum, expr)
char *filename;
int linenum;
char *expr;
#endif
{
if (filename != NULL && filename[0] != '\0')
{
fprintf (stderr, "%s:", filename);
if (linenum != -1)
fprintf (stderr, "%d: ", linenum);
}
fprintf (stderr, "GNU MP assertion failed: %s\n", expr);
abort();
/*NOTREACHED*/
return 0;
}

View File

@ -1,46 +0,0 @@
/* Old function entrypoints retained for binary compatibility. */
/*
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
/* mpn_divexact_by3 was a function in gmp 3.0, but as of gmp 3.1 it's a
macro calling mpn_divexact_by3c. */
int
__MPN (divexact_by3) (mp_ptr dst, mp_srcptr src, mp_size_t size)
{
return mpn_divexact_by3 (dst, src, size);
}
/* mpn_divmod_1 was a function in gmp 3.0 and earlier, but marked obsolete
in gmp 2 and 3. As of gmp 3.1 it's a macro calling mpn_divrem_1. */
int
__MPN (divmod_1) (mp_ptr dst, mp_srcptr src, mp_size_t size, mp_limb_t divisor)
{
return mpn_divmod_1 (dst, src, size, divisor);
}

BIN
gmp/config.guess vendored

Binary file not shown.

Binary file not shown.

BIN
gmp/config.sub vendored

Binary file not shown.

BIN
gmp/configure vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +0,0 @@
typedef union {
char *str;
int var;
} YYSTYPE;
#define EOS 257
#define BAD 258
#define HEX 259
#define DECIMAL 260
#define QUIT 261
#define ABS 262
#define BIN 263
#define FIB 264
#define GCD 265
#define LCM 266
#define NEXTPRIME 267
#define POWM 268
#define ROOT 269
#define SQRT 270
#define NUMBER 271
#define VARIABLE 272
#define LOR 273
#define LAND 274
#define EQ 275
#define NE 276
#define LE 277
#define GE 278
#define LSHIFT 279
#define RSHIFT 280
#define UMINUS 281
extern YYSTYPE yylval;

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,363 +0,0 @@
/* Factoring with Pollard's rho method.
Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; see the file COPYING. If not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gmp.h"
int flag_verbose = 0;
static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6};
#if defined (__hpux) || defined (__alpha) || defined (__svr4__) || defined (__SVR4)
/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */
long mrand48 ();
static long
random ()
{
return mrand48 ();
}
#else
/* Glibc stdlib.h has "int32_t random();" which, on i386 at least, conflicts
with a redeclaration as "long". */
#ifndef __GLIBC__
long random ();
#endif
#endif
void
factor_using_division (mpz_t t, unsigned int limit)
{
mpz_t q, r;
unsigned long int f;
int ai;
unsigned *addv = add;
unsigned int failures;
if (flag_verbose)
{
printf ("[trial division (%u)] ", limit);
fflush (stdout);
}
mpz_init (q);
mpz_init (r);
f = mpz_scan1 (t, 0);
mpz_div_2exp (t, t, f);
while (f)
{
printf ("2 ");
fflush (stdout);
--f;
}
for (;;)
{
mpz_tdiv_qr_ui (q, r, t, 3);
if (mpz_cmp_ui (r, 0) != 0)
break;
mpz_set (t, q);
printf ("3 ");
fflush (stdout);
}
for (;;)
{
mpz_tdiv_qr_ui (q, r, t, 5);
if (mpz_cmp_ui (r, 0) != 0)
break;
mpz_set (t, q);
printf ("5 ");
fflush (stdout);
}
failures = 0;
f = 7;
ai = 0;
while (mpz_cmp_ui (t, 1) != 0)
{
mpz_tdiv_qr_ui (q, r, t, f);
if (mpz_cmp_ui (r, 0) != 0)
{
f += addv[ai];
if (mpz_cmp_ui (q, f) < 0)
break;
ai = (ai + 1) & 7;
failures++;
if (failures > limit)
break;
}
else
{
mpz_swap (t, q);
printf ("%lu ", f);
fflush (stdout);
failures = 0;
}
}
mpz_clear (q);
mpz_clear (r);
}
void
factor_using_division_2kp (mpz_t t, unsigned int limit, unsigned long p)
{
mpz_t r;
mpz_t f;
unsigned int k;
mpz_init (r);
mpz_init_set_ui (f, 2 * p);
mpz_add_ui (f, f, 1);
for (k = 1; k < limit; k++)
{
mpz_tdiv_r (r, t, f);
while (mpz_cmp_ui (r, 0) == 0)
{
mpz_tdiv_q (t, t, f);
mpz_tdiv_r (r, t, f);
mpz_out_str (stdout, 10, f);
fflush (stdout);
fputc (' ', stdout);
}
mpz_add_ui (f, f, 2 * p);
}
mpz_clear (f);
mpz_clear (r);
}
void
factor_using_pollard_rho (mpz_t n, int a_int, unsigned long p)
{
mpz_t x, x1, y, P;
mpz_t a;
mpz_t g;
mpz_t t1, t2;
int k, l, c, i;
if (flag_verbose)
{
printf ("[pollard-rho (%d)] ", a_int);
fflush (stdout);
}
mpz_init (g);
mpz_init (t1);
mpz_init (t2);
mpz_init_set_si (a, a_int);
mpz_init_set_si (y, 2);
mpz_init_set_si (x, 2);
mpz_init_set_si (x1, 2);
k = 1;
l = 1;
mpz_init_set_ui (P, 1);
c = 0;
while (mpz_cmp_ui (n, 1) != 0)
{
S2:
if (p != 0)
{
mpz_powm_ui (x, x, p, n); mpz_add (x, x, a);
}
else
{
mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
}
mpz_sub (t1, x1, x); mpz_mul (t2, P, t1); mpz_mod (P, t2, n);
c++;
if (c == 20)
{
c = 0;
mpz_gcd (g, P, n);
if (mpz_cmp_ui (g, 1) != 0)
goto S4;
mpz_set (y, x);
}
S3:
k--;
if (k != 0)
goto S2;
mpz_gcd (g, P, n);
if (mpz_cmp_ui (g, 1) != 0)
goto S4;
mpz_set (x1, x);
k = l;
l = 2 * l;
for (i = 0; i < k; i++)
{
if (p != 0)
{
mpz_powm_ui (x, x, p, n); mpz_add (x, x, a);
}
else
{
mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
}
}
mpz_set (y, x);
c = 0;
goto S2;
S4:
do
{
if (p != 0)
{
mpz_powm_ui (y, y, p, n); mpz_add (y, y, a);
}
else
{
mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n);
}
mpz_sub (t1, x1, y); mpz_gcd (g, t1, n);
}
while (mpz_cmp_ui (g, 1) == 0);
if (!mpz_probab_prime_p (g, 3))
{
do
a_int = random ();
while (a_int == -2 || a_int == 0);
if (flag_verbose)
{
printf ("[composite factor--restarting pollard-rho] ");
fflush (stdout);
}
factor_using_pollard_rho (g, a_int, p);
break;
}
else
{
mpz_out_str (stdout, 10, g);
fflush (stdout);
fputc (' ', stdout);
}
mpz_div (n, n, g);
mpz_mod (x, x, n);
mpz_mod (x1, x1, n);
mpz_mod (y, y, n);
if (mpz_probab_prime_p (n, 3))
{
mpz_out_str (stdout, 10, n);
fflush (stdout);
fputc (' ', stdout);
break;
}
}
mpz_clear (g);
mpz_clear (P);
mpz_clear (t2);
mpz_clear (t1);
mpz_clear (a);
mpz_clear (x1);
mpz_clear (x);
mpz_clear (y);
}
void
factor (mpz_t t, unsigned long p)
{
unsigned int division_limit;
/* Set the trial division limit according the size of t. */
division_limit = mpz_sizeinbase (t, 2);
if (division_limit > 1000)
division_limit = 1000 * 1000;
else
division_limit = division_limit * division_limit;
if (p != 0)
factor_using_division_2kp (t, division_limit / 10, p);
else
factor_using_division (t, division_limit);
if (mpz_cmp_ui (t, 1) != 0)
{
if (flag_verbose)
{
printf ("[is number prime?] ");
fflush (stdout);
}
if (mpz_probab_prime_p (t, 3))
mpz_out_str (stdout, 10, t);
else
factor_using_pollard_rho (t, 1, p);
}
}
main (int argc, char *argv[])
{
mpz_t t;
unsigned long p;
int i;
if (argc > 1 && !strcmp (argv[1], "-v"))
{
flag_verbose = 1;
argv++;
argc--;
}
p = 0;
for (i = 1; i < argc; i++)
{
if (!strncmp (argv[i], "-Mp", 3))
{
p = atoi (argv[i] + 3);
mpz_init_set_ui (t, 1);
mpz_mul_2exp (t, t, p);
mpz_sub_ui (t, t, 1);
}
else if (!strncmp (argv[i], "-2kp", 4))
{
p = atoi (argv[i] + 4);
continue;
}
else
{
mpz_init_set_str (t, argv[i], 0);
}
if (mpz_cmp_ui (t, 0) == 0)
puts ("-");
else
{
factor (t, p);
puts ("");
}
}
exit (0);
}
void
dmp (mpz_t x)
{
mpz_out_str (stdout, 10, x);
puts ("");
}

View File

@ -1,65 +0,0 @@
/* Classify numbers as probable primes, primes or composites.
With -q return true if the folowing argument is a (probable) prime.
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <stdio.h>
#include "gmp.h"
char *progname;
main (int argc, char **argv)
{
mpz_t n;
int i;
progname = argv[0];
if (argc < 2)
print_usage_and_exit ();
mpz_init (n);
if (argc == 3 && strcmp (argv[1], "-q") == 0)
{
if (mpz_set_str (n, argv[2], 0) != 0)
print_usage_and_exit ();
exit (mpz_probab_prime_p (n, 5) == 0);
}
for (i = 1; i < argc; i++)
{
int class;
if (mpz_set_str (n, argv[i], 0) != 0)
print_usage_and_exit ();
class = mpz_probab_prime_p (n, 5);
mpz_out_str (stdout, 10, n);
if (class == 0)
puts (" is composite");
else if (class == 1)
puts (" is a probable prime");
else /* class == 2 */
puts (" is a prime");
}
exit (0);
}
print_usage_and_exit ()
{
fprintf (stderr, "usage: %s -q nnn\n", progname);
fprintf (stderr, "usage: %s nnn ...\n", progname);
exit (-1);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,145 +0,0 @@
/* List and count primes.
Copyright (C) 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <stdlib.h>
#include <stdio.h>
#include "gmp.h"
/* Sieve table size */
#define ST_SIZE 30000
/* Largest prime to sieve with */
#define MAX_S_PRIME 1000
main (int argc, char **argv)
{
char *progname = argv[0];
mpz_t r0, r1; /* range */
mpz_t cur;
unsigned char *st;
unsigned long i, ii;
unsigned long nprimes = 0;
unsigned long last;
int flag_print = 1;
int flag_count = 0;
st = malloc (ST_SIZE);
while (argc != 1)
{
if (strcmp (argv[1], "-c") == 0)
{
flag_count = 1;
argv++;
argc--;
}
else if (strcmp (argv[1], "-p") == 0)
{
flag_print = 2;
argv++;
argc--;
}
else
break;
}
if (flag_count)
flag_print--; /* clear unless an explicit -p */
mpz_init (r0);
mpz_init (r1);
mpz_init (cur);
if (argc == 2)
{
mpz_set_ui (r0, 2);
mpz_set_str (r1, argv[1], 0);
}
else if (argc == 3)
{
mpz_set_str (r0, argv[1], 0);
if (argv[2][0] == '+')
{
mpz_set_str (r1, argv[2] + 1, 0);
mpz_add (r1, r1, r0);
}
else
mpz_set_str (r1, argv[2], 0);
}
else
{
fprintf (stderr, "usage: %s [-c] [-g] [from [+]]to\n", progname);
exit (1);
}
if (mpz_cmp_ui (r0, 2) < 0)
mpz_set_ui (r0, 2);
if ((mpz_get_ui (r0) & 1) == 0)
{
if (mpz_cmp_ui (r0, 2) == 0)
{
if (flag_print)
puts ("2");
nprimes++;
}
mpz_add_ui (r0, r0, 1);
}
mpz_set (cur, r0);
while (mpz_cmp (cur, r1) <= 0)
{
memset (st, 1, ST_SIZE);
for (i = 3; i < MAX_S_PRIME; i += 2)
{
unsigned long start;
start = mpz_tdiv_ui (cur, i);
if (start != 0)
start = i - start;
if (mpz_cmp_ui (cur, i - start) == 0)
start += i;
for (ii = start; ii < ST_SIZE; ii += i)
st[ii] = 0;
}
last = 0;
for (ii = 0; ii < ST_SIZE; ii += 2)
{
if (st[ii] != 0)
{
mpz_add_ui (cur, cur, ii - last);
last = ii;
if (mpz_cmp (cur, r1) > 0)
goto done;
if (mpz_probab_prime_p (cur, 3))
{
nprimes++;
if (flag_print)
{
mpz_out_str (stdout, 10, cur); puts ("");
}
}
}
}
mpz_add_ui (cur, cur, ST_SIZE - last);
}
done:
if (flag_count)
printf ("Pi(interval) = %lu\n", nprimes);
exit (0);
}

View File

@ -1,151 +0,0 @@
/* Use mpz_kronecker_ui() to calculate an estimate for the quadratic
class number h(d), for a given negative fundamental discriminant, using
Dirichlet's analytic formula. */
/*
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Usage: qcn <discriminant>...
A fundamental discriminant means one of the form D or 4*D with D
square-free. Each argument is checked to see it's congruent to 0 or 1
mod 4 (as all discriminants must be), and that it's negative, but there's
no check on D being square-free.
This program is a bit of a toy, there are better methods for calculating
the class number and class group structure.
Reference:
Daniel Shanks, "Class Number, A Theory of Factorization, and Genera",
Proc. Symp. Pure Math., vol 20, 1970, pages 415-440.
*/
#include <math.h>
#include <stdio.h>
#include "gmp.h"
/* A simple but slow primality test. */
int
prime_p (unsigned long n)
{
unsigned long i, limit;
if (n == 2)
return 1;
if (n < 2 || !(n&1))
return 0;
limit = (unsigned long) floor (sqrt ((double) n));
for (i = 3; i <= limit; i+=2)
if ((n % i) == 0)
return 0;
return 1;
}
/* The formula is as follows, with d < 0.
w * sqrt(-d) inf p
h(d) = ------------ * product --------
2 * pi p=2 p - (d/p)
(d/p) is the Kronecker symbol and the product is over primes p. w is 6
when d=-3, 4 when d=-4, or 2 otherwise.
Calculating the product up to p=infinity would take a long time, so for
the estimate primes up to 132,000 are used. Shanks found this giving an
accuracy of about 1 part in 1000, in normal cases. */
double
qcn_estimate (mpz_t d)
{
#define P_LIMIT 132000
double h;
unsigned long p;
/* p=2 */
h = sqrt (-mpz_get_d (d)) / M_PI
* 2.0 / (2.0 - mpz_kronecker_ui (d, 2));
if (mpz_cmp_si (d, -3) == 0) h *= 3;
else if (mpz_cmp_si (d, -4) == 0) h *= 2;
for (p = 3; p < P_LIMIT; p += 2)
if (prime_p (p))
h *= (double) p / (double) (p - mpz_kronecker_ui (d, p));
return h;
}
void
qcn_str (char *num)
{
mpz_t z;
mpz_init_set_str (z, num, 0);
if (mpz_sgn (z) >= 0)
{
mpz_out_str (stdout, 0, z);
printf (" is not supported (negatives only)\n");
}
else if (mpz_fdiv_ui (z, 4) != 0 && mpz_fdiv_ui (z, 4) != 1)
{
mpz_out_str (stdout, 0, z);
printf (" is not a discriminant (must == 0 or 1 mod 4)\n");
}
else
{
printf ("h(");
mpz_out_str (stdout, 0, z);
printf (") approx %.1f\n", qcn_estimate (z));
}
mpz_clear (z);
}
int
main (int argc, char *argv[])
{
int i;
if (argc < 2)
{
qcn_str ("-85702502803"); /* is 16259 */
qcn_str ("-328878692999"); /* is 1499699 */
qcn_str ("-928185925902146563"); /* is 52739552 */
qcn_str ("-84148631888752647283"); /* is 496652272 */
}
else
{
for (i = 1; i < argc; i++)
qcn_str (argv[i]);
}
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,194 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>
GMP Development Projects
</title>
</head>
<body bgcolor=pink>
<center>
<h1>
GMP Development Projects
</h1>
</center>
<comment>
An up-to-date version of this file is available at
<a href="http://www.swox.com/gmp/projects.html">http://www.swox.com/gmp/projects.html</a>.
</comment>
<p> This file lists projects suitable for volunteers. Please see the
<a href="tasks.html">tasks file</a> for smaller tasks.
<p> If you want to work on any of the projects below, please let tege@swox.com
know. If you want to help with a project that already somebody else is
working on, please talk to that person too, tege@swox.com can put you in
touch. (There are no email addresses of volunteers below, due to spamming
problems.)
<ul>
<li> <strong>C++ wrapper</strong>
<p> A C++ wrapper for GMP is highly desirable. Several people have started
writing one, but nobody has so far finished it. For a wrapper to be useful,
one needs to pay attention to efficiency.
<ol>
<li> Write arithmetic functions for direct applications of most
elementary C++ types. This might be necessary to avoid
ambiguities, but it is also desirable from an efficiency
standpoint.
<li> Avoid running constructors/destructors when not necessary.
For example, implement <code>a&nbsp+=&nbsp;b</code> by directly applying mpz_add.
</ol>
<p> <li> <strong>Faster multiplication</strong>
<p> The current multiplication code uses Karatsuba, 3-way Toom-Cook,
or Fermat FFT. Several new developments are desirable:
<ol>
<li> Handle multiplication of operands with different digit count
better than today. We now split the operands in a very
inefficient way, see mpn/generic/mul.c.
<li> Consider N-way Toom-Cook. See Knuth's Seminumerical
Algorithms for details on the method. Code implementing it
exists. This is asymptotically inferior to FFTs, but is finer
grained. A toom-4 might fit in between toom-3 and the FFTs
(or it might not).
<li> It's possible CPU dependent effects like cache locality will
have a greater impact on speed than algorithmic improvements.
</ol>
<p> <li> <strong>Assembly routines</strong>
<p> Write new and tune existing assembly routines. The programs in mpn/tests
and the tune/speed.c program are useful for testing and timing the routines
you write. See the README files in those directories for more information.
<p> Please make sure your new routines are fast for these three situations:
<ol>
<li> Operands that fit into the cache.
<li> Small operands of less than, say, 10 limbs.
<li> Huge operands that does not fit into the cache.
</ol>
<p> The most important routines are mpn_addmul_1, mpn_mul_basecase and
mpn_sqr_basecase. The latter two don't exist for all machines, while
mpn_addmul_1 exists for almost all machines.
<p> Standard techniques for these routines are unrolling, software
pipelining, and specialization for common operand values. For machines with
poor integer multiplication, it is often possible to improve the performance
using floating-point operations, or SIMD operations such as MMX or Sun's VIS.
<p> Using floating-point operations is interesting but somewhat tricky.
Since IEEE double has 53 bit of mantissa, one has to split the operands in
small prices, so that no result is greater than 2^53. For 32-bit computers,
splitting one operand into 16-bit pieces works. For 64-bit machines, one
operand can be split into 21-bit pieces and the other into 32-bit pieces. (A
64-bit operand can be split into just three 21-bit pieces if one allows the
split operands to be negative!)
<p> <li> <strong>Faster extended GCD</strong>
<p> We currently have extended GCD based on Lehmer's method.
But the binary method can quite easily be improved for bignums
in a similar way Lehmer improved Euclid's algorithm. The result should
beat Lehmer's method by about a factor of 2. Furthermore, the multiprecision
step of Lehmer's method and the binary method will be identical, so the
current code can mostly be reused. It should be possible to share code
between GCD and GCDEXT, and probably with Jacobi symbols too.
<p> <li> <strong>Math functions for the mpf layer</strong>
<p> Implement the functions of math.h for the GMP mpf layer! Check the book
"Pi and the AGM" by Borwein and Borwein for ideas how to do this. These
functions are desirable: acos, acosh, asin, asinh, atan, atanh, atan2, cos,
cosh, exp, log, log10, pow, sin, sinh, tan, tanh.
<p> <li> <strong>Faster sqrt</strong>
<p> The current code for computing square roots use a Newton iteration that
rely on division. It is possible to avoid using division by computing
1/sqrt(A) using this formula:
<pre>
2
x = x (3 - A x )/2.
i+1 i i </pre>
The final result is then computed without division using,
<pre>
sqrt(A) = A x .
n </pre>
The resulting code should be substantially faster than the current code.
<p> <li> <strong>Nth root</strong>
<p> Implement, at the mpn level, a routine for computing the nth root of a
number. The routine should use Newton's method, preferably without using
division.
<p> If the routine becomes fast enough, perhaps square roots could be computed
using this function.
<p> <li> <strong>More random number generators</strong>
<p> Implement some more pseudo random number generator algorithms.
Today there's only Linear Congruential.
<p> <li> <strong>Test Suite</strong>
<p> Add a test suite for old bugs. These tests wouldn't loop or use
random numbers, but just test for specific bugs found in the
past.
<p> More importantly, improve the random number controls for test
collections:
<ol>
<li> Use the new random number framework.
<li> Have every test accept a seed parameter.
<li> Allow `make check' to set the seed parameter.
<li> Add more tests for important, now untested functions.
</ol>
<p> With this in place, it should be possible to rid GMP of
practically all bugs by having some dedicated GMP test machines
running "make check" with ever increasing seeds (and
periodically updating to the latest GMP).
<p> If a few more ASSERTs were sprinkled through the code, running
some tests with --enable-assert might be useful, though not a
substitute for tests on the normal build.
<p> An important feature of any random tests will be to record the
seeds used, and perhaps to snapshot operands before performing
each test, so any problem exposed can be reproduced.
</ul>
<hr>
<table width="100%">
<tr>
<td>
<font size=2>
Please send comments about this page to
<a href="mailto:tege@swox.com">tege@swox.com</a>.<br>
Copyright (C) 1999, 2000 Torbjörn Granlund.
</font>
</td>
<td align=right>
</td>
</tr>
</table>
</body>
</html>

View File

@ -1,379 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>
GMP Itemized Development Tasks
</title>
</head>
<body bgcolor=lightgreen>
<center>
<h1>
GMP Itemized Development Tasks
</h1>
</center>
<comment>
An up-to-date html version of this file is available at
<a href="http://www.swox.com/gmp/tasks.html">http://www.swox.com/gmp/tasks.html</a>.
</comment>
<p> This file lists itemized GMP development tasks. Not all the tasks
listed here are suitable for volunteers, but many of them are.
Please see the <a href="projects.html">projects file</a> for more
sizeable projects.
<h4>Correctness and Completeness</h4>
<ul>
<li> HPUX 10.20 assembler requires a `.LEVEL 1.1' directive for accepting the
new instructions. Unfortunately, the HPUX 9 assembler as well as earlier
assemblers reject that directive. How very clever of HP! We will have to
pass assembler options, and make sure it works with new and old systems
and GNU assembler.
<li> The various reuse.c tests need to force reallocation by calling
<code>_mpz_realloc</code> with a small (1 limb) size.
<li> One reuse case is missing from mpX/tests/reuse.c: <code>mpz_XXX(a,a,a)</code>.
<li> When printing mpf_t numbers with exponents > 2^53 on machines with 64-bit
<code>mp_exp_t</code>, the precision of
<code>__mp_bases[base].chars_per_bit_exactly</code> is insufficient and
<code>mpf_get_str</code> aborts. Detect and compensate.
<li> Fix <code>mpz_get_si</code> to work properly for MIPS N32 ABI (and other
machines that use <code>long long</code> for storing limbs.)
<li> Make the string reading functions allow the `0x' prefix when the base is
explicitly 16. They currently only allow that prefix when the base is
unspecified.
<li> In the development sources, we return abs(a%b) in the
<code>mpz_*_ui</code> division routines. Perhaps make them return the
real remainder instead? Changes return type to <code>signed long int</code>.
<li> <code>mpf_eq</code> is not always correct, when one operand is
1000000000... and the other operand is 0111111111..., i.e., extremely
close. There is a special case in <code>mpf_sub</code> for this
situation; put similar code in <code>mpf_eq</code>.
<li> mpf_eq doesn't implement what gmp.texi specifies. It should not use just
whole limbs, but partial limbs.
<li> Install Alpha assembly changes (prec/gmp-alpha-patches).
<li> NeXT has problems with newlines in asm strings in longlong.h. Also,
<code>__builtin_constant_p</code> is unavailable? Same problem with MacOS
X.
<li> Shut up SGI's compiler by declaring <code>dump_abort</code> in
mp?/tests/*.c.
<li> <code>mpz_get_si</code> returns 0x80000000 for -0x100000000.
</ul>
<h4>Machine Independent Optimization</h4>
<ul>
<li> In hundreds of places in the code, we invoke count_leading_zeros and then
check if the returned count is zero. Instead check the most significant
bit of the operand, and avoid invoking <code>count_leading_zeros</code> if
the bit is set. This is an optimization on all machines, and significant
on machines with slow <code>count_leading_zeros</code>.
<li> In a couple of places <code>count_trailing_zeros</code> is used
on more or less uniformly distributed numbers. For some CPUs
<code>count_trailing_zeros</code> is slow and it's probably worth
handling the frequently occurring 0 to 2 trailing zeros cases specially.
<li> Change all places that use <code>udiv_qrnnd</code> for inverting limbs to
instead use <code>invert_limb</code>.
<li> Reorganize longlong.h so that we can inline the operations even for the
system compiler. When there is no such compiler feature, make calls to
stub functions. Write such stub functions for as many machines as
possible.
<li> Rewrite <code>umul_ppmm</code> to use floating-point for generating the
most significant limb (if <code>BITS_PER_MP_LIMB</code> &lt= 52 bits).
(Peter Montgomery has some ideas on this subject.)
<li> Improve the default <code>umul_ppmm</code> code in longlong.h: Add partial
products with fewer operations.
<li> Write new <code>mpn_get_str</code> and <code>mpn_set_str</code> running in
the sub O(n^2) range, using some divide-and-conquer approach, preferably
without using division.
<li> Copy tricky code for converting a limb from development version of
<code>mpn_get_str</code> to mpf/get_str. (Talk to Torbjörn about this.)
<li> Consider inlining these functions: <code>mpz_size</code>,
<code>mpz_set_ui</code>, <code>mpz_set_q</code>, <code>mpz_clear</code>,
<code>mpz_init</code>, <code>mpz_get_ui</code>, <code>mpz_scan0</code>,
<code>mpz_scan1</code>, <code>mpz_getlimbn</code>,
<code>mpz_init_set_ui</code>, <code>mpz_perfect_square_p</code>,
<code>mpz_popcount</code>, <code>mpf_size</code>,
<code>mpf_get_prec</code>, <code>mpf_set_prec_raw</code>,
<code>mpf_set_ui</code>, <code>mpf_init</code>, <code>mpf_init2</code>,
<code>mpf_clear</code>, <code>mpf_set_si</code>.
<li> <code>mpz_powm</code> and <code>mpz_powm_ui</code> aren't very
fast on one or two limb moduli, due to a lot of function call
overheads. These could perhaps be handled as special cases.
<li> <code>mpz_powm</code> and <code>mpz_powm_ui</code> want better
algorithm selection, and the latter should use REDC. Both could
change to use an <code>mpn_powm</code> and <code>mpn_redc</code>.
<li> <code>mpn_gcd</code> might be able to be sped up on small to
moderate sizes by improving <code>find_a</code>, possibly just by
providing an alternate implementation for CPUs with slowish
<code>count_leading_zeros</code>.
<li> Implement a cache localized evaluate and interpolate for the
toom3 <code>USE_MORE_MPN</code> code. The necessary
right-to-left <code>mpn_divexact_by3c</code> exists.
<li> <code>mpn_mul_basecase</code> on NxM with big N but small M could try for
better cache locality by taking N piece by piece. The current code could
be left available for CPUs without caching. Depending how karatsuba etc
is applied to unequal size operands it might be possible to assume M is
always smallish.
</ul>
<h4>Machine Dependent Optimization</h4>
<ul>
<li> Run the `tune' utility for more compiler/CPU combinations. We would like
to have gmp-mparam.h files in practically every implementation specific
mpn subdirectory, and repeat each *_THRESHOLD for gcc and the system
compiler. See the `tune' top-level directory for more information.
<li> Alpha: Rewrite <code>mpn_addmul_1</code>, <code>mpn_submul_1</code>, and
<code>mpn_mul_1</code> for the 21264. On 21264, they should run at 4, 3,
and 3 cycles/limb respectively, if the code is unrolled properly. (Ask
Torbjörn for his xm.s and xam.s skeleton files.)
<li> Alpha: Rewrite <code>mpn_addmul_1</code>, <code>mpn_submul_1</code>, and
<code>mpn_mul_1</code> for the 21164. This should use both integer
multiplies and floating-point multiplies. For the floating-point
operations, the single-limb multiplier should be split into three 21-bit
chunks.
<li> UltraSPARC: Rewrite 64-bit <code>mpn_addmul_1</code>,
<code>mpn_submul_1</code>, and <code>mpn_mul_1</code>. Should use
floating-point operations, and split the invariant single-limb multiplier
into 21-bit chunks. Should give about 18 cycles/limb, but the pipeline
will become very deep. (Torbjörn has C code that is useful as a starting
point.)
<li> UltraSPARC: Rewrite <code>mpn_lshift</code> and <code>mpn_rshift</code>.
Should give 2 cycles/limb. (Torbjörn has code that just needs to be
finished.)
<li> SPARC32/V9: Find out why the speed of <code>mpn_addmul_1</code>
and the other multiplies varies so much on successive sizes.
<li> PA64: Improve <code>mpn_addmul_1</code>, <code>mpn_submul_1</code>, and
<code>mpn_mul_1</code>. The current development code runs at 11
cycles/limb, which is already very good. But it should be possible to
saturate the cache, which will happen at 7.5 cycles/limb.
<li> Sparc & SparcV8: Enable umul.asm for native cc. The generic
longlong.h umul_ppmm is suspected to be causing sqr_basecase to
be slower than mul_basecase.
<li> UltraSPARC: Write <code>umul_ppmm</code>. Important in particular for
<code>mpn_sqr_basecase</code>. Using four "<code>mulx</code>"s either
with an asm block or via the generic C code is about 90 cycles.
<li> Implement <code>mpn_mul_basecase</code> and <code>mpn_sqr_basecase</code>
for important machines. Helping the generic sqr_basecase.c with an
<code>mpn_sqr_diagonal</code> might be enough for some of the RISCs.
<li> POWER2/POWER2SC: Schedule <code>mpn_lshift</code>/<code>mpn_rshift</code>.
Will bring time from 1.75 to 1.25 cycles/limb.
<li> X86: Optimize non-MMX <code>mpn_lshift</code> for shifts by 1. (See Pentium code.)
<li> Alpha: Optimize <code>count_leading_zeros</code>.
<li> Alpha: Optimize <code>udiv_qrnnd</code>. (Ask Torbjörn for the file
test-udiv-preinv.c as a starting point.)
<li> R10000/R12000: Rewrite <code>mpn_add_n</code> and <code>mpn_sub_n</code>.
It should just require 3 cycles/limb, but the current code propagates
carry poorly. The trick is to add carry-in later than we do now,
decreasing the number of operations used to generate carry-out from 4 to
to 3.
<li> PPC32: Try using fewer registers in the current <code>mpn_lshift</code>.
The pipeline is now extremely deep, perhaps unnecessarily deep. Also, r5
is unused. (Ask Torbjörn for a copy of the current code.)
<li> PPC32: Write <code>mpn_rshift</code> based on new <code>mpn_lshift</code>.
<li> PPC32: Rewrite <code>mpn_add_n</code> and <code>mpn_sub_n</code>. Should
run at just 3.25 cycles/limb. (Ask for xxx-add_n.s as a starting point.)
<li> Fujitsu VPP: Vectorize main functions, perhaps in assembly language.
<li> Fujitsu VPP: Write <code>mpn_mul_basecase</code> and
<code>mpn_sqr_basecase</code>. This should use a "vertical multiplication
method", to avoid carry propagation. splitting one of the operands in
11-bit chunks.
<li> Cray: Vectorize main functions, perhaps in assembly language.
<li> Cray: Write <code>mpn_mul_basecase</code> and
<code>mpn_sqr_basecase</code>. Same comment applies to this as to the
same functions for Fujitsu VPP.
<li> Improve <code>count_leading_zeros</code> for 64-bit machines:
<pre>
if ((x &gt&gt W_TYPE_SIZE-W_TYPE_SIZE/2) == 0) { x &lt&lt= W_TYPE_SIZE/2; cnt += W_TYPE_SIZE/2}
if ((x &gt&gt W_TYPE_SIZE-W_TYPE_SIZE/4) == 0) { x &lt&lt= W_TYPE_SIZE/4; cnt += W_TYPE_SIZE/4}
... </pre>
</ul>
<h4>New Functionality</h4>
<ul>
<li> <code>mpz_get_nth_ui</code>. Return the nth word (not necessarily the nth limb).
<li> Maybe add <code>mpz_crr</code> (Chinese Remainder Reconstruction).
<li> Let `0b' and `0B' mean binary input everywhere.
<li> Add <code>mpq_set_f</code> for assignment from <code>mpf_t</code>
(cf. <code>mpq_set_d</code>).
<li> Maybe make <code>mpz_init</code> (and <code>mpq_init</code>) do lazy
allocation. Set <code>ALLOC(var)</code> to 0, and have
<code>mpz_realloc</code> special-handle that case. Update functions that
rely on a single limb (like <code>mpz_set_ui</code>,
<code>mpz_[tfc]div_r_ui</code>, and others).
<li> Add <code>mpf_out_raw</code> and <code>mpf_inp_raw</code>. Make sure
format is portable between 32-bit and 64-bit machines, and between
little-endian and big-endian machines.
<li> Handle numeric exceptions: Call an error handler, and/or set
<code>gmp_errno</code>.
<li> Implement <code>gmp_fprintf</code>, <code>gmp_sprintf</code>, and
<code>gmp_snprintf</code>. Think about some sort of wrapper
around <code>printf</code> so it and its several variants don't
have to be completely reimplemented.
<li> Implement some <code>mpq</code> input and output functions.
<li> Implement a full precision <code>mpz_kronecker</code>, leave
<code>mpz_jacobi</code> for compatibility.
<li> Make the mpn logops and copys available in gmp.h. Since they can
be either library functions or inlines, gmp.h would need to be
generated from a gmp.in based on what's in the library. gmp.h
would still be compiler-independent though.
<li> Make versions of <code>mpz_set_str</code> etc taking string
lengths rather than null-terminators.
<li> Consider changing the thresholds to apply the simpler algorithm when
"<code>&lt;=</code>" rather than "<code>&lt;</code>", so a threshold can
be set to <code>MP_SIZE_T_MAX</code> to get only the simpler code (the
compiler will know <code>size &lt;= MP_SIZE_T_MAX</code> is always true).
<li> <code>mpz_cdiv_q_2exp</code> and <code>mpz_cdiv_r_2exp</code>
could be implemented to match the corresponding tdiv and fdiv.
Maybe some code sharing is possible.
</ul>
<h4>Configuration</h4>
<ul>
<li> Improve config.guess. We want to recognize the processor very
accurately, more accurately than other GNU packages.
config.guess does not currently make the distinctions we would
like it to do and a --target often needs to be set explicitly.
For example, "sparc" is not very useful as a machine architecture
denotation. We want to distinguish old 32-bit SPARC without
multiply support from newer 32-bit SPARC with such support. We
want to recognize a SuperSPARC, since its implementation of the
UDIV instruction is not complete, and will trap to the OS kernel
for certain operands. And we want to recognize 64-bit capable
SPARC processors as such. While the assembly routines can use
64-bit operations on all 64-bit SPARC processors, one can not use
64-bit limbs under all operating system. E.g., Solaris 2.5 and
2.6 doesn't preserve the upper 32 bits of most processor
registers. For SPARC we therefore sometimes need to choose GMP
configuration depending both on processor and operating system.
<li> Remember to make sure config.sub accepts any output from config.guess.
<li> Find out whether there's an alloca available and how to use it.
AC_FUNC_ALLOCA has various system dependencies covered, but we
don't want its alloca.c replacement. (One thing current cpp
tests don't cover: HPUX 10 C compiler supports alloca, but
cannot find any symbol to test in order to know if we're on
HPUX 10. Damn.)
<li> Identify Mips processor under Irix: `hinv -c processor'.
config.guess should say mips2, mips3, and mips4.
<li> Identify Alpha processor under OSF: "/usr/sbin/sizer -c".
Unfortunately, sizer is not available before some revision of
Dec Unix 4.0, and it also returns some rather cryptic names for
processors. Perhaps the <code>implver</code> and
<code>amask</code> assembly instructions are better, but that
doesn't differentiate between ev5 and ev56.
<li> Identify Sparc processors. config.guess should say supersparc,
microsparc, ultrasparc1, ultrasparc2, etc.
<li> Identify HPPA processors similarly.
<li> Get lots of information about a Solaris system: prtconf -vp
<li> For some target machines and some compilers, specific options
are needed (sparcv8/gcc needs -mv8, sparcv8/cc needs -cg92,
Irix64/cc needs -64, Irix32/cc might need -n32, etc). Some are
set already, add more, see configure.in.
<li> Options to be passed to the assembler (via the compiler, using
whatever syntax the compiler uses for passing options to the
assembler).
<li> On Solaris 7, check if gcc supports native v9 64-bit
arithmetic. If not compile using "cc -fast -xarch=v9".
(Problem: -fast requires that we link with -fast too, which
might not be very good. Pass "-xO4 -xtarget=native" instead?)
<li> Extend the "optional" compiler arguments to choose the first
that works from from a set, so when gcc gets athlon support it
can try -mcpu=athlon, -mcpu=pentiumpro, or -mcpu=i486,
whichever works.
<li> Detect gcc >=2.96 and enable -march=pentiumpro for relevant
x86s. (A bug in gcc 2.95.2 prevents it being used
unconditionally.)
<li> Build multiple variants of the library under certain systems.
An example is -n32, -o32, and -64 on Irix.
<li> There's a few filenames that don't fit in 14 chars, if this
matters.
<li> Enable support for FORTRAN versions of mpn files (eg. for
mpn/cray/mulww.f). Add "f" to the mpn path searching, run AC_PROG_F77 if
such a file is found. Automake will generate some of what's needed in the
makefiles, but libtool doesn't know fortran and so rules like the current
".asm.lo" will be needed.
<li> Only run GMP_PROG_M4 if it's needed, ie. if there's .asm files
selected from the mpn path. This might help say a generic C
build on weird systems.
</ul>
<p> In general, getting the exact right configuration, passing the
exact right options to the compiler, etc, might mean that the GMP
performance more than doubles.
<p> When testing, make sure to test at least the following for all out
target machines: (1) Both gcc and cc (and c89). (2) Both 32-bit mode
and 64-bit mode (such as -n32 vs -64 under Irix). (3) Both the system
`make' and GNU `make'. (4) With and without GNU binutils.
<h4>Miscellaneous</h4>
<ul>
<li> Work on the way we build the library. We now do it building
convenience libraries but then listing all the object files a
second time in the top level Makefile.am.
<li> Get rid of mp[zq]/sub.c, and instead define a compile parameter to
mp[zq]/add.c to decide whether it will add or subtract. Will decrease
redundancy. Similarly in other places.
<li> Make <code>mpz_div</code> and <code>mpz_divmod</code> use rounding
analogous to <code>mpz_mod</code>. Document, and list as an
incompatibility.
<li> Maybe make mpz_pow_ui.c more like mpz/ui_pow_ui.c, or write new
mpn/generic/pow_ui.
<li> Make mpz_invert call mpn_gcdext directly.
<li> Make a build option to enable execution profiling with gprof. In
particular look at getting the right <code>mcount</code> call at
the start of each assembler subroutine (for important targets at
least).
</ul>
<h4>Aids to Debugging</h4>
<ul>
<li> Make an option for stack-alloc.c to call <code>malloc</code>
separately for each <code>TMP_ALLOC</code> block, so a redzoning
malloc debugger could be used during development.
<li> Add <code>ASSERT</code>s at the start of each user-visible
mpz/mpq/mpf function to check the validity of each
<code>mp?_t</code> parameter, in particular to check they've been
<code>mp?_init</code>ed. This might catch elementary mistakes in
user programs. Care would need to be taken over
<code>MPZ_TMP_INIT</code>ed variables used internally.
</ul>
<h4>Documentation</h4>
<ul>
<li> Document conventions, like that <code> unsigned long int</code> is used for
bit counts/ranges, and that <code>mp_size_t</code> is used for limb counts.
<li> <code>mpz_inp_str</code> (etc) doesn't say when it stops reading digits.
</ul>
<hr>
<table width="100%">
<tr>
<td>
<font size=2>
Please send comments about this page to
<a href="mailto:tege@swox.com">tege@swox.com</a>.<br>
Copyright (C) 1999, 2000 Torbjörn Granlund.
</font>
</td>
<td align=right>
</td>
</tr>
</table>
</body>
</html>

View File

@ -1,26 +0,0 @@
/* gmp_errno -- The largest and most complex file in GMP.
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int gmp_errno = 0;

View File

@ -1,187 +0,0 @@
/* __gmp_extract_double -- convert from double to array of mp_limb_t.
Copyright (C) 1996, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#ifdef XDEBUG
#undef _GMP_IEEE_FLOATS
#endif
#ifndef _GMP_IEEE_FLOATS
#define _GMP_IEEE_FLOATS 0
#endif
/* Extract a non-negative double in d. */
int
#if __STDC__
__gmp_extract_double (mp_ptr rp, double d)
#else
__gmp_extract_double (rp, d)
mp_ptr rp;
double d;
#endif
{
long exp;
unsigned sc;
mp_limb_t manh, manl;
/* BUGS
1. Should handle Inf and NaN in IEEE specific code.
2. Handle Inf and NaN also in default code, to avoid hangs.
3. Generalize to handle all BITS_PER_MP_LIMB >= 32.
4. This lits is incomplete and misspelled.
*/
if (d == 0.0)
{
rp[0] = 0;
rp[1] = 0;
#if BITS_PER_MP_LIMB == 32
rp[2] = 0;
#endif
return 0;
}
#if _GMP_IEEE_FLOATS
{
#if defined (__alpha) && __GNUC__ == 2 && __GNUC_MINOR__ == 8
/* Work around alpha-specific bug in GCC 2.8.x. */
volatile
#endif
union ieee_double_extract x;
x.d = d;
exp = x.s.exp;
#if BITS_PER_MP_LIMB == 64
manl = (((mp_limb_t) 1 << 63)
| ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11));
if (exp == 0)
{
/* Denormalized number. Don't try to be clever about this,
since it is not an important case to make fast. */
exp = 1;
do
{
manl = manl << 1;
exp--;
}
while ((mp_limb_signed_t) manl >= 0);
}
#else
manh = ((mp_limb_t) 1 << 31) | (x.s.manh << 11) | (x.s.manl >> 21);
manl = x.s.manl << 11;
if (exp == 0)
{
/* Denormalized number. Don't try to be clever about this,
since it is not an important case to make fast. */
exp = 1;
do
{
manh = (manh << 1) | (manl >> 31);
manl = manl << 1;
exp--;
}
while ((mp_limb_signed_t) manh >= 0);
}
#endif
exp -= 1022; /* Remove IEEE bias. */
}
#else
{
/* Unknown (or known to be non-IEEE) double format. */
exp = 0;
if (d >= 1.0)
{
if (d * 0.5 == d)
abort ();
while (d >= 32768.0)
{
d *= (1.0 / 65536.0);
exp += 16;
}
while (d >= 1.0)
{
d *= 0.5;
exp += 1;
}
}
else if (d < 0.5)
{
while (d < (1.0 / 65536.0))
{
d *= 65536.0;
exp -= 16;
}
while (d < 0.5)
{
d *= 2.0;
exp -= 1;
}
}
d *= MP_BASE_AS_DOUBLE;
#if BITS_PER_MP_LIMB == 64
manl = d;
#else
manh = d;
manl = (d - manh) * MP_BASE_AS_DOUBLE;
#endif
}
#endif
sc = (unsigned) exp % BITS_PER_MP_LIMB;
/* We add something here to get rounding right. */
exp = (exp + 2048) / BITS_PER_MP_LIMB - 2048 / BITS_PER_MP_LIMB + 1;
#if BITS_PER_MP_LIMB == 64
if (sc != 0)
{
rp[1] = manl >> (BITS_PER_MP_LIMB - sc);
rp[0] = manl << sc;
}
else
{
rp[1] = manl;
rp[0] = 0;
exp--;
}
#else
if (sc != 0)
{
rp[2] = manh >> (BITS_PER_MP_LIMB - sc);
rp[1] = (manl >> (BITS_PER_MP_LIMB - sc)) | (manh << sc);
rp[0] = manl << sc;
}
else
{
rp[2] = manh;
rp[1] = manl;
rp[0] = 0;
exp--;
}
#endif
return exp;
}

File diff suppressed because it is too large Load Diff

1073
gmp/gmp.h

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,98 +0,0 @@
/* __gmp_insert_double -- convert from array of mp_limb_t to double.
Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#ifdef XDEBUG
#undef _GMP_IEEE_FLOATS
#endif
#ifndef _GMP_IEEE_FLOATS
#define _GMP_IEEE_FLOATS 0
#endif
double
#if __STDC__
__gmp_scale2 (double d, int exp)
#else
__gmp_scale2 (d, exp)
double d;
int exp;
#endif
{
#if _GMP_IEEE_FLOATS
{
#if defined (__alpha) && __GNUC__ == 2 && __GNUC_MINOR__ == 8
/* Work around alpha-specific bug in GCC 2.8.x. */
volatile
#endif
union ieee_double_extract x;
x.d = d;
exp += x.s.exp;
x.s.exp = exp;
if (exp >= 2047)
{
/* Return +-infinity */
x.s.exp = 2047;
x.s.manl = x.s.manh = 0;
}
else if (exp < 1)
{
x.s.exp = 1; /* smallest exponent (biased) */
/* Divide result by 2 until we have scaled it to the right IEEE
denormalized number, but stop if it becomes zero. */
while (exp < 1 && x.d != 0)
{
x.d *= 0.5;
exp++;
}
}
return x.d;
}
#else
{
double factor, r;
factor = 2.0;
if (exp < 0)
{
factor = 0.5;
exp = -exp;
}
r = d;
if (exp != 0)
{
if ((exp & 1) != 0)
r *= factor;
exp >>= 1;
while (exp != 0)
{
factor *= factor;
if ((exp & 1) != 0)
r *= factor;
exp >>= 1;
}
}
return r;
}
#endif
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
gmp/macos.1/configure vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,160 +0,0 @@
/* Memory allocation routines.
Copyright (C) 1991, 1993, 1994, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h> /* for malloc, realloc, free */
#include "gmp.h"
#include "gmp-impl.h"
#ifdef __NeXT__
#define static
#endif
void * (*_mp_allocate_func) _PROTO ((size_t)) = _mp_default_allocate;
void * (*_mp_reallocate_func) _PROTO ((void *, size_t, size_t))
= _mp_default_reallocate;
void (*_mp_free_func) _PROTO ((void *, size_t)) = _mp_default_free;
/* Default allocation functions. In case of failure to allocate/reallocate
an error message is written to stderr and the program aborts. */
void *
#if __STDC__
_mp_default_allocate (size_t size)
#else
_mp_default_allocate (size)
size_t size;
#endif
{
void *ret;
#ifdef DEBUG
size_t req_size = size;
size += 2 * BYTES_PER_MP_LIMB;
#endif
ret = malloc (size);
if (ret == 0)
{
perror ("cannot allocate in gmp");
abort ();
}
#ifdef DEBUG
{
mp_ptr p = ret;
p++;
p[-1] = (0xdeadbeef << 31) + 0xdeafdeed;
if (req_size % BYTES_PER_MP_LIMB == 0)
p[req_size / BYTES_PER_MP_LIMB] = ~((0xdeadbeef << 31) + 0xdeafdeed);
ret = p;
}
#endif
return ret;
}
void *
#if __STDC__
_mp_default_reallocate (void *oldptr, size_t old_size, size_t new_size)
#else
_mp_default_reallocate (oldptr, old_size, new_size)
void *oldptr;
size_t old_size;
size_t new_size;
#endif
{
void *ret;
#ifdef DEBUG
size_t req_size = new_size;
if (old_size != 0)
{
mp_ptr p = oldptr;
if (p[-1] != (0xdeadbeef << 31) + 0xdeafdeed)
{
fprintf (stderr, "gmp: (realloc) data clobbered before allocation block\n");
abort ();
}
if (old_size % BYTES_PER_MP_LIMB == 0)
if (p[old_size / BYTES_PER_MP_LIMB] != ~((0xdeadbeef << 31) + 0xdeafdeed))
{
fprintf (stderr, "gmp: (realloc) data clobbered after allocation block\n");
abort ();
}
oldptr = p - 1;
}
new_size += 2 * BYTES_PER_MP_LIMB;
#endif
ret = realloc (oldptr, new_size);
if (ret == 0)
{
perror ("cannot allocate in gmp");
abort ();
}
#ifdef DEBUG
{
mp_ptr p = ret;
p++;
p[-1] = (0xdeadbeef << 31) + 0xdeafdeed;
if (req_size % BYTES_PER_MP_LIMB == 0)
p[req_size / BYTES_PER_MP_LIMB] = ~((0xdeadbeef << 31) + 0xdeafdeed);
ret = p;
}
#endif
return ret;
}
void
#if __STDC__
_mp_default_free (void *blk_ptr, size_t blk_size)
#else
_mp_default_free (blk_ptr, blk_size)
void *blk_ptr;
size_t blk_size;
#endif
{
#ifdef DEBUG
{
mp_ptr p = blk_ptr;
if (blk_size != 0)
{
if (p[-1] != (0xdeadbeef << 31) + 0xdeafdeed)
{
fprintf (stderr, "gmp: (free) data clobbered before allocation block\n");
abort ();
}
if (blk_size % BYTES_PER_MP_LIMB == 0)
if (p[blk_size / BYTES_PER_MP_LIMB] != ~((0xdeadbeef << 31) + 0xdeafdeed))
{
fprintf (stderr, "gmp: (free) data clobbered after allocation block\n");
abort ();
}
}
blk_ptr = p - 1;
}
#endif
free (blk_ptr);
}

Binary file not shown.

Binary file not shown.

123
gmp/mp.h
View File

@ -1,123 +0,0 @@
/* mp.h -- Definitions for Berkeley compatible multiple precision functions.
Copyright (C) 1991, 1993, 1994, 1995, 1996, 2000 Free Software Foundation,
Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#ifndef __MP_H__
#ifndef __GNU_MP__ /* to allow inclusion of both gmp.h and mp.h */
#define __GNU_MP__ 3
#define __need_size_t
#include <stddef.h>
#undef __need_size_t
#if defined (__STDC__) || defined (__cplusplus)
#define __gmp_const const
#else
#define __gmp_const
#endif
#if defined (__GNUC__)
#define __gmp_inline __inline__
#else
#define __gmp_inline
#endif
#ifndef _EXTERN_INLINE
#ifdef __GNUC__
#define _EXTERN_INLINE extern __inline__
#else
#define _EXTERN_INLINE static
#endif
#endif
#ifdef _SHORT_LIMB
typedef unsigned int mp_limb_t;
typedef int mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int mp_limb_t;
typedef long long int mp_limb_signed_t;
#else
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef mp_limb_t * mp_ptr;
typedef __gmp_const mp_limb_t * mp_srcptr;
typedef int mp_size_t;
typedef long int mp_exp_t;
typedef struct
{
int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#endif /* __GNU_MP__ */
/* User-visible types. */
typedef __mpz_struct MINT;
#ifndef _PROTO
#if (__STDC__-0) || defined (__cplusplus)
#define _PROTO(x) x
#else
#define _PROTO(x) ()
#endif
#endif
#if defined (__cplusplus)
extern "C" {
#endif
void mp_set_memory_functions _PROTO ((void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t)));
MINT *itom _PROTO ((signed short int));
MINT *xtom _PROTO ((const char *));
void move _PROTO ((const MINT *, MINT *));
void madd _PROTO ((const MINT *, const MINT *, MINT *));
void msub _PROTO ((const MINT *, const MINT *, MINT *));
void mult _PROTO ((const MINT *, const MINT *, MINT *));
void mdiv _PROTO ((const MINT *, const MINT *, MINT *, MINT *));
void sdiv _PROTO ((const MINT *, signed short int, MINT *, signed short int *));
void msqrt _PROTO ((const MINT *, MINT *, MINT *));
void pow _PROTO ((const MINT *, const MINT *, const MINT *, MINT *));
void rpow _PROTO ((const MINT *, signed short int, MINT *));
void gcd _PROTO ((const MINT *, const MINT *, MINT *));
int mcmp _PROTO ((const MINT *, const MINT *));
void min _PROTO ((MINT *));
void mout _PROTO ((const MINT *));
char *mtox _PROTO ((const MINT *));
void mfree _PROTO ((MINT *));
#if defined (__cplusplus)
}
#endif
#define __MP_H__
#endif /* __MP_H__ */

View File

@ -1,27 +0,0 @@
/*
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
#include "gmp.h"
#include "gmp-impl.h"
const int mp_bits_per_limb = BITS_PER_MP_LIMB;
const int __gmp_0 = 0;
int __gmp_junk;

View File

@ -1,36 +0,0 @@
/* __clz_tab -- support for longlong.h
Copyright (C) 1991, 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
const
unsigned char __clz_tab[] =
{
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
};

View File

@ -1,50 +0,0 @@
/* A table of data supporting modlimb_invert().
THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND MAY CHANGE
INCOMPATIBLY OR DISAPPEAR IN A FUTURE GNU MP RELEASE. */
/*
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* modlimb_invert_table[i] is the multiplicative inverse of 2*i+1 mod 256,
ie. (modlimb_invert_table[i] * (2*i+1)) % 256 == 1 */
const unsigned char modlimb_invert_table[128] = {
0x01, 0xAB, 0xCD, 0xB7, 0x39, 0xA3, 0xC5, 0xEF,
0xF1, 0x1B, 0x3D, 0xA7, 0x29, 0x13, 0x35, 0xDF,
0xE1, 0x8B, 0xAD, 0x97, 0x19, 0x83, 0xA5, 0xCF,
0xD1, 0xFB, 0x1D, 0x87, 0x09, 0xF3, 0x15, 0xBF,
0xC1, 0x6B, 0x8D, 0x77, 0xF9, 0x63, 0x85, 0xAF,
0xB1, 0xDB, 0xFD, 0x67, 0xE9, 0xD3, 0xF5, 0x9F,
0xA1, 0x4B, 0x6D, 0x57, 0xD9, 0x43, 0x65, 0x8F,
0x91, 0xBB, 0xDD, 0x47, 0xC9, 0xB3, 0xD5, 0x7F,
0x81, 0x2B, 0x4D, 0x37, 0xB9, 0x23, 0x45, 0x6F,
0x71, 0x9B, 0xBD, 0x27, 0xA9, 0x93, 0xB5, 0x5F,
0x61, 0x0B, 0x2D, 0x17, 0x99, 0x03, 0x25, 0x4F,
0x51, 0x7B, 0x9D, 0x07, 0x89, 0x73, 0x95, 0x3F,
0x41, 0xEB, 0x0D, 0xF7, 0x79, 0xE3, 0x05, 0x2F,
0x31, 0x5B, 0x7D, 0xE7, 0x69, 0x53, 0x75, 0x1F,
0x21, 0xCB, 0xED, 0xD7, 0x59, 0xC3, 0xE5, 0x0F,
0x11, 0x3B, 0x5D, 0xC7, 0x49, 0x33, 0x55, 0xFF
};

View File

@ -1,48 +0,0 @@
/* mp_set_memory_functions -- Set the allocate, reallocate, and free functions
for use by the mp package.
Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mp_set_memory_functions (void *(*alloc_func) (size_t),
void *(*realloc_func) (void *, size_t, size_t),
void (*free_func) (void *, size_t))
#else
mp_set_memory_functions (alloc_func, realloc_func, free_func)
void *(*alloc_func) ();
void *(*realloc_func) ();
void (*free_func) ();
#endif
{
if (alloc_func == 0)
alloc_func = _mp_default_allocate;
if (realloc_func == 0)
realloc_func = _mp_default_reallocate;
if (free_func == 0)
free_func = _mp_default_free;
_mp_allocate_func = alloc_func;
_mp_reallocate_func = realloc_func;
_mp_free_func = free_func;
}

Binary file not shown.

Binary file not shown.

View File

@ -1,54 +0,0 @@
/* itom -- BSD compatible allocate and initiate a MINT.
Copyright (C) 1991, 1994, 1995, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
MINT *
#if __STDC__
itom (signed short int n)
#else
itom (n)
short int n;
#endif
{
MINT *x;
mp_ptr xp;
x = (MINT *) (*_mp_allocate_func) (sizeof (MINT));
x->_mp_alloc = 1;
x->_mp_d = xp = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB);
if (n > 0)
{
x->_mp_size = 1;
xp[0] = n;
}
else if (n < 0)
{
x->_mp_size = -1;
xp[0] = (unsigned short) -n;
}
else
x->_mp_size = 0;
return x;
}

View File

@ -1,36 +0,0 @@
/* mfree -- BSD compatible mfree.
Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mfree (MINT *m)
#else
mfree (m)
MINT *m;
#endif
{
(*_mp_free_func) (m->_mp_d, m->_mp_alloc * BYTES_PER_MP_LIMB);
(*_mp_free_func) (m, sizeof (MINT));
}

View File

@ -1,114 +0,0 @@
/* min(MINT) -- Do decimal input from standard input and store result in
MINT.
Copyright (C) 1991, 1994, 1996, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include <ctype.h>
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
static int
#if __STDC__
digit_value_in_base (int c, int base)
#else
digit_value_in_base (c, base)
int c;
int base;
#endif
{
int digit;
if (isdigit (c))
digit = c - '0';
else if (islower (c))
digit = c - 'a' + 10;
else if (isupper (c))
digit = c - 'A' + 10;
else
return -1;
if (digit < base)
return digit;
return -1;
}
void
#if __STDC__
min (MINT *dest)
#else
min (dest)
MINT *dest;
#endif
{
char *str;
size_t alloc_size, str_size;
int c;
int negative;
mp_size_t dest_size;
alloc_size = 100;
str = (char *) (*_mp_allocate_func) (alloc_size);
str_size = 0;
/* Skip whitespace. */
do
c = getc (stdin);
while (isspace (c));
negative = 0;
if (c == '-')
{
negative = 1;
c = getc (stdin);
}
if (digit_value_in_base (c, 10) < 0)
return; /* error if no digits */
for (;;)
{
int dig;
if (str_size >= alloc_size)
{
size_t old_alloc_size = alloc_size;
alloc_size = alloc_size * 3 / 2;
str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size);
}
dig = digit_value_in_base (c, 10);
if (dig < 0)
break;
str[str_size++] = dig;
c = getc (stdin);
}
ungetc (c, stdin);
dest_size = str_size / __mp_bases[10].chars_per_limb + 1;
if (dest->_mp_alloc < dest_size)
_mp_realloc (dest, dest_size);
dest_size = mpn_set_str (dest->_mp_d, (unsigned char *) str, str_size, 10);
dest->_mp_size = negative ? -dest_size : dest_size;
(*_mp_free_func) (str, alloc_size);
return;
}

View File

@ -1,97 +0,0 @@
/* mout(MINT) -- Do decimal output of MINT to standard output.
Copyright (C) 1991, 1994, 1996, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include <string.h>
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mout (const MINT *x)
#else
mout (x)
const MINT *x;
#endif
{
mp_ptr xp;
mp_size_t x_size = x->_mp_size;
unsigned char *str;
size_t str_size;
char *num_to_text;
int i;
TMP_DECL (marker);
if (x_size == 0)
{
fputc ('0', stdout);
return;
}
if (x_size < 0)
{
fputc ('-', stdout);
x_size = -x_size;
}
TMP_MARK (marker);
str_size = ((size_t) (x_size * BITS_PER_MP_LIMB
* __mp_bases[10].chars_per_bit_exactly)) + 3;
str = (unsigned char *) TMP_ALLOC (str_size);
/* Move the number to convert into temporary space, since mpn_get_str
clobbers its argument + needs one extra high limb.... */
xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB);
MPN_COPY (xp, x->_mp_d, x_size);
str_size = mpn_get_str (str, 10, xp, x_size);
/* mpn_get_str might make some leading zeros. Skip them. */
while (*str == 0)
{
str_size--;
str++;
}
/* Translate to printable chars. */
for (i = 0; i < str_size; i++)
str[i] = "0123456789"[str[i]];
str[str_size] = 0;
str_size = strlen ((char *) str);
if (str_size % 10 != 0)
{
fwrite (str, 1, str_size % 10, stdout);
str += str_size % 10;
str_size -= str_size % 10;
if (str_size != 0)
fputc (' ', stdout);
}
for (i = 0; i < str_size; i += 10)
{
fwrite (str, 1, 10, stdout);
str += 10;
if (i + 10 < str_size)
fputc (' ', stdout);
}
fputc ('\n', stdout);
TMP_FREE (marker);
}

View File

@ -1,46 +0,0 @@
/* move -- BSD compatible assignment.
Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
move (const MINT *u, MINT *w)
#else
move (u, w)
const MINT *u;
MINT *w;
#endif
{
mp_size_t usize;
mp_size_t abs_usize;
usize = u->_mp_size;
abs_usize = ABS (usize);
if (w->_mp_alloc < abs_usize)
_mp_realloc (w, abs_usize);
w->_mp_size = usize;
MPN_COPY (w->_mp_d, u->_mp_d, abs_usize);
}

View File

@ -1,81 +0,0 @@
/* mtox -- Convert OPERAND to hexadecimal and return a malloc'ed string
with the result of the conversion.
Copyright (C) 1991, 1994, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
char *
#if __STDC__
mtox (const MINT *x)
#else
mtox (x)
const MINT *x;
#endif
{
mp_ptr xp;
mp_size_t xsize = x->_mp_size;
mp_size_t xsign;
unsigned char *str, *s;
size_t str_size, i;
int zeros;
char *num_to_text;
TMP_DECL (marker);
if (xsize == 0)
{
str = (unsigned char *) (*_mp_allocate_func) (2);
str[0] = '0';
str[1] = 0;
return (char *) str;
}
xsign = xsize;
if (xsize < 0)
xsize = -xsize;
TMP_MARK (marker);
str_size = ((size_t) (xsize * BITS_PER_MP_LIMB
* __mp_bases[16].chars_per_bit_exactly)) + 3;
str = (unsigned char *) (*_mp_allocate_func) (str_size);
s = str;
if (xsign < 0)
*s++ = '-';
/* Move the number to convert into temporary space, since mpn_get_str
clobbers its argument + needs one extra high limb.... */
xp = (mp_ptr) TMP_ALLOC ((xsize + 1) * BYTES_PER_MP_LIMB);
MPN_COPY (xp, x->_mp_d, xsize);
str_size = mpn_get_str (s, 16, xp, xsize);
/* mpn_get_str might make some leading zeros. Skip them. */
for (zeros = 0; s[zeros] == 0; zeros++)
str_size--;
/* Translate to printable chars and move string down. */
for (i = 0; i < str_size; i++)
s[i] = "0123456789abcdef"[s[zeros + i]];
s[str_size] = 0;
return (char *) str;
}

View File

@ -1,77 +0,0 @@
/* sdiv -- Divide a MINT by a short integer. Produce a MINT quotient
and a short remainder.
Copyright (C) 1991, 1994, 1995, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#if __STDC__
sdiv (const MINT *dividend, signed short int divisor_short, MINT *quot, short *rem_ptr)
#else
sdiv (dividend, divisor_short, quot, rem_ptr)
const MINT *dividend;
short int divisor_short;
MINT *quot;
short *rem_ptr;
#endif
{
mp_size_t sign_dividend;
signed long int sign_divisor;
mp_size_t dividend_size, quot_size;
mp_ptr dividend_ptr, quot_ptr;
mp_limb_t divisor_limb;
mp_limb_t remainder_limb;
sign_dividend = dividend->_mp_size;
dividend_size = ABS (dividend->_mp_size);
if (dividend_size == 0)
{
quot->_mp_size = 0;
*rem_ptr = 0;
return;
}
sign_divisor = divisor_short;
divisor_limb = (unsigned short) ABS (divisor_short);
/* No need for temporary allocation and copying even if QUOT == DIVIDEND
as the divisor is just one limb, and thus no intermediate remainders
need to be stored. */
if (quot->_mp_alloc < dividend_size)
_mp_realloc (quot, dividend_size);
quot_ptr = quot->_mp_d;
dividend_ptr = dividend->_mp_d;
remainder_limb = mpn_divmod_1 (quot_ptr,
dividend_ptr, dividend_size, divisor_limb);
*rem_ptr = sign_dividend >= 0 ? remainder_limb : -remainder_limb;
/* The quotient is DIVIDEND_SIZE limbs, but the most significant
might be zero. Set QUOT_SIZE properly. */
quot_size = dividend_size - (quot_ptr[dividend_size - 1] == 0);
quot->_mp_size = (sign_divisor ^ sign_dividend) >= 0 ? quot_size : -quot_size;
}

Binary file not shown.

Binary file not shown.

View File

@ -1,58 +0,0 @@
/* A test program doing nothing really, just linking to all the BSD MP
functions that're supposed to exist. */
/*
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
#include "mp.h"
int
main (int argc, char *argv[])
{
MINT *a, *b, *c, *d;
short h;
a = itom (123);
b = xtom ("DEADBEEF");
c = itom (0);
d = itom (0);
move (a, b);
madd (a, b, c);
msub (a, b, c);
mult (a, b, c);
mdiv (b, a, c, d);
sdiv (b, 2, c, &h);
msqrt (a, c, d);
pow (b, a, a, c);
rpow (a, 3, c);
gcd (a, b, c);
mcmp (a, b);
if (argc > 1)
{
min (c);
mout (a);
}
mtox (b);
mfree(a);
exit (0);
}

View File

@ -1,28 +0,0 @@
/* A dummy do-nothing test program, which always passes. */
/*
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
int
main ()
{
exit (0);
}

View File

@ -1,74 +0,0 @@
/* Exercise various mpbsd functions. */
/*
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "mp.h"
#define SGN(x) ((x) < 0 ? -1 : (x) == 0 ? 0 : 1)
void
check_itom (void)
{
static const struct {
short m;
mp_size_t want_size;
mp_limb_t want_limb;
} data[] = {
{ 0L, 0 },
{ 1L, 1, 1 },
{ -1L, -1, 1 },
{ SHORT_MAX, 1, SHORT_MAX },
{ -SHORT_MAX, -1, SHORT_MAX },
{ SHORT_HIGHBIT, -1, USHORT_HIGHBIT },
};
MINT *m;
int i;
for (i = 0; i < numberof (data); i++)
{
m = itom (data[i].m);
if (m->_mp_size != data[i].want_size
|| (m->_mp_size != 0 && m->_mp_d[0] != data[i].want_limb))
{
printf ("itom wrong on data[%d]\n", i);
abort();
}
mfree (m);
}
}
int
main (void)
{
check_itom ();
exit (0);
}

View File

@ -1,116 +0,0 @@
/* xtom -- convert a hexadecimal string to a MINT, and return a pointer to
the MINT.
Copyright (C) 1991, 1994, 1995, 1996, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <string.h>
#include <ctype.h>
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
static int
#if __STDC__
digit_value_in_base (int c, int base)
#else
digit_value_in_base (c, base)
int c;
int base;
#endif
{
int digit;
if (isdigit (c))
digit = c - '0';
else if (islower (c))
digit = c - 'a' + 10;
else if (isupper (c))
digit = c - 'A' + 10;
else
return -1;
if (digit < base)
return digit;
return -1;
}
MINT *
#if __STDC__
xtom (const char *str)
#else
xtom (str)
const char *str;
#endif
{
size_t str_size;
char *s, *begs;
size_t i;
mp_size_t xsize;
int c;
int negative;
MINT *x = (MINT *) (*_mp_allocate_func) (sizeof (MINT));
TMP_DECL (marker);
/* Skip whitespace. */
do
c = *str++;
while (isspace (c));
negative = 0;
if (c == '-')
{
negative = 1;
c = *str++;
}
if (digit_value_in_base (c, 16) < 0)
return 0; /* error if no digits */
TMP_MARK (marker);
str_size = strlen (str - 1);
s = begs = (char *) TMP_ALLOC (str_size + 1);
for (i = 0; i < str_size; i++)
{
if (!isspace (c))
{
int dig = digit_value_in_base (c, 16);
if (dig < 0)
{
TMP_FREE (marker);
return 0;
}
*s++ = dig;
}
c = *str++;
}
str_size = s - begs;
xsize = str_size / __mp_bases[16].chars_per_limb + 1;
x->_mp_alloc = xsize;
x->_mp_d = (mp_ptr) (*_mp_allocate_func) (xsize * BYTES_PER_MP_LIMB);
xsize = mpn_set_str (x->_mp_d, (unsigned char *) begs, str_size, 16);
x->_mp_size = negative ? -xsize : xsize;
TMP_FREE (marker);
return x;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More