A little warning in GMP.h
Torbjorn Granlund
tege at swox.com
Sat Sep 25 00:59:24 CEST 2004
Brian Gladman <brg at gladman.plus.com> writes:
> return (__gmp_n != 0)?__gmp_l:0;
which produces:
mov edx,dword ptr [__gmp_n]
mov ecx,dword ptr [__gmp_l]
neg edx
sbb edx,edx
and edx,ecx
with Microsoft VC++ (optimiser on, fast code), whereas:
>>> return __gmp_l & (-(signed)(mp_limb_t) (__gmp_n != 0));
[This is an edited version of the original GMP code. The edits
have made it incorrect.]
produces:
mov ecx,dword ptr [__gmp_n]
xor edx,edx
test ecx,ecx
mov ecx,dword ptr [__gmp_l]
setne dl
neg edx
and edx,ecx
Another reason to avoid the Microsoft compiler; its optimizer
cannot canonicalize equivalent trivial branch-free expressions.
It is as if it statically generates fixed code from known idioms,
but doesn't really perform algebraic equivalence tranformations.
--
Torbjörn
More information about the gmp-discuss
mailing list