summaryrefslogtreecommitdiff
path: root/src/new32v3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/new32v3.c')
-rw-r--r--src/new32v3.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/new32v3.c b/src/new32v3.c
new file mode 100644
index 0000000..d64459d
--- /dev/null
+++ b/src/new32v3.c
@@ -0,0 +1,20 @@
+#include <stdint.h>
+
+static const unsigned int divtab[730] = {
+ [1] = 0xffff + 1l,
+ [3] = 0x5555 + 1l,
+ [9] = 0x1c71 + 1l,
+ [27] = 0x097b + 1l,
+ [81] = 0x0329 + 1l,
+ [243] = 0x010d + 1l,
+ [729] = 0x0059 + 1l
+};
+
+#define FASTDIV(n, d) (((n) * divtab[d]) >> 16)
+
+int new32v3(int i, int x, int y)
+{
+ int A;
+ A = i + x * y;
+ return A - 3 * y * (FASTDIV(A, 3 * y) - FASTDIV(i, 3 * y));
+}