Niels Möller nisse at
Wed Oct 6 20:12:40 UTC 2021

Torbjörn Granlund <tg at> writes:

> Unfortunately, x86 is not as easy.  The subtract-with-borrow
> instructions clobber all flags, making the new adcx/adox pretty
> pointless.  And no, there are no non-clobbering negation (or one's
> complement) instructions.

I revisited the x86 docs for another reason, and noticed that the NOT
(one's complement) instruction actually is documented as "Flags
affected: None".

If that's right, it seems one could compute s = a + b, d = a - b using
something like

	mov	(ap), s
	mov	(bp), b
	mov	s, d
	adcx	b, s
	not	b
	adox	b, d
	mov	s, (sp)
	mov	d, (dp)

Does that work? Looks to me like it could be pretty fast.

XOR, on the other hand, clobbers more or less all flags, including both
O and C. So if one needs *conditional* negation without clobbering
flags, one would have to combine not and cmov.


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

More information about the gmp-devel mailing list