From d6fdf14d5c320bdca455f910d58d652c5a7827da Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 17 Nov 2023 19:14:26 +0100 Subject: Simplified move and transform code --- utils/genmovecode.sh | 16 +++++++++------- utils/genmoveswitch.sh | 8 ++++++++ utils/gentranscode.sh | 38 ++++++++++---------------------------- utils/gentransswitch.sh | 8 +++++++- utils/h48_to_avx.c | 4 ++-- utils/h48_to_src.c | 4 ++-- utils/invert.c | 4 ++-- 7 files changed, 40 insertions(+), 42 deletions(-) create mode 100755 utils/genmoveswitch.sh (limited to 'utils') diff --git a/utils/genmovecode.sh b/utils/genmovecode.sh index 0857f31..9d5fa7a 100755 --- a/utils/genmovecode.sh +++ b/utils/genmovecode.sh @@ -4,16 +4,18 @@ type="${1:-src}" gcc -DDEBUG h48_to_"$type".c ../cube.c -o h48_to_"$type" -genfuncs() { +lineavx() { printf '#define _move_cube_%s ' "$1"; } +linesrc() { printf '_static cube_fast_t _move_cube_%s = ' "$1"; } +sedavx() { sed '1,2s/$/ \\/ ; 3s/$/)/ ; 3q'; } +sedsrc() { sed '3s/$/ };/ ; 3q'; } + +gen() { for f in move_??_*.txt; do move="$(echo $f | sed 's/.*_// ; s/\.txt//')" - printf 'static inline cube_fast_t\n_move_%s' "$move" - printf '(cube_fast_t c)\n{\n' - printf '\tcube_fast_t m = ' - ./h48_to_"$type" <"$f" | sed '2,4s/^/\t/' - printf ';\n\n\treturn compose_fast(c, m);\n}\n\n' + line$type "$move" + ./h48_to_"$type" <"$f" | sed$type done } -genfuncs +gen rm -f h48_to_"$type" invert diff --git a/utils/genmoveswitch.sh b/utils/genmoveswitch.sh new file mode 100755 index 0000000..cce18fc --- /dev/null +++ b/utils/genmoveswitch.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +printf '\tswitch (m) {\n' +for f in move_??_*.txt; do + t="$(echo $f | sed 's/.*_// ; s/\.txt//')" + printf '\tcase %s:\n\t\treturn _move(%s, c);\n' "$t" "$t" +done +printf '\t}\n' diff --git a/utils/gentranscode.sh b/utils/gentranscode.sh index 198ac93..b9d41b6 100755 --- a/utils/gentranscode.sh +++ b/utils/gentranscode.sh @@ -5,38 +5,20 @@ type="${1:-src}" gcc -DDEBUG h48_to_"$type".c ../cube.c -o h48_to_"$type" gcc -DDEBUG invert.c ../cube.c -o invert -# Old version -genarray() { - for f in transform_??_???.txt; do - trans="$(echo $f | sed 's/.*_// ; s/\.txt//')" - printf '[%s] = ' "$trans" - if [ "$1" = "-i" ]; then - ./invert <"$f" | ./h48_to_"$type" - else - ./h48_to_"$type" <"$f" - fi - printf ',\n' - done -} +lineavx() { printf '#define _trans_cube_%s ' "$1"; } +linesrc() { printf '_static cube_fast_t _trans_cube_%s = ' "$1"; } +sedavx() { sed '1,2s/$/ \\/ ; 3s/$/)/ ; 3q'; } +sedsrc() { sed '3s/$/ };/ ; 3q'; } -genfuncs() { +gen() { for f in transform_??_???.txt; do trans="$(echo $f | sed 's/.*_// ; s/\.txt//')" - printf 'static inline cube_fast_t\n_trans_%s' "$trans" - printf '(cube_fast_t c)\n{\n' - printf '\tcube_fast_t ret;\n\n' - printf '\tcube_fast_t tn = ' - ./h48_to_"$type" <"$f" | sed '2,4s/^/\t/' - printf ';\n\tcube_fast_t ti = ' - ./invert <"$f" | ./h48_to_"$type" | sed '2,4 s/^/\t/' - printf ';\n\n\tret = compose_fast(tn, c);\n' - printf '\tret = compose_fast(ret, ti);\n' - if [ -n "$(echo "$trans" | grep "m")" ]; then - printf '\tret = invertco_fast(ret);\n' - fi - printf '\n\treturn ret;\n}\n\n' + line$type "$trans" + ./h48_to_"$type" <"$f" | sed$type + line$type "${trans}_inverse" + ./invert <"$f" | ./h48_to_"$type" | sed$type done } -genfuncs +gen rm -f h48_to_"$type" invert diff --git a/utils/gentransswitch.sh b/utils/gentransswitch.sh index a08dff9..42726ce 100755 --- a/utils/gentransswitch.sh +++ b/utils/gentransswitch.sh @@ -3,6 +3,12 @@ printf '\tswitch (t) {\n' for f in transform_??_???.txt; do t="$(echo $f | sed 's/.*_// ; s/\.txt//')" - printf '\tcase %s:\n\t\treturn _trans_%s(c);\n' "$t" "$t" + mirror_or_rotation="$(echo $t | grep m)" + if [ -z "$mirror_or_rotation" ]; then + m="rotation" + else + m="mirrored" + fi + printf '\tcase %s:\n\t\treturn _trans_%s(%s, c);\n' "$t" "$m" "$t" done printf '\t}\n' diff --git a/utils/h48_to_avx.c b/utils/h48_to_avx.c index e5df2aa..ba82366 100644 --- a/utils/h48_to_avx.c +++ b/utils/h48_to_avx.c @@ -11,8 +11,8 @@ int main() { cube_t cube; fgets(str, STRLENMAX, stdin); - cube = readcube(H48, str); - writecube(AVX, cube, str); + cube = readcube("H48", str); + writecube("AVX", cube, str); fputs(str, stdout); return 0; diff --git a/utils/h48_to_src.c b/utils/h48_to_src.c index a8fda00..6fdea5c 100644 --- a/utils/h48_to_src.c +++ b/utils/h48_to_src.c @@ -11,8 +11,8 @@ int main() { cube_t cube; fgets(str, STRLENMAX, stdin); - cube = readcube(H48, str); - writecube(SRC, cube, str); + cube = readcube("H48", str); + writecube("SRC", cube, str); fputs(str, stdout); return 0; diff --git a/utils/invert.c b/utils/invert.c index aa912e5..cd54a87 100644 --- a/utils/invert.c +++ b/utils/invert.c @@ -11,8 +11,8 @@ int main() { cube_t cube; fgets(str, STRLENMAX, stdin); - cube = readcube(H48, str); - writecube(H48, inverse(cube), str); + cube = readcube("H48", str); + writecube("H48", inverse(cube), str); fputs(str, stdout); return 0; -- cgit v1.3