[Issue 4125] std.numeric.gcd can use a binary GCD

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 8 02:37:45 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=4125



--- Comment #4 from Don <clugdbug at yahoo.com.au> 2013-01-08 02:37:41 PST ---
FWIW, you can get rid of most of the conditional branches by using:

min(u,v) = v + ( (cast(int)(u-v)) >> (8*int.sizeof - 1)) & (u-v)

the shift smears the sign bit of u-v so that it makes a mask either 0x0000_0000
or 0xFFFF_FFFF.

I think the general consensus is that (at least if you use asm), binary GCD is
faster on all known processors, but not necessarily by a large amount.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list