Commit efb415a7 authored by Erick's avatar Erick

Complete rewriting of GMP-lite, the provided gmp compatible package.

Old GMP-lite was based on an old version of GMP. The new one is based
on the MPI library. It is a bit slow, but it is small and should be
easy to maintain.
parent cd742d62
STklos uses some libraries developped by other people.
These libraries are:
GMP: The Gnu MP library
=======================
- Version: 3.1.1 (the included version is only a subset of
original GMP)
GMP: The Gnu MP library
=======================
If you have a version of GMP installed, it will be used. Otherwise,
STklos uses a part of the MPI library which is provided in the package.
A wrapper for the subset of the functions used by STklos is built on
top of MPI to build a GMP API compatible library.
Note that STklos sources use only the GMP API.
for GMP:
- Version: the one installed
- License: LGPL
- Home Page: http://www.swox.com/gmp/
for MPI
- Version: 1.8.6
- Licence: Public Domain
- Home Page: http://spinning-yarns.org/michael/mpi
Note that if you have a version of GMP installed, it will be used
instead of the one provided in.
GC: The Boehm's conservative garbage collector for C and C++
============================================================
......
......@@ -6482,7 +6482,8 @@ esac
if test "$HAVE_GMP" = "no"
then
echo "No GMP library. Using the one provided with the package"
cmd="CC=\"$CC\" CFLAGS=\"$CFLAGS\" ./configure --prefix=$prefix"
cmd="CC=\"$CC\" CFLAGS=\"$CFLAGS -I../src -DFOR_STKLOS=1\" ./configure \
--prefix=$prefix"
echo "Configuring GMP"
echo $cmd
(cd gmp; eval $cmd)
......
......@@ -2,7 +2,7 @@
###
### Author: Erick Gallesio [eg@unice.fr]
### Creation date: 28-Dec-1999 21:19 (eg)
### Last file update: 7-Oct-2009 10:52 (eg)
### Last file update: 18-Oct-2009 23:21 (eg)
AC_PREREQ(2.64)
AC_INIT([stklos], [0.99dev])
......@@ -199,7 +199,8 @@ esac
if test "$HAVE_GMP" = "no"
then
echo "No GMP library. Using the one provided with the package"
cmd="CC=\"$CC\" CFLAGS=\"$CFLAGS\" ./configure --prefix=$prefix"
cmd="CC=\"$CC\" CFLAGS=\"$CFLAGS -I../src -DFOR_STKLOS=1\" ./configure \
--prefix=$prefix"
echo "Configuring GMP"
echo $cmd
(cd gmp; eval $cmd)
......
2003-06-04 Erick Gallesio <eg@unice.fr>
* This is a GMPlite version.
This version is built for STklos from the transitive closure of the
functions used in src/numbers.c
This version is used if there is no GMP library installed on the
system at configure time (otherwise the system GMP is used).
SUBDIRS=tests
noinst_LIBRARIES = libgmp.a
libgmp_a_SOURCES = \
assert.c \
errno.c \
insert-dbl.c \
memory.c \
mp_bpl.c \
mp_clz_tab.c \
mp_set_fns.c \
mpn-add_n.c \
mpn-addmul_1.c \
mpn-bz_divrem_n.c \
mpn-cmp.c \
mpn-diveby3.c \
mpn-divrem.c \
mpn-divrem_1.c \
mpn-divrem_2.c \
mpn-get_str.c \
mpn-lshift.c \
mpn-mp_bases.c \
mpn-mul.c \
mpn-mul_1.c \
mpn-mul_basecase.c \
mpn-mul_n.c \
mpn-rshift.c \
mpn-sb_divrem_mn.c \
mpn-set_str.c \
mpn-sqr_basecase.c \
mpn-sqrtrem.c \
mpn-sub_n.c \
mpn-submul_1.c \
mpn-tdiv_qr.c \
mpz-add.c \
mpz-and.c \
mpz-clear.c \
mpz-cmp_si.c \
mpz-cmp_ui.c \
mpz-com.c \
mpz-fdiv_qr.c \
mpz-fdiv_qr_ui.c \
mpz-get_d.c \
mpz-get_si.c \
mpz-get_str.c \
mpz-get_ui.c \
mpz-init.c \
mpz-ior.c \
mpz-iset.c \
mpz-iset_si.c \
mpz-iset_str.c \
mpz-iset_ui.c \
mpz-mul.c \
mpz-neg.c \
mpz-realloc.c \
mpz-set.c \
mpz-set_si.c \
mpz-set_str.c \
mpz-set_ui.c \
mpz-sizeinbase.c \
mpz-sqrtrem.c \
mpz-sub.c \
mpz-sub_ui.c \
mpz-tdiv_qr.c \
mpz-ui_pow_ui.c \
mpz-xor.c
libgmp_a_SOURCES = mpi.c gmp.c
test: all
(cd tests; $(MAKE) test)
check: test
clean:
/bin/rm -f configure.lineno
/bin/rm -f *.o *~ libgmp.a
(cd tests; make clean)
distclean: clean
(cd tests; make distclean)
/bin/rm -f config.h stamp-h1
/bin/rm -f config.status config.cache config.log configure.lineno \
config.status.lineno
/bin/rm -rf ./.deps
/bin/rm -f Makefile
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "gmp-stklos.h"
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
#undef ASSERT
#define ASSERT(expr)
#include <stdlib.h>
/* 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>
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;
}
/* config.h.in. Generated from configure.in by autoheader. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
/* Define to 1 if you have the `strchr' function. */
#undef HAVE_STRCHR
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Name of package */
#undef PACKAGE
......@@ -21,6 +48,9 @@
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
......@@ -29,3 +59,6 @@
/* Version number of package */
#undef VERSION
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
This diff is collapsed.
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.64])
AC_INIT([gmplite], [1.0])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([mpi.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([limits.h stdlib.h string.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
# Checks for library functions.
AC_CHECK_FUNCS([memset])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
dnl configure.in for GMPlite
dnl
dnl Author: Erick Gallesio [eg@unice.fr]
dnl Creation date: 4-Jul-2003 16:56 (eg)
dnl Last file update: 25-Jun-2007 08:46 (eg)
AC_INIT(gmp-impl.h)
dnl AC_PREREQ(2.52)
AM_INIT_AUTOMAKE(gmplite, 1.0)
AM_CONFIG_HEADER(config.h)
AC_PROG_MAKE_SET
dnl Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB
dnl Trick automake into thinking we've run AM_C_PROTOTYPES which it wants
dnl for ansi2knr, and instead use our own test. (It's only a warning
dnl automake prints, but it's good to suppress it.)
ifelse(0,1,[
AM_C_PROTOTYPES
])
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_FUNCS(strchr memset)
dnl
dnl define some constants used in gmp.h
dnl
case `uname -m` in
i*86)
BITS_PER_MP_LIMB=32
BYTES_PER_MP_LIMB=4
DEFN_LONG_LONG_LIMB="/* #undef _LONG_LONG_LIMB */"
HAVE_HOST_CPU_FAMILY_power=0
HAVE_HOST_CPU_FAMILY_powerpc=0
THE_ARCH=x86
LIBGMP_DLL=0
GMP_NAIL_BITS=0
;;
*86_64)
BITS_PER_MP_LIMB=32
BYTES_PER_MP_LIMB=4
DEFN_LONG_LONG_LIMB="/* #undef _LONG_LONG_LIMB */"
HAVE_HOST_CPU_FAMILY_power=0
HAVE_HOST_CPU_FAMILY_powerpc=0
THE_ARCH=x86_64
LIBGMP_DLL=0
GMP_NAIL_BITS=0
;;
Power\ Macintosh)
BITS_PER_MP_LIMB=32
BYTES_PER_MP_LIMB=4
DEFN_LONG_LONG_LIMB="/* #undef _LONG_LONG_LIMB */"
HAVE_HOST_CPU_FAMILY_power=0
HAVE_HOST_CPU_FAMILY_powerpc=1
THE_ARCH=ppc
LIBGMP_DLL=0
GMP_NAIL_BITS=0
;;
sun4u)
BITS_PER_MP_LIMB=32
BYTES_PER_MP_LIMB=4
DEFN_LONG_LONG_LIMB="/* #undef _LONG_LONG_LIMB */"
HAVE_HOST_CPU_FAMILY_power=0
HAVE_HOST_CPU_FAMILY_powerpc=0
THE_ARCH=sun4u
LIBGMP_DLL=0
GMP_NAIL_BITS=0
;;
*) echo "**********"
echo "
Your architecture is not known by GMP light. You have 2 solutions
- Use the official gmp package and install it. One this is done
you just need to reconfigure STklos et voila, it should work.
In this case, can you send the file gmp.h you obtained to
support@stklos.net
- try to hack some constants in the gmp/configure.in for your
architecture. When it works, send these values to
support@stklos.net
"
echo > NOGMP;;
esac
AC_SUBST(BITS_PER_MP_LIMB)
AC_SUBST(BYTES_PER_MP_LIMB)
AC_SUBST(DEFN_LONG_LONG_LIMB)
AC_SUBST(HAVE_HOST_CPU_FAMILY_power)
AC_SUBST(HAVE_HOST_CPU_FAMILY_powerpc)
AC_SUBST(GMP_NAIL_BITS)
AC_SUBST(LIBGMP_DLL)
AC_SUBST(THE_ARCH)
AC_OUTPUT(Makefile gmp-stklos.h)
#include "gmp-stklos.h"
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
#undef ASSERT
#define ASSERT(expr)
#include <stdlib.h>
/* 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. */
int gmp_errno = 0;
This diff is collapsed.
/* gmp-mparam.h -- Compiler/machine parameter header file.
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. */
#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
/*
* gmp-stklos.h -- GMP light for STklos. Some decalarations
*
* Copyright © 2004-2005 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
*
*
* 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.
*
* Author: Erick Gallesio [eg@essi.fr]
* Creation date: 29-Jun-2004 13:22 (eg)
* Last file update: 3-Aug-2005 10:39 (eg)
*/
#define WANT_TMP_ALLOCA 1
#define BYTES_PER_MP_LIMB @BYTES_PER_MP_LIMB@
#define _PROTO(x) x
#define THE_ARCH @THE_ARCH@
#if THE_ARCH == sun4u
# define __sparcv9
#endif
/*
* gmp.c -- The GMP wrapper
*
* Copyright 2009 Erick Gallesio - Polytech'Nice-Sophia <eg@unice.fr>
*
*
* 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.
*
* Author: Erick Gallesio [eg@unice.fr]
* Creation date: 12-Oct-2009 19:27 (eg)
* Last file update: 21-Oct-2009 22:36 (eg)
*/
#include <stdio.h>
#include <ctype.h>
#include "gmp.h"
#if 0
static void trace_bignum(mpz_t bn)
{
char *buffer = alloca(mp_radix_size(bn, 10) + 10);
mp_toradix(bn, (unsigned char *)buffer, 10);
fprintf(stderr, " [%s] ", buffer);
}
#endif
static void lowerstring(char *str)
{
while (*str) {
*str = tolower(*str);
str++;
}
}
/* ----------------------------------------------------------------------
* Memory functions
* ---------------------------------------------------------------------- */
void mp_set_memory_functions(void *(*allocate) (size_t),
void *(*reallocate) (void *, size_t, size_t),
void (*deallocate) (void *, size_t))
{
_gmp_alloc = allocate;
_gmp_free = deallocate;
}
/* ----------------------------------------------------------------------
* Initialisations
* ---------------------------------------------------------------------- */
#ifndef GMP_USE_MACROS
void mpz_init(mpz_t bn)
{
mp_init(bn);
}
void mpz_init_set(mpz_t bn1, mpz_t bn2)
{
mp_init(bn1);
mp_copy(bn2, bn1);
}
void mpz_init_set_si(mpz_t bn, signed long int si)
{
mp_init(bn);
mp_set_int(bn, (long) si);
}
#endif
int mpz_init_set_str(mpz_t bn, char *s, long base)
{
mp_init(bn);
return (mp_read_radix(bn, (unsigned char *) s, (int) base) == MP_YES)? 0 : -1;
}
void mpz_init_set_ui(mpz_t bn, unsigned long int ui)
{
char buffer[100];
snprintf(buffer, 100, "%ld", ui);
mpz_init_set_str(bn, buffer, 10L);
}
/* ----------------------------------------------------------------------
* Free
* ---------------------------------------------------------------------- */
#ifndef GMP_USE_MACROS
void mpz_clear(mpz_t bn)
{
mp_clear(bn);
}
#endif
/* ----------------------------------------------------------------------
* Getters
* ---------------------------------------------------------------------- */
signed long int mpz_get_si(mpz_t bn)
{
char buffer[100];
mp_toradix(bn, (unsigned char *)buffer, 10);
return atol(buffer);
}
unsigned long int mpz_get_ui(mpz_t bn)
{
char buffer[100];
mp_toradix(bn, (unsigned char *)buffer, 10);
return atof(buffer);
}
char *mpz_get_str(char *str, int base, mpz_t bn)
{
if (!str)
str = _gmp_alloc(mp_radix_size(bn, base) + 2);
mp_toradix(bn, (unsigned char *)str, base);
lowerstring(str);
return str;
}
/* ----------------------------------------------------------------------
* Comparison
* ---------------------------------------------------------------------- */
#ifndef GMP_USE_MACROS
int mpz_cmp_si(mpz_t bn, long v)
{
return mp_cmp_int(bn, v);
}
int mpz_cmp(mpz_t a, mpz_b b)
{
return mp_cmp(a, b);
}
int mpz_sgn(mpz_t a)
{
return mpz_cmp_z(a);
}
#endif
int mpz_cmp_ui(mpz_t bn, unsigned long int ui)
{
char buffer[100];
mpz_t tmp;
int res;
snprintf(buffer, 100, "%ld", ui);
mpz_init_set_str(tmp, buffer, 10);
res = mp_cmp(bn, tmp);
mp_clear(tmp);
return res;
}
/* ----------------------------------------------------------------------
* Operations
* ---------------------------------------------------------------------- */
#ifndef GMP_USE_MACROS
void mpz_add(mpz_t res, mpz_t a, mpz_t b)
{
mp_add(a, b, res);
}
void mpz_sub(mpz_t res, mpz_t a, mpz_t b)
{
mp_sub(a, b, res);
}
void mpz_mul(mpz_t res, mpz_t a, mpz_t b)
{
mp_mul(a, b, res);
}
void mpz_tdiv_qr(mpz_t q, mpz_t r, mpz_t a, mpz_t b)
{
mp_div(a, b, q, r);
}
void mpz_neg(mpz_t res, mpz_t a)
{
mp_neg(a, res);
}
void mpz_sqrt(mpz_t res, mpz_t bn)
{
mp_sqrt(bn, res);
}
#endif
void mpz_ui_pow_ui(mpz_t bn, unsigned long int base, unsigned long int exp)
{
mpz_t base_bn;
mpz_t exp_bn;
/* convert base and exp to bignums */
mpz_init_set_ui(exp_bn, exp);
mpz_init_set_ui(base_bn, base);
/* compute result */
mp_expt(base_bn, exp_bn, bn);
}
/* ----------------------------------------------------------------------
* Misc
* ---------------------------------------------------------------------- */
#ifndef GMP_USE_MACROS
size_t mpz_sizeinbase(mpz_t bn, int base)
{
return mp_radix_size(bn, base);