summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-06 13:18:04 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-06 13:18:04 +0200
commitc400208232b21c3eceb7d07d2cbf2d4d7b22845c (patch)
treefab2b34fef388eaf976f0fc5d7fc98f042d50651
parente5635b3fb7a2fe6ef1c78a770f052843f59bb8b2 (diff)
downloadct_sequence-c400208232b21c3eceb7d07d2cbf2d4d7b22845c.tar.gz
vork
-rw-r--r--makefile2
-rw-r--r--src/a2.c42
-rw-r--r--src/def.h15
-rw-r--r--src/main.c8
4 files changed, 58 insertions, 9 deletions
diff --git a/makefile b/makefile
index f3a1ffd..bc7ebc9 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) 100000000
+ run_cmd += && time ./$(out_file) 10000000
run_cmd += ; echo "----------------------------------------------------------------"
run_cmd += && cd ..
endif
diff --git a/src/a2.c b/src/a2.c
new file mode 100644
index 0000000..d0d735b
--- /dev/null
+++ b/src/a2.c
@@ -0,0 +1,42 @@
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define W 3
+
+void a2_init (uint64_t n);
+void a2_loop (uint64_t x0,uint64_t x1);
+
+algo_t a2 = {
+ .name = "a2",
+ .nmax = 1<<24,
+ .init = a2_init,
+ .loop = a2_loop,
+};
+
+static uint8_t *m;
+
+void a2_init(uint64_t n){
+ size_t size;
+
+ size = sizeof(uint8_t)*W*n;
+ m = aalloc(4096,size);
+ memset(m,0xFF,size);
+ if(!m) fuk("memory\n");
+}
+
+void a2_loop(uint64_t x0,uint64_t x1){
+ uint32_t x1_32 = x1;
+ for(uint32_t x = x0;x < x1_32;x++){
+ uint32_t z;
+ uint8_t *p;
+
+ z = 0;
+ p = &m[t*W];
+ memcpy(&z,p,W);
+ memcpy(p,&x,W);
+ t = z == 0x00FFFFFF ? 0 : x-z;
+ }
+}
+
diff --git a/src/def.h b/src/def.h
index 3da5f4e..68f0c41 100644
--- a/src/def.h
+++ b/src/def.h
@@ -3,7 +3,12 @@
#include <stdint.h>
-#define ALGO_CUNT 2
+#ifdef _WIN32
+ #include <windows.h>
+ #define aalloc(_a,_s) _aligned_malloc(_s,_a)
+#else
+ #define aalloc(_a,_s) aligned_alloc(_a,_s)
+#endif
typedef struct algo_t{
char const *name;
@@ -17,13 +22,17 @@ extern uint64_t t;
extern algo_t a0;
extern algo_t a1;
+extern algo_t a2;
-static algo_t *algos[ALGO_CUNT] = {
+static algo_t *algos[] = {
[0] = &a0,
[1] = &a1,
+ [2] = &a2,
};
-void fuk (char const *fmt,...);
+#define ALGO_CUNT (sizeof(algos)/sizeof(algo_t *))
+
+void fuk(char const *fmt,...);
#endif
diff --git a/src/main.c b/src/main.c
index 40b941b..44a1838 100644
--- a/src/main.c
+++ b/src/main.c
@@ -97,11 +97,9 @@ int main(int argc,char **argv){
if((int64_t)n <= 0) usake();
if(algo_i == (size_t)-1){
- if(n <= a0.nmax){
- algo_i = 0;
- }else{
- algo_i = 1;
- }
+ if (n <= a2.nmax) algo_i = 2;
+ else if(n <= a0.nmax) algo_i = 0;
+ else algo_i = 1;
}
algo = algos[algo_i];