diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-09-25 19:49:12 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-09-25 19:49:12 +0200 |
commit | 58c3bfc2b05cdeb53912bb659b4981e01502305a (patch) | |
tree | f5bcebc0ba8d11017069cbd8e08bab9d8f857ad5 /src | |
parent | 5fc99de1f5542554ed02edb0b5f6f43ceea3c09d (diff) |
Even faster, yet again.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/new32v3.c | 20 |
2 files changed, 23 insertions, 1 deletions
@@ -20,6 +20,7 @@ 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); +int new32v3(int i, int x, int y); void bigtab_init(void); int bigtab(int i, int x, int y); @@ -38,7 +39,8 @@ static struct solfunc solfuncs[ ] = { {"bigtab", bigtab}, {"new", new}, {"new32", new32}, - {"new32v2", new32v2} + {"new32v2", new32v2}, + {"new32v3", new32v3} }; #define PASSES 5 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)); +} |