From 08efbd62ef956327924aaea1fcfa97fde4dc1678 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 1 Nov 2023 19:26:09 +0100 Subject: Reworked moves and transformations, moved some stuff --- README.md | 44 +-- experiments/cube.c | 888 -------------------------------------------- experiments/cube.h | 27 -- old/_trans_move_arr.c | 389 ++++++++++++++++++++ old/inverses.c | 71 ++++ old/manualsimd/cube.c | 888 ++++++++++++++++++++++++++++++++++++++++++++ old/manualsimd/cube.h | 27 ++ src/_constants.c | 286 --------------- src/_move_logic_arr.c | 149 -------- src/_move_logic_avx2.c | 6 - src/_moves_arr.c | 264 ++++++++++++++ src/_moves_avx2.c | 2 + src/_trans_arr.c | 952 ++++++++++++++++++++++++++++++++++++++++++++++++ src/_trans_avx2.c | 0 src/_trans_move_arr.c | 389 -------------------- src/_trans_move_avx2.c | 2 - src/cube.c | 438 ++++++++++++++++++---- src/cube.h | 3 - utils/gentranscode.sh | 47 ++- utils/gentransswitch.sh | 8 + 20 files changed, 3024 insertions(+), 1856 deletions(-) delete mode 100644 experiments/cube.c delete mode 100644 experiments/cube.h create mode 100644 old/_trans_move_arr.c create mode 100644 old/inverses.c create mode 100644 old/manualsimd/cube.c create mode 100644 old/manualsimd/cube.h delete mode 100644 src/_constants.c delete mode 100644 src/_move_logic_arr.c delete mode 100644 src/_move_logic_avx2.c create mode 100644 src/_moves_arr.c create mode 100644 src/_moves_avx2.c create mode 100644 src/_trans_arr.c create mode 100644 src/_trans_avx2.c delete mode 100644 src/_trans_move_arr.c delete mode 100644 src/_trans_move_avx2.c create mode 100755 utils/gentransswitch.sh diff --git a/README.md b/README.md index 59a6bcc..b2e9424 100644 --- a/README.md +++ b/README.md @@ -13,51 +13,29 @@ $ make test ## TODO: -### Tests +### Make AVX2 work -* inverse_move -* inverse_trans - -### Simple additions - -* Write to AVX2-src format -* move() that takes a string (alg) as input - -### Changes - -* write one function (static inline or public?) for each move (and trans) -* only call the specific functions in performance-critical steps (i.e. solve - - if the functions are static inline, all performance-critical steps must - be internal to cube.c) -* this also enables skipping some unnecessary work (e.g. flip edges, twist - corners) for many moves (and mirror transformations) -* add benchmarks with moves / trans called directly instead of via the - generic function -* keep generic move and trans functions with big switch case -* bring back constants into cube.c, and maybe also moves (TBD: what to - do with architecture-specific code? leave in separate files like now, - use just one file for each architecture...) +* writecube to AVX2-src format (+ tests) +* generate moves and transformations with scripts in utils/ +* fix base get_ and set_ macros (constant arguments?) +* optimize things that use get_ and set_ ### Documentation and interface * inline some documentation as comments in cube.h or cube.c * README.md (maybe convert to txt?) becomes the reference documentation -### AVX2 - -* fix base get_ and set_ macros (constant arguments?) -* implement missing stuff (moves, transform) -* optimize things that use get_ and set_ - ### More features +* move() that takes a string (alg) as input * coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym -* pruning tables (1 bit per entry + fallback) -* solve.c -### Optimizations: +### Solving -* multi-move (up to 4/5 moves at once) +* Fixed depth +* pruning tables (1 bit per entry + fallback) +* Takes as parameters the amount of memory to use and a FILE for the tables +* Use multi-move (up to 4/5 moves at once) ### Things I need to learn: diff --git a/experiments/cube.c b/experiments/cube.c deleted file mode 100644 index 4372b5e..0000000 --- a/experiments/cube.c +++ /dev/null @@ -1,888 +0,0 @@ -/* -# Cube representation, moves, transformations and (tentatively) indexing - -## Textual description - -The functions readcube() and writecube() use the following format. -Each edge is represented by two letters denoting the sides it belongs to -and one number denoting its orientation (0 oriented, 1 mis-oriented). -Similarly, each corner is represented by three letters and a number -(0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise). -Edge orientation is relative to the F / B axis, corner orientation is -relative to the U / D axis. - -The correct order of the pieces is the same as that defined in the -section "Internal cube representation", except that pieces are read -left-to-right. Pieces are divided by slices, so the ordering is not the -most intuitive, but it is more convenient for the internal representation. - -Whitespaces between pieces are ignored when reading the cube, and a -single whitespace character is added between pieces when writing. - -For example, the solved cube looks like this: - -UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 \ (no newline) -UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 - -The cube after the moves R'U'F looks like this: - -FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0 \ (no newline) -UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0 - -More formats might be supported in the future. - -## Internal cube representation - -The cube_t data structure implemented in this file is designed to -efficiently perform common operations on a 3x3x3 Rubik's cube when -solving it with an iterative-deepening DFS search. It is not the most -general, complete, easy to read or compact one. Since the cube can -be trivially reoriented before the search, we only encode permutations -of the cube that keep the center pieces in a fixed position (that is, -we do not encode the position of the centers). - -The cube state is encoded in two 64-bit integers, one for edges and one -for centers. We explain how edges are encoded first, and the highlight -the few differences with corners afterwards. - -For encoding edges, only the 60 least-significant bits are used. Each -edge described by 5 bits. The position of a 5-bit block in the 64-bit -integer determine the position of the edge piece in the cube, according -to the following table (least-significant bits on the right): - -55-59 50-54 45-49 40-44 35-39 30-34 25-29 20-24 15-19 10-14 5-9 0-4 - BR BL FL FR DR DL UL UR DF DB UB UF -ossee ossee ossee ossee ossee ossee ossee ossee ossee ossee ossee ossee - -For each edge, the 4 least-significant bits ('ssee' in the table) -determine the piece. The two bits marked with 'ss' determine the internal -slice the piece belongs to, i.e. they are either '00' for M, '01' for -S or '10' for E. The other two bits (marked with 'ee') determine the -actual edge piece among the 4 in the same slice, and they are assigned -somewhat arbitarily. Using this representation and the ordering defined -in the table above, the edges are correctly permuted when these 4 bits -for each represent the numbers 0 to 11 in the correct order. - -The last bit determines the orientation. The orientation of an edge -depends on its position, and it is defined being 0 if the edge can be -moved to its place in the solved orientation by permutations in the -subgroup . - -Corners are encoded in the 48 least-significant bits, and are described -by 6 bits each, their position being defined by the following table: - - 35-39 30-34 25-29 20-24 15-19 10-14 5-9 0-4 - DBL DFL UBR UFL DBR DFL UBL UFR -oooxcc oooxcc oooxcc oooxcc oooxcc oooxcc oooxcc oooxcc - -The bit marked with an 'x' describes the axis the corner belongs to. -The 0 axis consists of the corners UFR, UBL, DFL and DBR, and the other -four corners form the axis marked with 1. Then two bits are needed to -identify the corner among the four of the same axis. The last three bits -determine the orientation, where one corner is defined to be oriented -(marked with '000') if its top or bottom sticker faces the top or bottom -side. A corner a clockwise turn away from being oriented, thus requiring -a counter-clockwise turn to be oriented correctly, is marked with '001', -and a corner a counter-clockwise turn away is marked with '010'. The most -significant bit is not used to determine the corner orientation, but it -must always be set to '0' to simplify the moving operations (see below). - -## Basic moves - -The 18 basic moves of the cube could be performed by applying a suitable -general permutation (see below), but they have instead been manually -implemented with a few simple operations each, to improve performance. - -For each move we first permute the pieces. This amounts to shifting -around 4 blocks of bits for edges and 4 for corners. Since in some cases -adjacent pieces on the cube are also adjacent in the bit representation we -use, we can save some operations by shifting multiple blocks together. - -There are some moves that change the orientation of the pieces. Namely, -the moves F, F', B and B' change the orientation of the edges and those -moves as well as R, R', L and L' change the orientation of the corners. -Edge orientation is easy to address: we simply xor the edge representation -by a bit mask with zeroes everywhere except for the 4 edges that need -to be flipped (i.e. the ones on the twisted face). - -Corner orientation is harder to reproduce efficiently working only with -bitwise operations, as it involves performing operations modulo 3. -However, with the help of the extra bit we reserved, we are able to -do this using only two additions and 3 bitwise operations, without -any multiplication, division or modulo operation. The trick is -to use the following formula to sum two numbers x, y in {0,1,2}: - - ((x+y) + (x+y+1)/4) % 4 - -The thrid bit is needed because x+y and x+y+1 can exceed 3. We can -apply this operation to multiple pairs of bits representing ternary -digits at once using binary operations. See the function coapply() -below for the details. - -## Inverting the cube - -TODO - -## Transformations (conjugations by full-cube rotations) - -TODO - -## Indexing (tentative) - -TODO - subgroup description etc - -*/ - -#include -#include -#include - -#ifdef DEBUG -#include -#endif - -#include "cube.h" - -#define _error 0xFFFFFFFF - -#define _eoblock 0x10ULL /* 10000 */ -#define _epblock 0x0FULL /* 01111 */ -#define _eblock 0x1FULL /* 11111 */ -#define _eblock2 0x3FFULL /* 1111111111 */ - -#define _coblock 0x18ULL /* 011000 */ -#define _cpblock 0x07ULL /* 000111 */ -#define _cblock 0x3FULL /* 111111 */ -#define _cblock2 0xFFFULL /* 111111111111 */ - -#define _eomask 0x842108421084210ULL /* 10000 repeated 12 times */ -#define _comask 0x618618618618ULL /* 011000 repeated 8 times */ -#define _coonemask 0x208208208208ULL /* 001000 repeated 8 times */ -#define _coextramask 0x820820820820ULL /* 100000 repeated 8 times */ - -#define _emask_u (_eblock2 | _eblock2 << 20ULL) -#define _emask_d (_eblock2 << 10ULL | _eblock2 << 30ULL) -#define _emask_r (_eblock << 20ULL | _eblock2 << 35ULL | _eblock << 55ULL) -#define _emask_l (_eblock2 << 45ULL | _eblock2 << 25ULL) -#define _emask_f (_eblock | _eblock << 15ULL | _eblock2 << 40ULL) -#define _emask_b (_eblock2 << 5ULL | _eblock2 << 50ULL) - -#define _cmask_u (_cblock2 | _cblock2 << 24ULL) -#define _cmask_d (_cblock2 << 12ULL | _cblock2 << 36ULL) -#define _cmask_r (_cblock | _cblock << 18ULL | _cblock2 << 30ULL) -#define _cmask_l (_cblock2 << 6ULL | _cblock << 24ULL | _cblock << 42ULL) -#define _cmask_f (_cblock | _cblock << 12ULL | _cblock << 24ULL | _cblock << 36ULL) -#define _cmask_b (_cblock << 6ULL | _cblock << 18ULL | _cblock << 30ULL | _cblock << 42ULL) - -#define _eomask_f (1ULL << 4ULL | 1ULL << 19ULL | 1ULL << 44ULL | 1ULL << 49ULL) -#define _eomask_b (1ULL << 9ULL | 1ULL << 14ULL | 1ULL << 54ULL | 1ULL << 59ULL) - -#define _comask_r (2ULL << 3ULL | 1ULL << 33ULL | 2ULL << 21ULL | 1ULL << 39ULL) -#define _comask_l (1ULL << 27ULL | 2ULL << 9ULL | 2ULL << 15ULL | 1ULL << 45ULL) -#define _comask_f (1ULL << 3ULL | 1ULL << 15ULL | 2ULL << 27ULL | 2ULL << 39ULL) -#define _comask_b (1ULL << 9ULL | 1ULL << 21ULL | 2ULL << 33ULL | 2ULL << 45ULL) - -static inline uint64_t coapply(uint64_t, uint64_t); -static uint64_t permsign(uint64_t *, int); -static uint64_t readep(char *); -static uint64_t readeo(char *); -static uint64_t readcp(char *); -static uint64_t readco(char *); -static uint64_t readmove(char); -static uint64_t readmodifier(char); - -static char *edgestr[] = { - "UF", "UB", "DB", "DF", - "UR", "UL", "DL", "DR", - "FR", "FL", "BL", "BR" -}; -static char *cornerstr[] = { - "UFR", "UBL", "DFL", "DBR", - "UFL", "UBR", "DFR", "DBL" -}; -static char *cornerstralt[] = { - "URF", "ULB", "DLF", "DRB", - "ULF", "URB", "DRF", "DLB" -}; -static char *movestr[] = { - [U] = "U", [U2] = "U2", [U3] = "U'", - [D] = "D", [D2] = "D2", [D3] = "D'", - [R] = "R", [R2] = "R2", [R3] = "R'", - [L] = "L", [L2] = "L2", [L3] = "L'", - [F] = "F", [F2] = "F2", [F3] = "F'", - [B] = "B", [B2] = "B2", [B3] = "B'", -}; - -cube_t solvedcube = { .e = 0x5A928398A418820ULL, .c = 0x1C61440C2040ULL }; -cube_t errorcube = { .e = _error, .c = _error }; - - -static uint64_t -permsign(uint64_t *a, int n) -{ - int i, j; - uint64_t ret; - - ret = 0; - - for (i = 0; i < n; i++) - for (j = i+1; j < n; j++) - ret += a[i] > a[j] ? 1 : 0; - - return ret % 2; -} - -bool -isconsistent(cube_t cube) -{ - uint64_t x, p[12], sum, co; - bool found[12]; - int i; - - sum = 0; - - /* Check for EP consistency */ - for (i = 0; i < 12; i++) - found[i] = false; - for (i = 0, x = cube.e; i < 12; i++, x >>= 5ULL) { - p[i] = x & _epblock; - if (p[i] >= 12) - goto inconsistent_ep; - found[p[i]] = true; - } - for (i = 0; i < 12; i++) - if (!found[i]) - goto inconsistent_ep; - sum = permsign(p, 12); - - /* Check for CP consistency */ - for (i = 0; i < 8; i++) - found[i] = false; - for (i = 0, x = cube.c; i < 8; i++, x >>= 6ULL) { - p[i] = x & _cpblock; - if (p[i] >= 8) - goto inconsistent_cp; - found[p[i]] = true; - } - for (i = 0; i < 8; i++) - if (!found[i]) - goto inconsistent_cp; - sum += permsign(p, 8); - - /* Check permutation parity */ - if (sum % 2 != 0) - goto inconsistent_parity; - - /* Check for EO parity */ - for (i = 0, sum = 0, x = cube.e; i < 12; i++, x >>= 5ULL) - sum += (x & _eoblock) >> 4ULL; - if (sum % 2 != 0) - goto inconsistent_eo; - - /* Check for CO parity */ - for (i = 0, sum = 0, x = cube.c; i < 8; i++, x >>= 6ULL) { - co = (x & _coblock) >> 3ULL; - if (co > 2) - goto inconsistent_co3; - sum += co; - } - if (sum % 3 != 0) - goto inconsistent_co; - - /* Check that CO extra bit is zero */ - if (cube.c & _coextramask) - goto inconsistent_coextra; - - return true; - -inconsistent_ep: -#ifdef DEBUG - fprintf(stderr, "Inconsistent EP\n"); -#endif - goto inconsistent_return; -inconsistent_cp: -#ifdef DEBUG - fprintf(stderr, "Inconsistent CP\n"); -#endif - goto inconsistent_return; -inconsistent_parity: -#ifdef DEBUG - fprintf(stderr, "Inconsistent parity\n"); -#endif - goto inconsistent_return; -inconsistent_eo: -#ifdef DEBUG - fprintf(stderr, "Inconsistent EO\n"); -#endif - goto inconsistent_return; -inconsistent_co3: -#ifdef DEBUG - fprintf(stderr, "Inconsistent CO=3\n"); -#endif - goto inconsistent_return; -inconsistent_co: -#ifdef DEBUG - fprintf(stderr, "Inconsistent CO\n"); -#endif - goto inconsistent_return; -inconsistent_coextra: -#ifdef DEBUG - fprintf(stderr, "Inconsistent extra bit for CO\n"); -#endif - goto inconsistent_return; -inconsistent_return: - return false; -} - -bool -issolved(cube_t cube) -{ - return cube.c == solvedcube.c && cube.e == solvedcube.e; -} - - -static uint64_t -readep(char *str) -{ - uint64_t e; - - for (e = 0; e < 12; e++) - if (!strncmp(str, edgestr[e], 2)) - return e; - -#ifdef DEBUG - fprintf(stderr, "Error reading EP\n"); -#endif - return _error; -} - -static uint64_t -readeo(char *str) -{ - if (*str == '0') - return 0ULL; - if (*str == '1') - return 1ULL; - -#ifdef DEBUG - fprintf(stderr, "Error reading EO\n"); -#endif - return _error; -} - -static uint64_t -readcp(char *str) -{ - uint64_t c; - - for (c = 0; c < 8; c++) - if (!strncmp(str, cornerstr[c], 3) || - !strncmp(str, cornerstralt[c], 3)) - return c; - -#ifdef DEBUG - fprintf(stderr, "Error reading CP\n"); -#endif - return _error; -} - -static uint64_t -readco(char *str) -{ - if (*str == '0') - return 0ULL; - if (*str == '1') - return 1ULL; - if (*str == '2') - return 2ULL; - -#ifdef DEBUG - fprintf(stderr, "Error reading CO\n"); -#endif - return _error; -} - -cube_t -readcube(char *buf) -{ - int i; - uint64_t piece, orient; - cube_t ret = {0}; - char *b = buf; - - for (i = 0; i < 12; i++) { - while (*b == ' ' || *b == '\t' || *b == '\n') - b++; - if ((piece = readep(b)) == _error) - goto readcube_error; - b += 2; - if ((orient = readeo(b)) == _error) - goto readcube_error; - b++; - ret.e |= (piece << (i * 5ULL)) | (orient << (i * 5ULL + 4ULL)); - } - for (i = 0; i < 8; i++) { - while (*b == ' ' || *b == '\t' || *b == '\n') - b++; - if ((piece = readcp(b)) == _error) - goto readcube_error; - b += 3; - if ((orient = readco(b)) == _error) - goto readcube_error; - b++; - ret.c |= (piece << (i * 6ULL)) | (orient << (i * 6ULL + 3ULL)); - } - - return ret; - -readcube_error: -#ifdef DEBUG - fprintf(stderr, "readcube error\n"); -#endif - return errorcube; -} - -void -writecube(cube_t cube, char *buf) -{ - char *errormsg; - uint64_t piece, orien, x; - size_t len; - int i; - - if (!isconsistent(cube)) { - errormsg = "ERROR: cannot write inconsistent cube"; - goto writecube_error; - } - - for (i = 0, x = cube.e; i < 12; i++, x >>= 5ULL) { - piece = x & _epblock; - orien = (x & _eoblock) >> 4ULL; - buf[4*i ] = edgestr[piece][0]; - buf[4*i + 1] = edgestr[piece][1]; - buf[4*i + 2] = orien + '0'; - buf[4*i + 3] = ' '; - } - for (i = 0, x = cube.c; i < 8; i++, x >>= 6ULL) { - piece = x & _cpblock; - orien = (x & _coblock) >> 3ULL; - buf[48 + 5*i ] = cornerstr[piece][0]; - buf[48 + 5*i + 1] = cornerstr[piece][1]; - buf[48 + 5*i + 2] = cornerstr[piece][2]; - buf[48 + 5*i + 3] = orien + '0'; - buf[48 + 5*i + 4] = ' '; - } - - buf[48+39] = '\0'; - - return; - -writecube_error: -#ifdef DEBUG - fprintf(stderr, "writecube error, see stdout for details\n"); -#endif - len = strlen(errormsg); - memcpy(buf, errormsg, len); - buf[len] = '\n'; - buf[len+1] = '\0'; -} - - -static uint64_t -readmove(char c) -{ - switch (c) { - case 'U': - return U; - case 'D': - return D; - case 'R': - return R; - case 'L': - return L; - case 'F': - return F; - case 'B': - return B; - default: - return _error; - } -} - -static uint64_t -readmodifier(char c) -{ - switch (c) { - case '1': /* Fallthrough */ - case '2': /* Fallthrough */ - case '3': - return c - '0' - 1; - case '\'': - return 2; - default: - return 0; - } -} - -int -readmoves(char *buf, move_t *m) -{ - int n; - uint64_t r; - char *b; - - for (b = buf, n = 0; *b != '\0'; b++) { - while (*b == ' ' || *b == '\t' || *b == '\n') - b++; - if (*b == '\0') - return n; - if ((r = readmove(*b)) == _error) - goto readmoves_error; - m[n] = (move_t)r; - if ((r = readmodifier(*(b+1))) != 0) { - b++; - m[n] += r; - } - n++; - } - - return n; - -readmoves_error: -#ifdef DEBUG - fprintf(stderr, "readmoves error\n"); -#endif - return -1; -} - -void -writemoves(move_t *m, int n, char *buf) -{ - int i; - size_t len; - char *b, *s; - - for (i = 0, b = buf; i < n; i++, b++) { - s = movestr[m[i]]; - len = strlen(s); - memcpy(b, s, len); - b += len; - *b = ' '; - } - *b = '\0'; -} - - -static inline uint64_t -coapply(uint64_t c, uint64_t m) -{ - uint64_t z, b; - - z = c + m; - b = ((z + _coonemask) & _coextramask) >> 2ULL; - - return (z + b) & ~_coextramask; -} - -cube_t -move(cube_t c, move_t m) -{ - cube_t ret = {0}; - -#ifdef DEBUG - if (!isconsistent(c)) { - fprintf(stderr, "move error, inconsistent cube\n"); - goto move_error; - } -#endif - - switch (m) { - case U: - ret.e = c.e & ~_emask_u; - ret.e |= - (c.e & _eblock) << 25ULL | - (c.e & _eblock << 5ULL) << 15ULL | - (c.e & _eblock2 << 20ULL) >> 20ULL; - - ret.c = c.c & ~_cmask_u; - ret.c |= - (c.c & _cblock2) << 24ULL | - (c.c & _cblock << 24ULL) >> 18ULL | - (c.c & _cblock << 30ULL) >> 30ULL; - - return ret; - case U2: - ret.e = c.e & ~_emask_u; - ret.e |= - (c.e & (_eblock | _eblock << 20ULL)) << 5ULL | - (c.e & (_eblock << 5ULL | _eblock << 25ULL)) >> 5ULL; - - ret.c = c.c & ~_cmask_u; - ret.c |= - (c.c & (_cblock | _cblock << 24ULL)) << 6ULL | - (c.c & (_cblock << 6ULL | _cblock << 30ULL)) >> 6ULL; - - return ret; - case U3: - ret.e = c.e & ~_emask_u; - ret.e |= - (c.e & _eblock2) << 20ULL | - (c.e & _eblock << 25ULL) >> 25ULL | - (c.e & _eblock << 20ULL) >> 15ULL; - - ret.c = c.c & ~_cmask_u; - ret.c |= - (c.c & _cblock) << 30ULL | - (c.c & _cblock << 6ULL) << 18ULL | - (c.c & _cblock2 << 24ULL) >> 24ULL; - - return ret; - case D: - ret.e = c.e & ~_emask_d; - ret.e |= - (c.e & _eblock2 << 10ULL) << 20ULL | - (c.e & _eblock << 30ULL) >> 15ULL | - (c.e & _eblock << 35ULL) >> 25ULL; - - ret.c = c.c & ~_cmask_d; - ret.c |= - (c.c & _cblock2 << 12ULL) << 24ULL | - (c.c & _cblock << 36ULL) >> 18ULL | - (c.c & _cblock << 42ULL) >> 30ULL; - - return ret; - case D2: - ret.e = c.e & ~_emask_d; - ret.e |= - (c.e & (_eblock << 10ULL | _eblock << 30ULL)) << 5ULL | - (c.e & (_eblock << 15ULL | _eblock << 35ULL)) >> 5ULL; - - ret.c = c.c & ~_cmask_d; - ret.c |= - (c.c & (_cblock << 12ULL | _cblock << 36ULL)) << 6ULL | - (c.c & (_cblock << 18ULL | _cblock << 42ULL)) >> 6ULL; - - return ret; - case D3: - ret.e = c.e & ~_emask_d; - ret.e |= - (c.e & _eblock << 10ULL) << 25ULL | - (c.e & _eblock << 15ULL) << 15ULL | - (c.e & _eblock2 << 30ULL) >> 20ULL; - - ret.c = c.c & ~_cmask_d; - ret.c |= - (c.c & _cblock << 12ULL) << 30ULL | - (c.c & _cblock << 18ULL) << 18ULL | - (c.c & _cblock2 << 36ULL) >> 24ULL; - - return ret; - case R: - ret.e = c.e & ~_emask_r; - ret.e |= - (c.e & _eblock << 20ULL) << 35ULL | - (c.e & _eblock << 55ULL) >> 20ULL | - (c.e & _eblock << 35ULL) << 5ULL | - (c.e & _eblock << 40ULL) >> 20ULL; - - ret.c = c.c & ~_cmask_r; - ret.c |= - (c.c & _cblock) << 30ULL | - (c.c & _cblock << 30ULL) >> 12ULL | - (c.c & _cblock << 18ULL) << 18ULL | - (c.c & _cblock << 36ULL) >> 36ULL; - - ret.c = coapply(ret.c, _comask_r); - - return ret; - case R2: - ret.e = c.e & ~_emask_r; - ret.e |= - (c.e & (_eblock << 20ULL | _eblock << 40ULL)) << 15ULL | - (c.e & (_eblock << 35ULL | _eblock << 55ULL)) >> 15ULL; - - ret.c = c.c & ~_cmask_r; - ret.c |= - (c.c & _cblock) << 18ULL | - (c.c & _cblock << 18ULL) >> 18ULL | - (c.c & _cblock << 30ULL) << 6ULL | - (c.c & _cblock << 36ULL) >> 6ULL; - - return ret; - case R3: - ret.e = c.e & ~_emask_r; - ret.e |= - (c.e & (_eblock << 20ULL | _eblock << 35ULL)) << 20ULL | - (c.e & _eblock << 55ULL) >> 35ULL | - (c.e & _eblock << 40ULL) >> 5ULL; - - ret.c = c.c & ~_cmask_r; - ret.c |= - (c.c & _cblock) << 36ULL | - (c.c & _cblock << 30ULL) >> 30ULL | - (c.c & _cblock << 18ULL) << 12ULL | - (c.c & _cblock << 36ULL) >> 18ULL; - - ret.c = coapply(ret.c, _comask_r); - - return ret; - case L: - ret.e = c.e & ~_emask_l; - ret.e |= - (c.e & _eblock2 << 25ULL) << 20ULL | - (c.e & _eblock << 45ULL) >> 15ULL | - (c.e & _eblock << 50ULL) >> 25ULL; - - ret.c = c.c & ~_cmask_l; - ret.c |= - (c.c & _cblock << 6ULL) << 18ULL | - (c.c & _cblock << 12ULL) << 30ULL | - (c.c & _cblock << 24ULL) >> 12ULL | - (c.c & _cblock << 42ULL) >> 36ULL; - - ret.c = coapply(ret.c, _comask_l); - - return ret; - case L2: - ret.e = c.e & ~_emask_l; - ret.e |= - (c.e & (_eblock << 25ULL | _eblock << 45ULL)) << 5ULL | - (c.e & (_eblock << 30ULL | _eblock << 50ULL)) >> 5ULL; - - ret.c = c.c & ~_cmask_l; - ret.c |= - (c.c & _cblock << 6ULL) << 6ULL | - (c.c & _cblock << 12ULL) >> 6ULL | - (c.c & _cblock << 24ULL) << 18ULL | - (c.c & _cblock << 42ULL) >> 18ULL; - - return ret; - case L3: - ret.e = c.e & ~_emask_l; - ret.e |= - (c.e & _eblock << 25ULL) << 25ULL | - (c.e & _eblock << 30ULL) << 15ULL | - (c.e & _eblock2 << 45ULL) >> 20ULL; - - ret.c = c.c & ~_cmask_l; - ret.c |= - (c.c & _cblock << 6ULL) << 36ULL | - (c.c & _cblock << 12ULL) << 12ULL | - (c.c & _cblock << 24ULL) >> 18ULL | - (c.c & _cblock << 42ULL) >> 30ULL; - - ret.c = coapply(ret.c, _comask_l); - - return ret; - case F: - ret.e = c.e & ~_emask_f; - ret.e |= - (c.e & _eblock) << 40ULL | - (c.e & _eblock << 15ULL) << 30ULL | - (c.e & _eblock << 40ULL) >> 25ULL | - (c.e & _eblock << 45ULL) >> 45ULL; - - ret.e ^= _eomask_f; - - ret.c = c.c & ~_cmask_f; - ret.c |= - (c.c & _cblock) << 36ULL | - (c.c & (_cblock << 24ULL | _cblock << 36ULL)) >> 24ULL | - (c.c & _cblock << 12ULL) << 12ULL; - - ret.c = coapply(ret.c, _comask_f); - - return ret; - case F2: - ret.e = c.e & ~_emask_f; - ret.e |= - (c.e & _eblock) << 15ULL | - (c.e & _eblock << 15ULL) >> 15ULL | - (c.e & _eblock << 40ULL) << 5ULL | - (c.e & _eblock << 45ULL) >> 5ULL; - - ret.c = c.c & ~_cmask_f; - ret.c |= - (c.c & (_cblock | _cblock << 24ULL)) << 12ULL | - (c.c & (_cblock << 12ULL | _cblock << 36ULL)) >> 12ULL; - - return ret; - case F3: - ret.e = c.e & ~_emask_f; - ret.e |= - (c.e & _eblock) << 45ULL | - (c.e & _eblock << 15ULL) << 25ULL | - (c.e & _eblock << 40ULL) >> 40ULL | - (c.e & _eblock << 45ULL) >> 30ULL; - - ret.e ^= _eomask_f; - - ret.c = c.c & ~_cmask_f; - ret.c |= - (c.c & (_cblock | _cblock << 12ULL)) << 24ULL | - (c.c & _cblock << 24ULL) >> 12ULL | - (c.c & _cblock << 36ULL) >> 36ULL; - - ret.c = coapply(ret.c, _comask_f); - - return ret; - case B: - ret.e = c.e & ~_emask_b; - ret.e |= - (c.e & _eblock2 << 5ULL) << 45ULL | - (c.e & _eblock << 50ULL) >> 40ULL | - (c.e & _eblock << 55ULL) >> 50ULL; - - ret.e ^= _eomask_b; - - ret.c = c.c & ~_cmask_b; - ret.c |= - (c.c & _cblock << 6ULL) << 36ULL | - (c.c & _cblock << 18ULL) << 12ULL | - (c.c & (_cblock << 30ULL | _cblock << 42ULL)) >> 24ULL; - - ret.c = coapply(ret.c, _comask_b); - - return ret; - case B2: - ret.e = c.e & ~_emask_b; - ret.e |= - (c.e & (_eblock << 5ULL | _eblock << 50ULL)) << 5ULL | - (c.e & (_eblock << 10ULL | _eblock << 55ULL)) >> 5ULL; - - ret.c = c.c & ~_cmask_b; - ret.c |= - (c.c & (_cblock << 6ULL | _cblock << 30ULL)) << 12ULL | - (c.c & (_cblock << 18ULL | _cblock << 42ULL)) >> 12ULL; - - return ret; - case B3: - ret.e = c.e & ~_emask_b; - ret.e |= - (c.e & _eblock << 5ULL) << 50ULL | - (c.e & _eblock << 10ULL) << 40ULL | - (c.e & _eblock2 << 50ULL) >> 45ULL; - - ret.e ^= _eomask_b; - - ret.c = c.c & ~_cmask_b; - ret.c |= - (c.c & (_cblock << 6ULL | _cblock << 18ULL)) << 24ULL | - (c.c & _cblock << 30ULL) >> 12ULL | - (c.c & _cblock << 42ULL) >> 36ULL; - - ret.c = coapply(ret.c, _comask_b); - - return ret; - default: - goto move_unknown; - } - -move_unknown: -#ifdef DEBUG - fprintf(stderr, "move error, unknow move\n"); -#endif - goto move_error; -move_error: - return errorcube; -} diff --git a/experiments/cube.h b/experiments/cube.h deleted file mode 100644 index b916f96..0000000 --- a/experiments/cube.h +++ /dev/null @@ -1,27 +0,0 @@ -typedef enum { - U, U2, U3, D, D2, D3, - R, R2, R3, L, L2, L3, - F, F2, F3, B, B2, B3 -} move_t; -typedef struct { - uint64_t e; - uint64_t c; -} cube_t; - -extern cube_t solvedcube; -extern cube_t errorcube; - -bool isconsistent(cube_t); -bool issolved(cube_t); - -cube_t readcube(char *); -void writecube(cube_t, char *); - -int readmoves(char *, move_t *); -void writemoves(move_t *, int, char *); - -cube_t move(cube_t, move_t); - -/* -cube_t inverse(cube_t); -*/ diff --git a/old/_trans_move_arr.c b/old/_trans_move_arr.c new file mode 100644 index 0000000..a00105f --- /dev/null +++ b/old/_trans_move_arr.c @@ -0,0 +1,389 @@ +static cube_t trans_move_cube[] = { + [UFr] = { + .c = {0, 1, 2, 3, 4, 5, 6, 7}, + .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }, + [ULr] = { + .c = {4, 5, 7, 6, 1, 0, 2, 3}, + .e = {5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24} + }, + [UBr] = { + .c = {1, 0, 3, 2, 5, 4, 7, 6}, + .e = {1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9} + }, + [URr] = { + .c = {5, 4, 6, 7, 0, 1, 3, 2}, + .e = {4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26} + }, + [DFr] = { + .c = {2, 3, 0, 1, 6, 7, 4, 5}, + .e = {3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10} + }, + [DLr] = { + .c = {7, 6, 4, 5, 2, 3, 1, 0}, + .e = {6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27} + }, + [DBr] = { + .c = {3, 2, 1, 0, 7, 6, 5, 4}, + .e = {2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8} + }, + [DRr] = { + .c = {6, 7, 5, 4, 3, 2, 0, 1}, + .e = {7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25} + }, + [RUr] = { + .c = {64, 67, 65, 66, 37, 38, 36, 39}, + .e = {20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3} + }, + [RFr] = { + .c = {38, 37, 36, 39, 64, 67, 66, 65}, + .e = {24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18} + }, + [RDr] = { + .c = {67, 64, 66, 65, 38, 37, 39, 36}, + .e = {23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1} + }, + [RBr] = { + .c = {37, 38, 39, 36, 67, 64, 65, 66}, + .e = {27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16} + }, + [LUr] = { + .c = {65, 66, 64, 67, 36, 39, 37, 38}, + .e = {21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2} + }, + [LFr] = { + .c = {36, 39, 38, 37, 66, 65, 64, 67}, + .e = {25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17} + }, + [LDr] = { + .c = {66, 65, 67, 64, 39, 36, 38, 37}, + .e = {22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0} + }, + [LBr] = { + .c = {39, 36, 37, 38, 65, 66, 67, 64}, + .e = {26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19} + }, + [FUr] = { + .c = {68, 70, 69, 71, 32, 34, 33, 35}, + .e = {16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6} + }, + [FRr] = { + .c = {32, 34, 35, 33, 70, 68, 69, 71}, + .e = {8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21} + }, + [FDr] = { + .c = {70, 68, 71, 69, 34, 32, 35, 33}, + .e = {19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4} + }, + [FLr] = { + .c = {34, 32, 33, 35, 68, 70, 71, 69}, + .e = {9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23} + }, + [BUr] = { + .c = {69, 71, 68, 70, 33, 35, 32, 34}, + .e = {17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7} + }, + [BRr] = { + .c = {35, 33, 32, 34, 69, 71, 70, 68}, + .e = {11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22} + }, + [BDr] = { + .c = {71, 69, 70, 68, 35, 33, 34, 32}, + .e = {18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5} + }, + [BLr] = { + .c = {33, 35, 34, 32, 71, 69, 68, 70}, + .e = {10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20} + }, + [UFm] = { + .c = {4, 5, 6, 7, 0, 1, 2, 3}, + .e = {0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10} + }, + [ULm] = { + .c = {0, 1, 3, 2, 5, 4, 6, 7}, + .e = {4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25} + }, + [UBm] = { + .c = {5, 4, 7, 6, 1, 0, 3, 2}, + .e = {1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8} + }, + [URm] = { + .c = {1, 0, 2, 3, 4, 5, 7, 6}, + .e = {5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27} + }, + [DFm] = { + .c = {6, 7, 4, 5, 2, 3, 0, 1}, + .e = {3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11} + }, + [DLm] = { + .c = {3, 2, 0, 1, 6, 7, 5, 4}, + .e = {7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26} + }, + [DBm] = { + .c = {7, 6, 5, 4, 3, 2, 1, 0}, + .e = {2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9} + }, + [DRm] = { + .c = {2, 3, 1, 0, 7, 6, 4, 5}, + .e = {6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24} + }, + [RUm] = { + .c = {68, 71, 69, 70, 33, 34, 32, 35}, + .e = {21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3} + }, + [RFm] = { + .c = {34, 33, 32, 35, 68, 71, 70, 69}, + .e = {25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18} + }, + [RDm] = { + .c = {71, 68, 70, 69, 34, 33, 35, 32}, + .e = {22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1} + }, + [RBm] = { + .c = {33, 34, 35, 32, 71, 68, 69, 70}, + .e = {26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16} + }, + [LUm] = { + .c = {69, 70, 68, 71, 32, 35, 33, 34}, + .e = {20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2} + }, + [LFm] = { + .c = {32, 35, 34, 33, 70, 69, 68, 71}, + .e = {24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17} + }, + [LDm] = { + .c = {70, 69, 71, 68, 35, 32, 34, 33}, + .e = {23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0} + }, + [LBm] = { + .c = {35, 32, 33, 34, 69, 70, 71, 68}, + .e = {27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19} + }, + [FUm] = { + .c = {64, 66, 65, 67, 36, 38, 37, 39}, + .e = {16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7} + }, + [FRm] = { + .c = {36, 38, 39, 37, 66, 64, 65, 67}, + .e = {9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20} + }, + [FDm] = { + .c = {66, 64, 67, 65, 38, 36, 39, 37}, + .e = {19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5} + }, + [FLm] = { + .c = {38, 36, 37, 39, 64, 66, 67, 65}, + .e = {8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22} + }, + [BUm] = { + .c = {65, 67, 64, 66, 37, 39, 36, 38}, + .e = {17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6} + }, + [BRm] = { + .c = {39, 37, 36, 38, 65, 67, 66, 64}, + .e = {10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23} + }, + [BDm] = { + .c = {67, 65, 66, 64, 39, 37, 38, 36}, + .e = {18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4} + }, + [BLm] = { + .c = {37, 39, 38, 36, 67, 65, 64, 66}, + .e = {11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21} + }, +}; + +static cube_t trans_move_cube_inverse[] = { + [UFr] = { + .c = {0, 1, 2, 3, 4, 5, 6, 7}, + .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }, + [ULr] = { + .c = {5, 4, 6, 7, 0, 1, 3, 2}, + .e = {4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26} + }, + [UBr] = { + .c = {1, 0, 3, 2, 5, 4, 7, 6}, + .e = {1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9} + }, + [URr] = { + .c = {4, 5, 7, 6, 1, 0, 2, 3}, + .e = {5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24} + }, + [DFr] = { + .c = {2, 3, 0, 1, 6, 7, 4, 5}, + .e = {3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10} + }, + [DLr] = { + .c = {7, 6, 4, 5, 2, 3, 1, 0}, + .e = {6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27} + }, + [DBr] = { + .c = {3, 2, 1, 0, 7, 6, 5, 4}, + .e = {2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8} + }, + [DRr] = { + .c = {6, 7, 5, 4, 3, 2, 0, 1}, + .e = {7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25} + }, + [RUr] = { + .c = {32, 34, 35, 33, 70, 68, 69, 71}, + .e = {8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21} + }, + [RFr] = { + .c = {36, 39, 38, 37, 66, 65, 64, 67}, + .e = {25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17} + }, + [RDr] = { + .c = {33, 35, 34, 32, 71, 69, 68, 70}, + .e = {10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20} + }, + [RBr] = { + .c = {37, 38, 39, 36, 67, 64, 65, 66}, + .e = {27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16} + }, + [LUr] = { + .c = {34, 32, 33, 35, 68, 70, 71, 69}, + .e = {9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23} + }, + [LFr] = { + .c = {38, 37, 36, 39, 64, 67, 66, 65}, + .e = {24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18} + }, + [LDr] = { + .c = {35, 33, 32, 34, 69, 71, 70, 68}, + .e = {11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22} + }, + [LBr] = { + .c = {39, 36, 37, 38, 65, 66, 67, 64}, + .e = {26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19} + }, + [FUr] = { + .c = {68, 70, 69, 71, 32, 34, 33, 35}, + .e = {16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6} + }, + [FRr] = { + .c = {64, 67, 65, 66, 37, 38, 36, 39}, + .e = {20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3} + }, + [FDr] = { + .c = {69, 71, 68, 70, 33, 35, 32, 34}, + .e = {17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7} + }, + [FLr] = { + .c = {65, 66, 64, 67, 36, 39, 37, 38}, + .e = {21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2} + }, + [BUr] = { + .c = {70, 68, 71, 69, 34, 32, 35, 33}, + .e = {19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4} + }, + [BRr] = { + .c = {66, 65, 67, 64, 39, 36, 38, 37}, + .e = {22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0} + }, + [BDr] = { + .c = {71, 69, 70, 68, 35, 33, 34, 32}, + .e = {18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5} + }, + [BLr] = { + .c = {67, 64, 66, 65, 38, 37, 39, 36}, + .e = {23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1} + }, + [UFm] = { + .c = {4, 5, 6, 7, 0, 1, 2, 3}, + .e = {0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10} + }, + [ULm] = { + .c = {0, 1, 3, 2, 5, 4, 6, 7}, + .e = {4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25} + }, + [UBm] = { + .c = {5, 4, 7, 6, 1, 0, 3, 2}, + .e = {1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8} + }, + [URm] = { + .c = {1, 0, 2, 3, 4, 5, 7, 6}, + .e = {5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27} + }, + [DFm] = { + .c = {6, 7, 4, 5, 2, 3, 0, 1}, + .e = {3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11} + }, + [DLm] = { + .c = {2, 3, 1, 0, 7, 6, 4, 5}, + .e = {6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24} + }, + [DBm] = { + .c = {7, 6, 5, 4, 3, 2, 1, 0}, + .e = {2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9} + }, + [DRm] = { + .c = {3, 2, 0, 1, 6, 7, 5, 4}, + .e = {7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26} + }, + [RUm] = { + .c = {70, 68, 69, 71, 32, 34, 35, 33}, + .e = {8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22} + }, + [RFm] = { + .c = {66, 65, 64, 67, 36, 39, 38, 37}, + .e = {25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18} + }, + [RDm] = { + .c = {71, 69, 68, 70, 33, 35, 34, 32}, + .e = {10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23} + }, + [RBm] = { + .c = {67, 64, 65, 66, 37, 38, 39, 36}, + .e = {27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19} + }, + [LUm] = { + .c = {68, 70, 71, 69, 34, 32, 33, 35}, + .e = {9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20} + }, + [LFm] = { + .c = {64, 67, 66, 65, 38, 37, 36, 39}, + .e = {24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17} + }, + [LDm] = { + .c = {69, 71, 70, 68, 35, 33, 32, 34}, + .e = {11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21} + }, + [LBm] = { + .c = {65, 66, 67, 64, 39, 36, 37, 38}, + .e = {26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16} + }, + [FUm] = { + .c = {32, 34, 33, 35, 68, 70, 69, 71}, + .e = {16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7} + }, + [FRm] = { + .c = {37, 38, 36, 39, 64, 67, 65, 66}, + .e = {20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2} + }, + [FDm] = { + .c = {33, 35, 32, 34, 69, 71, 68, 70}, + .e = {17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6} + }, + [FLm] = { + .c = {36, 39, 37, 38, 65, 66, 64, 67}, + .e = {21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3} + }, + [BUm] = { + .c = {34, 32, 35, 33, 70, 68, 71, 69}, + .e = {19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5} + }, + [BRm] = { + .c = {39, 36, 38, 37, 66, 65, 67, 64}, + .e = {22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1} + }, + [BDm] = { + .c = {35, 33, 34, 32, 71, 69, 70, 68}, + .e = {18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4} + }, + [BLm] = { + .c = {38, 37, 39, 36, 67, 64, 66, 65}, + .e = {23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0} + }, +}; diff --git a/old/inverses.c b/old/inverses.c new file mode 100644 index 0000000..eb8e80b --- /dev/null +++ b/old/inverses.c @@ -0,0 +1,71 @@ +static move_t inverse_move_arr[] = { + [U] = U3, + [U2] = U2, + [U3] = U, + [D] = D3, + [D2] = D2, + [D3] = D, + [R] = R3, + [R2] = R2, + [R3] = R, + [L] = L3, + [L2] = L2, + [L3] = L, + [F] = F3, + [F2] = F2, + [F3] = F, + [B] = B3, + [B2] = B2, + [B3] = B, +}; + +static trans_t inverse_trans_arr[] = { + [UFr] = UFr, + [ULr] = URr, + [UBr] = UBr, + [URr] = URr, + [DFr] = DFr, + [DLr] = DLr, + [DRr] = DRr, + [DBr] = DBr, + [RUr] = FRr, + [RFr] = LFr, + [RDr] = BLr, + [RBr] = RBr, + [LUr] = FLr, + [LFr] = RFr, + [LDr] = BRr, + [LBr] = LBr, + [FUr] = FUr, + [FRr] = RUr, + [FDr] = BUr, + [FLr] = LUr, + [BUr] = FDr, + [BLr] = RDr, + [BDr] = BDr, + [BRr] = LDr, + [UFm] = UFm, + [ULm] = ULm, + [UBm] = UBm, + [URm] = ULm, + [DFm] = DFm, + [DLm] = DRm, + [DRm] = DLm, + [DBm] = DBm, + [RUm] = FLm, + [RFm] = RFm, + [RDm] = BRm, + [RBm] = LBm, + [LUm] = FRm, + [LFm] = LFm, + [LDm] = BLm, + [LBm] = RBm, + [FUm] = FUm, + [FRm] = LUm, + [FDm] = BUm, + [FLm] = RUm, + [BUm] = FDm, + [BLm] = LDm, + [BDm] = BDm, + [BRm] = RDm, +}; diff --git a/old/manualsimd/cube.c b/old/manualsimd/cube.c new file mode 100644 index 0000000..4372b5e --- /dev/null +++ b/old/manualsimd/cube.c @@ -0,0 +1,888 @@ +/* +# Cube representation, moves, transformations and (tentatively) indexing + +## Textual description + +The functions readcube() and writecube() use the following format. +Each edge is represented by two letters denoting the sides it belongs to +and one number denoting its orientation (0 oriented, 1 mis-oriented). +Similarly, each corner is represented by three letters and a number +(0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise). +Edge orientation is relative to the F / B axis, corner orientation is +relative to the U / D axis. + +The correct order of the pieces is the same as that defined in the +section "Internal cube representation", except that pieces are read +left-to-right. Pieces are divided by slices, so the ordering is not the +most intuitive, but it is more convenient for the internal representation. + +Whitespaces between pieces are ignored when reading the cube, and a +single whitespace character is added between pieces when writing. + +For example, the solved cube looks like this: + +UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 \ (no newline) +UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 + +The cube after the moves R'U'F looks like this: + +FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0 \ (no newline) +UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0 + +More formats might be supported in the future. + +## Internal cube representation + +The cube_t data structure implemented in this file is designed to +efficiently perform common operations on a 3x3x3 Rubik's cube when +solving it with an iterative-deepening DFS search. It is not the most +general, complete, easy to read or compact one. Since the cube can +be trivially reoriented before the search, we only encode permutations +of the cube that keep the center pieces in a fixed position (that is, +we do not encode the position of the centers). + +The cube state is encoded in two 64-bit integers, one for edges and one +for centers. We explain how edges are encoded first, and the highlight +the few differences with corners afterwards. + +For encoding edges, only the 60 least-significant bits are used. Each +edge described by 5 bits. The position of a 5-bit block in the 64-bit +integer determine the position of the edge piece in the cube, according +to the following table (least-significant bits on the right): + +55-59 50-54 45-49 40-44 35-39 30-34 25-29 20-24 15-19 10-14 5-9 0-4 + BR BL FL FR DR DL UL UR DF DB UB UF +ossee ossee ossee ossee ossee ossee ossee ossee ossee ossee ossee ossee + +For each edge, the 4 least-significant bits ('ssee' in the table) +determine the piece. The two bits marked with 'ss' determine the internal +slice the piece belongs to, i.e. they are either '00' for M, '01' for +S or '10' for E. The other two bits (marked with 'ee') determine the +actual edge piece among the 4 in the same slice, and they are assigned +somewhat arbitarily. Using this representation and the ordering defined +in the table above, the edges are correctly permuted when these 4 bits +for each represent the numbers 0 to 11 in the correct order. + +The last bit determines the orientation. The orientation of an edge +depends on its position, and it is defined being 0 if the edge can be +moved to its place in the solved orientation by permutations in the +subgroup . + +Corners are encoded in the 48 least-significant bits, and are described +by 6 bits each, their position being defined by the following table: + + 35-39 30-34 25-29 20-24 15-19 10-14 5-9 0-4 + DBL DFL UBR UFL DBR DFL UBL UFR +oooxcc oooxcc oooxcc oooxcc oooxcc oooxcc oooxcc oooxcc + +The bit marked with an 'x' describes the axis the corner belongs to. +The 0 axis consists of the corners UFR, UBL, DFL and DBR, and the other +four corners form the axis marked with 1. Then two bits are needed to +identify the corner among the four of the same axis. The last three bits +determine the orientation, where one corner is defined to be oriented +(marked with '000') if its top or bottom sticker faces the top or bottom +side. A corner a clockwise turn away from being oriented, thus requiring +a counter-clockwise turn to be oriented correctly, is marked with '001', +and a corner a counter-clockwise turn away is marked with '010'. The most +significant bit is not used to determine the corner orientation, but it +must always be set to '0' to simplify the moving operations (see below). + +## Basic moves + +The 18 basic moves of the cube could be performed by applying a suitable +general permutation (see below), but they have instead been manually +implemented with a few simple operations each, to improve performance. + +For each move we first permute the pieces. This amounts to shifting +around 4 blocks of bits for edges and 4 for corners. Since in some cases +adjacent pieces on the cube are also adjacent in the bit representation we +use, we can save some operations by shifting multiple blocks together. + +There are some moves that change the orientation of the pieces. Namely, +the moves F, F', B and B' change the orientation of the edges and those +moves as well as R, R', L and L' change the orientation of the corners. +Edge orientation is easy to address: we simply xor the edge representation +by a bit mask with zeroes everywhere except for the 4 edges that need +to be flipped (i.e. the ones on the twisted face). + +Corner orientation is harder to reproduce efficiently working only with +bitwise operations, as it involves performing operations modulo 3. +However, with the help of the extra bit we reserved, we are able to +do this using only two additions and 3 bitwise operations, without +any multiplication, division or modulo operation. The trick is +to use the following formula to sum two numbers x, y in {0,1,2}: + + ((x+y) + (x+y+1)/4) % 4 + +The thrid bit is needed because x+y and x+y+1 can exceed 3. We can +apply this operation to multiple pairs of bits representing ternary +digits at once using binary operations. See the function coapply() +below for the details. + +## Inverting the cube + +TODO + +## Transformations (conjugations by full-cube rotations) + +TODO + +## Indexing (tentative) + +TODO - subgroup description etc + +*/ + +#include +#include +#include + +#ifdef DEBUG +#include +#endif + +#include "cube.h" + +#define _error 0xFFFFFFFF + +#define _eoblock 0x10ULL /* 10000 */ +#define _epblock 0x0FULL /* 01111 */ +#define _eblock 0x1FULL /* 11111 */ +#define _eblock2 0x3FFULL /* 1111111111 */ + +#define _coblock 0x18ULL /* 011000 */ +#define _cpblock 0x07ULL /* 000111 */ +#define _cblock 0x3FULL /* 111111 */ +#define _cblock2 0xFFFULL /* 111111111111 */ + +#define _eomask 0x842108421084210ULL /* 10000 repeated 12 times */ +#define _comask 0x618618618618ULL /* 011000 repeated 8 times */ +#define _coonemask 0x208208208208ULL /* 001000 repeated 8 times */ +#define _coextramask 0x820820820820ULL /* 100000 repeated 8 times */ + +#define _emask_u (_eblock2 | _eblock2 << 20ULL) +#define _emask_d (_eblock2 << 10ULL | _eblock2 << 30ULL) +#define _emask_r (_eblock << 20ULL | _eblock2 << 35ULL | _eblock << 55ULL) +#define _emask_l (_eblock2 << 45ULL | _eblock2 << 25ULL) +#define _emask_f (_eblock | _eblock << 15ULL | _eblock2 << 40ULL) +#define _emask_b (_eblock2 << 5ULL | _eblock2 << 50ULL) + +#define _cmask_u (_cblock2 | _cblock2 << 24ULL) +#define _cmask_d (_cblock2 << 12ULL | _cblock2 << 36ULL) +#define _cmask_r (_cblock | _cblock << 18ULL | _cblock2 << 30ULL) +#define _cmask_l (_cblock2 << 6ULL | _cblock << 24ULL | _cblock << 42ULL) +#define _cmask_f (_cblock | _cblock << 12ULL | _cblock << 24ULL | _cblock << 36ULL) +#define _cmask_b (_cblock << 6ULL | _cblock << 18ULL | _cblock << 30ULL | _cblock << 42ULL) + +#define _eomask_f (1ULL << 4ULL | 1ULL << 19ULL | 1ULL << 44ULL | 1ULL << 49ULL) +#define _eomask_b (1ULL << 9ULL | 1ULL << 14ULL | 1ULL << 54ULL | 1ULL << 59ULL) + +#define _comask_r (2ULL << 3ULL | 1ULL << 33ULL | 2ULL << 21ULL | 1ULL << 39ULL) +#define _comask_l (1ULL << 27ULL | 2ULL << 9ULL | 2ULL << 15ULL | 1ULL << 45ULL) +#define _comask_f (1ULL << 3ULL | 1ULL << 15ULL | 2ULL << 27ULL | 2ULL << 39ULL) +#define _comask_b (1ULL << 9ULL | 1ULL << 21ULL | 2ULL << 33ULL | 2ULL << 45ULL) + +static inline uint64_t coapply(uint64_t, uint64_t); +static uint64_t permsign(uint64_t *, int); +static uint64_t readep(char *); +static uint64_t readeo(char *); +static uint64_t readcp(char *); +static uint64_t readco(char *); +static uint64_t readmove(char); +static uint64_t readmodifier(char); + +static char *edgestr[] = { + "UF", "UB", "DB", "DF", + "UR", "UL", "DL", "DR", + "FR", "FL", "BL", "BR" +}; +static char *cornerstr[] = { + "UFR", "UBL", "DFL", "DBR", + "UFL", "UBR", "DFR", "DBL" +}; +static char *cornerstralt[] = { + "URF", "ULB", "DLF", "DRB", + "ULF", "URB", "DRF", "DLB" +}; +static char *movestr[] = { + [U] = "U", [U2] = "U2", [U3] = "U'", + [D] = "D", [D2] = "D2", [D3] = "D'", + [R] = "R", [R2] = "R2", [R3] = "R'", + [L] = "L", [L2] = "L2", [L3] = "L'", + [F] = "F", [F2] = "F2", [F3] = "F'", + [B] = "B", [B2] = "B2", [B3] = "B'", +}; + +cube_t solvedcube = { .e = 0x5A928398A418820ULL, .c = 0x1C61440C2040ULL }; +cube_t errorcube = { .e = _error, .c = _error }; + + +static uint64_t +permsign(uint64_t *a, int n) +{ + int i, j; + uint64_t ret; + + ret = 0; + + for (i = 0; i < n; i++) + for (j = i+1; j < n; j++) + ret += a[i] > a[j] ? 1 : 0; + + return ret % 2; +} + +bool +isconsistent(cube_t cube) +{ + uint64_t x, p[12], sum, co; + bool found[12]; + int i; + + sum = 0; + + /* Check for EP consistency */ + for (i = 0; i < 12; i++) + found[i] = false; + for (i = 0, x = cube.e; i < 12; i++, x >>= 5ULL) { + p[i] = x & _epblock; + if (p[i] >= 12) + goto inconsistent_ep; + found[p[i]] = true; + } + for (i = 0; i < 12; i++) + if (!found[i]) + goto inconsistent_ep; + sum = permsign(p, 12); + + /* Check for CP consistency */ + for (i = 0; i < 8; i++) + found[i] = false; + for (i = 0, x = cube.c; i < 8; i++, x >>= 6ULL) { + p[i] = x & _cpblock; + if (p[i] >= 8) + goto inconsistent_cp; + found[p[i]] = true; + } + for (i = 0; i < 8; i++) + if (!found[i]) + goto inconsistent_cp; + sum += permsign(p, 8); + + /* Check permutation parity */ + if (sum % 2 != 0) + goto inconsistent_parity; + + /* Check for EO parity */ + for (i = 0, sum = 0, x = cube.e; i < 12; i++, x >>= 5ULL) + sum += (x & _eoblock) >> 4ULL; + if (sum % 2 != 0) + goto inconsistent_eo; + + /* Check for CO parity */ + for (i = 0, sum = 0, x = cube.c; i < 8; i++, x >>= 6ULL) { + co = (x & _coblock) >> 3ULL; + if (co > 2) + goto inconsistent_co3; + sum += co; + } + if (sum % 3 != 0) + goto inconsistent_co; + + /* Check that CO extra bit is zero */ + if (cube.c & _coextramask) + goto inconsistent_coextra; + + return true; + +inconsistent_ep: +#ifdef DEBUG + fprintf(stderr, "Inconsistent EP\n"); +#endif + goto inconsistent_return; +inconsistent_cp: +#ifdef DEBUG + fprintf(stderr, "Inconsistent CP\n"); +#endif + goto inconsistent_return; +inconsistent_parity: +#ifdef DEBUG + fprintf(stderr, "Inconsistent parity\n"); +#endif + goto inconsistent_return; +inconsistent_eo: +#ifdef DEBUG + fprintf(stderr, "Inconsistent EO\n"); +#endif + goto inconsistent_return; +inconsistent_co3: +#ifdef DEBUG + fprintf(stderr, "Inconsistent CO=3\n"); +#endif + goto inconsistent_return; +inconsistent_co: +#ifdef DEBUG + fprintf(stderr, "Inconsistent CO\n"); +#endif + goto inconsistent_return; +inconsistent_coextra: +#ifdef DEBUG + fprintf(stderr, "Inconsistent extra bit for CO\n"); +#endif + goto inconsistent_return; +inconsistent_return: + return false; +} + +bool +issolved(cube_t cube) +{ + return cube.c == solvedcube.c && cube.e == solvedcube.e; +} + + +static uint64_t +readep(char *str) +{ + uint64_t e; + + for (e = 0; e < 12; e++) + if (!strncmp(str, edgestr[e], 2)) + return e; + +#ifdef DEBUG + fprintf(stderr, "Error reading EP\n"); +#endif + return _error; +} + +static uint64_t +readeo(char *str) +{ + if (*str == '0') + return 0ULL; + if (*str == '1') + return 1ULL; + +#ifdef DEBUG + fprintf(stderr, "Error reading EO\n"); +#endif + return _error; +} + +static uint64_t +readcp(char *str) +{ + uint64_t c; + + for (c = 0; c < 8; c++) + if (!strncmp(str, cornerstr[c], 3) || + !strncmp(str, cornerstralt[c], 3)) + return c; + +#ifdef DEBUG + fprintf(stderr, "Error reading CP\n"); +#endif + return _error; +} + +static uint64_t +readco(char *str) +{ + if (*str == '0') + return 0ULL; + if (*str == '1') + return 1ULL; + if (*str == '2') + return 2ULL; + +#ifdef DEBUG + fprintf(stderr, "Error reading CO\n"); +#endif + return _error; +} + +cube_t +readcube(char *buf) +{ + int i; + uint64_t piece, orient; + cube_t ret = {0}; + char *b = buf; + + for (i = 0; i < 12; i++) { + while (*b == ' ' || *b == '\t' || *b == '\n') + b++; + if ((piece = readep(b)) == _error) + goto readcube_error; + b += 2; + if ((orient = readeo(b)) == _error) + goto readcube_error; + b++; + ret.e |= (piece << (i * 5ULL)) | (orient << (i * 5ULL + 4ULL)); + } + for (i = 0; i < 8; i++) { + while (*b == ' ' || *b == '\t' || *b == '\n') + b++; + if ((piece = readcp(b)) == _error) + goto readcube_error; + b += 3; + if ((orient = readco(b)) == _error) + goto readcube_error; + b++; + ret.c |= (piece << (i * 6ULL)) | (orient << (i * 6ULL + 3ULL)); + } + + return ret; + +readcube_error: +#ifdef DEBUG + fprintf(stderr, "readcube error\n"); +#endif + return errorcube; +} + +void +writecube(cube_t cube, char *buf) +{ + char *errormsg; + uint64_t piece, orien, x; + size_t len; + int i; + + if (!isconsistent(cube)) { + errormsg = "ERROR: cannot write inconsistent cube"; + goto writecube_error; + } + + for (i = 0, x = cube.e; i < 12; i++, x >>= 5ULL) { + piece = x & _epblock; + orien = (x & _eoblock) >> 4ULL; + buf[4*i ] = edgestr[piece][0]; + buf[4*i + 1] = edgestr[piece][1]; + buf[4*i + 2] = orien + '0'; + buf[4*i + 3] = ' '; + } + for (i = 0, x = cube.c; i < 8; i++, x >>= 6ULL) { + piece = x & _cpblock; + orien = (x & _coblock) >> 3ULL; + buf[48 + 5*i ] = cornerstr[piece][0]; + buf[48 + 5*i + 1] = cornerstr[piece][1]; + buf[48 + 5*i + 2] = cornerstr[piece][2]; + buf[48 + 5*i + 3] = orien + '0'; + buf[48 + 5*i + 4] = ' '; + } + + buf[48+39] = '\0'; + + return; + +writecube_error: +#ifdef DEBUG + fprintf(stderr, "writecube error, see stdout for details\n"); +#endif + len = strlen(errormsg); + memcpy(buf, errormsg, len); + buf[len] = '\n'; + buf[len+1] = '\0'; +} + + +static uint64_t +readmove(char c) +{ + switch (c) { + case 'U': + return U; + case 'D': + return D; + case 'R': + return R; + case 'L': + return L; + case 'F': + return F; + case 'B': + return B; + default: + return _error; + } +} + +static uint64_t +readmodifier(char c) +{ + switch (c) { + case '1': /* Fallthrough */ + case '2': /* Fallthrough */ + case '3': + return c - '0' - 1; + case '\'': + return 2; + default: + return 0; + } +} + +int +readmoves(char *buf, move_t *m) +{ + int n; + uint64_t r; + char *b; + + for (b = buf, n = 0; *b != '\0'; b++) { + while (*b == ' ' || *b == '\t' || *b == '\n') + b++; + if (*b == '\0') + return n; + if ((r = readmove(*b)) == _error) + goto readmoves_error; + m[n] = (move_t)r; + if ((r = readmodifier(*(b+1))) != 0) { + b++; + m[n] += r; + } + n++; + } + + return n; + +readmoves_error: +#ifdef DEBUG + fprintf(stderr, "readmoves error\n"); +#endif + return -1; +} + +void +writemoves(move_t *m, int n, char *buf) +{ + int i; + size_t len; + char *b, *s; + + for (i = 0, b = buf; i < n; i++, b++) { + s = movestr[m[i]]; + len = strlen(s); + memcpy(b, s, len); + b += len; + *b = ' '; + } + *b = '\0'; +} + + +static inline uint64_t +coapply(uint64_t c, uint64_t m) +{ + uint64_t z, b; + + z = c + m; + b = ((z + _coonemask) & _coextramask) >> 2ULL; + + return (z + b) & ~_coextramask; +} + +cube_t +move(cube_t c, move_t m) +{ + cube_t ret = {0}; + +#ifdef DEBUG + if (!isconsistent(c)) { + fprintf(stderr, "move error, inconsistent cube\n"); + goto move_error; + } +#endif + + switch (m) { + case U: + ret.e = c.e & ~_emask_u; + ret.e |= + (c.e & _eblock) << 25ULL | + (c.e & _eblock << 5ULL) << 15ULL | + (c.e & _eblock2 << 20ULL) >> 20ULL; + + ret.c = c.c & ~_cmask_u; + ret.c |= + (c.c & _cblock2) << 24ULL | + (c.c & _cblock << 24ULL) >> 18ULL | + (c.c & _cblock << 30ULL) >> 30ULL; + + return ret; + case U2: + ret.e = c.e & ~_emask_u; + ret.e |= + (c.e & (_eblock | _eblock << 20ULL)) << 5ULL | + (c.e & (_eblock << 5ULL | _eblock << 25ULL)) >> 5ULL; + + ret.c = c.c & ~_cmask_u; + ret.c |= + (c.c & (_cblock | _cblock << 24ULL)) << 6ULL | + (c.c & (_cblock << 6ULL | _cblock << 30ULL)) >> 6ULL; + + return ret; + case U3: + ret.e = c.e & ~_emask_u; + ret.e |= + (c.e & _eblock2) << 20ULL | + (c.e & _eblock << 25ULL) >> 25ULL | + (c.e & _eblock << 20ULL) >> 15ULL; + + ret.c = c.c & ~_cmask_u; + ret.c |= + (c.c & _cblock) << 30ULL | + (c.c & _cblock << 6ULL) << 18ULL | + (c.c & _cblock2 << 24ULL) >> 24ULL; + + return ret; + case D: + ret.e = c.e & ~_emask_d; + ret.e |= + (c.e & _eblock2 << 10ULL) << 20ULL | + (c.e & _eblock << 30ULL) >> 15ULL | + (c.e & _eblock << 35ULL) >> 25ULL; + + ret.c = c.c & ~_cmask_d; + ret.c |= + (c.c & _cblock2 << 12ULL) << 24ULL | + (c.c & _cblock << 36ULL) >> 18ULL | + (c.c & _cblock << 42ULL) >> 30ULL; + + return ret; + case D2: + ret.e = c.e & ~_emask_d; + ret.e |= + (c.e & (_eblock << 10ULL | _eblock << 30ULL)) << 5ULL | + (c.e & (_eblock << 15ULL | _eblock << 35ULL)) >> 5ULL; + + ret.c = c.c & ~_cmask_d; + ret.c |= + (c.c & (_cblock << 12ULL | _cblock << 36ULL)) << 6ULL | + (c.c & (_cblock << 18ULL | _cblock << 42ULL)) >> 6ULL; + + return ret; + case D3: + ret.e = c.e & ~_emask_d; + ret.e |= + (c.e & _eblock << 10ULL) << 25ULL | + (c.e & _eblock << 15ULL) << 15ULL | + (c.e & _eblock2 << 30ULL) >> 20ULL; + + ret.c = c.c & ~_cmask_d; + ret.c |= + (c.c & _cblock << 12ULL) << 30ULL | + (c.c & _cblock << 18ULL) << 18ULL | + (c.c & _cblock2 << 36ULL) >> 24ULL; + + return ret; + case R: + ret.e = c.e & ~_emask_r; + ret.e |= + (c.e & _eblock << 20ULL) << 35ULL | + (c.e & _eblock << 55ULL) >> 20ULL | + (c.e & _eblock << 35ULL) << 5ULL | + (c.e & _eblock << 40ULL) >> 20ULL; + + ret.c = c.c & ~_cmask_r; + ret.c |= + (c.c & _cblock) << 30ULL | + (c.c & _cblock << 30ULL) >> 12ULL | + (c.c & _cblock << 18ULL) << 18ULL | + (c.c & _cblock << 36ULL) >> 36ULL; + + ret.c = coapply(ret.c, _comask_r); + + return ret; + case R2: + ret.e = c.e & ~_emask_r; + ret.e |= + (c.e & (_eblock << 20ULL | _eblock << 40ULL)) << 15ULL | + (c.e & (_eblock << 35ULL | _eblock << 55ULL)) >> 15ULL; + + ret.c = c.c & ~_cmask_r; + ret.c |= + (c.c & _cblock) << 18ULL | + (c.c & _cblock << 18ULL) >> 18ULL | + (c.c & _cblock << 30ULL) << 6ULL | + (c.c & _cblock << 36ULL) >> 6ULL; + + return ret; + case R3: + ret.e = c.e & ~_emask_r; + ret.e |= + (c.e & (_eblock << 20ULL | _eblock << 35ULL)) << 20ULL | + (c.e & _eblock << 55ULL) >> 35ULL | + (c.e & _eblock << 40ULL) >> 5ULL; + + ret.c = c.c & ~_cmask_r; + ret.c |= + (c.c & _cblock) << 36ULL | + (c.c & _cblock << 30ULL) >> 30ULL | + (c.c & _cblock << 18ULL) << 12ULL | + (c.c & _cblock << 36ULL) >> 18ULL; + + ret.c = coapply(ret.c, _comask_r); + + return ret; + case L: + ret.e = c.e & ~_emask_l; + ret.e |= + (c.e & _eblock2 << 25ULL) << 20ULL | + (c.e & _eblock << 45ULL) >> 15ULL | + (c.e & _eblock << 50ULL) >> 25ULL; + + ret.c = c.c & ~_cmask_l; + ret.c |= + (c.c & _cblock << 6ULL) << 18ULL | + (c.c & _cblock << 12ULL) << 30ULL | + (c.c & _cblock << 24ULL) >> 12ULL | + (c.c & _cblock << 42ULL) >> 36ULL; + + ret.c = coapply(ret.c, _comask_l); + + return ret; + case L2: + ret.e = c.e & ~_emask_l; + ret.e |= + (c.e & (_eblock << 25ULL | _eblock << 45ULL)) << 5ULL | + (c.e & (_eblock << 30ULL | _eblock << 50ULL)) >> 5ULL; + + ret.c = c.c & ~_cmask_l; + ret.c |= + (c.c & _cblock << 6ULL) << 6ULL | + (c.c & _cblock << 12ULL) >> 6ULL | + (c.c & _cblock << 24ULL) << 18ULL | + (c.c & _cblock << 42ULL) >> 18ULL; + + return ret; + case L3: + ret.e = c.e & ~_emask_l; + ret.e |= + (c.e & _eblock << 25ULL) << 25ULL | + (c.e & _eblock << 30ULL) << 15ULL | + (c.e & _eblock2 << 45ULL) >> 20ULL; + + ret.c = c.c & ~_cmask_l; + ret.c |= + (c.c & _cblock << 6ULL) << 36ULL | + (c.c & _cblock << 12ULL) << 12ULL | + (c.c & _cblock << 24ULL) >> 18ULL | + (c.c & _cblock << 42ULL) >> 30ULL; + + ret.c = coapply(ret.c, _comask_l); + + return ret; + case F: + ret.e = c.e & ~_emask_f; + ret.e |= + (c.e & _eblock) << 40ULL | + (c.e & _eblock << 15ULL) << 30ULL | + (c.e & _eblock << 40ULL) >> 25ULL | + (c.e & _eblock << 45ULL) >> 45ULL; + + ret.e ^= _eomask_f; + + ret.c = c.c & ~_cmask_f; + ret.c |= + (c.c & _cblock) << 36ULL | + (c.c & (_cblock << 24ULL | _cblock << 36ULL)) >> 24ULL | + (c.c & _cblock << 12ULL) << 12ULL; + + ret.c = coapply(ret.c, _comask_f); + + return ret; + case F2: + ret.e = c.e & ~_emask_f; + ret.e |= + (c.e & _eblock) << 15ULL | + (c.e & _eblock << 15ULL) >> 15ULL | + (c.e & _eblock << 40ULL) << 5ULL | + (c.e & _eblock << 45ULL) >> 5ULL; + + ret.c = c.c & ~_cmask_f; + ret.c |= + (c.c & (_cblock | _cblock << 24ULL)) << 12ULL | + (c.c & (_cblock << 12ULL | _cblock << 36ULL)) >> 12ULL; + + return ret; + case F3: + ret.e = c.e & ~_emask_f; + ret.e |= + (c.e & _eblock) << 45ULL | + (c.e & _eblock << 15ULL) << 25ULL | + (c.e & _eblock << 40ULL) >> 40ULL | + (c.e & _eblock << 45ULL) >> 30ULL; + + ret.e ^= _eomask_f; + + ret.c = c.c & ~_cmask_f; + ret.c |= + (c.c & (_cblock | _cblock << 12ULL)) << 24ULL | + (c.c & _cblock << 24ULL) >> 12ULL | + (c.c & _cblock << 36ULL) >> 36ULL; + + ret.c = coapply(ret.c, _comask_f); + + return ret; + case B: + ret.e = c.e & ~_emask_b; + ret.e |= + (c.e & _eblock2 << 5ULL) << 45ULL | + (c.e & _eblock << 50ULL) >> 40ULL | + (c.e & _eblock << 55ULL) >> 50ULL; + + ret.e ^= _eomask_b; + + ret.c = c.c & ~_cmask_b; + ret.c |= + (c.c & _cblock << 6ULL) << 36ULL | + (c.c & _cblock << 18ULL) << 12ULL | + (c.c & (_cblock << 30ULL | _cblock << 42ULL)) >> 24ULL; + + ret.c = coapply(ret.c, _comask_b); + + return ret; + case B2: + ret.e = c.e & ~_emask_b; + ret.e |= + (c.e & (_eblock << 5ULL | _eblock << 50ULL)) << 5ULL | + (c.e & (_eblock << 10ULL | _eblock << 55ULL)) >> 5ULL; + + ret.c = c.c & ~_cmask_b; + ret.c |= + (c.c & (_cblock << 6ULL | _cblock << 30ULL)) << 12ULL | + (c.c & (_cblock << 18ULL | _cblock << 42ULL)) >> 12ULL; + + return ret; + case B3: + ret.e = c.e & ~_emask_b; + ret.e |= + (c.e & _eblock << 5ULL) << 50ULL | + (c.e & _eblock << 10ULL) << 40ULL | + (c.e & _eblock2 << 50ULL) >> 45ULL; + + ret.e ^= _eomask_b; + + ret.c = c.c & ~_cmask_b; + ret.c |= + (c.c & (_cblock << 6ULL | _cblock << 18ULL)) << 24ULL | + (c.c & _cblock << 30ULL) >> 12ULL | + (c.c & _cblock << 42ULL) >> 36ULL; + + ret.c = coapply(ret.c, _comask_b); + + return ret; + default: + goto move_unknown; + } + +move_unknown: +#ifdef DEBUG + fprintf(stderr, "move error, unknow move\n"); +#endif + goto move_error; +move_error: + return errorcube; +} diff --git a/old/manualsimd/cube.h b/old/manualsimd/cube.h new file mode 100644 index 0000000..b916f96 --- /dev/null +++ b/old/manualsimd/cube.h @@ -0,0 +1,27 @@ +typedef enum { + U, U2, U3, D, D2, D3, + R, R2, R3, L, L2, L3, + F, F2, F3, B, B2, B3 +} move_t; +typedef struct { + uint64_t e; + uint64_t c; +} cube_t; + +extern cube_t solvedcube; +extern cube_t errorcube; + +bool isconsistent(cube_t); +bool issolved(cube_t); + +cube_t readcube(char *); +void writecube(cube_t, char *); + +int readmoves(char *, move_t *); +void writemoves(move_t *, int, char *); + +cube_t move(cube_t, move_t); + +/* +cube_t inverse(cube_t); +*/ diff --git a/src/_constants.c b/src/_constants.c deleted file mode 100644 index a6b19fe..0000000 --- a/src/_constants.c +++ /dev/null @@ -1,286 +0,0 @@ -#define U 0U -#define U2 1U -#define U3 2U -#define D 3U -#define D2 4U -#define D3 5U -#define R 6U -#define R2 7U -#define R3 8U -#define L 9U -#define L2 10U -#define L3 11U -#define F 12U -#define F2 13U -#define F3 14U -#define B 15U -#define B2 16U -#define B3 17U - -#define UFr 0 -#define ULr 1 -#define UBr 2 -#define URr 3 -#define DFr 4 -#define DLr 5 -#define DBr 6 -#define DRr 7 -#define RUr 8 -#define RFr 9 -#define RDr 10 -#define RBr 11 -#define LUr 12 -#define LFr 13 -#define LDr 14 -#define LBr 15 -#define FUr 16 -#define FRr 17 -#define FDr 18 -#define FLr 19 -#define BUr 20 -#define BRr 21 -#define BDr 22 -#define BLr 23 - -#define UFm 24 -#define ULm 25 -#define UBm 26 -#define URm 27 -#define DFm 28 -#define DLm 29 -#define DBm 30 -#define DRm 31 -#define RUm 32 -#define RFm 33 -#define RDm 34 -#define RBm 35 -#define LUm 36 -#define LFm 37 -#define LDm 38 -#define LBm 39 -#define FUm 40 -#define FRm 41 -#define FDm 42 -#define FLm 43 -#define BUm 44 -#define BRm 45 -#define BDm 46 -#define BLm 47 - -#define errormove 99U -#define errortrans 99U - -#define _c_ufr 0U -#define _c_ubl 1U -#define _c_dfl 2U -#define _c_dbr 3U -#define _c_ufl 4U -#define _c_ubr 5U -#define _c_dfr 6U -#define _c_dbl 7U - -#define _e_uf 0U -#define _e_ub 1U -#define _e_db 2U -#define _e_df 3U -#define _e_ur 4U -#define _e_ul 5U -#define _e_dl 6U -#define _e_dr 7U -#define _e_fr 8U -#define _e_fl 9U -#define _e_bl 10U -#define _e_br 11U - -#define _eoshift 4U -#define _coshift 5U - -#define _pbits 0xFU -#define _eobit 0x10U -#define _cobits 0xF0U -#define _cobits2 0x60U -#define _ctwist_cw 0x20U -#define _ctwist_ccw 0x40U -#define _eflip 0x10U -#define _error 0xFFU - -static move_t inverse_move_arr[] = { - [U] = U3, - [U2] = U2, - [U3] = U, - [D] = D3, - [D2] = D2, - [D3] = D, - [R] = R3, - [R2] = R2, - [R3] = R, - [L] = L3, - [L2] = L2, - [L3] = L, - [F] = F3, - [F2] = F2, - [F3] = F, - [B] = B3, - [B2] = B2, - [B3] = B, -}; - -static trans_t inverse_trans_arr[] = { - [UFr] = UFr, - [ULr] = URr, - [UBr] = UBr, - [URr] = URr, - [DFr] = DFr, - [DLr] = DLr, - [DRr] = DRr, - [DBr] = DBr, - [RUr] = FRr, - [RFr] = LFr, - [RDr] = BLr, - [RBr] = RBr, - [LUr] = FLr, - [LFr] = RFr, - [LDr] = BRr, - [LBr] = LBr, - [FUr] = FUr, - [FRr] = RUr, - [FDr] = BUr, - [FLr] = LUr, - [BUr] = FDr, - [BLr] = RDr, - [BDr] = BDr, - [BRr] = LDr, - [UFm] = UFm, - [ULm] = ULm, - [UBm] = UBm, - [URm] = ULm, - [DFm] = DFm, - [DLm] = DRm, - [DRm] = DLm, - [DBm] = DBm, - [RUm] = FLm, - [RFm] = RFm, - [RDm] = BRm, - [RBm] = LBm, - [LUm] = FRm, - [LFm] = LFm, - [LDm] = BLm, - [LBm] = RBm, - [FUm] = FUm, - [FRm] = LUm, - [FDm] = BUm, - [FLm] = RUm, - [BUm] = FDm, - [BLm] = LDm, - [BDm] = BDm, - [BRm] = RDm, -}; - -static char *cornerstr[] = { - [_c_ufr] = "UFR", - [_c_ubl] = "UBL", - [_c_dfl] = "DFL", - [_c_dbr] = "DBR", - [_c_ufl] = "UFL", - [_c_ubr] = "UBR", - [_c_dfr] = "DFR", - [_c_dbl] = "DBL" -}; - -static char *cornerstralt[] = { - [_c_ufr] = "URF", - [_c_ubl] = "ULB", - [_c_dfl] = "DLF", - [_c_dbr] = "DRB", - [_c_ufl] = "ULF", - [_c_ubr] = "URB", - [_c_dfr] = "DRF", - [_c_dbl] = "DLB" -}; - -static char *edgestr[] = { - [_e_uf] = "UF", - [_e_ub] = "UB", - [_e_db] = "DB", - [_e_df] = "DF", - [_e_ur] = "UR", - [_e_ul] = "UL", - [_e_dl] = "DL", - [_e_dr] = "DR", - [_e_fr] = "FR", - [_e_fl] = "FL", - [_e_bl] = "BL", - [_e_br] = "BR" -}; - -static char *movestr[] = { - [U] = "U", - [U2] = "U2", - [U3] = "U'", - [D] = "D", - [D2] = "D2", - [D3] = "D'", - [R] = "R", - [R2] = "R2", - [R3] = "R'", - [L] = "L", - [L2] = "L2", - [L3] = "L'", - [F] = "F", - [F2] = "F2", - [F3] = "F'", - [B] = "B", - [B2] = "B2", - [B3] = "B'", -}; - -static char *transstr[] = { - [UFr] = "rotation UF", - [UFm] = "mirrored UF", - [ULr] = "rotation UL", - [ULm] = "mirrored UL", - [UBr] = "rotation UB", - [UBm] = "mirrored UB", - [URr] = "rotation UR", - [URm] = "mirrored UR", - [DFr] = "rotation DF", - [DFm] = "mirrored DF", - [DLr] = "rotation DL", - [DLm] = "mirrored DL", - [DBr] = "rotation DB", - [DBm] = "mirrored DB", - [DRr] = "rotation DR", - [DRm] = "mirrored DR", - [RUr] = "rotation RU", - [RUm] = "mirrored RU", - [RFr] = "rotation RF", - [RFm] = "mirrored RF", - [RDr] = "rotation RD", - [RDm] = "mirrored RD", - [RBr] = "rotation RB", - [RBm] = "mirrored RB", - [LUr] = "rotation LU", - [LUm] = "mirrored LU", - [LFr] = "rotation LF", - [LFm] = "mirrored LF", - [LDr] = "rotation LD", - [LDm] = "mirrored LD", - [LBr] = "rotation LB", - [LBm] = "mirrored LB", - [FUr] = "rotation FU", - [FUm] = "mirrored FU", - [FRr] = "rotation FR", - [FRm] = "mirrored FR", - [FDr] = "rotation FD", - [FDm] = "mirrored FD", - [FLr] = "rotation FL", - [FLm] = "mirrored FL", - [BUr] = "rotation BU", - [BUm] = "mirrored BU", - [BRr] = "rotation BR", - [BRm] = "mirrored BR", - [BDr] = "rotation BD", - [BDm] = "mirrored BD", - [BLr] = "rotation BL", - [BLm] = "mirrored BL", -}; diff --git a/src/_move_logic_arr.c b/src/_move_logic_arr.c deleted file mode 100644 index d8aec10..0000000 --- a/src/_move_logic_arr.c +++ /dev/null @@ -1,149 +0,0 @@ -#define PERM4(r, i, j, k, l) \ - aux = r[i]; \ - r[i] = r[l]; \ - r[l] = r[k]; \ - r[k] = r[j]; \ - r[j] = aux; -#define PERM22(r, i, j, k, l) \ - aux = r[i]; \ - r[i] = r[j]; \ - r[j] = aux; \ - aux = r[k]; \ - r[k] = r[l]; \ - r[l] = aux; -#define CO(a, b) \ - aux = (a & _cobits) + (b & _cobits); \ - auy = (aux + _ctwist_cw) >> 2U; \ - auz = (aux + auy) & _cobits2; \ - a = (a & _pbits) | auz; -#define CO4(r, i, j, k, l) \ - CO(r[i], _ctwist_cw) \ - CO(r[j], _ctwist_cw) \ - CO(r[k], _ctwist_ccw) \ - CO(r[l], _ctwist_ccw) -#define EO4(r, i, j, k, l) \ - r[i] ^= _eobit; \ - r[j] ^= _eobit; \ - r[k] ^= _eobit; \ - r[l] ^= _eobit; - -uint8_t aux, auy, auz; -cube_t ret = c; - -switch (m) { -case U: - PERM4(ret.e, _e_uf, _e_ul, _e_ub, _e_ur) - PERM4(ret.c, _c_ufr, _c_ufl, _c_ubl, _c_ubr) - - return ret; -case U2: - PERM22(ret.e, _e_uf, _e_ub, _e_ul, _e_ur) - PERM22(ret.c, _c_ufr, _c_ubl, _c_ufl, _c_ubr) - - return ret; -case U3: - PERM4(ret.e, _e_uf, _e_ur, _e_ub, _e_ul) - PERM4(ret.c, _c_ufr, _c_ubr, _c_ubl, _c_ufl) - - return ret; -case D: - PERM4(ret.e, _e_df, _e_dr, _e_db, _e_dl) - PERM4(ret.c, _c_dfr, _c_dbr, _c_dbl, _c_dfl) - - return ret; -case D2: - PERM22(ret.e, _e_df, _e_db, _e_dr, _e_dl) - PERM22(ret.c, _c_dfr, _c_dbl, _c_dbr, _c_dfl) - - return ret; -case D3: - PERM4(ret.e, _e_df, _e_dl, _e_db, _e_dr) - PERM4(ret.c, _c_dfr, _c_dfl, _c_dbl, _c_dbr) - - return ret; -case R: - PERM4(ret.e, _e_ur, _e_br, _e_dr, _e_fr) - PERM4(ret.c, _c_ufr, _c_ubr, _c_dbr, _c_dfr) - - CO4(ret.c, _c_ubr, _c_dfr, _c_ufr, _c_dbr) - - return ret; -case R2: - PERM22(ret.e, _e_ur, _e_dr, _e_fr, _e_br) - PERM22(ret.c, _c_ufr, _c_dbr, _c_ubr, _c_dfr) - - return ret; -case R3: - PERM4(ret.e, _e_ur, _e_fr, _e_dr, _e_br) - PERM4(ret.c, _c_ufr, _c_dfr, _c_dbr, _c_ubr) - - CO4(ret.c, _c_ubr, _c_dfr, _c_ufr, _c_dbr) - - return ret; -case L: - PERM4(ret.e, _e_ul, _e_fl, _e_dl, _e_bl) - PERM4(ret.c, _c_ufl, _c_dfl, _c_dbl, _c_ubl) - - CO4(ret.c, _c_ufl, _c_dbl, _c_dfl, _c_ubl) - - return ret; -case L2: - PERM22(ret.e, _e_ul, _e_dl, _e_fl, _e_bl) - PERM22(ret.c, _c_ufl, _c_dbl, _c_ubl, _c_dfl) - - return ret; -case L3: - PERM4(ret.e, _e_ul, _e_bl, _e_dl, _e_fl) - PERM4(ret.c, _c_ufl, _c_ubl, _c_dbl, _c_dfl) - - CO4(ret.c, _c_ufl, _c_dbl, _c_dfl, _c_ubl) - - return ret; -case F: - PERM4(ret.e, _e_uf, _e_fr, _e_df, _e_fl) - PERM4(ret.c, _c_ufr, _c_dfr, _c_dfl, _c_ufl) - - EO4(ret.e, _e_uf, _e_fr, _e_df, _e_fl) - CO4(ret.c, _c_ufr, _c_dfl, _c_dfr, _c_ufl) - - return ret; -case F2: - PERM22(ret.e, _e_uf, _e_df, _e_fr, _e_fl) - PERM22(ret.c, _c_ufr, _c_dfl, _c_ufl, _c_dfr) - - return ret; -case F3: - PERM4(ret.e, _e_uf, _e_fl, _e_df, _e_fr) - PERM4(ret.c, _c_ufr, _c_ufl, _c_dfl, _c_dfr) - - EO4(ret.e, _e_uf, _e_fr, _e_df, _e_fl) - CO4(ret.c, _c_ufr, _c_dfl, _c_dfr, _c_ufl) - - return ret; -case B: - PERM4(ret.e, _e_ub, _e_bl, _e_db, _e_br) - PERM4(ret.c, _c_ubr, _c_ubl, _c_dbl, _c_dbr) - - EO4(ret.e, _e_ub, _e_br, _e_db, _e_bl) - CO4(ret.c, _c_ubl, _c_dbr, _c_dbl, _c_ubr) - - return ret; -case B2: - PERM22(ret.e, _e_ub, _e_db, _e_br, _e_bl) - PERM22(ret.c, _c_ubr, _c_dbl, _c_ubl, _c_dbr) - - return ret; -case B3: - PERM4(ret.e, _e_ub, _e_br, _e_db, _e_bl) - PERM4(ret.c, _c_ubr, _c_dbr, _c_dbl, _c_ubl) - - EO4(ret.e, _e_ub, _e_br, _e_db, _e_bl) - CO4(ret.c, _c_ubl, _c_dbr, _c_dbl, _c_ubr) - - return ret; -default: -#ifdef DEBUG - fprintf(stderr, "mover error, unknown move\n"); -#endif - goto move_error; -} diff --git a/src/_move_logic_avx2.c b/src/_move_logic_avx2.c deleted file mode 100644 index 29df776..0000000 --- a/src/_move_logic_avx2.c +++ /dev/null @@ -1,6 +0,0 @@ -/* TODO: -static cube_t move_cube[18]; -return compose(move_cube[m], c); -*/ - -goto move_error; diff --git a/src/_moves_arr.c b/src/_moves_arr.c new file mode 100644 index 0000000..bea0fee --- /dev/null +++ b/src/_moves_arr.c @@ -0,0 +1,264 @@ +#define PERM4(r, i, j, k, l) \ + aux = r[i]; \ + r[i] = r[l]; \ + r[l] = r[k]; \ + r[k] = r[j]; \ + r[j] = aux; +#define PERM22(r, i, j, k, l) \ + aux = r[i]; \ + r[i] = r[j]; \ + r[j] = aux; \ + aux = r[k]; \ + r[k] = r[l]; \ + r[l] = aux; +#define CO(a, b) \ + aux = (a & _cobits) + (b & _cobits); \ + auy = (aux + _ctwist_cw) >> 2U; \ + auz = (aux + auy) & _cobits2; \ + a = (a & _pbits) | auz; +#define CO4(r, i, j, k, l) \ + CO(r[i], _ctwist_cw) \ + CO(r[j], _ctwist_cw) \ + CO(r[k], _ctwist_ccw) \ + CO(r[l], _ctwist_ccw) +#define EO4(r, i, j, k, l) \ + r[i] ^= _eobit; \ + r[j] ^= _eobit; \ + r[k] ^= _eobit; \ + r[l] ^= _eobit; + +static inline cube_t +inline_move_U(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM4(ret.e, _e_uf, _e_ul, _e_ub, _e_ur) + PERM4(ret.c, _c_ufr, _c_ufl, _c_ubl, _c_ubr) + + return ret; +} + +static inline cube_t +inline_move_U2(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM22(ret.e, _e_uf, _e_ub, _e_ul, _e_ur) + PERM22(ret.c, _c_ufr, _c_ubl, _c_ufl, _c_ubr) + + return ret; +} + +static inline cube_t +inline_move_U3(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM4(ret.e, _e_uf, _e_ur, _e_ub, _e_ul) + PERM4(ret.c, _c_ufr, _c_ubr, _c_ubl, _c_ufl) + + return ret; +} + +static inline cube_t +inline_move_D(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM4(ret.e, _e_df, _e_dr, _e_db, _e_dl) + PERM4(ret.c, _c_dfr, _c_dbr, _c_dbl, _c_dfl) + + return ret; +} + +static inline cube_t +inline_move_D2(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM22(ret.e, _e_df, _e_db, _e_dr, _e_dl) + PERM22(ret.c, _c_dfr, _c_dbl, _c_dbr, _c_dfl) + + return ret; +} + +static inline cube_t +inline_move_D3(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM4(ret.e, _e_df, _e_dl, _e_db, _e_dr) + PERM4(ret.c, _c_dfr, _c_dfl, _c_dbl, _c_dbr) + + return ret; +} + +static inline cube_t +inline_move_R(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_ur, _e_br, _e_dr, _e_fr) + PERM4(ret.c, _c_ufr, _c_ubr, _c_dbr, _c_dfr) + + CO4(ret.c, _c_ubr, _c_dfr, _c_ufr, _c_dbr) + + return ret; +} + +static inline cube_t +inline_move_R2(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM22(ret.e, _e_ur, _e_dr, _e_fr, _e_br) + PERM22(ret.c, _c_ufr, _c_dbr, _c_ubr, _c_dfr) + + return ret; +} + +static inline cube_t +inline_move_R3(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_ur, _e_fr, _e_dr, _e_br) + PERM4(ret.c, _c_ufr, _c_dfr, _c_dbr, _c_ubr) + + CO4(ret.c, _c_ubr, _c_dfr, _c_ufr, _c_dbr) + + return ret; +} + +static inline cube_t +inline_move_L(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_ul, _e_fl, _e_dl, _e_bl) + PERM4(ret.c, _c_ufl, _c_dfl, _c_dbl, _c_ubl) + + CO4(ret.c, _c_ufl, _c_dbl, _c_dfl, _c_ubl) + + return ret; +} + +static inline cube_t +inline_move_L2(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM22(ret.e, _e_ul, _e_dl, _e_fl, _e_bl) + PERM22(ret.c, _c_ufl, _c_dbl, _c_ubl, _c_dfl) + + return ret; +} + +static inline cube_t +inline_move_L3(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_ul, _e_bl, _e_dl, _e_fl) + PERM4(ret.c, _c_ufl, _c_ubl, _c_dbl, _c_dfl) + + CO4(ret.c, _c_ufl, _c_dbl, _c_dfl, _c_ubl) + + return ret; +} + +static inline cube_t +inline_move_F(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_uf, _e_fr, _e_df, _e_fl) + PERM4(ret.c, _c_ufr, _c_dfr, _c_dfl, _c_ufl) + + EO4(ret.e, _e_uf, _e_fr, _e_df, _e_fl) + CO4(ret.c, _c_ufr, _c_dfl, _c_dfr, _c_ufl) + + return ret; +} + +static inline cube_t +inline_move_F2(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM22(ret.e, _e_uf, _e_df, _e_fr, _e_fl) + PERM22(ret.c, _c_ufr, _c_dfl, _c_ufl, _c_dfr) + + return ret; +} + +static inline cube_t +inline_move_F3(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_uf, _e_fl, _e_df, _e_fr) + PERM4(ret.c, _c_ufr, _c_ufl, _c_dfl, _c_dfr) + + EO4(ret.e, _e_uf, _e_fr, _e_df, _e_fl) + CO4(ret.c, _c_ufr, _c_dfl, _c_dfr, _c_ufl) + + return ret; +} + +static inline cube_t +inline_move_B(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_ub, _e_bl, _e_db, _e_br) + PERM4(ret.c, _c_ubr, _c_ubl, _c_dbl, _c_dbr) + + EO4(ret.e, _e_ub, _e_br, _e_db, _e_bl) + CO4(ret.c, _c_ubl, _c_dbr, _c_dbl, _c_ubr) + + return ret; +} + +static inline cube_t +inline_move_B2(cube_t c) +{ + uint8_t aux; + cube_t ret = c; + + PERM22(ret.e, _e_ub, _e_db, _e_br, _e_bl) + PERM22(ret.c, _c_ubr, _c_dbl, _c_ubl, _c_dbr) + + return ret; +} + +static inline cube_t +inline_move_B3(cube_t c) +{ + uint8_t aux, auy, auz; + cube_t ret = c; + + PERM4(ret.e, _e_ub, _e_br, _e_db, _e_bl) + PERM4(ret.c, _c_ubr, _c_dbr, _c_dbl, _c_ubl) + + EO4(ret.e, _e_ub, _e_br, _e_db, _e_bl) + CO4(ret.c, _c_ubl, _c_dbr, _c_dbl, _c_ubr) + + return ret; +} diff --git a/src/_moves_avx2.c b/src/_moves_avx2.c new file mode 100644 index 0000000..d72f45f --- /dev/null +++ b/src/_moves_avx2.c @@ -0,0 +1,2 @@ +/* TODO: return compose(c, (some avx garbage)); +*/ diff --git a/src/_trans_arr.c b/src/_trans_arr.c new file mode 100644 index 0000000..3a7c843 --- /dev/null +++ b/src/_trans_arr.c @@ -0,0 +1,952 @@ +static inline cube_t +flipallcorners(cube_t c) +{ + uint8_t i, piece, orien; + cube_t ret; + + ret = c; + for (i = 0; i < 8; i++) { + piece = get_corner(c, i); + orien = ((piece << 1) | (piece >> 1)) & _cobits2; + set_corner(ret, i, (piece & _pbits) | orien); + } + + return ret; +} + +static inline cube_t +inline_trans_UFr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {0, 1, 2, 3, 4, 5, 6, 7}, + .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }; + cube_t ti = { + .c = {0, 1, 2, 3, 4, 5, 6, 7}, + .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_ULr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {4, 5, 7, 6, 1, 0, 2, 3}, + .e = {5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24} + }; + cube_t ti = { + .c = {5, 4, 6, 7, 0, 1, 3, 2}, + .e = {4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_UBr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {1, 0, 3, 2, 5, 4, 7, 6}, + .e = {1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9} + }; + cube_t ti = { + .c = {1, 0, 3, 2, 5, 4, 7, 6}, + .e = {1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_URr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {5, 4, 6, 7, 0, 1, 3, 2}, + .e = {4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26} + }; + cube_t ti = { + .c = {4, 5, 7, 6, 1, 0, 2, 3}, + .e = {5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_DFr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {2, 3, 0, 1, 6, 7, 4, 5}, + .e = {3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10} + }; + cube_t ti = { + .c = {2, 3, 0, 1, 6, 7, 4, 5}, + .e = {3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_DLr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {7, 6, 4, 5, 2, 3, 1, 0}, + .e = {6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27} + }; + cube_t ti = { + .c = {7, 6, 4, 5, 2, 3, 1, 0}, + .e = {6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_DBr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {3, 2, 1, 0, 7, 6, 5, 4}, + .e = {2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8} + }; + cube_t ti = { + .c = {3, 2, 1, 0, 7, 6, 5, 4}, + .e = {2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_DRr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {6, 7, 5, 4, 3, 2, 0, 1}, + .e = {7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25} + }; + cube_t ti = { + .c = {6, 7, 5, 4, 3, 2, 0, 1}, + .e = {7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_RUr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {64, 67, 65, 66, 37, 38, 36, 39}, + .e = {20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3} + }; + cube_t ti = { + .c = {32, 34, 35, 33, 70, 68, 69, 71}, + .e = {8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_RFr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {38, 37, 36, 39, 64, 67, 66, 65}, + .e = {24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18} + }; + cube_t ti = { + .c = {36, 39, 38, 37, 66, 65, 64, 67}, + .e = {25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_RDr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {67, 64, 66, 65, 38, 37, 39, 36}, + .e = {23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1} + }; + cube_t ti = { + .c = {33, 35, 34, 32, 71, 69, 68, 70}, + .e = {10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_RBr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {37, 38, 39, 36, 67, 64, 65, 66}, + .e = {27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16} + }; + cube_t ti = { + .c = {37, 38, 39, 36, 67, 64, 65, 66}, + .e = {27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_LUr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {65, 66, 64, 67, 36, 39, 37, 38}, + .e = {21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2} + }; + cube_t ti = { + .c = {34, 32, 33, 35, 68, 70, 71, 69}, + .e = {9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_LFr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {36, 39, 38, 37, 66, 65, 64, 67}, + .e = {25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17} + }; + cube_t ti = { + .c = {38, 37, 36, 39, 64, 67, 66, 65}, + .e = {24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_LDr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {66, 65, 67, 64, 39, 36, 38, 37}, + .e = {22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0} + }; + cube_t ti = { + .c = {35, 33, 32, 34, 69, 71, 70, 68}, + .e = {11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_LBr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {39, 36, 37, 38, 65, 66, 67, 64}, + .e = {26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19} + }; + cube_t ti = { + .c = {39, 36, 37, 38, 65, 66, 67, 64}, + .e = {26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_FUr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {68, 70, 69, 71, 32, 34, 33, 35}, + .e = {16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6} + }; + cube_t ti = { + .c = {68, 70, 69, 71, 32, 34, 33, 35}, + .e = {16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_FRr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {32, 34, 35, 33, 70, 68, 69, 71}, + .e = {8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21} + }; + cube_t ti = { + .c = {64, 67, 65, 66, 37, 38, 36, 39}, + .e = {20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_FDr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {70, 68, 71, 69, 34, 32, 35, 33}, + .e = {19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4} + }; + cube_t ti = { + .c = {69, 71, 68, 70, 33, 35, 32, 34}, + .e = {17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_FLr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {34, 32, 33, 35, 68, 70, 71, 69}, + .e = {9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23} + }; + cube_t ti = { + .c = {65, 66, 64, 67, 36, 39, 37, 38}, + .e = {21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_BUr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {69, 71, 68, 70, 33, 35, 32, 34}, + .e = {17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7} + }; + cube_t ti = { + .c = {70, 68, 71, 69, 34, 32, 35, 33}, + .e = {19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_BRr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {35, 33, 32, 34, 69, 71, 70, 68}, + .e = {11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22} + }; + cube_t ti = { + .c = {66, 65, 67, 64, 39, 36, 38, 37}, + .e = {22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_BDr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {71, 69, 70, 68, 35, 33, 34, 32}, + .e = {18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5} + }; + cube_t ti = { + .c = {71, 69, 70, 68, 35, 33, 34, 32}, + .e = {18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_BLr(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {33, 35, 34, 32, 71, 69, 68, 70}, + .e = {10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20} + }; + cube_t ti = { + .c = {67, 64, 66, 65, 38, 37, 39, 36}, + .e = {23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + + return ret; +} + +static inline cube_t +inline_trans_UFm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {4, 5, 6, 7, 0, 1, 2, 3}, + .e = {0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10} + }; + cube_t ti = { + .c = {4, 5, 6, 7, 0, 1, 2, 3}, + .e = {0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_ULm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {0, 1, 3, 2, 5, 4, 6, 7}, + .e = {4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25} + }; + cube_t ti = { + .c = {0, 1, 3, 2, 5, 4, 6, 7}, + .e = {4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_UBm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {5, 4, 7, 6, 1, 0, 3, 2}, + .e = {1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8} + }; + cube_t ti = { + .c = {5, 4, 7, 6, 1, 0, 3, 2}, + .e = {1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_URm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {1, 0, 2, 3, 4, 5, 7, 6}, + .e = {5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27} + }; + cube_t ti = { + .c = {1, 0, 2, 3, 4, 5, 7, 6}, + .e = {5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_DFm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {6, 7, 4, 5, 2, 3, 0, 1}, + .e = {3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11} + }; + cube_t ti = { + .c = {6, 7, 4, 5, 2, 3, 0, 1}, + .e = {3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_DLm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {3, 2, 0, 1, 6, 7, 5, 4}, + .e = {7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26} + }; + cube_t ti = { + .c = {2, 3, 1, 0, 7, 6, 4, 5}, + .e = {6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_DBm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {7, 6, 5, 4, 3, 2, 1, 0}, + .e = {2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9} + }; + cube_t ti = { + .c = {7, 6, 5, 4, 3, 2, 1, 0}, + .e = {2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_DRm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {2, 3, 1, 0, 7, 6, 4, 5}, + .e = {6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24} + }; + cube_t ti = { + .c = {3, 2, 0, 1, 6, 7, 5, 4}, + .e = {7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_RUm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {68, 71, 69, 70, 33, 34, 32, 35}, + .e = {21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3} + }; + cube_t ti = { + .c = {70, 68, 69, 71, 32, 34, 35, 33}, + .e = {8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_RFm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {34, 33, 32, 35, 68, 71, 70, 69}, + .e = {25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18} + }; + cube_t ti = { + .c = {66, 65, 64, 67, 36, 39, 38, 37}, + .e = {25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_RDm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {71, 68, 70, 69, 34, 33, 35, 32}, + .e = {22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1} + }; + cube_t ti = { + .c = {71, 69, 68, 70, 33, 35, 34, 32}, + .e = {10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_RBm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {33, 34, 35, 32, 71, 68, 69, 70}, + .e = {26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16} + }; + cube_t ti = { + .c = {67, 64, 65, 66, 37, 38, 39, 36}, + .e = {27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_LUm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {69, 70, 68, 71, 32, 35, 33, 34}, + .e = {20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2} + }; + cube_t ti = { + .c = {68, 70, 71, 69, 34, 32, 33, 35}, + .e = {9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_LFm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {32, 35, 34, 33, 70, 69, 68, 71}, + .e = {24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17} + }; + cube_t ti = { + .c = {64, 67, 66, 65, 38, 37, 36, 39}, + .e = {24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_LDm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {70, 69, 71, 68, 35, 32, 34, 33}, + .e = {23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0} + }; + cube_t ti = { + .c = {69, 71, 70, 68, 35, 33, 32, 34}, + .e = {11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_LBm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {35, 32, 33, 34, 69, 70, 71, 68}, + .e = {27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19} + }; + cube_t ti = { + .c = {65, 66, 67, 64, 39, 36, 37, 38}, + .e = {26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_FUm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {64, 66, 65, 67, 36, 38, 37, 39}, + .e = {16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7} + }; + cube_t ti = { + .c = {32, 34, 33, 35, 68, 70, 69, 71}, + .e = {16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_FRm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {36, 38, 39, 37, 66, 64, 65, 67}, + .e = {9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20} + }; + cube_t ti = { + .c = {37, 38, 36, 39, 64, 67, 65, 66}, + .e = {20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_FDm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {66, 64, 67, 65, 38, 36, 39, 37}, + .e = {19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5} + }; + cube_t ti = { + .c = {33, 35, 32, 34, 69, 71, 68, 70}, + .e = {17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_FLm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {38, 36, 37, 39, 64, 66, 67, 65}, + .e = {8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22} + }; + cube_t ti = { + .c = {36, 39, 37, 38, 65, 66, 64, 67}, + .e = {21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_BUm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {65, 67, 64, 66, 37, 39, 36, 38}, + .e = {17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6} + }; + cube_t ti = { + .c = {34, 32, 35, 33, 70, 68, 71, 69}, + .e = {19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_BRm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {39, 37, 36, 38, 65, 67, 66, 64}, + .e = {10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23} + }; + cube_t ti = { + .c = {39, 36, 38, 37, 66, 65, 67, 64}, + .e = {22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_BDm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {67, 65, 66, 64, 39, 37, 38, 36}, + .e = {18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4} + }; + cube_t ti = { + .c = {35, 33, 34, 32, 71, 69, 70, 68}, + .e = {18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + +static inline cube_t +inline_trans_BLm(cube_t c) +{ + cube_t ret; + cube_t tn = { + .c = {37, 39, 38, 36, 67, 65, 64, 66}, + .e = {11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21} + }; + cube_t ti = { + .c = {38, 37, 39, 36, 67, 64, 66, 65}, + .e = {23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0} + }; + + ret = compose(tn, c); + ret = compose(ret, ti); + ret = flipallcorners(ret); + + return ret; +} + diff --git a/src/_trans_avx2.c b/src/_trans_avx2.c new file mode 100644 index 0000000..e69de29 diff --git a/src/_trans_move_arr.c b/src/_trans_move_arr.c deleted file mode 100644 index a00105f..0000000 --- a/src/_trans_move_arr.c +++ /dev/null @@ -1,389 +0,0 @@ -static cube_t trans_move_cube[] = { - [UFr] = { - .c = {0, 1, 2, 3, 4, 5, 6, 7}, - .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} - }, - [ULr] = { - .c = {4, 5, 7, 6, 1, 0, 2, 3}, - .e = {5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24} - }, - [UBr] = { - .c = {1, 0, 3, 2, 5, 4, 7, 6}, - .e = {1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9} - }, - [URr] = { - .c = {5, 4, 6, 7, 0, 1, 3, 2}, - .e = {4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26} - }, - [DFr] = { - .c = {2, 3, 0, 1, 6, 7, 4, 5}, - .e = {3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10} - }, - [DLr] = { - .c = {7, 6, 4, 5, 2, 3, 1, 0}, - .e = {6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27} - }, - [DBr] = { - .c = {3, 2, 1, 0, 7, 6, 5, 4}, - .e = {2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8} - }, - [DRr] = { - .c = {6, 7, 5, 4, 3, 2, 0, 1}, - .e = {7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25} - }, - [RUr] = { - .c = {64, 67, 65, 66, 37, 38, 36, 39}, - .e = {20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3} - }, - [RFr] = { - .c = {38, 37, 36, 39, 64, 67, 66, 65}, - .e = {24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18} - }, - [RDr] = { - .c = {67, 64, 66, 65, 38, 37, 39, 36}, - .e = {23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1} - }, - [RBr] = { - .c = {37, 38, 39, 36, 67, 64, 65, 66}, - .e = {27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16} - }, - [LUr] = { - .c = {65, 66, 64, 67, 36, 39, 37, 38}, - .e = {21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2} - }, - [LFr] = { - .c = {36, 39, 38, 37, 66, 65, 64, 67}, - .e = {25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17} - }, - [LDr] = { - .c = {66, 65, 67, 64, 39, 36, 38, 37}, - .e = {22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0} - }, - [LBr] = { - .c = {39, 36, 37, 38, 65, 66, 67, 64}, - .e = {26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19} - }, - [FUr] = { - .c = {68, 70, 69, 71, 32, 34, 33, 35}, - .e = {16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6} - }, - [FRr] = { - .c = {32, 34, 35, 33, 70, 68, 69, 71}, - .e = {8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21} - }, - [FDr] = { - .c = {70, 68, 71, 69, 34, 32, 35, 33}, - .e = {19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4} - }, - [FLr] = { - .c = {34, 32, 33, 35, 68, 70, 71, 69}, - .e = {9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23} - }, - [BUr] = { - .c = {69, 71, 68, 70, 33, 35, 32, 34}, - .e = {17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7} - }, - [BRr] = { - .c = {35, 33, 32, 34, 69, 71, 70, 68}, - .e = {11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22} - }, - [BDr] = { - .c = {71, 69, 70, 68, 35, 33, 34, 32}, - .e = {18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5} - }, - [BLr] = { - .c = {33, 35, 34, 32, 71, 69, 68, 70}, - .e = {10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20} - }, - [UFm] = { - .c = {4, 5, 6, 7, 0, 1, 2, 3}, - .e = {0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10} - }, - [ULm] = { - .c = {0, 1, 3, 2, 5, 4, 6, 7}, - .e = {4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25} - }, - [UBm] = { - .c = {5, 4, 7, 6, 1, 0, 3, 2}, - .e = {1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8} - }, - [URm] = { - .c = {1, 0, 2, 3, 4, 5, 7, 6}, - .e = {5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27} - }, - [DFm] = { - .c = {6, 7, 4, 5, 2, 3, 0, 1}, - .e = {3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11} - }, - [DLm] = { - .c = {3, 2, 0, 1, 6, 7, 5, 4}, - .e = {7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26} - }, - [DBm] = { - .c = {7, 6, 5, 4, 3, 2, 1, 0}, - .e = {2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9} - }, - [DRm] = { - .c = {2, 3, 1, 0, 7, 6, 4, 5}, - .e = {6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24} - }, - [RUm] = { - .c = {68, 71, 69, 70, 33, 34, 32, 35}, - .e = {21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3} - }, - [RFm] = { - .c = {34, 33, 32, 35, 68, 71, 70, 69}, - .e = {25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18} - }, - [RDm] = { - .c = {71, 68, 70, 69, 34, 33, 35, 32}, - .e = {22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1} - }, - [RBm] = { - .c = {33, 34, 35, 32, 71, 68, 69, 70}, - .e = {26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16} - }, - [LUm] = { - .c = {69, 70, 68, 71, 32, 35, 33, 34}, - .e = {20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2} - }, - [LFm] = { - .c = {32, 35, 34, 33, 70, 69, 68, 71}, - .e = {24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17} - }, - [LDm] = { - .c = {70, 69, 71, 68, 35, 32, 34, 33}, - .e = {23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0} - }, - [LBm] = { - .c = {35, 32, 33, 34, 69, 70, 71, 68}, - .e = {27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19} - }, - [FUm] = { - .c = {64, 66, 65, 67, 36, 38, 37, 39}, - .e = {16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7} - }, - [FRm] = { - .c = {36, 38, 39, 37, 66, 64, 65, 67}, - .e = {9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20} - }, - [FDm] = { - .c = {66, 64, 67, 65, 38, 36, 39, 37}, - .e = {19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5} - }, - [FLm] = { - .c = {38, 36, 37, 39, 64, 66, 67, 65}, - .e = {8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22} - }, - [BUm] = { - .c = {65, 67, 64, 66, 37, 39, 36, 38}, - .e = {17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6} - }, - [BRm] = { - .c = {39, 37, 36, 38, 65, 67, 66, 64}, - .e = {10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23} - }, - [BDm] = { - .c = {67, 65, 66, 64, 39, 37, 38, 36}, - .e = {18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4} - }, - [BLm] = { - .c = {37, 39, 38, 36, 67, 65, 64, 66}, - .e = {11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21} - }, -}; - -static cube_t trans_move_cube_inverse[] = { - [UFr] = { - .c = {0, 1, 2, 3, 4, 5, 6, 7}, - .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} - }, - [ULr] = { - .c = {5, 4, 6, 7, 0, 1, 3, 2}, - .e = {4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26} - }, - [UBr] = { - .c = {1, 0, 3, 2, 5, 4, 7, 6}, - .e = {1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9} - }, - [URr] = { - .c = {4, 5, 7, 6, 1, 0, 2, 3}, - .e = {5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24} - }, - [DFr] = { - .c = {2, 3, 0, 1, 6, 7, 4, 5}, - .e = {3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10} - }, - [DLr] = { - .c = {7, 6, 4, 5, 2, 3, 1, 0}, - .e = {6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27} - }, - [DBr] = { - .c = {3, 2, 1, 0, 7, 6, 5, 4}, - .e = {2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8} - }, - [DRr] = { - .c = {6, 7, 5, 4, 3, 2, 0, 1}, - .e = {7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25} - }, - [RUr] = { - .c = {32, 34, 35, 33, 70, 68, 69, 71}, - .e = {8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21} - }, - [RFr] = { - .c = {36, 39, 38, 37, 66, 65, 64, 67}, - .e = {25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17} - }, - [RDr] = { - .c = {33, 35, 34, 32, 71, 69, 68, 70}, - .e = {10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20} - }, - [RBr] = { - .c = {37, 38, 39, 36, 67, 64, 65, 66}, - .e = {27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16} - }, - [LUr] = { - .c = {34, 32, 33, 35, 68, 70, 71, 69}, - .e = {9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23} - }, - [LFr] = { - .c = {38, 37, 36, 39, 64, 67, 66, 65}, - .e = {24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18} - }, - [LDr] = { - .c = {35, 33, 32, 34, 69, 71, 70, 68}, - .e = {11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22} - }, - [LBr] = { - .c = {39, 36, 37, 38, 65, 66, 67, 64}, - .e = {26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19} - }, - [FUr] = { - .c = {68, 70, 69, 71, 32, 34, 33, 35}, - .e = {16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6} - }, - [FRr] = { - .c = {64, 67, 65, 66, 37, 38, 36, 39}, - .e = {20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3} - }, - [FDr] = { - .c = {69, 71, 68, 70, 33, 35, 32, 34}, - .e = {17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7} - }, - [FLr] = { - .c = {65, 66, 64, 67, 36, 39, 37, 38}, - .e = {21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2} - }, - [BUr] = { - .c = {70, 68, 71, 69, 34, 32, 35, 33}, - .e = {19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4} - }, - [BRr] = { - .c = {66, 65, 67, 64, 39, 36, 38, 37}, - .e = {22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0} - }, - [BDr] = { - .c = {71, 69, 70, 68, 35, 33, 34, 32}, - .e = {18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5} - }, - [BLr] = { - .c = {67, 64, 66, 65, 38, 37, 39, 36}, - .e = {23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1} - }, - [UFm] = { - .c = {4, 5, 6, 7, 0, 1, 2, 3}, - .e = {0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10} - }, - [ULm] = { - .c = {0, 1, 3, 2, 5, 4, 6, 7}, - .e = {4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25} - }, - [UBm] = { - .c = {5, 4, 7, 6, 1, 0, 3, 2}, - .e = {1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8} - }, - [URm] = { - .c = {1, 0, 2, 3, 4, 5, 7, 6}, - .e = {5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27} - }, - [DFm] = { - .c = {6, 7, 4, 5, 2, 3, 0, 1}, - .e = {3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11} - }, - [DLm] = { - .c = {2, 3, 1, 0, 7, 6, 4, 5}, - .e = {6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24} - }, - [DBm] = { - .c = {7, 6, 5, 4, 3, 2, 1, 0}, - .e = {2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9} - }, - [DRm] = { - .c = {3, 2, 0, 1, 6, 7, 5, 4}, - .e = {7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26} - }, - [RUm] = { - .c = {70, 68, 69, 71, 32, 34, 35, 33}, - .e = {8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22} - }, - [RFm] = { - .c = {66, 65, 64, 67, 36, 39, 38, 37}, - .e = {25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18} - }, - [RDm] = { - .c = {71, 69, 68, 70, 33, 35, 34, 32}, - .e = {10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23} - }, - [RBm] = { - .c = {67, 64, 65, 66, 37, 38, 39, 36}, - .e = {27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19} - }, - [LUm] = { - .c = {68, 70, 71, 69, 34, 32, 33, 35}, - .e = {9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20} - }, - [LFm] = { - .c = {64, 67, 66, 65, 38, 37, 36, 39}, - .e = {24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17} - }, - [LDm] = { - .c = {69, 71, 70, 68, 35, 33, 32, 34}, - .e = {11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21} - }, - [LBm] = { - .c = {65, 66, 67, 64, 39, 36, 37, 38}, - .e = {26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16} - }, - [FUm] = { - .c = {32, 34, 33, 35, 68, 70, 69, 71}, - .e = {16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7} - }, - [FRm] = { - .c = {37, 38, 36, 39, 64, 67, 65, 66}, - .e = {20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2} - }, - [FDm] = { - .c = {33, 35, 32, 34, 69, 71, 68, 70}, - .e = {17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6} - }, - [FLm] = { - .c = {36, 39, 37, 38, 65, 66, 64, 67}, - .e = {21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3} - }, - [BUm] = { - .c = {34, 32, 35, 33, 70, 68, 71, 69}, - .e = {19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5} - }, - [BRm] = { - .c = {39, 36, 38, 37, 66, 65, 67, 64}, - .e = {22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1} - }, - [BDm] = { - .c = {35, 33, 34, 32, 71, 69, 70, 68}, - .e = {18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4} - }, - [BLm] = { - .c = {38, 37, 39, 36, 67, 64, 66, 65}, - .e = {23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0} - }, -}; diff --git a/src/_trans_move_avx2.c b/src/_trans_move_avx2.c deleted file mode 100644 index 38b825e..0000000 --- a/src/_trans_move_avx2.c +++ /dev/null @@ -1,2 +0,0 @@ -static cube_t trans_move_cube[48]; -static cube_t trans_move_cube_inverse[48]; diff --git a/src/cube.c b/src/cube.c index fc04ee7..bb36447 100644 --- a/src/cube.c +++ b/src/cube.c @@ -2,17 +2,121 @@ #include #include -#ifdef CUBE_AVX2 -#include -#endif - #ifdef DEBUG #include #endif +#ifdef AVX2 +#include +#endif + #include "cube.h" -#include "_constants.c" +#define U 0U +#define U2 1U +#define U3 2U +#define D 3U +#define D2 4U +#define D3 5U +#define R 6U +#define R2 7U +#define R3 8U +#define L 9U +#define L2 10U +#define L3 11U +#define F 12U +#define F2 13U +#define F3 14U +#define B 15U +#define B2 16U +#define B3 17U + +#define UFr 0 +#define ULr 1 +#define UBr 2 +#define URr 3 +#define DFr 4 +#define DLr 5 +#define DBr 6 +#define DRr 7 +#define RUr 8 +#define RFr 9 +#define RDr 10 +#define RBr 11 +#define LUr 12 +#define LFr 13 +#define LDr 14 +#define LBr 15 +#define FUr 16 +#define FRr 17 +#define FDr 18 +#define FLr 19 +#define BUr 20 +#define BRr 21 +#define BDr 22 +#define BLr 23 + +#define UFm 24 +#define ULm 25 +#define UBm 26 +#define URm 27 +#define DFm 28 +#define DLm 29 +#define DBm 30 +#define DRm 31 +#define RUm 32 +#define RFm 33 +#define RDm 34 +#define RBm 35 +#define LUm 36 +#define LFm 37 +#define LDm 38 +#define LBm 39 +#define FUm 40 +#define FRm 41 +#define FDm 42 +#define FLm 43 +#define BUm 44 +#define BRm 45 +#define BDm 46 +#define BLm 47 + +#define errormove 99U +#define errortrans 99U + +#define _c_ufr 0U +#define _c_ubl 1U +#define _c_dfl 2U +#define _c_dbr 3U +#define _c_ufl 4U +#define _c_ubr 5U +#define _c_dfr 6U +#define _c_dbl 7U + +#define _e_uf 0U +#define _e_ub 1U +#define _e_db 2U +#define _e_df 3U +#define _e_ur 4U +#define _e_ul 5U +#define _e_dl 6U +#define _e_dr 7U +#define _e_fr 8U +#define _e_fl 9U +#define _e_bl 10U +#define _e_br 11U + +#define _eoshift 4U +#define _coshift 5U + +#define _pbits 0xFU +#define _eobit 0x10U +#define _cobits 0xF0U +#define _cobits2 0x60U +#define _ctwist_cw 0x20U +#define _ctwist_ccw 0x40U +#define _eflip 0x10U +#define _error 0xFFU cube_arr_t solvedcube_arr = { .c = {0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0}, @@ -36,18 +140,133 @@ cube_arr_t zerocube_arr = { .e = {0}, .c = {0} }; _mm256_andnot_si256(cube, _mm256_slli_si256(_c, 0)), \ _mm256_and_si256(_mm256_set1_epi8(p), _mm256_slli_si256(_c, 0))) +#include "_moves_avx2.c" +#include "_trans_avx2.c" + #else #define setsolved(cube) cube = solvedcube_arr #define setzero(cube) cube = zerocube_arr -#define _c _mm256_set_epi64x(0, 0, 0, 0xFF) #define get_edge(cube, i) (cube).e[(i)] #define get_corner(cube, i) (cube).c[(i)] #define set_edge(cube, i, p) (cube).e[(i)] = (p) #define set_corner(cube, i, p) (cube).c[(i)] = (p) +#include "_moves_arr.c" +#include "_trans_arr.c" + #endif + +static char *cornerstr[] = { + [_c_ufr] = "UFR", + [_c_ubl] = "UBL", + [_c_dfl] = "DFL", + [_c_dbr] = "DBR", + [_c_ufl] = "UFL", + [_c_ubr] = "UBR", + [_c_dfr] = "DFR", + [_c_dbl] = "DBL" +}; + +static char *cornerstralt[] = { + [_c_ufr] = "URF", + [_c_ubl] = "ULB", + [_c_dfl] = "DLF", + [_c_dbr] = "DRB", + [_c_ufl] = "ULF", + [_c_ubr] = "URB", + [_c_dfr] = "DRF", + [_c_dbl] = "DLB" +}; + +static char *edgestr[] = { + [_e_uf] = "UF", + [_e_ub] = "UB", + [_e_db] = "DB", + [_e_df] = "DF", + [_e_ur] = "UR", + [_e_ul] = "UL", + [_e_dl] = "DL", + [_e_dr] = "DR", + [_e_fr] = "FR", + [_e_fl] = "FL", + [_e_bl] = "BL", + [_e_br] = "BR" +}; + +static char *movestr[] = { + [U] = "U", + [U2] = "U2", + [U3] = "U'", + [D] = "D", + [D2] = "D2", + [D3] = "D'", + [R] = "R", + [R2] = "R2", + [R3] = "R'", + [L] = "L", + [L2] = "L2", + [L3] = "L'", + [F] = "F", + [F2] = "F2", + [F3] = "F'", + [B] = "B", + [B2] = "B2", + [B3] = "B'", +}; + +static char *transstr[] = { + [UFr] = "rotation UF", + [UFm] = "mirrored UF", + [ULr] = "rotation UL", + [ULm] = "mirrored UL", + [UBr] = "rotation UB", + [UBm] = "mirrored UB", + [URr] = "rotation UR", + [URm] = "mirrored UR", + [DFr] = "rotation DF", + [DFm] = "mirrored DF", + [DLr] = "rotation DL", + [DLm] = "mirrored DL", + [DBr] = "rotation DB", + [DBm] = "mirrored DB", + [DRr] = "rotation DR", + [DRm] = "mirrored DR", + [RUr] = "rotation RU", + [RUm] = "mirrored RU", + [RFr] = "rotation RF", + [RFm] = "mirrored RF", + [RDr] = "rotation RD", + [RDm] = "mirrored RD", + [RBr] = "rotation RB", + [RBm] = "mirrored RB", + [LUr] = "rotation LU", + [LUm] = "mirrored LU", + [LFr] = "rotation LF", + [LFm] = "mirrored LF", + [LDr] = "rotation LD", + [LDm] = "mirrored LD", + [LBr] = "rotation LB", + [LBm] = "mirrored LB", + [FUr] = "rotation FU", + [FUm] = "mirrored FU", + [FRr] = "rotation FR", + [FRm] = "mirrored FR", + [FDr] = "rotation FD", + [FDm] = "mirrored FD", + [FLr] = "rotation FL", + [FLm] = "mirrored FL", + [BUr] = "rotation BU", + [BUm] = "mirrored BU", + [BRr] = "rotation BR", + [BRm] = "mirrored BR", + [BDr] = "rotation BD", + [BDm] = "mirrored BD", + [BLr] = "rotation BL", + [BLm] = "mirrored BL", +}; + static bool isconsistent(cube_t); static cube_t flipallcorners(cube_t); static uint8_t readco(char *); @@ -187,9 +406,9 @@ readcube(format_t format, char *buf) ret = readcube_H48(buf); break; default: - #ifdef DEBUG +#ifdef DEBUG fprintf(stderr, "Cannot read cube in the given format\n"); - #endif +#endif setzero(ret); } @@ -421,18 +640,6 @@ writetrans(trans_t t, char *buf) buf[11] = '\0'; } -move_t -inverse_move(move_t m) -{ - return inverse_move_arr[m]; -} - -trans_t -inverse_trans(trans_t t) -{ - return inverse_trans_arr[t]; -} - static int permsign(uint8_t *a, int n) { @@ -617,11 +824,49 @@ move(cube_t c, move_t m) } #endif -#ifdef CUBE_AVX2 -#include "_move_logic_avx2.c" -#else -#include "_move_logic_arr.c" + switch (m) { + case U: + return inline_move_U(c); + case U2: + return inline_move_U2(c); + case U3: + return inline_move_U3(c); + case D: + return inline_move_D(c); + case D2: + return inline_move_D2(c); + case D3: + return inline_move_D3(c); + case R: + return inline_move_R(c); + case R2: + return inline_move_R2(c); + case R3: + return inline_move_R3(c); + case L: + return inline_move_L(c); + case L2: + return inline_move_L2(c); + case L3: + return inline_move_L3(c); + case F: + return inline_move_F(c); + case F2: + return inline_move_F2(c); + case F3: + return inline_move_F3(c); + case B: + return inline_move_B(c); + case B2: + return inline_move_B2(c); + case B3: + return inline_move_B3(c); + default: +#ifdef DEBUG + fprintf(stderr, "mover error, unknown move\n"); #endif + goto move_error; + } move_error: setzero(err); @@ -696,56 +941,123 @@ compose(cube_t c1, cube_t c2) return ret; } -static cube_t -flipallcorners(cube_t c) -{ -/* TODO: optimize for avx2, can be a couple of instructions */ - - uint8_t i, piece, orien; - cube_t ret; - - ret = c; - for (i = 0; i < 8; i++) { - piece = get_corner(c, i); - orien = ((piece << 1) | (piece >> 1)) & _cobits2; - set_corner(ret, i, (piece & _pbits) | orien); - } - - return ret; -} - cube_t transform(cube_t c, trans_t t) { - cube_t ret, solved; + cube_t ret; #ifdef DEBUG - setzero(ret); if (!isconsistent(c)) { fprintf(stderr, "transform error, inconsistent cube\n"); - return ret; - } - if (t >= 48) { - fprintf(stderr, "transform error, unknown transformation\n"); - return ret; + goto trans_error; } #endif -#ifdef CUBE_AVX2 -#include "_trans_move_avx2.c" -#else -#include "_trans_move_arr.c" + switch (t) { + case UFr: + return inline_trans_UFr(c); + case ULr: + return inline_trans_ULr(c); + case UBr: + return inline_trans_UBr(c); + case URr: + return inline_trans_URr(c); + case DFr: + return inline_trans_DFr(c); + case DLr: + return inline_trans_DLr(c); + case DBr: + return inline_trans_DBr(c); + case DRr: + return inline_trans_DRr(c); + case RUr: + return inline_trans_RUr(c); + case RFr: + return inline_trans_RFr(c); + case RDr: + return inline_trans_RDr(c); + case RBr: + return inline_trans_RBr(c); + case LUr: + return inline_trans_LUr(c); + case LFr: + return inline_trans_LFr(c); + case LDr: + return inline_trans_LDr(c); + case LBr: + return inline_trans_LBr(c); + case FUr: + return inline_trans_FUr(c); + case FRr: + return inline_trans_FRr(c); + case FDr: + return inline_trans_FDr(c); + case FLr: + return inline_trans_FLr(c); + case BUr: + return inline_trans_BUr(c); + case BRr: + return inline_trans_BRr(c); + case BDr: + return inline_trans_BDr(c); + case BLr: + return inline_trans_BLr(c); + case UFm: + return inline_trans_UFm(c); + case ULm: + return inline_trans_ULm(c); + case UBm: + return inline_trans_UBm(c); + case URm: + return inline_trans_URm(c); + case DFm: + return inline_trans_DFm(c); + case DLm: + return inline_trans_DLm(c); + case DBm: + return inline_trans_DBm(c); + case DRm: + return inline_trans_DRm(c); + case RUm: + return inline_trans_RUm(c); + case RFm: + return inline_trans_RFm(c); + case RDm: + return inline_trans_RDm(c); + case RBm: + return inline_trans_RBm(c); + case LUm: + return inline_trans_LUm(c); + case LFm: + return inline_trans_LFm(c); + case LDm: + return inline_trans_LDm(c); + case LBm: + return inline_trans_LBm(c); + case FUm: + return inline_trans_FUm(c); + case FRm: + return inline_trans_FRm(c); + case FDm: + return inline_trans_FDm(c); + case FLm: + return inline_trans_FLm(c); + case BUm: + return inline_trans_BUm(c); + case BRm: + return inline_trans_BRm(c); + case BDm: + return inline_trans_BDm(c); + case BLm: + return inline_trans_BLm(c); + default: +#ifdef DEBUG + fprintf(stderr, "transform error, unknown transformation\n"); #endif + goto trans_error; + } - setsolved(solved); - - ret = compose(solved, trans_move_cube[t]); - ret = compose(ret, c); - ret = compose(ret, trans_move_cube_inverse[t]); - - /* TODO: work out a better way to do this */ - if (t >= 24) - ret = flipallcorners(ret); - +trans_error: + setzero(ret); return ret; } diff --git a/src/cube.h b/src/cube.h index fd0d3e8..9ddeefa 100644 --- a/src/cube.h +++ b/src/cube.h @@ -16,9 +16,6 @@ void writemoves(move_t *, int, char *); trans_t readtrans(char *); void writetrans(trans_t, char *); -move_t inverse_move(move_t); -trans_t inverse_trans(trans_t); - typedef enum {H48, SRC} format_t; cube_t readcube(format_t, char *); /* Supports: H48 */ void writecube(format_t, cube_t, char *); /* Supports: H48, SRC */ diff --git a/utils/gentranscode.sh b/utils/gentranscode.sh index f820d7c..63888c6 100755 --- a/utils/gentranscode.sh +++ b/utils/gentranscode.sh @@ -3,15 +3,42 @@ gcc -DDEBUG h48_to_src.c ../src/cube.c -o h48_to_src gcc -DDEBUG invert.c ../src/cube.c -o invert -for f in transform_??_???.txt; do - trans="$(echo $f | sed 's/.*_// ; s/\.txt//')" - printf '[%s] = ' "$trans" - if [ "$1" = "-i" ]; then - ./invert <"$f" | ./h48_to_src - else - ./h48_to_src <"$f" - fi - printf ',\n' -done +# 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_src + else + ./h48_to_src <"$f" + fi + printf ',\n' + done +} +genfuncs() { + for f in transform_??_???.txt; do + trans="$(echo $f | sed 's/.*_// ; s/\.txt//')" + printf 'static inline cube_t\ninline_trans_%s' "$trans" + [ "$1" = "-i" ] && printf '_inverse' + printf '(cube_t c)\n{\n' + printf '\tcube_t ret;\n' + printf '\tcube_t tn = {\n' + ./h48_to_src <"$f" | sed 's/^/\t/' | \ + tail -n 3 | head -n 2 + printf '\t};\n\tcube_t ti = {\n' + ./invert <"$f" | ./h48_to_src | sed 's/^/\t/' | \ + tail -n 3 | head -n 2 + printf '\t};\n\n' + printf '\tret = compose(tn, c);\n' + printf '\tret = compose(ret, ti);\n' + if [ -n "$(echo "$trans" | grep "m")" ]; then + printf '\tret = flipallcorners(ret);\n' + fi + printf '\n\treturn ret;\n}\n\n' + done +} + +genfuncs rm -f h48_to_src invert diff --git a/utils/gentransswitch.sh b/utils/gentransswitch.sh new file mode 100755 index 0000000..6883973 --- /dev/null +++ b/utils/gentransswitch.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +printf '\tswitch (t) {\n' +for f in transform_??_???.txt; do + t="$(echo $f | sed 's/.*_// ; s/\.txt//')" + printf '\tcase %s:\n\t\treturn inline_trans_%s(c);\n' "$t" "$t" +done +printf '\t}\n' -- cgit v1.3