summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-05 03:32:41 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-05 03:32:41 +0200
commit1f093b409b8a4a07cc1913c0fd015e2d36f4be36 (patch)
tree561a062c51ce2c281410fcf4e00b73aaef68aaab
parentb34264e1a66b3017cfe704fead04c145caea6cb5 (diff)
downloadct_sequence-1f093b409b8a4a07cc1913c0fd015e2d36f4be36.tar.gz
mor vork
-rw-r--r--makefile3
-rw-r--r--src/def.h12
-rw-r--r--src/main.c23
-rw-r--r--src/n1.c14
-rw-r--r--src/n3.c12
5 files changed, 44 insertions, 20 deletions
diff --git a/makefile b/makefile
index 049cc71..f3a1ffd 100644
--- a/makefile
+++ b/makefile
@@ -38,7 +38,6 @@ ifeq ($(build),debug)
CFLAGS += -g
else ifeq ($(build),release)
CFLAGS += -Ofast -march=native -mtune=native -fomit-frame-pointer
- #CFLAGS += -Wunused-variable -Wunused-function -Wunused-parameter -Wunused-label
LDFLAGS += $(RELFLAGS)
else ifeq ($(build),analyze)
CC := clang
@@ -56,7 +55,7 @@ ifneq ($(run),)
run_cmd := @echo "run $(bin)"
run_cmd += && cd bin
run_cmd += && echo "----------------------------------------------------------------"
- run_cmd += && time ./$(out_file) 10000000
+ run_cmd += && time ./$(out_file) 100000000
run_cmd += ; echo "----------------------------------------------------------------"
run_cmd += && cd ..
endif
diff --git a/src/def.h b/src/def.h
index 82f3fd7..567a85e 100644
--- a/src/def.h
+++ b/src/def.h
@@ -3,15 +3,21 @@
#include <stdint.h>
+typedef struct algo_t{
+ char const *name;
+ void (*init)(uint64_t n);
+ void (*loop)(uint64_t,uint64_t);
+}algo_t;
+
extern uint64_t t;
-void fuk (char const *fmt,...);
+extern algo_t n1;
+extern algo_t n3;
void n1_init (uint64_t n);
void n1_loop (uint64_t x0,uint64_t x1);
-void n3_init (uint64_t n);
-void n3_loop (uint64_t x0,uint64_t x1);
+void fuk (char const *fmt,...);
#endif
diff --git a/src/main.c b/src/main.c
index f0c20fb..980f059 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,9 +9,9 @@ uint64_t t;
static ftimer_t ft;
static uint64_t n;
-static void (*init)(uint64_t n);
+static algo_t *algo;
+
static void (*nump)(void);
-static void (*loop)(uint64_t,uint64_t);
void fuk(char const *fmt,...){
va_list args;
@@ -37,7 +37,7 @@ static void perse(int p){
}
static void numper(void){
- loop(1,n);
+ algo->loop(1,n);
}
static void numper_p(void){
@@ -53,7 +53,7 @@ static void numper_p(void){
x1 = x0+agurk;
if(x1 > n) x1 = n;
if(y == 0) x0++;
- loop(x0,x1);
+ algo->loop(x0,x1);
perse(y+1);
}
}
@@ -63,8 +63,6 @@ int main(int argc,char **argv){
SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS);
#endif
- init = n1_init;
- loop = n1_loop;
nump = numper;
if(argc < 2){
@@ -85,11 +83,18 @@ int main(int argc,char **argv){
n = strtoull(argv[argc-1],0,10);
- printf("n = %llu\n",n); fflush(stdout);
- init(n);
+ if(n <= 1ULL<<32){
+ algo = &n1;
+ }else{
+ algo = &n3;
+ }
+
+ printf("algo = %s\n",algo->name); fflush(stdout);
+ 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
index 8b24562..aa847a9 100644
--- a/src/n1.c
+++ b/src/n1.c
@@ -3,7 +3,14 @@
#include <stdlib.h>
#include <string.h>
-#define BITS 36
+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;
@@ -16,8 +23,9 @@ void n1_init(uint64_t n){
}
void n1_loop(uint64_t x0,uint64_t x1){
- for(uint64_t x = x0;x < x1;x++){
- uint64_t z;
+ 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;
diff --git a/src/n3.c b/src/n3.c
index c636bcb..139add3 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -3,11 +3,17 @@
#include <stdlib.h>
#include <string.h>
-#define U32_MAX ((1ULL<<32)-1)
-#define I32_MAX ((1ULL<<31)-1)
-
#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",
+};
+
static uint8_t *h;
static uint64_t load_store(uint64_t t,uint64_t i);