aboutsummaryrefslogtreecommitdiff
path: root/contrib/libgmp/mpbsd
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libgmp/mpbsd')
-rw-r--r--contrib/libgmp/mpbsd/Makefile.in84
-rw-r--r--contrib/libgmp/mpbsd/configure.in20
-rw-r--r--contrib/libgmp/mpbsd/itom.c54
-rw-r--r--contrib/libgmp/mpbsd/mdiv.c39
-rw-r--r--contrib/libgmp/mpbsd/mfree.c36
-rw-r--r--contrib/libgmp/mpbsd/min.c89
-rw-r--r--contrib/libgmp/mpbsd/mout.c96
-rw-r--r--contrib/libgmp/mpbsd/move.c46
-rw-r--r--contrib/libgmp/mpbsd/mtox.c81
-rw-r--r--contrib/libgmp/mpbsd/realloc.c44
-rw-r--r--contrib/libgmp/mpbsd/sdiv.c77
-rw-r--r--contrib/libgmp/mpbsd/xtom.c110
12 files changed, 776 insertions, 0 deletions
diff --git a/contrib/libgmp/mpbsd/Makefile.in b/contrib/libgmp/mpbsd/Makefile.in
new file mode 100644
index 000000000000..a517c1aba1cb
--- /dev/null
+++ b/contrib/libgmp/mpbsd/Makefile.in
@@ -0,0 +1,84 @@
+# Makefile for GNU MP/mpbsd functions
+# Copyright (C) 1991, 1993, 1994, 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 Library General Public License as published by
+# the Free Software Foundation; either version 2 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 Library General Public
+# License for more details.
+
+# You should have received a copy of the GNU Library 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.
+
+srcdir = .
+
+CC = gcc
+
+# If you cross compile on a machine with the same sizes of the integral
+# types ("int", "long int", "short int", and "char") define this as the
+# local compiler. Otherwise, you need to look for the uses of LOCAL_CC below,
+# and handle those cases manually.
+LOCAL_CC = $(CC)
+CFLAGS = -g -O
+AR = ar
+SHELL = /bin/sh
+
+#### host and target specific makefile fragments come in here.
+###
+
+MPBSD_LINKS = add.c cmp.c gcd.c mul.c pow_ui.c powm.c sqrtrem.c sub.c
+MPBSD_SRCS = itom.c mdiv.c mfree.c min.c mout.c move.c mtox.c sdiv.c xtom.c \
+ realloc.c $(MPBSD_LINKS)
+
+MPBSD_OBJS = itom.o mdiv.o mfree.o min.o mout.o move.o mtox.o sdiv.o xtom.o \
+ realloc.o add.o cmp.o gcd.o mul.o pow_ui.o powm.o sqrtrem.o sub.o
+
+INCLUDES = -I. -I.. -I$(srcdir)/../mpz -I../mpn -I$(srcdir)/..
+
+libmpbsd.a: Makefile.in $(MPBSD_OBJS)
+ rm -f $@
+ $(AR) cr $@ $(MPBSD_OBJS)
+
+.c.o:
+ $(CC) -c $(INCLUDES) -DBERKELEY_MP $(CFLAGS) $(XCFLAGS) $<
+
+check:
+ true
+
+clean mostlyclean:
+ rm -f *.o libmpbsd.a
+distclean maintainer-clean: clean
+ rm -f Makefile config.status $(MPBSD_LINKS)
+
+Makefile: $(srcdir)/Makefile.in
+ $(SHELL) ./config.status
+
+H = $(srcdir)/../gmp.h $(srcdir)/../gmp-impl.h ../mpn/gmp-mparam.h
+L = $(srcdir)/../longlong.h
+
+itom.o: $(srcdir)/itom.c ../mp.h $(H)
+mdiv.o: $(srcdir)/mdiv.c ../mp.h $(H) $(L) $(srcdir)/../mpz/dmincl.c
+mfree.o: $(srcdir)/mfree.c ../mp.h $(H)
+min.o: $(srcdir)/min.c ../mp.h $(H)
+mout.o: $(srcdir)/mout.c ../mp.h $(H)
+move.o: $(srcdir)/move.c ../mp.h $(H)
+mtox.o: $(srcdir)/mtox.c ../mp.h $(H)
+sdiv.o: $(srcdir)/sdiv.c ../mp.h $(H) $(L)
+xtom.o: $(srcdir)/xtom.c ../mp.h $(H)
+add.o: $(srcdir)/../mpz/add.c $(H)
+cmp.o: $(srcdir)/../mpz/cmp.c $(H)
+gcd.o: $(srcdir)/../mpz/gcd.c $(H) $(L)
+mul.o: $(srcdir)/../mpz/mul.c $(H)
+pow_ui.o: $(srcdir)/../mpz/pow_ui.c $(H) $(L)
+powm.o: $(srcdir)/../mpz/powm.c $(H) $(L)
+realloc.o: $(srcdir)/realloc.c $(H)
+sqrtrem.o: $(srcdir)/../mpz/sqrtrem.c $(H)
+sub.o: $(srcdir)/../mpz/sub.c $(H)
diff --git a/contrib/libgmp/mpbsd/configure.in b/contrib/libgmp/mpbsd/configure.in
new file mode 100644
index 000000000000..ec220753b079
--- /dev/null
+++ b/contrib/libgmp/mpbsd/configure.in
@@ -0,0 +1,20 @@
+# This file is a shell script fragment that supplies the information
+# necessary for a configure script to process the program in
+# this directory. For more information, look at ../configure.
+
+configdirs=
+srctrigger=itom.c
+srcname="GNU Multi-Precision library/mpbsd"
+
+# per-host:
+
+# per-target:
+
+mpzfiles="add.c cmp.c gcd.c mul.c pow_ui.c powm.c sqrtrem.c sub.c"
+
+for fn in $mpzfiles
+ do
+ rm -f $fn
+ files="$files ../mpz/$fn"
+ links="$links $fn"
+ done
diff --git a/contrib/libgmp/mpbsd/itom.c b/contrib/libgmp/mpbsd/itom.c
new file mode 100644
index 000000000000..719a4dcdcb21
--- /dev/null
+++ b/contrib/libgmp/mpbsd/itom.c
@@ -0,0 +1,54 @@
+/* itom -- BSD compatible allocate and initiate a MINT.
+
+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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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] = -n;
+ }
+ else
+ x->_mp_size = 0;
+
+ return x;
+}
diff --git a/contrib/libgmp/mpbsd/mdiv.c b/contrib/libgmp/mpbsd/mdiv.c
new file mode 100644
index 000000000000..103c2c307adc
--- /dev/null
+++ b/contrib/libgmp/mpbsd/mdiv.c
@@ -0,0 +1,39 @@
+/* mdiv -- BSD compatible divide producing both remainder and quotient.
+
+Copyright (C) 1991, 1994, 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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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__
+mdiv (const MINT *num, const MINT *den, MINT *quot, MINT *rem)
+#else
+mdiv (num, den, quot, rem)
+ const MINT *num;
+ const MINT *den;
+ MINT *quot;
+ MINT *rem;
+#endif
+
+#define COMPUTE_QUOTIENT
+#include "dmincl.c"
diff --git a/contrib/libgmp/mpbsd/mfree.c b/contrib/libgmp/mpbsd/mfree.c
new file mode 100644
index 000000000000..ef931e3f42ff
--- /dev/null
+++ b/contrib/libgmp/mpbsd/mfree.c
@@ -0,0 +1,36 @@
+/* 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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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));
+}
diff --git a/contrib/libgmp/mpbsd/min.c b/contrib/libgmp/mpbsd/min.c
new file mode 100644
index 000000000000..6edb1716628a
--- /dev/null
+++ b/contrib/libgmp/mpbsd/min.c
@@ -0,0 +1,89 @@
+/* min(MINT) -- Do decimal input from standard input and store result in
+ MINT.
+
+Copyright (C) 1991, 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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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"
+
+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;
+}
diff --git a/contrib/libgmp/mpbsd/mout.c b/contrib/libgmp/mpbsd/mout.c
new file mode 100644
index 000000000000..a6b62be8516d
--- /dev/null
+++ b/contrib/libgmp/mpbsd/mout.c
@@ -0,0 +1,96 @@
+/* mout(MINT) -- Do decimal output of MINT to standard output.
+
+Copyright (C) 1991, 1994, 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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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 "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 (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);
+}
diff --git a/contrib/libgmp/mpbsd/move.c b/contrib/libgmp/mpbsd/move.c
new file mode 100644
index 000000000000..8256cc704c52
--- /dev/null
+++ b/contrib/libgmp/mpbsd/move.c
@@ -0,0 +1,46 @@
+/* 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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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);
+}
diff --git a/contrib/libgmp/mpbsd/mtox.c b/contrib/libgmp/mpbsd/mtox.c
new file mode 100644
index 000000000000..8baec2a1ec8a
--- /dev/null
+++ b/contrib/libgmp/mpbsd/mtox.c
@@ -0,0 +1,81 @@
+/* mtox -- Convert OPERAND to hexadecimal and return a malloc'ed string
+ with the result of the conversion.
+
+Copyright (C) 1991, 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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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 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 str;
+}
diff --git a/contrib/libgmp/mpbsd/realloc.c b/contrib/libgmp/mpbsd/realloc.c
new file mode 100644
index 000000000000..64bee76f1f1c
--- /dev/null
+++ b/contrib/libgmp/mpbsd/realloc.c
@@ -0,0 +1,44 @@
+/* _mp_realloc -- make the MINT* have NEW_SIZE digits allocated.
+
+Copyright (C) 1991, 1993, 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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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__
+_mp_realloc (MINT *m, mp_size_t new_size)
+#else
+_mp_realloc (m, new_size)
+ MINT *m;
+ mp_size_t new_size;
+#endif
+{
+ /* Never allocate zero space. */
+ if (new_size == 0)
+ new_size = 1;
+
+ m->_mp_d = (mp_ptr) (*_mp_reallocate_func) (m->_mp_d,
+ m->_mp_alloc * BYTES_PER_MP_LIMB,
+ new_size * BYTES_PER_MP_LIMB);
+ m->_mp_alloc = new_size;
+ return (void *) m->_mp_d;
+}
diff --git a/contrib/libgmp/mpbsd/sdiv.c b/contrib/libgmp/mpbsd/sdiv.c
new file mode 100644
index 000000000000..6982e200949e
--- /dev/null
+++ b/contrib/libgmp/mpbsd/sdiv.c
@@ -0,0 +1,77 @@
+/* sdiv -- Divide a MINT by a short integer. Produce a MINT quotient
+ and a short remainder.
+
+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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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 = 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;
+}
diff --git a/contrib/libgmp/mpbsd/xtom.c b/contrib/libgmp/mpbsd/xtom.c
new file mode 100644
index 000000000000..5a529e8e46ea
--- /dev/null
+++ b/contrib/libgmp/mpbsd/xtom.c
@@ -0,0 +1,110 @@
+/* xtom -- convert a hexadecimal string to a MINT, and return a pointer to
+ the MINT.
+
+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 Library General Public License as published by
+the Free Software Foundation; either version 2 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library 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"
+
+static int
+digit_value_in_base (c, base)
+ int c;
+ int base;
+{
+ 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;
+}