diff options
author | jonsykkel <jonrevold@gmail.com> | 2020-04-06 20:16:04 +0200 |
---|---|---|
committer | jonsykkel <jonrevold@gmail.com> | 2020-04-06 20:16:04 +0200 |
commit | 0cd2f683be106cae58df7cac11a37ef7ed679fcc (patch) | |
tree | 58633316a4b6f28d61a846fc858823f61c631cdf | |
parent | 7b09424e449ff290a1e2397305abafb3a2eeef59 (diff) | |
download | ct_sequence-0cd2f683be106cae58df7cac11a37ef7ed679fcc.tar.gz |
vork
-rw-r--r-- | makefile | 8 | ||||
-rw-r--r-- | src/a0.c | 13 | ||||
-rw-r--r-- | src/a1.c | 20 | ||||
-rw-r--r-- | src/a2.c | 14 | ||||
-rw-r--r-- | src/def.h | 6 | ||||
-rw-r--r-- | src/main.c | 30 |
6 files changed, 44 insertions, 47 deletions
@@ -10,7 +10,7 @@ src_dir := src CFLAGS := -std=c11 -fdata-sections -ffunction-sections -D_POSIX_C_SOURCE=200809L CFLAGS += -pedantic -Wall -Wextra -Wcast-qual -Wstrict-aliasing -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wvla -Wno-parentheses -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-label LDFLAGS := -Wl,--gc-sections -LDLIBS := -lokelib2 +LDLIBS := ARFLAGS := -rcs compile = $(CC) $(CFLAGS) -MMD -c $< -o $@ @@ -27,7 +27,7 @@ bin := $(bin_dir)/$(out_file) ifneq ($(MSYSTEM),) bin := $(bin).exe LDFLAGS += -static - RELFLAGS := -s -mwindows + RELFLAGS := -s else RELFLAGS := endif @@ -37,7 +37,7 @@ out := $(bin) ifeq ($(build),debug) CFLAGS += -g else ifeq ($(build),release) - CFLAGS += -Ofast -march=native -mtune=native -fomit-frame-pointer + CFLAGS += -Ofast -march=native -mtune=native LDFLAGS += $(RELFLAGS) else ifeq ($(build),analyze) CC := clang @@ -55,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 @@ -3,14 +3,14 @@ #include <stdlib.h> #include <string.h> -void a0_init (uint64_t n); -void a0_loop (uint64_t x0,uint64_t x1); +void a0_init(uint64_t n); +void a0_loop(uint64_t x0,uint64_t x1); algo_t a0 = { - .name = "a0", - .nmax = UINT32_MAX, - .init = a0_init, - .loop = a0_loop, + .name = "a0", + .nmax = 1ULL<<32, + .init = a0_init, + .loop = a0_loop, }; static uint32_t *m; //mammory @@ -28,6 +28,7 @@ void a0_loop(uint64_t x0,uint64_t x1){ uint32_t x1_32 = x1; for(uint32_t x = x0;x < x1_32;x++){ uint32_t r; //index readed + r = m[t]; m[t] = x; t = r == 0 ? 0 : x-r; @@ -5,14 +5,14 @@ #define BITS 36 -void a1_init (uint64_t n); -void a1_loop (uint64_t x0,uint64_t x1); +void a1_init(uint64_t n); +void a1_loop(uint64_t x0,uint64_t x1); algo_t a1 = { - .name = "a1", - .nmax = 1ULL<<BITS, - .init = a1_init, - .loop = a1_loop, + .name = "a1", + .nmax = 1ULL<<BITS, + .init = a1_init, + .loop = a1_loop, }; static uint8_t *m; //mammory @@ -21,7 +21,7 @@ void a1_init(uint64_t n){ size_t size; //size t = 0; - size = sizeof(uint8_t)*n*BITS>>3; + size = (sizeof(uint8_t)*n*BITS)>>3; m = calloc(size,1); if(!m) fuk("memory\n"); } @@ -37,12 +37,12 @@ void a1_loop(uint64_t x0,uint64_t x1){ w = x; memcpy(&r,p,5); if(t & 1){ - r >>= 4; w <<= 4; - w |= p[0] & 0x0F; + w |= r & 0x000000000000000F; + r >>= 4; }else{ + w |= r & 0x000000F000000000; r &= 0x0000000FFFFFFFFF; - w |= (uint64_t)(p[4] & 0xF0)<<32; } memcpy(p,&w,5); t = r == 0 ? 0 : x-r; @@ -5,14 +5,14 @@ #define WIDTH 3 -void a2_init (uint64_t n); -void a2_loop (uint64_t x0,uint64_t x1); +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, + .name = "a2", + .nmax = 1<<(WIDTH*8), + .init = a2_init, + .loop = a2_loop, }; static uint8_t *m; //mammory @@ -33,7 +33,7 @@ void a2_loop(uint64_t x0,uint64_t x1){ uint8_t *p; //addr of elemten r = 0; - p = &m[t*WIDTH]; + p = m+(t*WIDTH); memcpy(&r,p,WIDTH); memcpy(p,&x,WIDTH); t = r == 0 ? 0 : x-r; @@ -3,12 +3,14 @@ #include <stdint.h> +/* #ifdef _WIN32 #include <windows.h> - #define aalloc(_a,_s) _aligned_malloc(_s,_a) + #define AALLOC(_a,_s) _aligned_malloc(_s,_a) #else - #define aalloc(_a,_s) aligned_alloc(_a,_s) + #define AALLOC(_a,_s) aligned_alloc(_a,_s) #endif +*/ typedef struct algo_t{ char const *name; @@ -25,7 +25,7 @@ void fuk(char const *fmt,...){ static void perse(int p){ ftime_t t = ftimer_time(&ft); - float f = (float)t/FTIME_SEC; + float f = ftime_float(t); printf("%9.3f\t%3u%%\n",f,p); fflush(stdout); } @@ -35,13 +35,12 @@ static void calc_fast(uint64_t n){ } static void calc_perse(uint64_t n){ - uint64_t agurk; - uint64_t outer; - uint64_t last; - uint64_t x0; - uint64_t x1; + uint64_t agurk; + uint64_t x0; + uint64_t x1; agurk = n/100; + perse(0); for(uint64_t y = 0;y < 100;y++){ x0 = y*agurk; x1 = x0+agurk; @@ -55,7 +54,7 @@ static void calc_perse(uint64_t n){ static void usake(void){ printf("usake: numper [options] <n>\n"); printf(" -p display progress percentage\n"); - printf(" -a<n> use algorithm n\n"); + printf(" -a<n> use algorithm n (0,1,2)\n"); fflush(stdout); exit(0); } @@ -72,11 +71,11 @@ int main(int argc,char **argv){ calc = calc_fast; algo_i = -1; - if(argc < 2){ - usake(); - } - #define OPT(O) (strcmp(argv[x],O) == 0) + if(argc < 2) usake(); + n = strtoull(argv[argc-1],0,10); + if((int64_t)n <= 0) usake(); + for(int x = 1;x < argc-1;x++){ if(OPT("-p")){ calc = calc_perse; @@ -84,16 +83,13 @@ int main(int argc,char **argv){ argv[x][1] == 'a'){ algo_i = (size_t)argv[x][2]-(size_t)'0'; if(algo_i >= ALGO_CUNT){ - fuk("unrecognized algorithm: a%zu\n",algo_i); + fuk("unrecognized algorithm\n"); } }else{ fuk("unrecognized option: %s\n",argv[x]); } } - n = strtoull(argv[argc-1],0,10); - if((int64_t)n <= 0) usake(); - if(algo_i == (size_t)-1){ if (n <= a2.nmax) algo_i = 2; else if(n <= a0.nmax) algo_i = 0; @@ -103,21 +99,19 @@ int main(int argc,char **argv){ algo = algos[algo_i]; if(n > algo->nmax){ - fuk("n exceeds algorithm nmax\n"); + fuk("n exceeds algorithm a%zu nmax (%llu > %llu)\n",algo_i,n,algo->nmax); } printf("algo = %s\n", algo->name); printf("n = %llu\n",n); fflush(stdout); - //for(size_t x = 0;x < 10;x++){ algo->init(n); ftimer_init(&ft); calc(n); printf("t = %llu\n",t); fflush(stdout); - //} return 0; } |