A little warning in GMP.h

Brian Gladman brg at gladman.plus.com
Thu Sep 23 18:10:56 CEST 2004

Brian Hurt wrote:

 > Can I ask a possibly stupid question: this rather confusing idiom is 
trying to replace:

 >     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));


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

    Brian Gladman

More information about the gmp-discuss mailing list