Alternative div_qr_1

Niels Möller nisse at
Mon May 10 22:12:53 CEST 2010

Torbjorn Granlund <tg at> writes:

> One trick on x86 is to precompute the negation of <c1,c0>, since then it will
> be possible to do the conditional "subtract" using two LEA and two CMOV.

But it's a two-limb number that should be added, and the carries from
both limbs are needed. That rules out the use of LEA as far as I see.

And the condition value can be generated as a mask with no extra effort
(sbb mask, mask; ...; sbc $0, mask, then the condition is true iff mask
is all ones and iff the Z flag is clear). I don't know if it makes much
difference to do

  ... get condition as a mask in t1...
  mov c0, t0
  and t1, t0
  and c1, t1


  xor t0, t0
  xor t1, t1
  ... get condition, in Z flag ...
  cmovne c0, t0
  cmovne c1, t1

(And I should have written a conditional *addition*, not a subtraction,
but that doesn't matter much, since the constants can be negated at will).


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list