summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-08 12:41:02 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-08 12:41:02 +0200
commit13de4d7d44bff1c3db33664a90b201ded7401aec (patch)
treeba80d1f34c980f2478d43a9f802ee9e43baef8a3
parent6f8e8f5bf55f9e755b27e50c02107b86d3eb1f7f (diff)
downloadct_sequence-13de4d7d44bff1c3db33664a90b201ded7401aec.tar.gz
a4
-rw-r--r--makefile2
-rw-r--r--src/a4.c122
-rw-r--r--src/def.h2
3 files changed, 125 insertions, 1 deletions
diff --git a/makefile b/makefile
index 3423546..196110b 100644
--- a/makefile
+++ b/makefile
@@ -55,7 +55,7 @@ ifneq ($(run),)
run_cmd := @echo "run $(bin)"
run_cmd += && cd bin
run_cmd += && echo "----------------------------------------------------------------"
- run_cmd += && time ./$(out_file) -a3 100000000
+ run_cmd += && time ./$(out_file) -a4 100000000
run_cmd += ; echo "----------------------------------------------------------------"
run_cmd += && cd ..
endif
diff --git a/src/a4.c b/src/a4.c
new file mode 100644
index 0000000..97946e4
--- /dev/null
+++ b/src/a4.c
@@ -0,0 +1,122 @@
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+void a4_init(uint64_t n);
+void a4_loop(uint64_t x0,uint64_t x1);
+
+algo_t a4 = {
+ .name = "a4 codename \"fuk my life\" aka SDI1 aka what a fukig disaster",
+ .nmax = 1ULL<<32,
+ .init = a4_init,
+ .loop = a4_loop,
+};
+
+#define M24_SIZE 3
+#define M24_RANGE (1<<(M24_SIZE*8))
+
+#define M32_SIZE 4
+
+#define CROSSOVER (1<<15)
+#define CROSSOVER_MASK (~(CROSSOVER-1))
+
+static uint8_t *m;
+static uint8_t *m_32ik; //TMP
+static size_t m24_n;
+static size_t m32_n;
+static uint32_t m32_off;
+
+static void inner (uint32_t x);
+static void inner_bias(uint32_t x);
+
+void a4_init(uint64_t n){
+ size_t size;
+ t = 0;
+ m24_n = n > CROSSOVER ? CROSSOVER : n;
+ m32_n = n-m24_n;
+ size = sizeof(uint8_t)*M24_SIZE*m24_n;
+ m32_off = size;
+ size += sizeof(uint8_t)*M32_SIZE*m32_n;
+ m = calloc(size,1);
+ m_32ik = m+m32_off;
+ if(!m) fuk("memory\n");
+}
+
+void a4_loop(uint64_t x0,uint64_t x1){
+ uint32_t x;
+ uint32_t x1_32;
+ uint32_t x1_first;
+
+ x1_32 = x1;
+ x1_first = x0+M24_RANGE;
+ if(x1_first > x1_32) x1_first = x1_32;
+
+ for(x = x0;x < x1_first;x++){
+ inner(x);
+ }
+ for(;x < x1_32;x++){
+ inner_bias(x);
+ }
+}
+
+static void inner(uint32_t x){
+ uint32_t r;
+ uint32_t i;
+ uint8_t *p;
+ uint32_t m_sel;
+ uint32_t m_size;
+ uint32_t m_off;
+ uint32_t m_mask;
+ uint32_t rnzero;
+ uint32_t rxdiff;
+
+ m_sel = ((int32_t)t-CROSSOVER)>>31; //FFFFetc.. if t < CROSSOVER
+ m_mask = 0x00FFFFFF | ~m_sel; //mask bytes used
+ m_size = (m_sel & M24_SIZE) | (~m_sel & M32_SIZE);
+ m_off = ~m_sel & m32_off;
+ m_off += m_size*t;
+ p = m+m_off;
+ memcpy(&r,p,M32_SIZE);
+ i = r;
+ r &= m_mask;
+ i &= ~m_mask;
+ i |= x & m_mask;
+ memcpy(p,&i,M32_SIZE);
+ rnzero = (-(int32_t)r)>>31; //FFFFetc.. if r != 0
+ rxdiff = x-r;
+ rxdiff &= rnzero; //clear rxdiff if r == 0
+ t = rxdiff;
+}
+
+static void inner_bias(uint32_t x){
+ uint32_t r;
+ uint32_t i;
+ uint8_t *p;
+ uint32_t m_sel;
+ uint32_t m_size;
+ uint32_t m_off;
+ uint32_t m_mask;
+ uint32_t rnzero;
+ uint32_t rxdiff;
+
+ m_sel = ((int32_t)t-CROSSOVER)>>31; //FFFFetc.. if t < CROSSOVER
+ m_mask = 0x00FFFFFF | ~m_sel; //mask bytes used
+ m_size = (m_sel & M24_SIZE) | (~m_sel & M32_SIZE);
+ m_off = ~m_sel & m32_off;
+ m_off += m_size*t;
+ p = m+m_off;
+ memcpy(&r,p,M32_SIZE);
+ i = r;
+ r &= m_mask;
+ i &= ~m_mask;
+ i |= x & m_mask;
+ memcpy(p,&i,M32_SIZE);
+ rnzero = (-(int32_t)r)>>31; //FFFFetc.. if r != 0
+ rxdiff = x-r;
+ rxdiff &= m_mask;
+ rxdiff &= m_sel | rnzero; //clear rxdiff if t >= CROSSOVER and r == 0
+ t = rxdiff;
+}
+
diff --git a/src/def.h b/src/def.h
index 0f3072a..49de066 100644
--- a/src/def.h
+++ b/src/def.h
@@ -26,12 +26,14 @@ extern algo_t a0;
extern algo_t a1;
extern algo_t a2;
extern algo_t a3;
+extern algo_t a4;
static algo_t *algos[] = {
[0] = &a0,
[1] = &a1,
[2] = &a2,
[3] = &a3,
+ [4] = &a4,
};
#define ALGO_CUNT (sizeof(algos)/sizeof(algo_t *))