commit 08efbd62ef956327924aaea1fcfa97fde4dc1678
parent d65ce8e86b517ef3f7d48cf5ded1101444e05b2b
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Wed, 1 Nov 2023 19:26:09 +0100
Reworked moves and transformations, moved some stuff
Diffstat:
17 files changed, 1720 insertions(+), 552 deletions(-)
diff --git 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/src/_trans_move_arr.c b/old/_trans_move_arr.c
diff --git a/old/inverses.c 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/experiments/cube.c b/old/manualsimd/cube.c
diff --git a/experiments/cube.h b/old/manualsimd/cube.h
diff --git a/src/_constants.c b/src/_constants.c
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,2 @@
+/* TODO: return compose(c, (some avx garbage));
+*/
diff --git a/src/_trans_arr.c 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
diff --git a/src/_trans_move_avx2.c b/src/_trans_move_avx2.c
@@ -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
@@ -2,17 +2,121 @@
#include <stdbool.h>
#include <string.h>
-#ifdef CUBE_AVX2
-#include <immintrin.h>
-#endif
-
#ifdef DEBUG
#include <stdio.h>
#endif
+#ifdef AVX2
+#include <immintrin.h>
+#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
@@ -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
@@ -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
@@ -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'