GMP allocation changes

Torbjorn Granlund
23 Oct 2002 21:01:18 +0200

I would like to make two changes to allocation for 4.2, mainly at
the mpn level:

1. Avoid stack-based TMP_ALLOC for large blocks.
2. Pass scratch areas to all internal functions.

We currently have problems with huge stack on many platforms.
Stack-based allocation is fast, and therefore good for small
operations where malloc overhead would be a problem.  Today, we
also use the stack for huge allocations of Toom and FFT
multiplication, and in Divide-and-Conquer division.

2. Passing scratch areas to internal functions often reduces
total temporary allocation.  An example is Newton inversion,
which uses some alternating scratch variables.  Its underlying
multiplication needs could reuse some of that memory, instead of
allocating its own.

We should have a coherent internal allocation macro set, such as
<FUNCTION_NAME>_SCRATCH_ALLOC which returns the needed limb count
from passed arguments.

Opinions?  Want to help implement this?

These mpn/generic files are the ones that will be affected:


Some work will also be needed at the mpz level to reduce stack
allocation.  But we should start at the mpn level, I think.