GMP symbol naming (and the history thereof)?

Niels Möller nisse at lysator.liu.se
Sun Mar 3 16:38:14 CET 2013


Torbjorn Granlund <tg at gmplib.org> writes:

> As a start, I automatically made a list of symbols.

Here are some comments on a few that stood out.

> __gmpn_add_n_sub_n                              
> __gmpn_add_nc                                   

I think these make sense as public (we'd need to investigate how one
best does both _n and _nc in C, with duplication or a tail call).

> __gmpn_addcnd_n

And this. (I think I'd prefer

  mp_limb_t
  mpn_cnd_add_n (mp_limb_t cnd, mp_ptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n)

but that's a minor detail, and view the cnd_-prefix as a family of
functions. Some other potential members are mpn_cnd_copy, mpn_cnd_neg
and mpn_cnd_swap, see
http://git.lysator.liu.se/nettle/nettle/blobs/ecc-support/sec-modinv.c
for one application).

> __gmpn_addlsh1_n                                
> __gmpn_addlsh2_n                                
> __gmpn_addlsh_n                                 

Some of these would make sense as public (with some kind of fallback to
addmul_1 if no more efficient loop is implemented).

> __gmpn_divisible_p                              

Would make sense as public, I think.

> __gmpn_gcdext_lehmer_n                          

I think this would make sense as public, under a different name, e.g.,
mpn_gcdext_n_basecase.

BTW, the other day I realized I'd like to extend the gcdext functions to
allow gp == NULL, so callers who use them for modular inversion don't
need to allocate space for a potentially large gcd. In this case, the
functions should return 1 and produce the cofactor only if the gcd is 1,
and otherwise return 0 to indicate failure.

> __gmpn_hgcd                                     
> __gmpn_hgcd2                                    

Some hgcd function should be public, possibly with interface tweaks.

> __gmpn_invert                           doc     

The doc flag is a false positive. But it would make sense to have public
invert and invertappr. (Or "reciprocal", if that's better).

> __gmpn_mulmod_bnm1                      doc

Another false positive. But since this function has turned out to be so
useful, it would make sense to make it public in some form.

> __gmpn_powlo                                    
> __gmpn_powm                                     
> __gmpn_powm_sec                                 
> __gmpn_powm_sec_itch

Should be public, possibly with interface tweaks.

> __gmpn_redc_1                                   
> __gmpn_redc_2                                   
> __gmpn_redc_n

Should be public in some form, but since the bdiv interface redesign is
not yet integrated, redc interfaces should change a bit too for
consistency.

> __gmpn_sqr_basecase                             

This (and also mul_basecase) should be public. They're useful for crypto
applications where numbers are known to be of moderate size and where
low code complexity is desired.

> __gmpn_zero                             doc decl

Missing in the list is mpn_zero_p. Should be public.

Since it's easy, that function is at the top of my list when making
additional mpn functions public. Not entirely sure how to deal with
inline functions, but there are others in gmp-h.in so I should be able
to figure that out.

Regards,
/Niels

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


More information about the gmp-devel mailing list