gmp_pi1_t
Joerg Arndt
arndt at jjj.de
Sun Dec 13 23:47:49 CET 2009
* Niels Möller <nisse at lysator.liu.se> [Dec 14. 2009 09:02]:
> Torbjorn Granlund <tg at gmplib.org> writes:
>
> > nisse at lysator.liu.se (Niels Möller) writes:
>
> > If I do that, should I eliminate the gmp_pi1_t type as well, and pass a
> > single limb (the remaining inv32 member) instead of a gmp_pi1_t *?
> >
> > I supoose there is no harm with keeping gmp_pi1_t, since it will be
> > easier to modify it. Or do you see some harm?
>
> Estetic considerations aside, the only obvious drawback is that the
> function call overhead will be a cycle or two less for passing the limb
> directly in a register, than for storing it in memory and passing a
> poiter to it. But I don't know if that difference is going to be
> measurable.
The 'inline' keyword is your friend.
Inlined functions are optimized across their
boundaries which is often more important than
just avoiding call overhead.
Note that (AMD64) a few args are passed in registers
and the call overhead can be neglected unless there
are very many calls.
>
> (In recent years I've been under some influence of "extreme programming"
> thinking, so I'm suspicious to adding abstractings that do nothing
> useful today but are supposed to be useful in some future version).
The compiler should remove 'fall through' functions entirely.
IIRC there is some optimization switch regarding this issue.
>
> > I expect more gmp_piX_t structures in the future, BTW.
>
> Anyway, I think structures like these should be const declared in the
> prototypes, for both clarity and performance. So that code like
>
> gmp_pi1_t inv;
>
> ... inv->inv32 ...;
> foo (..., &inv);
> ... inv->inv32 ...;
>
> can keep the value of inv32 in a register over the function call. Are
> gcc or other compilers clever enough to do that optimization?
With inlined functions _much_ more is done.
Inspect the generated machine code as follows:
# create assembler code:
c++ -S -fverbose-asm -g -O2 test.cc -o test.s
# create asm interlaced with source lines:
as -alhnd test.s > test.lst
>
> Regards,
> /Niels
>
> --
> Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
> Internet email is subject to wholesale government surveillance.
> _______________________________________________
> gmp-devel mailing list
> gmp-devel at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-devel
More information about the gmp-devel
mailing list