summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-07 14:41:24 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-07 14:41:24 +0200
commit1bf2fcd400498bc6d477e6daca44ede6aa8e84b7 (patch)
tree610e4d5564507d849c02d417ed74f6e960b83977
parentca0329fb7490b66b836448fea90d33a9658065b2 (diff)
downloadct_sequence-1bf2fcd400498bc6d477e6daca44ede6aa8e84b7.tar.gz
vork
-rw-r--r--src/a3.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/src/a3.c b/src/a3.c
index 61c1b71..8645e97 100644
--- a/src/a3.c
+++ b/src/a3.c
@@ -14,22 +14,21 @@ algo_t a3 = {
.loop = a3_loop,
};
-#define CROSSOVER 24576
-#define M24_SIZE 3
-#define M24_RANGE (1<<24)
+#define CROSSOVER 32768
+#define CROSSOVER_MASK 0xFFFFFFFFFFFF8000
+#define M24_SIZE 3
+#define M24_RANGE (1<<24)
static uint8_t *m24;
static uint32_t *m32;
static size_t m24_n;
static size_t m32_n;
-static uint32_t bias;
static void inner (uint32_t x);
static void inner_bias(uint32_t x);
void a3_init(uint64_t n){
t = 0;
- bias = 0;
m24_n = n > CROSSOVER ? CROSSOVER : n;
m32_n = n-m24_n;
m24 = calloc(sizeof(uint8_t)*M24_SIZE*m24_n,1);
@@ -38,68 +37,56 @@ void a3_init(uint64_t n){
}
void a3_loop(uint64_t x0,uint64_t x1){
- uint32_t x1_32 = x1;
- printf("MAIN %10u -> %10u\n\n",(uint32_t)x0,x1_32);
- for(uint32_t x = x0;x < x1_32;){
- if(x+M24_RANGE >= x1_32){
- printf("LAST %10u -> %10u\n",x,x1_32);
- for(;x < x1_32;x++){
- inner_bias(x); //TODO blabla
- }
- break;
- }else{
- printf(" %10u -> %10u\n",x,x+M24_RANGE);
- uint32_t max = x+M24_RANGE;
- if(bias == 0){
- for(;x < max;x++){
- inner(x);
- }
- }else{
- for(;x < max;x++){
- inner_bias(x);
- }
- }
- bias += M24_RANGE;
- }
+ 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;
- if(t < CROSSOVER){
+ if(t & CROSSOVER_MASK){
+ uint64_t i = t-m24_n;
+ r = m32[i];
+ m32[i] = x;
+ }else{
uint8_t *p;
r = 0;
p = m24+(t*M24_SIZE);
memcpy(&r,p,M24_SIZE);
memcpy(p,&x,M24_SIZE);
- t = r == 0 ? 0 : x-r;
- }else{
- uint64_t i = t-m24_n;
- r = m32[i];
- m32[i] = x;
- t = r == 0 ? 0 : x-r;
}
+ t = r == 0 ? 0 : x-r;
}
static void inner_bias(uint32_t x){
uint32_t r;
- if(t < CROSSOVER){
+ if(t & CROSSOVER_MASK){
+ uint64_t i = t-m24_n;
+ r = m32[i];
+ m32[i] = x;
+ t = r == 0 ? 0 : x-r;
+ }else{
uint8_t *p;
r = 0;
p = m24+(t*M24_SIZE);
- uint32_t i = x & 0x00FFFFFF;
memcpy(&r,p,M24_SIZE);
- memcpy(p,&i,M24_SIZE);
- t = (i-r) & 0x00FFFFFF;
- }else{
- uint64_t i = t-m24_n;
- r = m32[i];
- m32[i] = x;
- t = r == 0 ? 0 : x-r;
+ memcpy(p,&x,M24_SIZE);
+ t = (x-r) & 0x00FFFFFF;
}
}