From 8a6506b69ab4a022c6feab4e572029ef39d96ec9 Mon Sep 17 00:00:00 2001 From: simonm <unknown> Date: Fri, 5 Jun 1998 14:37:48 +0000 Subject: [PATCH] [project @ 1998-06-05 14:37:48 by simonm] Import GMP 2.0.2 --- ghc/rts/gmp/mp_set_fns.c | 48 +++++++++++++++++ ghc/rts/gmp/mpn/README | 15 ++++++ ghc/rts/gmp/stack-alloc.c | 108 ++++++++++++++++++++++++++++++++++++++ ghc/rts/gmp/stack-alloc.h | 56 ++++++++++++++++++++ ghc/rts/gmp/version.c | 1 + 5 files changed, 228 insertions(+) create mode 100644 ghc/rts/gmp/mp_set_fns.c create mode 100644 ghc/rts/gmp/mpn/README create mode 100644 ghc/rts/gmp/stack-alloc.c create mode 100644 ghc/rts/gmp/stack-alloc.h create mode 100644 ghc/rts/gmp/version.c diff --git a/ghc/rts/gmp/mp_set_fns.c b/ghc/rts/gmp/mp_set_fns.c new file mode 100644 index 000000000000..35a462c11d46 --- /dev/null +++ b/ghc/rts/gmp/mp_set_fns.c @@ -0,0 +1,48 @@ +/* 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 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 "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; +} diff --git a/ghc/rts/gmp/mpn/README b/ghc/rts/gmp/mpn/README new file mode 100644 index 000000000000..3da559e509ac --- /dev/null +++ b/ghc/rts/gmp/mpn/README @@ -0,0 +1,15 @@ +This directory contains all code for the mpn layer of GMP. + +Most subdirectories contain machine-dependent code, written in assembly or +C. The `generic' subdirectory contains default code, used when there is no +machine-dependent replacement for a particular machine. + +There is one subdirectory for each architecture. Note that e.g., 32-bit +sparc and 64-bit sparc cannot share any code, and are therefore considered +completely different architecture. + +A particular machine will only use code from one such subdirectory, and the +`generic' subdirectory. The architecture-specific subdirectory contains a +hierachy of directories for various architecture variants and +implementations; the top-most level contains code that runs correctly on all +variants. diff --git a/ghc/rts/gmp/stack-alloc.c b/ghc/rts/gmp/stack-alloc.c new file mode 100644 index 000000000000..d9619f6222c9 --- /dev/null +++ b/ghc/rts/gmp/stack-alloc.c @@ -0,0 +1,108 @@ +/* Stack allocation routines. This is intended for machines without support + for the `alloca' function. + +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 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 "stack-alloc.h" + +typedef struct tmp_stack tmp_stack; + +void *malloc (); +static unsigned long max_total_allocation = 0; +static unsigned long current_total_allocation = 0; + +static tmp_stack xxx = {&xxx, &xxx, 0}; +static tmp_stack *current = &xxx; + +/* Allocate a block of exactly <size> bytes. This should only be called + through the TMP_ALLOC macro, which takes care of rounding/alignment. */ +void * +__tmp_alloc (size) + unsigned long size; +{ + void *this; + + if (size > (char *) current->end - (char *) current->alloc_point) + { + void *chunk; + tmp_stack *header; + unsigned long chunk_size; + unsigned long now; + + /* Allocate a chunk that makes the total current allocation somewhat + larger than the maximum allocation ever. If size is very large, we + allocate that much. */ + + now = current_total_allocation + size; + if (now > max_total_allocation) + { + /* We need more temporary memory than ever before. Increase + for future needs. */ + now = now * 3 / 2; + chunk_size = now - current_total_allocation + sizeof (tmp_stack); + current_total_allocation = now; + max_total_allocation = current_total_allocation; + } + else + { + chunk_size = max_total_allocation - current_total_allocation + sizeof (tmp_stack); + current_total_allocation = max_total_allocation; + } + + chunk = malloc (chunk_size); + header = chunk; + header->end = (char *) chunk + chunk_size; + header->alloc_point = (char *) chunk + sizeof (tmp_stack); + header->prev = current; + current = header; + } + + this = current->alloc_point; + current->alloc_point = (char *) this + size; + return this; +} + +/* Typically called at function entry. <mark> is assigned so that __tmp_free + can later be used to reclaim all subsecuently allocated storage. */ +void +__tmp_mark (mark) + tmp_marker *mark; +{ + mark->which_chunk = current; + mark->alloc_point = current->alloc_point; +} + +/* Free everything allocated since <mark> was assigned by __tmp_mark */ +void +__tmp_free (mark) + tmp_marker *mark; +{ + while (mark->which_chunk != current) + { + tmp_stack *tmp; + + tmp = current; + current = tmp->prev; + current_total_allocation -= (((char *) (tmp->end) - (char *) tmp) + - sizeof (tmp_stack)); + free (tmp); + } + current->alloc_point = mark->alloc_point; +} diff --git a/ghc/rts/gmp/stack-alloc.h b/ghc/rts/gmp/stack-alloc.h new file mode 100644 index 000000000000..a84eeff58da4 --- /dev/null +++ b/ghc/rts/gmp/stack-alloc.h @@ -0,0 +1,56 @@ +/* Stack allocation routines. This is intended for machines without support + for the `alloca' function. + +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 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. */ + +struct tmp_stack +{ + void *end; + void *alloc_point; + struct tmp_stack *prev; +}; + +struct tmp_marker +{ + struct tmp_stack *which_chunk; + void *alloc_point; +}; + +typedef struct tmp_marker tmp_marker; + +#if __STDC__ +void *__tmp_alloc (unsigned long); +void __tmp_mark (tmp_marker *); +void __tmp_free (tmp_marker *); +#else +void *__tmp_alloc (); +void __tmp_mark (); +void __tmp_free (); +#endif + +#ifndef __TMP_ALIGN +#define __TMP_ALIGN 8 +#endif + +#define TMP_DECL(marker) tmp_marker marker +#define TMP_ALLOC(size) \ + __tmp_alloc (((unsigned long) (size) + __TMP_ALIGN - 1) & -__TMP_ALIGN) +#define TMP_MARK(marker) __tmp_mark (&marker) +#define TMP_FREE(marker) __tmp_free (&marker) diff --git a/ghc/rts/gmp/version.c b/ghc/rts/gmp/version.c new file mode 100644 index 000000000000..70502394b3ec --- /dev/null +++ b/ghc/rts/gmp/version.c @@ -0,0 +1 @@ +static char *gmp_version = "2.0.1"; -- GitLab