gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] TMP_ALLOC in mpn_mul_n


From: Camm Maguire
Subject: [Gcl-devel] TMP_ALLOC in mpn_mul_n
Date: Tue, 30 Jul 2002 13:05:49 -0400
User-agent: WEMI/1.13.7 (Shimada) FLIM/1.13.2 (Kasanui) Emacs/20.7 (i386-debian-linux-gnu) MULE/4.0 (HANANOEN)

Greetings!  I'm maintaining gcl now that Dr. Schelter has
unfortunately passed away, and I'd like to follow up on a request he
made before he died.  

gcl uses gmp for its 'bignum' support, but currently uses its own very
slightly patched version.  I would very much like to have gcl use the
standard gmp shared lib.  

The issue lies in the calling of alloc in mpn_mul_n
(mpn/generic/mul_n.c).  gcl uses a garbage collector, and redefines
malloc, so this call incurs a lot of overhead at such a low level
position.  The patch Dr. Schelter used is:

=============================================================================
diff -ruN ../libgmp3-4.0.1/mpn/generic/mul_n.c gmp/mpn/generic/mul_n.c
--- ../libgmp3-4.0.1/mpn/generic/mul_n.c        Thu Jun 28 19:04:08 2001
+++ gmp/mpn/generic/mul_n.c     Sun Jul 28 14:01:36 2002
@@ -1144,9 +1144,15 @@
        * multiplication will take much longer than malloc()/free().  */
       mp_limb_t wsLen, *ws;
       wsLen = MPN_TOOM3_MUL_N_TSIZE (n);
+#ifdef BAD_ALLOCA
       ws = __GMP_ALLOCATE_FUNC_LIMBS ((size_t) wsLen);
+#else
+      ws = TMP_ALLOC ((size_t) wsLen * sizeof(mp_limb_t));
+#endif
       mpn_toom3_mul_n (p, a, b, n, ws);
+#ifdef BAD_ALLOCA
       __GMP_FREE_FUNC_LIMBS (ws, (size_t) wsLen);
+#endif
     }
 #if WANT_FFT || TUNE_PROGRAM_BUILD
   else
=============================================================================

Now I understand that gmp probably wants to use the heap by default
for those really large 'bignums', but would it be possible to provide
a runtime option to use alloca and the C stack here?  Either via a
separate function, or a routine setting an internal variable, similar
to the way in which one can set the (non-stack) allocation functions
in mp_set_memory_functions?

Take care,

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah



reply via email to

[Prev in Thread] Current Thread [Next in Thread]