__builtin_constant_p for trivial operations

Torbjorn Granlund tg at gmplib.org
Sun Feb 20 14:47:21 CET 2011


Marc Glisse <marc.glisse at inria.fr> writes:

  would something like the attached ugliness be acceptable? (don't take
  it as a real patch, it wasn't properly tested and is incomplete)
  
I think we cannot change e.g. mpz_add_ui from a function to a macro,
since we have documented it as a function.  There are surely programs
out there which make a function pointer, perhaps through a function
table, to mpz_add_ui.

  The goal is that, if I have a C++ mpz_class variable z, z*=-1 and z/2
  get translated to mpz_neg and mpz_tdiv_q_2exp instead of mpz_mul_si
  and mpz_tdiv_q_ui. With zero runtime penalty.
  
Could that not be made at the C++ level?  It might seem better to do
that also for C, but I apart from the compatibility problems, I suspect
it to be less common that people use mul_si for negationm that it is in
C++'s with its more seductive syntax...

-- 
Torbjörn


More information about the gmp-discuss mailing list