diff options
author | jonsykkel <jonrevold@gmail.com> | 2020-04-06 13:18:04 +0200 |
---|---|---|
committer | jonsykkel <jonrevold@gmail.com> | 2020-04-06 13:18:04 +0200 |
commit | c400208232b21c3eceb7d07d2cbf2d4d7b22845c (patch) | |
tree | fab2b34fef388eaf976f0fc5d7fc98f042d50651 | |
parent | e5635b3fb7a2fe6ef1c78a770f052843f59bb8b2 (diff) | |
download | ct_sequence-c400208232b21c3eceb7d07d2cbf2d4d7b22845c.tar.gz |
vork
-rw-r--r-- | makefile | 2 | ||||
-rw-r--r-- | src/a2.c | 42 | ||||
-rw-r--r-- | src/def.h | 15 | ||||
-rw-r--r-- | src/main.c | 8 |
4 files changed, 58 insertions, 9 deletions
@@ -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; + } +} + @@ -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 @@ -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]; |