diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-17 19:14:26 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-17 19:14:26 +0100 |
| commit | d6fdf14d5c320bdca455f910d58d652c5a7827da (patch) | |
| tree | 15642a013e719e81526cf02b6656ce22adb8a3cf /utils | |
| parent | a26ae103faf8fa53b65f7757fb8b4255a37fcd22 (diff) | |
| download | nissy-core-d6fdf14d5c320bdca455f910d58d652c5a7827da.tar.gz nissy-core-d6fdf14d5c320bdca455f910d58d652c5a7827da.zip | |
Simplified move and transform code
Diffstat (limited to '')
| -rwxr-xr-x | utils/genmovecode.sh | 16 | ||||
| -rwxr-xr-x | utils/genmoveswitch.sh | 8 | ||||
| -rwxr-xr-x | utils/gentranscode.sh | 38 | ||||
| -rwxr-xr-x | utils/gentransswitch.sh | 8 | ||||
| -rw-r--r-- | utils/h48_to_avx.c | 4 | ||||
| -rw-r--r-- | utils/h48_to_src.c | 4 | ||||
| -rw-r--r-- | utils/invert.c | 4 |
7 files changed, 40 insertions, 42 deletions
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}" | |||
| 4 | 4 | ||
| 5 | gcc -DDEBUG h48_to_"$type".c ../cube.c -o h48_to_"$type" | 5 | gcc -DDEBUG h48_to_"$type".c ../cube.c -o h48_to_"$type" |
| 6 | 6 | ||
| 7 | genfuncs() { | 7 | lineavx() { printf '#define _move_cube_%s ' "$1"; } |
| 8 | linesrc() { printf '_static cube_fast_t _move_cube_%s = ' "$1"; } | ||
| 9 | sedavx() { sed '1,2s/$/ \\/ ; 3s/$/)/ ; 3q'; } | ||
| 10 | sedsrc() { sed '3s/$/ };/ ; 3q'; } | ||
| 11 | |||
| 12 | gen() { | ||
| 8 | for f in move_??_*.txt; do | 13 | for f in move_??_*.txt; do |
| 9 | move="$(echo $f | sed 's/.*_// ; s/\.txt//')" | 14 | move="$(echo $f | sed 's/.*_// ; s/\.txt//')" |
| 10 | printf 'static inline cube_fast_t\n_move_%s' "$move" | 15 | line$type "$move" |
| 11 | printf '(cube_fast_t c)\n{\n' | 16 | ./h48_to_"$type" <"$f" | sed$type |
| 12 | printf '\tcube_fast_t m = ' | ||
| 13 | ./h48_to_"$type" <"$f" | sed '2,4s/^/\t/' | ||
| 14 | printf ';\n\n\treturn compose_fast(c, m);\n}\n\n' | ||
| 15 | done | 17 | done |
| 16 | } | 18 | } |
| 17 | 19 | ||
| 18 | genfuncs | 20 | gen |
| 19 | rm -f h48_to_"$type" invert | 21 | 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 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | printf '\tswitch (m) {\n' | ||
| 4 | for f in move_??_*.txt; do | ||
| 5 | t="$(echo $f | sed 's/.*_// ; s/\.txt//')" | ||
| 6 | printf '\tcase %s:\n\t\treturn _move(%s, c);\n' "$t" "$t" | ||
| 7 | done | ||
| 8 | 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}" | |||
| 5 | gcc -DDEBUG h48_to_"$type".c ../cube.c -o h48_to_"$type" | 5 | gcc -DDEBUG h48_to_"$type".c ../cube.c -o h48_to_"$type" |
| 6 | gcc -DDEBUG invert.c ../cube.c -o invert | 6 | gcc -DDEBUG invert.c ../cube.c -o invert |
| 7 | 7 | ||
| 8 | # Old version | 8 | lineavx() { printf '#define _trans_cube_%s ' "$1"; } |
| 9 | genarray() { | 9 | linesrc() { printf '_static cube_fast_t _trans_cube_%s = ' "$1"; } |
| 10 | for f in transform_??_???.txt; do | 10 | sedavx() { sed '1,2s/$/ \\/ ; 3s/$/)/ ; 3q'; } |
| 11 | trans="$(echo $f | sed 's/.*_// ; s/\.txt//')" | 11 | sedsrc() { sed '3s/$/ };/ ; 3q'; } |
| 12 | printf '[%s] = ' "$trans" | ||
| 13 | if [ "$1" = "-i" ]; then | ||
| 14 | ./invert <"$f" | ./h48_to_"$type" | ||
| 15 | else | ||
| 16 | ./h48_to_"$type" <"$f" | ||
| 17 | fi | ||
| 18 | printf ',\n' | ||
| 19 | done | ||
| 20 | } | ||
| 21 | 12 | ||
| 22 | genfuncs() { | 13 | gen() { |
| 23 | for f in transform_??_???.txt; do | 14 | for f in transform_??_???.txt; do |
| 24 | trans="$(echo $f | sed 's/.*_// ; s/\.txt//')" | 15 | trans="$(echo $f | sed 's/.*_// ; s/\.txt//')" |
| 25 | printf 'static inline cube_fast_t\n_trans_%s' "$trans" | 16 | line$type "$trans" |
| 26 | printf '(cube_fast_t c)\n{\n' | 17 | ./h48_to_"$type" <"$f" | sed$type |
| 27 | printf '\tcube_fast_t ret;\n\n' | 18 | line$type "${trans}_inverse" |
| 28 | printf '\tcube_fast_t tn = ' | 19 | ./invert <"$f" | ./h48_to_"$type" | sed$type |
| 29 | ./h48_to_"$type" <"$f" | sed '2,4s/^/\t/' | ||
| 30 | printf ';\n\tcube_fast_t ti = ' | ||
| 31 | ./invert <"$f" | ./h48_to_"$type" | sed '2,4 s/^/\t/' | ||
| 32 | printf ';\n\n\tret = compose_fast(tn, c);\n' | ||
| 33 | printf '\tret = compose_fast(ret, ti);\n' | ||
| 34 | if [ -n "$(echo "$trans" | grep "m")" ]; then | ||
| 35 | printf '\tret = invertco_fast(ret);\n' | ||
| 36 | fi | ||
| 37 | printf '\n\treturn ret;\n}\n\n' | ||
| 38 | done | 20 | done |
| 39 | } | 21 | } |
| 40 | 22 | ||
| 41 | genfuncs | 23 | gen |
| 42 | rm -f h48_to_"$type" invert | 24 | 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 @@ | |||
| 3 | printf '\tswitch (t) {\n' | 3 | printf '\tswitch (t) {\n' |
| 4 | for f in transform_??_???.txt; do | 4 | for f in transform_??_???.txt; do |
| 5 | t="$(echo $f | sed 's/.*_// ; s/\.txt//')" | 5 | t="$(echo $f | sed 's/.*_// ; s/\.txt//')" |
| 6 | printf '\tcase %s:\n\t\treturn _trans_%s(c);\n' "$t" "$t" | 6 | mirror_or_rotation="$(echo $t | grep m)" |
| 7 | if [ -z "$mirror_or_rotation" ]; then | ||
| 8 | m="rotation" | ||
| 9 | else | ||
| 10 | m="mirrored" | ||
| 11 | fi | ||
| 12 | printf '\tcase %s:\n\t\treturn _trans_%s(%s, c);\n' "$t" "$m" "$t" | ||
| 7 | done | 13 | done |
| 8 | printf '\t}\n' | 14 | 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() { | |||
| 11 | cube_t cube; | 11 | cube_t cube; |
| 12 | 12 | ||
| 13 | fgets(str, STRLENMAX, stdin); | 13 | fgets(str, STRLENMAX, stdin); |
| 14 | cube = readcube(H48, str); | 14 | cube = readcube("H48", str); |
| 15 | writecube(AVX, cube, str); | 15 | writecube("AVX", cube, str); |
| 16 | fputs(str, stdout); | 16 | fputs(str, stdout); |
| 17 | 17 | ||
| 18 | return 0; | 18 | 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() { | |||
| 11 | cube_t cube; | 11 | cube_t cube; |
| 12 | 12 | ||
| 13 | fgets(str, STRLENMAX, stdin); | 13 | fgets(str, STRLENMAX, stdin); |
| 14 | cube = readcube(H48, str); | 14 | cube = readcube("H48", str); |
| 15 | writecube(SRC, cube, str); | 15 | writecube("SRC", cube, str); |
| 16 | fputs(str, stdout); | 16 | fputs(str, stdout); |
| 17 | 17 | ||
| 18 | return 0; | 18 | 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() { | |||
| 11 | cube_t cube; | 11 | cube_t cube; |
| 12 | 12 | ||
| 13 | fgets(str, STRLENMAX, stdin); | 13 | fgets(str, STRLENMAX, stdin); |
| 14 | cube = readcube(H48, str); | 14 | cube = readcube("H48", str); |
| 15 | writecube(H48, inverse(cube), str); | 15 | writecube("H48", inverse(cube), str); |
| 16 | fputs(str, stdout); | 16 | fputs(str, stdout); |
| 17 | 17 | ||
| 18 | return 0; | 18 | return 0; |
