summaryrefslogtreecommitdiff
path: root/src/mpfr-gmp.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-11-08 17:04:45 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-11-08 17:04:45 +0000
commitd9d4a87efaf8eceac00e8f4f5a7a079d46d3244e (patch)
treeec0704ea2846301b6793e6beccfb67d1c55a5de4 /src/mpfr-gmp.c
parentb10c40de7fe6b7eaca6be5cc75ac5cb916e72d2c (diff)
downloadmpfr-d9d4a87efaf8eceac00e8f4f5a7a079d46d3244e.tar.gz
Change the way memory is allocated (as discussed partly in private).
* src/mpfr-gmp.c, src/mpfr-gmp.h, src/mpfr-impl.h: update. * src/free_cache.c, src/mpfr.h: added mpfr_mp_memory_cleanup function. * NEWS: describe API change. * TODO: added 2 related items (future clean-up and feature). * doc/mpfr.texi: update. * tests/talloc-cache.c: take API change into account. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11807 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/mpfr-gmp.c')
-rw-r--r--src/mpfr-gmp.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/mpfr-gmp.c b/src/mpfr-gmp.c
index faf02e383..519a24b70 100644
--- a/src/mpfr-gmp.c
+++ b/src/mpfr-gmp.c
@@ -300,16 +300,42 @@ mpfr_assert_fail (const char *filename, int linenum,
abort();
}
-/* putting 0 as initial values forces those symbols to be fully defined,
- and always resolved, otherwise they are only tentatively defined, which
- leads to problems on e.g. MacOS, cf
- http://lists.gforge.inria.fr/pipermail/mpc-discuss/2008-November/000048.html
- and http://software.intel.com/en-us/articles/intelr-fortran-compiler-for-mac-os-non_lazy_ptr-unresolved-references-from-linking
- Note that using ranlib -c or libtool -c is another fix.
-*/
-MPFR_THREAD_VAR (mpfr_allocate_func_t, mpfr_allocate_func, 0)
-MPFR_THREAD_VAR (mpfr_reallocate_func_t, mpfr_reallocate_func, 0)
-MPFR_THREAD_VAR (mpfr_free_func_t, mpfr_free_func, 0)
+/* Performing a concentration for theses indirect functions may be
+ good for performance since branch prediction for indirect calls
+ is not well supported by a lot of CPU's (typically they can only
+ predict a limited number of indirections). */
+MPFR_HOT_FUNCTION_ATTR void *
+mpfr_allocate_func (size_t alloc_size)
+{
+ void * (*allocate_func) (size_t);
+ void * (*reallocate_func) (void *, size_t, size_t);
+ void (*free_func) (void *, size_t);
+ /* Always calling with the 3 arguments smooths branch prediction. */
+ mp_get_memory_functions (&allocate_func, &reallocate_func, &free_func);
+ return (*allocate_func) (alloc_size);
+}
+
+MPFR_HOT_FUNCTION_ATTR void *
+mpfr_reallocate_func (void * ptr, size_t old_size, size_t new_size)
+{
+ void * (*allocate_func) (size_t);
+ void * (*reallocate_func) (void *, size_t, size_t);
+ void (*free_func) (void *, size_t);
+ /* Always calling with the 3 arguments smooths branch prediction. */
+ mp_get_memory_functions (&allocate_func, &reallocate_func, &free_func);
+ return (*reallocate_func) (ptr, old_size, new_size);
+}
+
+MPFR_HOT_FUNCTION_ATTR void
+mpfr_free_func (void *ptr, size_t size)
+{
+ void * (*allocate_func) (size_t);
+ void * (*reallocate_func) (void *, size_t, size_t);
+ void (*free_func) (void *, size_t);
+ /* Always calling with the 3 arguments smooths branch prediction. */
+ mp_get_memory_functions (&allocate_func, &reallocate_func, &free_func);
+ (*free_func) (ptr, size);
+}
void *
mpfr_tmp_allocate (struct tmp_marker **tmp_marker, size_t size)