mpn_add or mpn_add_n+MPN_COPY+MPN_INCR_U ?

bodrato at bodrato at
Sat Jun 14 14:08:30 UTC 2014


Looking at the code in mpn/generic/mul.c I've found lots of structures
like the following:

cy = mpn_add_n (prodp, prodp, ws, vn);
MPN_COPY (prodp + vn, ws + vn, un);
mpn_incr_u (prodp + vn, cy);

that is logically equivalent to

ASSERT_NOCARRY (mpn_add (prodp, ws, vn + un, prodp, vn));

Unfortunately, this compact way to write the same operation (that should
be optimal wrt read from/write to memory) is slower, at least on my amd64.
Probably because add_n, COPY and incr are asm-optimized, while mpn_add is

I'm tempted to substitute some mpn_add_1 in the code with COPY+INCR, or to
write a new macro NOCARRY_MPN_ADD...


More information about the gmp-devel mailing list