summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjon <jonrevold@gmail.com>2020-04-08 19:27:34 +0200
committerjon <jonrevold@gmail.com>2020-04-08 19:27:34 +0200
commit640b35017ec14088fe6b0ce212fcbd967a572a7f (patch)
tree4bb9d14c0e94559177d2fe5d343cf0a2e0ebb7a1
parenteaf9d0f1938a8812f49b9cf2ee90b9b6e9ef2732 (diff)
parent8838a7bd931de3cabbf6cd3cea53a4c2f43ff643 (diff)
downloadct_sequence-640b35017ec14088fe6b0ce212fcbd967a572a7f.tar.gz
Merge branch 'master' of zzz.ink:git/ct_sequence
-rw-r--r--makefile4
-rw-r--r--src/a4.c122
-rw-r--r--src/a5.c58
-rw-r--r--src/def.h6
-rw-r--r--src/nt5.c52
5 files changed, 240 insertions, 2 deletions
diff --git a/makefile b/makefile
index ed04db5..b8fa6a6 100644
--- a/makefile
+++ b/makefile
@@ -27,7 +27,7 @@ bin := $(bin_dir)/$(out_file)
ifneq ($(MSYSTEM),)
bin := $(bin).exe
LDFLAGS += -static
- RELFLAGS := -s
+ #RELFLAGS := -s
else
RELFLAGS :=
endif
@@ -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) -a5 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/a5.c b/src/a5.c
new file mode 100644
index 0000000..87f4b2e
--- /dev/null
+++ b/src/a5.c
@@ -0,0 +1,58 @@
+
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+void a5_init(uint64_t n);
+void a5_loop(uint64_t x0,uint64_t x1);
+
+algo_t a5 = {
+ .name = "a5 (bassed on NT5 tek)",
+ .nmax = 1ULL<<32,
+ .init = a5_init,
+ .loop = a5_loop,
+};
+
+static uint32_t *lastp;
+static uint64_t *index;
+static uint32_t filled;
+
+void a5_init(uint64_t n){
+ size_t lastp_size;
+ size_t index_size;
+
+ t = 0;
+ filled = 0;
+ index_size = (n-1)/8+1;
+ lastp_size = n*sizeof(uint32_t);
+ index = calloc(index_size,1);
+ lastp = malloc(lastp_size);
+}
+
+void a5_loop(uint64_t x0,uint64_t x1){
+ uint32_t x1_32 = x1;
+
+ for(uint32_t x = x0;x < x1_32;x++){
+ uint32_t next;
+ uint64_t *index_ptr;
+ int index_bit;
+
+ index_ptr = index+(t>>6);
+ index_bit = t & 63;
+
+ if(t < filled || ((*index_ptr>>index_bit) & 1)){
+ next = x-lastp[t];
+ }else{
+ next = 0;
+ *index_ptr |= 1ULL<<index_bit;
+ }
+
+ lastp[t] = x;
+ if(t == filled){
+ while(lastp[++filled]);
+ }
+ t = next;
+ }
+}
+
diff --git a/src/def.h b/src/def.h
index 0f3072a..4053dcf 100644
--- a/src/def.h
+++ b/src/def.h
@@ -26,12 +26,18 @@ extern algo_t a0;
extern algo_t a1;
extern algo_t a2;
extern algo_t a3;
+extern algo_t a4;
+extern algo_t a5;
+
+extern algo_t nt5;
static algo_t *algos[] = {
[0] = &a0,
[1] = &a1,
[2] = &a2,
[3] = &a3,
+ [4] = &a4,
+ [5] = &a5,
};
#define ALGO_CUNT (sizeof(algos)/sizeof(algo_t *))
diff --git a/src/nt5.c b/src/nt5.c
new file mode 100644
index 0000000..8cb558e
--- /dev/null
+++ b/src/nt5.c
@@ -0,0 +1,52 @@
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+void nt5_init(uint64_t n);
+void nt5_loop(uint64_t x0,uint64_t x1);
+
+algo_t nt5 = {
+ .name = "nt5",
+ .nmax = 1ULL<<32,
+ .init = nt5_init,
+ .loop = nt5_loop,
+};
+
+static unsigned char *temp;
+static unsigned long long *index;
+static unsigned int *lastpos;
+static unsigned int current;
+static unsigned int cont_filled;
+
+void nt5_init(uint64_t n){
+ size_t size = (n-1)/8+1+n*sizeof(unsigned int);
+ //size_t size = n/8+n*sizeof(unsigned int);
+ temp = malloc(size);
+ memset(temp, 0, size);
+ index = (unsigned long long *)temp;
+ //lastpos = (unsigned int *)(&temp[n / 8]);
+ lastpos = (unsigned int *)(&temp[(n-1)/8+1]);
+ current = 0;
+ cont_filled = 0;
+}
+
+void nt5_loop(uint64_t x0,uint64_t x1){
+ uint32_t x1_32 = x1;
+ for(uint32_t i = x0;i < x1_32;i++){
+ unsigned int next;
+ if (current < cont_filled || (index[current / 64] >> (current % 64)) & 1) {
+ next = i - lastpos[current];
+ } else {
+ next = 0;
+ index[current / 64] |= ((unsigned long long)1) << (current % 64);
+ }
+ lastpos[current] = i;
+ if (current == cont_filled) {
+ while (lastpos[++cont_filled]);
+ }
+ current = next;
+ }
+ t = current;
+}
+