summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-09 17:54:39 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-09 17:54:39 +0200
commitb44473967e21364383cbe6dd8ea61e060d87dd01 (patch)
tree5afc26a1eea5dd42cdf798bc4d0efb6b727386d9
parent06b70d9eed751ecf7a8d41ffec9d1209a315e496 (diff)
downloadct_sequence-b44473967e21364383cbe6dd8ea61e060d87dd01.tar.gz
fuk
-rw-r--r--makefile2
-rw-r--r--src/a5.c4
-rw-r--r--src/a7.c75
-rw-r--r--src/def.h2
4 files changed, 78 insertions, 5 deletions
diff --git a/makefile b/makefile
index b8fa6a6..f18d207 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) -a5 100000000
+ run_cmd += && time ./$(out_file) -a7 10000000
run_cmd += ; echo "----------------------------------------------------------------"
run_cmd += && cd ..
endif
diff --git a/src/a5.c b/src/a5.c
index af90ca0..ad1f42d 100644
--- a/src/a5.c
+++ b/src/a5.c
@@ -1,4 +1,3 @@
-
#include "def.h"
#include <stdint.h>
#include <stdlib.h>
@@ -52,13 +51,10 @@ void a5_loop(uint64_t x0,uint64_t x1){
*index_ptr |= index_bit;
}
}
-
lastp[t] = x;
-
if(t == filled){
while(lastp[++filled]);
}
-
t = next;
}
}
diff --git a/src/a7.c b/src/a7.c
new file mode 100644
index 0000000..3d73129
--- /dev/null
+++ b/src/a7.c
@@ -0,0 +1,75 @@
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define WIDTH 3
+void a7_init(uint64_t n);
+void a7_loop(uint64_t x0,uint64_t x1);
+
+algo_t a7 = {
+ .name = "a7 (NT5 tek)",
+ .nmax = 1<<(WIDTH*8),
+ .init = a7_init,
+ .loop = a7_loop,
+};
+
+static uint8_t *lastp;
+static uint64_t *index;
+static uint64_t filled;
+
+void a7_init(uint64_t n){
+ size_t index_n;
+ size_t index_size;
+ size_t lastp_size;
+
+ t = 0;
+ filled = 0;
+ index_n = (n-1)/64+1;
+ index_size = index_n*sizeof(uint64_t);
+ lastp_size = n*WIDTH;
+ index = calloc(index_size,1);
+ lastp = calloc(lastp_size,1);
+}
+
+void a7_loop(uint64_t x0,uint64_t x1){
+ for(uint64_t x = x0;x < x1;x++){
+ uint64_t next;
+ uint8_t *p;
+
+ p = lastp+(t*WIDTH);
+
+ if(t < filled){
+ uint32_t r = 0;
+ memcpy(&r,p,WIDTH);
+ next = x-r;
+ }else{
+ uint64_t *index_ptr;
+ uint64_t index_bit;
+
+ index_ptr = index+(t/64);
+ index_bit = 1ULL<<(t%64);
+
+ if(*index_ptr & index_bit){
+ uint32_t r = 0;
+ memcpy(&r,p,WIDTH);
+ next = x-r;
+ }else{
+ next = 0;
+ *index_ptr |= index_bit;
+ }
+ }
+ memcpy(p,&x,WIDTH);
+ if(t == filled){
+ uint32_t r;
+ do{
+ uint8_t *p;
+ r = 0;
+ p = lastp+(++filled*WIDTH);
+ memcpy(&r,p,WIDTH);
+ }while(r);
+ }
+ t = next;
+ }
+}
+
diff --git a/src/def.h b/src/def.h
index 0a7acab..29b106a 100644
--- a/src/def.h
+++ b/src/def.h
@@ -27,6 +27,7 @@ extern algo_t a3;
extern algo_t a4;
extern algo_t a5;
extern algo_t a6;
+extern algo_t a7;
extern algo_t nt5;
@@ -38,6 +39,7 @@ static algo_t *algos[] = {
[4] = &a4,
[5] = &a5,
[6] = &a6,
+ [7] = &a7,
};
#define ALGO_CUNT (sizeof(algos)/sizeof(algo_t *))