commit b3622e04dfb8317b745f8c911d31dc80bc2f9d66
parent 4a7e2dccaa54bc42a4b67cf35cf8b926cf357bb3
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun, 22 Oct 2023 23:34:53 +0200
Preparatory work for benchmarks, little fixes
Diffstat:
7 files changed, 64 insertions(+), 51 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,5 +1,6 @@
+benchmark/results.txt
+benchmark/run
test/*/runtest
test/run
test/last.*
-test/*.o
*.o
diff --git a/Makefile b/Makefile
@@ -2,7 +2,7 @@
CFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \
-Wno-unused-parameter -O3
-DBGFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \
+DBGFLAGS = -DDEBUG -std=c99 -pthread -pedantic -Wall -Wextra \
-Wno-unused-parameter -Wno-unused-function -g3 \
-fsanitize=address -fsanitize=undefined
@@ -10,16 +10,19 @@ CC = cc
all: solve
-solve: clean
- ${CC} ${CFLAGS} -o solve src/*.c
+cube.o: clean
+ ${CC} ${CFLAGS} -c -o cube.o src/*.c
-debug:
- ${CC} ${DBGFLAGS} -o solve src/*.c
+debugcube.o:
+ ${CC} ${DBGFLAGS} -c -o debugcube.o src/*.c
clean:
rm -rf solve
-test:
+test: debugcube.o
./test/test.sh
-.PHONY: all debug clean test
+benchmark: cube.o
+ ./benchmark/bench.sh
+
+.PHONY: all clean test benchmark
diff --git a/benchmark/bench.c b/benchmark/bench.c
@@ -0,0 +1,11 @@
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include "../src/cube.h"
+
+int main() {
+ printf("Benchmarks not yet set up\n");
+
+ return 0;
+}
diff --git a/benchmark/bench.sh b/benchmark/bench.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+BENCHBIN="benchmark/run"
+BENCHOUT="benchmark/results.txt"
+CUBEOBJ="cube.o"
+
+cc -std=c99 -pthread -O3 -o $BENCHBIN benchmark/bench.c $CUBEOBJ || exit 1;
+
+$BENCHBIN | tee $BENCHOUT
+echo "Results saved to $BENCHOUT"
+
+rm -rf $BENCHBIN $CUBEOBJ
diff --git a/h48_to_src b/h48_to_src
Binary files differ.
diff --git a/src/cube.c b/src/cube.c
@@ -605,8 +605,10 @@ issolvable(cube_t cube)
int8_t i, eo, co;
#ifdef DEBUG
- if (!isconsistent(cube))
- goto issolvable_inconsistent;
+ if (!isconsistent(cube)) {
+ fprintf(stderr, "issolvable: cube is inconsistent\n");
+ return false;
+ }
#endif
if (permsign(cube.e, 12) != permsign(cube.c, 8))
@@ -626,11 +628,6 @@ issolvable(cube_t cube)
return true;
-issolvable_inconsistent:
-#ifdef DEBUG
- fprintf(stderr, "issolvable: cube is inconsistent\n");
-#endif
- return false;
issolvable_parity:
#ifdef DEBUG
fprintf(stderr, "EP and CP parities are different\n");
@@ -683,8 +680,10 @@ move(cube_t c, move_t m)
uint8_t aux, auy, auz;
#ifdef DEBUG
- if (!isconsistent(c))
- goto move_inconsistent;
+ if (!isconsistent(c)) {
+ fprintf(stderr, "move error, inconsistent cube\n");
+ goto move_error;
+ }
#endif
#define PERM4(r, i, j, k, l) \
@@ -830,15 +829,12 @@ move(cube_t c, move_t m)
return ret;
default:
- goto move_unknown;
+#ifdef DEBUG
+ fprintf(stderr, "mover error, unknown move\n");
+#endif
+ goto move_error;
}
-move_inconsistent:
- fprintf(stderr, "move error, inconsistent cube\n");
- goto move_error;
-move_unknown:
- fprintf(stderr, "mover error, unknown move\n");
- goto move_error;
move_error:
return errorcube;
}
@@ -850,8 +846,10 @@ inverse(cube_t c)
cube_t ret = {0};
#ifdef DEBUG
- if (!isconsistent(c))
- goto inverse_inconsistent;
+ if (!isconsistent(c)) {
+ fprintf(stderr, "inverse error, inconsistent cube\n");
+ return errorcube;
+ }
#endif
for (i = 0; i < 12; i++) {
@@ -867,10 +865,6 @@ inverse(cube_t c)
}
return ret;
-
-inverse_inconsistent:
- fprintf(stderr, "inverse error, inconsistent cube\n");
- return errorcube;
}
cube_t
@@ -880,8 +874,10 @@ compose(cube_t c1, cube_t c2)
cube_t ret = {0};
#ifdef DEBUG
- if (!isconsistent(c1) || !isconsistent(c2))
- goto compose_inconsistent;
+ if (!isconsistent(c1) || !isconsistent(c2)) {
+ fprintf(stderr, "compose error, inconsistent cube\n");
+ return errorcube;
+ }
#endif
for (i = 0; i < 12; i++) {
@@ -899,10 +895,6 @@ compose(cube_t c1, cube_t c2)
}
return ret;
-
-compose_inconsistent:
- fprintf(stderr, "compose error, inconsistent cube\n");
- return errorcube;
}
static cube_t
@@ -1122,10 +1114,14 @@ transform(cube_t c, trans_t t)
cube_t ret;
#ifdef DEBUG
- if (!isconsistent(c))
- goto transform_inconsistent;
- if (t >= 48)
- goto transform_errortrans;
+ if (!isconsistent(c)) {
+ fprintf(stderr, "transform error, inconsistent cube\n");
+ return errorcube;
+ }
+ if (t >= 48) {
+ fprintf(stderr, "transform error, unknown transformation\n");
+ return errorcube;
+ }
#endif
ret = compose(solvedcube, trans_move_cube[t]);
@@ -1138,11 +1134,4 @@ transform(cube_t c, trans_t t)
ret = flipallcorners(ret);
return ret;
-
-transform_inconsistent:
- fprintf(stderr, "transform error, inconsistent cube\n");
- return errorcube;
-transform_errortrans:
- fprintf(stderr, "transform error, unknown transformation\n");
- return errorcube;
}
diff --git a/test/test.sh b/test/test.sh
@@ -5,13 +5,10 @@ CC="cc -DDEBUG -std=c99 -pthread -pedantic -Wall -Wextra \
if [ $(uname) != "OpenBSD" ]; then
CC="$CC -fsanitize=address -fsanitize=undefined"
fi
-SRC="src/cube.c"
TESTBIN="test/run"
TESTOUT="test/last.out"
TESTERR="test/last.err"
-CUBEOBJ="test/cube.o"
-
-$CC -c $SRC -o $CUBEOBJ || exit 1
+CUBEOBJ="debugcube.o"
for t in test/*; do
if [ ! -d $t ]; then continue; fi