summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-05 02:10:41 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-05 02:10:41 +0200
commitb0d24f74e8c8a449236560d5fc47e6f80e11657d (patch)
tree9c52b97cd9942f34e8759e72ec21f8007e9e53b5
parent15df55d10b01aef56936ff1d651e2abc7ff500ae (diff)
downloadct_sequence-b0d24f74e8c8a449236560d5fc47e6f80e11657d.tar.gz
oke
-rw-r--r--src/def.h14
-rw-r--r--src/main.c85
-rw-r--r--src/n3.c54
3 files changed, 92 insertions, 61 deletions
diff --git a/src/def.h b/src/def.h
new file mode 100644
index 0000000..bd43d01
--- /dev/null
+++ b/src/def.h
@@ -0,0 +1,14 @@
+#ifndef DEF_H
+#define DEF_H
+
+#include <stdint.h>
+
+extern uint64_t t;
+
+void fuk (char const *str);
+
+void n3_init (uint64_t n);
+void n3_loop (uint64_t x0,uint64_t x1);
+
+#endif
+
diff --git a/src/main.c b/src/main.c
index 0d40355..8035b84 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,47 +1,46 @@
+#include "def.h"
#include <stdio.h>
-#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <okelib2/okelib2.h>
-#define U32_MAX ((1ULL<<32)-1)
-#define I32_MAX ((1ULL<<31)-1)
-
-#define BITS 36
+uint64_t t;
static ftimer_t ft;
-static uint8_t *h;
-static uint64_t t;
static uint64_t n;
-static uint64_t agurk;
-static uint64_t outer;
-static uint64_t last;
+static void (*init)(uint64_t n);
+static void (*nump)(void);
static void (*loop)(uint64_t,uint64_t);
-static void fuk(char const *str){
+void fuk(char const *str){
printf("error!( %s\n",str);
fflush(stdout);
exit(1);
}
static void perse(int p){
- char buf[FMTFTIME_BUFSIZE];
+ //char buf[FMTFTIME_BUFSIZE];
ftime_t t;
+ float f;
t = ftimer_time(&ft);
- fmtftime(buf,t);
- printf("%12s %3u%%\n",buf,p);
+ f = (float)t/FTIME_SEC;
+ //fmtftime(buf,t);
+ //printf("%12s %3u%%\n",buf,p);
+ printf("%9.3f\t%3u%%\n",f,p);
fflush(stdout);
}
-static void init(uint64_t n){
- size_t size;
+static void numper(void){
+ loop(1,n);
+ perse(100);
+}
- size = sizeof(uint8_t)*n*BITS>>3;
- h = malloc(size);
- if(!h) fuk("memory");
- memset(h,0x00,size);
+static void numper_perse(void){
+ uint64_t agurk;
+ uint64_t outer;
+ uint64_t last;
t = 0;
agurk = n/100;
@@ -51,46 +50,7 @@ static void init(uint64_t n){
last = agurk;
outer--;
}
-}
-
-static uint64_t load_store(uint64_t t,uint64_t i){
- uint64_t r;
- uint8_t *p;
-
- r = 0;
- p = h+(t*BITS>>3);
- memcpy(&r,p,5);
- if(t & 1){
- r >>= 4;
- }else{
- r &= 0x0000000FFFFFFFFF;
- }
- if(t & 1){
- i <<= 4;
- i |= p[0] & 0x0F;
- }else{
- i |= (uint64_t)(p[4] & 0xF0)<<32;
- }
- memcpy(p,&i,5);
-
- return r;
-}
-
-static void loop_36(uint64_t x0,uint64_t x1){
- for(uint64_t x = x0;x < x1;x++){
- uint64_t z;
- z = load_store(t,x);
- t = z == 0 ? 0 : x-z;
- }
-}
-
-static void numper(void){
- loop(1,n);
- perse(100);
-}
-
-static void numper_perse(void){
perse(0);
for(uint64_t y = 0;y < outer;y++){
uint64_t beg = y*agurk;
@@ -108,13 +68,16 @@ int main(int argc,char **argv){
return 1;
}
+ init = n3_init;
+ loop = n3_loop;
+ nump = numper;
+
n = strtoull(argv[1],0,10);
printf("n = %llu\n",n); fflush(stdout);
init(n);
- loop = loop_36;
ftimer_init(&ft);
- numper();
+ nump();
printf("result = %llu\n",t); fflush(stdout);
return 0;
diff --git a/src/n3.c b/src/n3.c
new file mode 100644
index 0000000..518bed2
--- /dev/null
+++ b/src/n3.c
@@ -0,0 +1,54 @@
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define U32_MAX ((1ULL<<32)-1)
+#define I32_MAX ((1ULL<<31)-1)
+
+#define BITS 36
+
+static uint8_t *h;
+static uint64_t load_store(uint64_t t,uint64_t i);
+
+void n3_init(uint64_t n){
+ size_t size;
+
+ size = sizeof(uint8_t)*n*BITS>>3;
+ h = malloc(size);
+ if(!h) fuk("memory");
+ memset(h,0x00,size);
+}
+
+void n3_loop(uint64_t x0,uint64_t x1){
+ for(uint64_t x = x0;x < x1;x++){
+ uint64_t z;
+ z = load_store(t,x);
+ t = z == 0 ? 0 : x-z;
+ }
+}
+
+static uint64_t load_store(uint64_t t,uint64_t i){
+ uint64_t r;
+ uint8_t *p;
+
+ r = 0;
+ p = h+(t*BITS>>3);
+ memcpy(&r,p,5);
+ if(t & 1){
+ r >>= 4;
+ }else{
+ r &= 0x0000000FFFFFFFFF;
+ }
+
+ if(t & 1){
+ i <<= 4;
+ i |= p[0] & 0x0F;
+ }else{
+ i |= (uint64_t)(p[4] & 0xF0)<<32;
+ }
+ memcpy(p,&i,5);
+
+ return r;
+}
+