summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-05 03:40:08 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-05 03:40:08 +0200
commit423572799b8fcb456780efd2522ad0eec167c733 (patch)
tree9cb5c3e2db16830fca06741afba52912b1d8c875
parent1f093b409b8a4a07cc1913c0fd015e2d36f4be36 (diff)
downloadct_sequence-423572799b8fcb456780efd2522ad0eec167c733.tar.gz
VORK
-rw-r--r--src/a1.c35
-rw-r--r--src/a3.c (renamed from src/n3.c)27
-rw-r--r--src/def.h10
-rw-r--r--src/main.c19
-rw-r--r--src/n1.c34
5 files changed, 67 insertions, 58 deletions
diff --git a/src/a1.c b/src/a1.c
new file mode 100644
index 0000000..4afab2e
--- /dev/null
+++ b/src/a1.c
@@ -0,0 +1,35 @@
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+void a1_init (uint64_t n);
+void a1_loop (uint64_t x0,uint64_t x1);
+
+algo_t a1 = {
+ .name = "a1",
+ .nmax = UINT32_MAX,
+ .init = a1_init,
+ .loop = a1_loop,
+};
+
+static uint32_t *m;
+
+void a1_init(uint64_t n){
+ size_t size;
+
+ size = sizeof(uint32_t)*n;
+ m = calloc(size,1);
+ if(!m) fuk("memory");
+}
+
+void a1_loop(uint64_t x0,uint64_t x1){
+ uint32_t x1_32 = x1;
+ for(uint32_t x = x0;x < x1_32;x++){
+ uint32_t z;
+ z = m[t];
+ m[t] = x;
+ t = z == 0 ? 0 : x-z;
+ }
+}
+
diff --git a/src/n3.c b/src/a3.c
index 139add3..65e9160 100644
--- a/src/n3.c
+++ b/src/a3.c
@@ -5,27 +5,28 @@
#define BITS 36
-void n3_init (uint64_t n);
-void n3_loop (uint64_t x0,uint64_t x1);
-
-algo_t n3 = {
- .init = n3_init,
- .loop = n3_loop,
- .name = "n3",
+void a3_init (uint64_t n);
+void a3_loop (uint64_t x0,uint64_t x1);
+
+algo_t a3 = {
+ .name = "a1",
+ .nmax = 1ULL<<BITS,
+ .init = a3_init,
+ .loop = a3_loop,
};
-static uint8_t *h;
+static uint8_t *m;
static uint64_t load_store(uint64_t t,uint64_t i);
-void n3_init(uint64_t n){
+void a3_init(uint64_t n){
size_t size;
size = sizeof(uint8_t)*n*BITS>>3;
- h = calloc(size,1);
- if(!h) fuk("memory");
+ m = calloc(size,1);
+ if(!m) fuk("memory");
}
-void n3_loop(uint64_t x0,uint64_t x1){
+void a3_loop(uint64_t x0,uint64_t x1){
for(uint64_t x = x0;x < x1;x++){
uint64_t z;
z = load_store(t,x);
@@ -38,7 +39,7 @@ static uint64_t load_store(uint64_t t,uint64_t i){
uint8_t *p;
r = 0;
- p = h+(t*BITS>>3);
+ p = m+(t*BITS>>3);
memcpy(&r,p,5);
if(t & 1){
r >>= 4;
diff --git a/src/def.h b/src/def.h
index 567a85e..ebaa1bd 100644
--- a/src/def.h
+++ b/src/def.h
@@ -5,17 +5,19 @@
typedef struct algo_t{
char const *name;
+ uint64_t nmax;
+
void (*init)(uint64_t n);
void (*loop)(uint64_t,uint64_t);
}algo_t;
extern uint64_t t;
-extern algo_t n1;
-extern algo_t n3;
+extern algo_t a1;
+extern algo_t a3;
-void n1_init (uint64_t n);
-void n1_loop (uint64_t x0,uint64_t x1);
+void a1_init (uint64_t n);
+void a1_loop (uint64_t x0,uint64_t x1);
void fuk (char const *fmt,...);
diff --git a/src/main.c b/src/main.c
index 980f059..693ae4b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -67,7 +67,8 @@ int main(int argc,char **argv){
if(argc < 2){
printf("usake: numper [-p] <n>\n");
- printf(" -p display progress percentage\n");
+ printf(" -p display progress percentage\n");
+ printf(" -aN force usage of algo N\n");
fflush(stdout);
exit(0);
}
@@ -83,18 +84,22 @@ int main(int argc,char **argv){
n = strtoull(argv[argc-1],0,10);
- if(n <= 1ULL<<32){
- algo = &n1;
+ if(n <= a1.nmax){
+ algo = &a1;
}else{
- algo = &n3;
+ algo = &a3;
}
- printf("algo = %s\n",algo->name); fflush(stdout);
- printf("n = %llu\n",n); fflush(stdout);
+ printf("algo = %s\n",algo->name);
+ printf("n = %llu\n",n);
+ fflush(stdout);
+
algo->init(n);
ftimer_init(&ft);
nump();
- printf("t = %llu\n",t); fflush(stdout);
+
+ printf("t = %llu\n",t);
+ fflush(stdout);
return 0;
}
diff --git a/src/n1.c b/src/n1.c
deleted file mode 100644
index aa847a9..0000000
--- a/src/n1.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "def.h"
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-void n1_init (uint64_t n);
-void n1_loop (uint64_t x0,uint64_t x1);
-
-algo_t n1 = {
- .init = n1_init,
- .loop = n1_loop,
- .name = "n1",
-};
-
-static uint32_t *h;
-
-void n1_init(uint64_t n){
- size_t size;
-
- size = sizeof(uint32_t)*n;
- h = calloc(size,1);
- if(!h) fuk("memory");
-}
-
-void n1_loop(uint64_t x0,uint64_t x1){
- uint32_t x1_32 = x1;
- for(uint32_t x = x0;x < x1_32;x++){
- uint32_t z;
- z = h[t];
- h[t] = x;
- t = z == 0 ? 0 : x-z;
- }
-}
-