commit 444efd5878e9e0ba06b0caa714a51530145f45e7 Author: Avril Date: Tue Dec 1 16:10:53 2020 +0000 day1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3100c04 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +input* +part1* +part2* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dd36202 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ + +DAYS= day1 + +.PHONY: all + +day%/part2: day% + cd $< && $(MAKE) + +all: $(addsuffix /part2,$(DAYS)) + diff --git a/day1/Makefile b/day1/Makefile new file mode 100644 index 0000000..6a697e0 --- /dev/null +++ b/day1/Makefile @@ -0,0 +1,43 @@ + +OPT_FLAGS?= -march=native -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 + +.PHONY: all +all: part1 part2 + +.PHONY: big +big: part1-big part2-big + +input.h: input + @rm -f $@ + while read line; do \ + echo "$$line," >> $@; \ + done < $< + +input-big.h: input-big + @rm -f $@ + while read line; do \ + echo "$${line}ul," >> $@; \ + done < $< + + +part1: input.h + gcc day1.c -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto + strip $@ + +part2: input.h + gcc day1.c -DPART2 -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto + strip $@ + +part1-big: input-big.h + gcc day1.c -DBIG -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto + strip $@ + +part2-big: input-big.h + gcc day1.c -DBIG -DPART2 -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto + strip $@ + +clean: + rm -f part{1,2} + rm -f input.h diff --git a/day1/day1.c b/day1/day1.c new file mode 100644 index 0000000..2daee80 --- /dev/null +++ b/day1/day1.c @@ -0,0 +1,40 @@ +#include +#include + +typedef unsigned long u64; + +#ifdef BIG +#define TARGET 99920044 +#else +#define TARGET 2020 +#endif + +const u64 input[] = { +#ifdef BIG +#include "input-big.h" +#else +#include "input.h" +#endif +}; +const size_t input_sz = sizeof(input)/sizeof(u64); + +int main() +{ + for(register u64 i=0;i