diff --git a/day11/Makefile b/day11/Makefile new file mode 100644 index 0000000..dcd6a88 --- /dev/null +++ b/day11/Makefile @@ -0,0 +1,36 @@ + +OPT_FLAGS?= -march=native -flto \ + -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \ + -floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \ + -fno-stack-check -fno-strict-aliasing + +CFLAGS+= -Wall -pedantic --std=gnu11 -Wextra -Wstrict-aliasing +CFLAGS+= $(OPT_FLAGS) +CFLAGS+= -O3 -pipe +LDFLAGS?= -O3 -flto + +INCLUDE?=../common/include +CFLAGS+= -I$(INCLUDE) + +STRIP=strip + +.PHONY: all +all: part1 part2 + +inpu%-sz.h: inpu% + echo "#define input_sz (`head -n 1 $< | wc -m`)" > $@ + +inpu%.h: inpu% | input-sz.h + @rm -f $@ + while read line; do \ + echo "\"$$line\"," >> $@; \ + done < $< + + +part1: day11.c | input.h + $(CC) $< $(CFLAGS) -o $@ $(LDFLAGS) + $(STRIP) $@ + +clean: + rm -f input{,-sz}.h + rm -f part{1,2} diff --git a/day11/day11.c b/day11/day11.c new file mode 100644 index 0000000..4e1144a --- /dev/null +++ b/day11/day11.c @@ -0,0 +1,69 @@ +#include + +#include +#include + +const char* const input[] = { +#include "input.h" +}; + +// input_sz // +#include "input-sz.h" +#define INPUT_WIDTH (input_sz-1) +#define INPUT_HEIGHT (sizeof(input)/sizeof(char*)) + +#define box(t) aligned_alloc(_Alignof(t), sizeof(t)) + +enum gol_state { + STATE_INVALID=0, + STATE_FLOOR='.', + STATE_EMPTY='L', + STATE_OCCU='#', +}; + +#define GOL_INDEX(w,h) ((h*INPUT_WIDTH)+w) + +typedef struct gol_arena { + enum gol_state arena[INPUT_HEIGHT*INPUT_WIDTH]; +} gol_t; + +gol_t* gol_clone(const gol_t* from) +{ + gol_t* out = box(gol_t); + *out = *from; + return out; +} + +pure gol_t generate_arena() +{ + gol_t gol; + for(size_t h=0;h= (int)INPUT_WIDTH || y<0 || y >= (int)INPUT_HEIGHT) return STATE_FLOOR; + return gol->arena[GOL_INDEX(x,y)]; +} + +static inline void gol_set(gol_t* restrict gol, int x,int y, enum gol_state st) +{ + if (x<0 || x >= (int)INPUT_WIDTH || y<0 || y >= (int)INPUT_HEIGHT) return; + + gol->arena[GOL_INDEX(x,y)] = st; +} + +int main() +{ + gol_t* arena = box(gol_t); + *arena = generate_arena(); + + printf("%lu\n", sizeof(arena)); + + free(arena); + return 0; +}