in reply to Re^2: Simple arithmetic? (And the winner is ... )
in thread Simple arithmetic?
And no sooner have I said that, and I think of a way to use _BitScanForward64() that improves upon the original by 70+%:
C:\test\C>gcm anonyM: gcm for s=2147483648 & r=1 to 1073741824 took:8.535316994670 anonyM: gcm2 for s=2147483648 & r=1 to 1073741824 took:2.271266720696
Pre-masking the scanned var, avoids the later subtraction being conditional:
U64 gcm2( U64 max, U64 lcm ) { I32 b; _BitScanForward64( &b, lcm & 0xfff ); lcm <<= ( 12 - b ); return ( max / lcm ) * lcm; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Simple arithmetic? (And the winner is ... )
by oiskuu (Hermit) on Mar 09, 2015 at 21:52 UTC |