Lazy mpz allocation

Torbjörn Granlund tg at
Mon Aug 31 16:27:30 UTC 2015

  >   mpz_init (mpz_ptr x)
  >   {
  >     ALLOC (x) = 0; /* ZERO, any MPZ_REALLOC will allocate */
  >     PTR (x) = & static_const_limb_shared_by_all_instances;
  >     SIZ (x) = 0;
  >   }
  > I suppose we should do this!
  Me too! Actually, mpz_init could then be
    static const mp_limb_t dummy_limb = 0;
    #define INITIAL_MPZ {0, 0, &dummy_limb};
    static const mpz_t initial_mpz = INITIAL_MPZ;  
    mpz_init (mpz_ptr x)
       *x = initial_mpz; /* Inline or memcpy, depending on compiler */
  and later on we can consider some public interface for initializing an
  mpz without any library call. 
I actually think this is inferior to Marco's variant; just writing to
memory (or cache) is faster than reading + writing...

(We should use 'attribute ((visibility ("hidden")))' for the the
constant zero limbs at any rate.  I'll commit a basic patch for that

Please encrypt, key id 0xC8601622

More information about the gmp-devel mailing list