diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-10-22 23:34:53 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-10-22 23:43:36 +0200 |
| commit | b3622e04dfb8317b745f8c911d31dc80bc2f9d66 (patch) | |
| tree | 825e54d062667a6cb76ff36730a8e36444fa20ba | |
| parent | 4a7e2dccaa54bc42a4b67cf35cf8b926cf357bb3 (diff) | |
| download | nissy-core-b3622e04dfb8317b745f8c911d31dc80bc2f9d66.tar.gz nissy-core-b3622e04dfb8317b745f8c911d31dc80bc2f9d66.zip | |
Preparatory work for benchmarks, little fixes
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 17 | ||||
| -rw-r--r-- | benchmark/bench.c | 11 | ||||
| -rwxr-xr-x | benchmark/bench.sh | 12 | ||||
| -rwxr-xr-x | h48_to_src | bin | 35272 -> 0 bytes | |||
| -rw-r--r-- | src/cube.c | 67 | ||||
| -rwxr-xr-x | test/test.sh | 5 |
7 files changed, 64 insertions, 51 deletions
| @@ -1,5 +1,6 @@ | |||
| 1 | benchmark/results.txt | ||
| 2 | benchmark/run | ||
| 1 | test/*/runtest | 3 | test/*/runtest |
| 2 | test/run | 4 | test/run |
| 3 | test/last.* | 5 | test/last.* |
| 4 | test/*.o | ||
| 5 | *.o | 6 | *.o |
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | CFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \ | 3 | CFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \ |
| 4 | -Wno-unused-parameter -O3 | 4 | -Wno-unused-parameter -O3 |
| 5 | DBGFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \ | 5 | DBGFLAGS = -DDEBUG -std=c99 -pthread -pedantic -Wall -Wextra \ |
| 6 | -Wno-unused-parameter -Wno-unused-function -g3 \ | 6 | -Wno-unused-parameter -Wno-unused-function -g3 \ |
| 7 | -fsanitize=address -fsanitize=undefined | 7 | -fsanitize=address -fsanitize=undefined |
| 8 | 8 | ||
| @@ -10,16 +10,19 @@ CC = cc | |||
| 10 | 10 | ||
| 11 | all: solve | 11 | all: solve |
| 12 | 12 | ||
| 13 | solve: clean | 13 | cube.o: clean |
| 14 | ${CC} ${CFLAGS} -o solve src/*.c | 14 | ${CC} ${CFLAGS} -c -o cube.o src/*.c |
| 15 | 15 | ||
| 16 | debug: | 16 | debugcube.o: |
| 17 | ${CC} ${DBGFLAGS} -o solve src/*.c | 17 | ${CC} ${DBGFLAGS} -c -o debugcube.o src/*.c |
| 18 | 18 | ||
| 19 | clean: | 19 | clean: |
| 20 | rm -rf solve | 20 | rm -rf solve |
| 21 | 21 | ||
| 22 | test: | 22 | test: debugcube.o |
| 23 | ./test/test.sh | 23 | ./test/test.sh |
| 24 | 24 | ||
| 25 | .PHONY: all debug clean test | 25 | benchmark: cube.o |
| 26 | ./benchmark/bench.sh | ||
| 27 | |||
| 28 | .PHONY: all clean test benchmark | ||
diff --git a/benchmark/bench.c b/benchmark/bench.c new file mode 100644 index 0000000..046e965 --- /dev/null +++ b/benchmark/bench.c | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | #include "../src/cube.h" | ||
| 6 | |||
| 7 | int main() { | ||
| 8 | printf("Benchmarks not yet set up\n"); | ||
| 9 | |||
| 10 | return 0; | ||
| 11 | } | ||
diff --git a/benchmark/bench.sh b/benchmark/bench.sh new file mode 100755 index 0000000..288db05 --- /dev/null +++ b/benchmark/bench.sh | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | BENCHBIN="benchmark/run" | ||
| 4 | BENCHOUT="benchmark/results.txt" | ||
| 5 | CUBEOBJ="cube.o" | ||
| 6 | |||
| 7 | cc -std=c99 -pthread -O3 -o $BENCHBIN benchmark/bench.c $CUBEOBJ || exit 1; | ||
| 8 | |||
| 9 | $BENCHBIN | tee $BENCHOUT | ||
| 10 | echo "Results saved to $BENCHOUT" | ||
| 11 | |||
| 12 | rm -rf $BENCHBIN $CUBEOBJ | ||
diff --git a/h48_to_src b/h48_to_src deleted file mode 100755 index 8cf38e3..0000000 --- a/h48_to_src +++ /dev/null | |||
| Binary files differ | |||
| @@ -605,8 +605,10 @@ issolvable(cube_t cube) | |||
| 605 | int8_t i, eo, co; | 605 | int8_t i, eo, co; |
| 606 | 606 | ||
| 607 | #ifdef DEBUG | 607 | #ifdef DEBUG |
| 608 | if (!isconsistent(cube)) | 608 | if (!isconsistent(cube)) { |
| 609 | goto issolvable_inconsistent; | 609 | fprintf(stderr, "issolvable: cube is inconsistent\n"); |
| 610 | return false; | ||
| 611 | } | ||
| 610 | #endif | 612 | #endif |
| 611 | 613 | ||
| 612 | if (permsign(cube.e, 12) != permsign(cube.c, 8)) | 614 | if (permsign(cube.e, 12) != permsign(cube.c, 8)) |
| @@ -626,11 +628,6 @@ issolvable(cube_t cube) | |||
| 626 | 628 | ||
| 627 | return true; | 629 | return true; |
| 628 | 630 | ||
| 629 | issolvable_inconsistent: | ||
| 630 | #ifdef DEBUG | ||
| 631 | fprintf(stderr, "issolvable: cube is inconsistent\n"); | ||
| 632 | #endif | ||
| 633 | return false; | ||
| 634 | issolvable_parity: | 631 | issolvable_parity: |
| 635 | #ifdef DEBUG | 632 | #ifdef DEBUG |
| 636 | fprintf(stderr, "EP and CP parities are different\n"); | 633 | fprintf(stderr, "EP and CP parities are different\n"); |
| @@ -683,8 +680,10 @@ move(cube_t c, move_t m) | |||
| 683 | uint8_t aux, auy, auz; | 680 | uint8_t aux, auy, auz; |
| 684 | 681 | ||
| 685 | #ifdef DEBUG | 682 | #ifdef DEBUG |
| 686 | if (!isconsistent(c)) | 683 | if (!isconsistent(c)) { |
| 687 | goto move_inconsistent; | 684 | fprintf(stderr, "move error, inconsistent cube\n"); |
| 685 | goto move_error; | ||
| 686 | } | ||
| 688 | #endif | 687 | #endif |
| 689 | 688 | ||
| 690 | #define PERM4(r, i, j, k, l) \ | 689 | #define PERM4(r, i, j, k, l) \ |
| @@ -830,15 +829,12 @@ move(cube_t c, move_t m) | |||
| 830 | 829 | ||
| 831 | return ret; | 830 | return ret; |
| 832 | default: | 831 | default: |
| 833 | goto move_unknown; | 832 | #ifdef DEBUG |
| 833 | fprintf(stderr, "mover error, unknown move\n"); | ||
| 834 | #endif | ||
| 835 | goto move_error; | ||
| 834 | } | 836 | } |
| 835 | 837 | ||
| 836 | move_inconsistent: | ||
| 837 | fprintf(stderr, "move error, inconsistent cube\n"); | ||
| 838 | goto move_error; | ||
| 839 | move_unknown: | ||
| 840 | fprintf(stderr, "mover error, unknown move\n"); | ||
| 841 | goto move_error; | ||
| 842 | move_error: | 838 | move_error: |
| 843 | return errorcube; | 839 | return errorcube; |
| 844 | } | 840 | } |
| @@ -850,8 +846,10 @@ inverse(cube_t c) | |||
| 850 | cube_t ret = {0}; | 846 | cube_t ret = {0}; |
| 851 | 847 | ||
| 852 | #ifdef DEBUG | 848 | #ifdef DEBUG |
| 853 | if (!isconsistent(c)) | 849 | if (!isconsistent(c)) { |
| 854 | goto inverse_inconsistent; | 850 | fprintf(stderr, "inverse error, inconsistent cube\n"); |
| 851 | return errorcube; | ||
| 852 | } | ||
| 855 | #endif | 853 | #endif |
| 856 | 854 | ||
| 857 | for (i = 0; i < 12; i++) { | 855 | for (i = 0; i < 12; i++) { |
| @@ -867,10 +865,6 @@ inverse(cube_t c) | |||
| 867 | } | 865 | } |
| 868 | 866 | ||
| 869 | return ret; | 867 | return ret; |
| 870 | |||
| 871 | inverse_inconsistent: | ||
| 872 | fprintf(stderr, "inverse error, inconsistent cube\n"); | ||
| 873 | return errorcube; | ||
| 874 | } | 868 | } |
| 875 | 869 | ||
| 876 | cube_t | 870 | cube_t |
| @@ -880,8 +874,10 @@ compose(cube_t c1, cube_t c2) | |||
| 880 | cube_t ret = {0}; | 874 | cube_t ret = {0}; |
| 881 | 875 | ||
| 882 | #ifdef DEBUG | 876 | #ifdef DEBUG |
| 883 | if (!isconsistent(c1) || !isconsistent(c2)) | 877 | if (!isconsistent(c1) || !isconsistent(c2)) { |
| 884 | goto compose_inconsistent; | 878 | fprintf(stderr, "compose error, inconsistent cube\n"); |
| 879 | return errorcube; | ||
| 880 | } | ||
| 885 | #endif | 881 | #endif |
| 886 | 882 | ||
| 887 | for (i = 0; i < 12; i++) { | 883 | for (i = 0; i < 12; i++) { |
| @@ -899,10 +895,6 @@ compose(cube_t c1, cube_t c2) | |||
| 899 | } | 895 | } |
| 900 | 896 | ||
| 901 | return ret; | 897 | return ret; |
| 902 | |||
| 903 | compose_inconsistent: | ||
| 904 | fprintf(stderr, "compose error, inconsistent cube\n"); | ||
| 905 | return errorcube; | ||
| 906 | } | 898 | } |
| 907 | 899 | ||
| 908 | static cube_t | 900 | static cube_t |
| @@ -1122,10 +1114,14 @@ transform(cube_t c, trans_t t) | |||
| 1122 | cube_t ret; | 1114 | cube_t ret; |
| 1123 | 1115 | ||
| 1124 | #ifdef DEBUG | 1116 | #ifdef DEBUG |
| 1125 | if (!isconsistent(c)) | 1117 | if (!isconsistent(c)) { |
| 1126 | goto transform_inconsistent; | 1118 | fprintf(stderr, "transform error, inconsistent cube\n"); |
| 1127 | if (t >= 48) | 1119 | return errorcube; |
| 1128 | goto transform_errortrans; | 1120 | } |
| 1121 | if (t >= 48) { | ||
| 1122 | fprintf(stderr, "transform error, unknown transformation\n"); | ||
| 1123 | return errorcube; | ||
| 1124 | } | ||
| 1129 | #endif | 1125 | #endif |
| 1130 | 1126 | ||
| 1131 | ret = compose(solvedcube, trans_move_cube[t]); | 1127 | ret = compose(solvedcube, trans_move_cube[t]); |
| @@ -1138,11 +1134,4 @@ transform(cube_t c, trans_t t) | |||
| 1138 | ret = flipallcorners(ret); | 1134 | ret = flipallcorners(ret); |
| 1139 | 1135 | ||
| 1140 | return ret; | 1136 | return ret; |
| 1141 | |||
| 1142 | transform_inconsistent: | ||
| 1143 | fprintf(stderr, "transform error, inconsistent cube\n"); | ||
| 1144 | return errorcube; | ||
| 1145 | transform_errortrans: | ||
| 1146 | fprintf(stderr, "transform error, unknown transformation\n"); | ||
| 1147 | return errorcube; | ||
| 1148 | } | 1137 | } |
diff --git a/test/test.sh b/test/test.sh index 00dd5ce..9e064b2 100755 --- a/test/test.sh +++ b/test/test.sh | |||
| @@ -5,13 +5,10 @@ CC="cc -DDEBUG -std=c99 -pthread -pedantic -Wall -Wextra \ | |||
| 5 | if [ $(uname) != "OpenBSD" ]; then | 5 | if [ $(uname) != "OpenBSD" ]; then |
| 6 | CC="$CC -fsanitize=address -fsanitize=undefined" | 6 | CC="$CC -fsanitize=address -fsanitize=undefined" |
| 7 | fi | 7 | fi |
| 8 | SRC="src/cube.c" | ||
| 9 | TESTBIN="test/run" | 8 | TESTBIN="test/run" |
| 10 | TESTOUT="test/last.out" | 9 | TESTOUT="test/last.out" |
| 11 | TESTERR="test/last.err" | 10 | TESTERR="test/last.err" |
| 12 | CUBEOBJ="test/cube.o" | 11 | CUBEOBJ="debugcube.o" |
| 13 | |||
| 14 | $CC -c $SRC -o $CUBEOBJ || exit 1 | ||
| 15 | 12 | ||
| 16 | for t in test/*; do | 13 | for t in test/*; do |
| 17 | if [ ! -d $t ]; then continue; fi | 14 | if [ ! -d $t ]; then continue; fi |
