gcd_11 without abs
Torbjörn Granlund
tg at gmplib.org
Sat Nov 21 12:17:10 UTC 2020
Niels Möller <nisse at lysator.liu.se> writes:
One could get rid of the absolute value by letting one of the working
values be negative. Something like this, in pseudo code
b = - b
while ( (sum = a + b) != 0)
{
if (sum > 0) a = sum;
else b = sum;
}
[snip]
That's one instruction less than the current code, but looks quite
clumsy. It's annoying that bsf clobbers the carry flag. Since we can't
use carry from the first addition anyway, we can use lea for that and
save a mov. But then we still need a mov + add to get the carry later
on; here negation works against us, since that makes the compare
instruction useless.
The way to improve the current code on almost any processor is by
shortening the critical dependency path. reducing the insn count helps
very few CPUs these days.
Do you think you can shorten the dependency path?
--
Torbjörn
Please encrypt, key id 0xC8601622
More information about the gmp-devel
mailing list