Using MPZ_ROINIT_N in mpz sources

Niels Möller nisse at lysator.liu.se
Mon Nov 28 11:31:36 UTC 2016


"Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:

> A single shared limb is my goal too, but it's a cost (comparable to a
> function call?) if we must use a shared symbol for it. IIRC Torbjörn said
> that the symbol hiding stuff might not be able to mitigate this cost,
> because of the PIC-only policy of some Linux distributions...
> On the other side, inlining a function with a static const var inside
> means, I believe, replicating lots of statics variables everywhere...

Sounds a bit hairy. If we need a function call, ideally, we should have
only one, and that should be calling mpz_init...

My understanding is that both data and rodata are loaded at a link time
constant offset from the code, so the address of a *static* constant would
be instruction pointer + link time constant offset. While the address of
a global constant is a single load from the GOT, which in turn is
located in the data sigment at a link-time constant offset from the
code.

So if we have
 
  x._mp_data = &constant_limb;

and %rdp points to x, that should be something like

  lea (%rsp, constant_limb), %rax
  move %rax, _mp_data_offset(%rdp)

or

  mov (%rsp, constant_limb at GOT), %rax
  move %rax, _mp_data_offset(%rdp)

for a static and externally visible constant, respectively. Do I get
this right?

> One to be used in the declaration phase:
> mpz_t temp = MPZ_PREINIT(...);

I was thinking of something like

  mpz_t temp = MPZ_INITALIZER;

The nice thing about that is that it should work also for compound
initialization, like

  struct { int x; mpz_t y; } foo = { 1, MPZ_INITIALIZER; };

I think it might be useful to eventually make public too.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list