summaryrefslogtreecommitdiff
path: root/src/new32v2.c
blob: 1fd4c6faeb3a773931a886c7192a87fba8e1b852 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdint.h>

static const unsigned int divtab[244] = {
	[1] = 0xffff + 1l,
	[3] = 0x5555 + 1l,
	[9] = 0x1c71 + 1l,
	[27] = 0x097b + 1l,
	[81] = 0x0329 + 1l,
	[243] = 0x010d + 1l
};

#define FASTDIV(n, d) (((n) * divtab[d]) >> 16)

int new32v2(int i, int x, int y)
{
	int A;

	A = FASTDIV(i, y);

	return i + (x - 3 * FASTDIV(A + x, 3) + 3 * FASTDIV(A, 3)) * y;
}