_mp_alloc vs ALLOC

Torbjorn Granlund tg at gmplib.org
Fri Feb 24 10:11:33 CET 2012


nisse at lysator.liu.se (Niels Möller) writes:

  Torbjorn Granlund <tg at gmplib.org> writes:
  
  > Surely a plain TMP_ALLOC adds red zones?  If not, that is something we
  > ought to fix.
  
  But
  
    tp = TMP_ALLOC_LIMBS (2*n);
    xp = tp + n;
  
  does not add any between T and X (intended to hold n limbs each). So if
  one doesn't use TMP_ALLOC_LIMBS_2, one should instead write
  
    tp = TMP_ALLOC_LIMBS (n);
    xp = TMP_ALLOC_LIMBS (n);
  
  to get red zones for this common case. Right?
  
  Maybe this is more overhead, in the non-debug case, than using
  TMP_ALLOC_LIMBS_2. I'm not sure.
  
TMP_ALLOC_LIMBS_2 makes two TMP_ALLOC_LIMBS calls if WANT_TMP_DEBUG,
else one.  So the red zones will be there when we want them.

I think the conclusion is that TMP_ALLOC_LIMBS_2 could save some cycles
by collapsing two malloc calls into one, when allocating large blocks
using TMP_ALLOC (as opposed to TMP_BALLOC or TMP_SALLOC).

My idea is that these cycles saved are unimportant, following GMP's
founding principle of relative overhead: Adding a million cycles to a
billion cycle computation does not matter, but adding 1 cycle to a 10
cycle computation is unforgivable.

-- 
Torbjörn


More information about the gmp-devel mailing list