4 ms·
Hmm, I wonder if this is more efficient than calculating mod 15 directly. It's basically something like gcd15(int x) { return ((x * 0xaaaaaaab) <
by contravariant 10y ago
Hmm, I wonder if this is more efficient than calculating mod 15 directly. It's basically something like
gcd15(int x) {
return ((x * 0xaaaaaaab) < (0xfffffff/3 + 1) ? 1 : 3)
* ((x * 0xaaaaaaab) < (0xfffffff/5 + 1) ? 1 : 5)
}
versus something like
gcd15(int x) {
LOOKUP_TABLE = { /* gcd(n,15) for n = 0,...,15 */ }
int q = (x * ((1 << 28) / 15)) >> 28;
return LOOKUP_TABLE[x - 15 * q];
}
Well, you're probably better of using the method in the article for the division, but this should work for small numbers.