mpn_sqrtrem1

Marco Bodrato bodrato at mail.dm.unipi.it
Wed Dec 21 06:45:56 UTC 2016


Ciao,

Il Mer, 21 Dicembre 2016 12:20 am, Niels Möller ha scritto:
> "Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:
>> +    __x1 = (mp_limb_t) __ul * __vl;				\
> [...]
>> +    if (__vh)							\
>> +      {								\
>> +	__x2 += __x1;						\
>> +	__ul += __x2 < __x1;					\

> I think I'd arrange this as a branch free conditional negation +
> sign-extend of __x1. If __vh represents sign as 0 or ~0, that would be
> something like

__vh is half a limb only, it should be promoted.

>   __x1 = (__x1 ^ __vh) - __vh;

That's the trick I used for |__xl - __xh|...

> Now {__vh, __x1} is a two-limb two's complement representation of the

... but I did not think the sign-extension to compensate carry/borrow!

> product (__ul - __uh) * (__vl - __vh), where the notation in the latter

Also using an mp_limb_signed_t product may be explored, maybe...

> But it still won't beat the plain version on any machine with a
> reasonable mul-instruction.

... but I agree :-)

Best regards,
m

-- 
http://bodrato.it/



More information about the gmp-devel mailing list