summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-09-25 18:41:21 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-09-25 18:41:21 +0200
commit67b80a01a681870031a81960a2ae310c367827a8 (patch)
treef303c2ef1d24eb590081d2a97ca2ba432674c6e8
parent0e11a91fce4d7e1a4cdcd91f8bd042fa89d6b9cc (diff)
new32v2, an even faster solution.
-rw-r--r--Makefile1
-rw-r--r--src/main.c4
-rw-r--r--src/new32v2.c21
3 files changed, 25 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index f3400a6..d85c7c7 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ SRC := src/bigtab.c \
src/main.c \
src/new.c \
src/new32.c \
+ src/new32v2.c \
src/null.c \
src/ref.c
diff --git a/src/main.c b/src/main.c
index 8d82af5..4961879 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,6 +19,7 @@ int ref1(int i, int x, int y);
int ref2(int i, int x, int y);
int new(int i, int x, int y);
int new32(int i, int x, int y);
+int new32v2(int i, int x, int y);
void bigtab_init(void);
int bigtab(int i, int x, int y);
@@ -36,7 +37,8 @@ static struct solfunc solfuncs[ ] = {
{"ref2", ref2},
{"bigtab", bigtab},
{"new", new},
- {"new32", new32}
+ {"new32", new32},
+ {"new32v2", new32v2}
};
#define PASSES 5
diff --git a/src/new32v2.c b/src/new32v2.c
new file mode 100644
index 0000000..a755d6d
--- /dev/null
+++ b/src/new32v2.c
@@ -0,0 +1,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;
+}