h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit fd5ddb3db9f50411ca579d84f225f265ca35b56a
parent c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Thu,  5 Sep 2024 08:53:38 +0200

Rename constants from _underscore to CAPS

Diffstat:
Msrc/arch/avx2.h | 40++++++++++++++++++++--------------------
Msrc/arch/common.h | 38+++++++++++++++++++-------------------
Msrc/arch/neon.h | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/arch/portable.h | 80++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/core/constant_cubes.h | 228++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/core/cube.h | 70+++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/core/io_cube.h | 104++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/core/io_moves.h | 26+++++++++++++-------------
Msrc/core/io_trans.h | 10+++++-----
Msrc/core/moves.h | 122++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/core/transform.h | 229++++++++++++++++++++++++++++++++++++-------------------------------------------
Msrc/core/transform_with_switch.h | 616++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/nissy.c | 8++++----
Msrc/solvers/generic/generic.h | 20++++++++++----------
Msrc/solvers/h48/coordinate.h | 14+++++++-------
Msrc/solvers/h48/gendata_cocsep.h | 22+++++++++++-----------
Msrc/solvers/h48/gendata_h48.h | 48++++++++++++++++++++++++------------------------
Msrc/solvers/h48/map.h | 30+++++++++++++++---------------
Msrc/solvers/h48/solve.h | 42+++++++++++++++++++++---------------------
Msrc/utils/constants.h | 526+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/utils/dbg_log.h | 8++++----
Msrc/utils/math.h | 54+++++++++++++++++++++++++++---------------------------
22 files changed, 1192 insertions(+), 1217 deletions(-)

diff --git a/src/arch/avx2.h b/src/arch/avx2.h @@ -16,7 +16,7 @@ #define solved static_cube( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -_static void +STATIC void pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) { uint8_t aux[32]; @@ -26,7 +26,7 @@ pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) memcpy(e, aux+16, 12); } -_static_inline bool +STATIC_INLINE bool equal(cube_t c1, cube_t c2) { int32_t mask; @@ -38,7 +38,7 @@ equal(cube_t c1, cube_t c2) return mask == ~0; } -_static_inline cube_t +STATIC_INLINE cube_t invertco(cube_t c) { cube_t co, shleft, shright, summed, newco, cleanco, ret; @@ -54,7 +54,7 @@ invertco(cube_t c) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t compose_epcpeo(cube_t c1, cube_t c2) { cube_t b, s, eo2; @@ -74,13 +74,13 @@ compose_epcpeo(cube_t c1, cube_t c2) return s; } -_static_inline cube_t +STATIC_INLINE cube_t compose_edges(cube_t c1, cube_t c2) { return compose_epcpeo(c1, c2); } -_static_inline cube_t +STATIC_INLINE cube_t compose_corners(cube_t c1, cube_t c2) { /* @@ -91,7 +91,7 @@ compose_corners(cube_t c1, cube_t c2) return compose(c1, c2); } -_static_inline cube_t +STATIC_INLINE cube_t compose(cube_t c1, cube_t c2) { cube_t s, co1, co2, aux, auy1, auy2, auz1, auz2; @@ -114,7 +114,7 @@ compose(cube_t c1, cube_t c2) return s; } -_static_inline cube_t +STATIC_INLINE cube_t cleanaftershuffle(cube_t c) { __m256i b; @@ -127,7 +127,7 @@ cleanaftershuffle(cube_t c) return _mm256_andnot_si256(b, c); } -_static_inline cube_t +STATIC_INLINE cube_t inverse(cube_t c) { /* Method taken from Andrew Skalski's vcube[1]. The addition sequence @@ -166,7 +166,7 @@ inverse(cube_t c) return invertco(ret); } -_static_inline int64_t +STATIC_INLINE int64_t coord_co(cube_t c) { cube_t co; @@ -182,7 +182,7 @@ coord_co(cube_t c) return ret; } -_static_inline int64_t +STATIC_INLINE int64_t coord_csep(cube_t c) { cube_t cp, shifted; @@ -195,13 +195,13 @@ coord_csep(cube_t c) return mask & 0x7F; } -_static_inline int64_t +STATIC_INLINE int64_t coord_cocsep(cube_t c) { return (coord_co(c) << 7) + coord_csep(c); } -_static_inline int64_t +STATIC_INLINE int64_t coord_eo(cube_t c) { cube_t eo, shifted; @@ -214,7 +214,7 @@ coord_eo(cube_t c) return mask >> 17; } -_static_inline int64_t +STATIC_INLINE int64_t coord_esep(cube_t c) { cube_t ep; @@ -229,8 +229,8 @@ coord_esep(cube_t c) for (i = 0, j = 0; i < 12; i++, mem[i/8 + 2] >>= 8) { e = mem[i/8 + 2]; - bit1 = (e & _esepbit1) >> 2; - bit2 = (e & _esepbit2) >> 3; + bit1 = (e & ESEPBIT_1) >> 2; + bit2 = (e & ESEPBIT_2) >> 3; is1 = (1 - bit2) * bit1; ret1 += bit2 * binomial[11-i][k]; @@ -245,19 +245,19 @@ coord_esep(cube_t c) return ret1 * 70 + ret2; } -_static_inline void +STATIC_INLINE void copy_corners(cube_t *dest, cube_t src) { *dest = _mm256_blend_epi32(*dest, src, 0x0F); } -_static_inline void +STATIC_INLINE void copy_edges(cube_t *dest, cube_t src) { *dest = _mm256_blend_epi32(*dest, src, 0xF0); } -_static_inline void +STATIC_INLINE void set_eo(cube_t *cube, int64_t eo) { int64_t eo12, eotop, eobot; @@ -282,7 +282,7 @@ set_eo(cube_t *cube, int64_t eo) *cube = _mm256_or_si256(*cube, veo); } -_static_inline cube_t +STATIC_INLINE cube_t invcoord_esep(int64_t esep) { cube_t eee, ret; diff --git a/src/arch/common.h b/src/arch/common.h @@ -1,26 +1,26 @@ -_static void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]); -_static_inline bool equal(cube_t, cube_t); -_static_inline cube_t invertco(cube_t); -_static_inline cube_t compose_epcpeo(cube_t, cube_t); -_static_inline cube_t compose_edges(cube_t, cube_t); -_static_inline cube_t compose_corners(cube_t, cube_t); -_static_inline cube_t compose(cube_t, cube_t); -_static_inline cube_t inverse(cube_t); +STATIC void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]); +STATIC_INLINE bool equal(cube_t, cube_t); +STATIC_INLINE cube_t invertco(cube_t); +STATIC_INLINE cube_t compose_epcpeo(cube_t, cube_t); +STATIC_INLINE cube_t compose_edges(cube_t, cube_t); +STATIC_INLINE cube_t compose_corners(cube_t, cube_t); +STATIC_INLINE cube_t compose(cube_t, cube_t); +STATIC_INLINE cube_t inverse(cube_t); -_static_inline int64_t coord_co(cube_t); -_static_inline int64_t coord_csep(cube_t); -_static_inline int64_t coord_cocsep(cube_t); -_static_inline int64_t coord_eo(cube_t); -_static_inline int64_t coord_esep(cube_t); +STATIC_INLINE int64_t coord_co(cube_t); +STATIC_INLINE int64_t coord_csep(cube_t); +STATIC_INLINE int64_t coord_cocsep(cube_t); +STATIC_INLINE int64_t coord_eo(cube_t); +STATIC_INLINE int64_t coord_esep(cube_t); -_static_inline void copy_corners(cube_t *, cube_t); -_static_inline void copy_edges(cube_t *, cube_t); -_static_inline void set_eo(cube_t *, int64_t); -_static_inline cube_t invcoord_esep(int64_t); +STATIC_INLINE void copy_corners(cube_t *, cube_t); +STATIC_INLINE void copy_edges(cube_t *, cube_t); +STATIC_INLINE void set_eo(cube_t *, int64_t); +STATIC_INLINE cube_t invcoord_esep(int64_t); -_static_inline void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); +STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); -_static_inline void +STATIC_INLINE void invcoord_esep_array(int64_t set1, int64_t set2, uint8_t mem[static 12]) { int64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1; diff --git a/src/arch/neon.h b/src/arch/neon.h @@ -4,8 +4,8 @@ #define _ep_neon vcombine_u8(vdupq_n_u8(0x0F), vdupq_n_u8(0x0F)) #define _eo_neon vcombine_u8(vdupq_n_u8(0x10), vdupq_n_u8(0x10)) -_static_inline uint8x16_t compose_edges_slim(uint8x16_t, uint8x16_t); -_static_inline uint8x16_t compose_corners_slim(uint8x16_t, uint8x16_t); +STATIC_INLINE uint8x16_t compose_edges_slim(uint8x16_t, uint8x16_t); +STATIC_INLINE uint8x16_t compose_corners_slim(uint8x16_t, uint8x16_t); // static cube #define static_cube(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ @@ -26,7 +26,7 @@ _static_inline uint8x16_t compose_corners_slim(uint8x16_t, uint8x16_t); #define solved static_cube( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -_static void +STATIC void pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) { // First 8 bytes of the corner vector are copied from the c array @@ -39,7 +39,7 @@ pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) vst1_lane_u32((uint32_t *)(e + 8), vreinterpret_u32_u8(vget_high_u8(cube->edge)), 0); } -_static_inline bool +STATIC_INLINE bool equal(cube_t c1, cube_t c2) { uint8x16_t cmp_corner, cmp_edge; @@ -62,7 +62,7 @@ equal(cube_t c1, cube_t c2) return vgetq_lane_u64(cmp_result, 0) == ~0ULL && vgetq_lane_u64(cmp_result, 1) == ~0ULL; } -_static_inline cube_t +STATIC_INLINE cube_t invertco(cube_t c) { cube_t ret; @@ -80,7 +80,7 @@ invertco(cube_t c) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t compose_edges(cube_t c1, cube_t c2) { cube_t ret = {0}; @@ -88,7 +88,7 @@ compose_edges(cube_t c1, cube_t c2) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t compose_corners(cube_t c1, cube_t c2) { cube_t ret = {0}; @@ -96,12 +96,12 @@ compose_corners(cube_t c1, cube_t c2) return ret; } -_static_inline uint8x16_t +STATIC_INLINE uint8x16_t compose_edges_slim(uint8x16_t edge1, uint8x16_t edge2) { // Masks - uint8x16_t p_bits = vdupq_n_u8(_pbits); - uint8x16_t eo_bit = vdupq_n_u8(_eobit); + uint8x16_t p_bits = vdupq_n_u8(PBITS); + uint8x16_t eo_bit = vdupq_n_u8(EOBIT); // Find the index and permutation uint8x16_t p = vandq_u8(edge2, p_bits); @@ -120,14 +120,14 @@ compose_edges_slim(uint8x16_t edge1, uint8x16_t edge2) return ret; } -_static_inline uint8x16_t +STATIC_INLINE uint8x16_t compose_corners_slim(uint8x16_t corner1, uint8x16_t corner2) { // Masks - uint8x16_t p_bits = vdupq_n_u8(_pbits); - uint8x16_t cobits = vdupq_n_u8(_cobits); - uint8x16_t cobits2 = vdupq_n_u8(_cobits2); - uint8x16_t twist_cw = vdupq_n_u8(_ctwist_cw); + uint8x16_t p_bits = vdupq_n_u8(PBITS); + uint8x16_t cobits = vdupq_n_u8(COBITS); + uint8x16_t cobits2 = vdupq_n_u8(COBITS_2); + uint8x16_t twist_cw = vdupq_n_u8(CTWIST_CW); // Find the index and permutation uint8x16_t p = vandq_u8(corner2, p_bits); @@ -148,7 +148,7 @@ compose_corners_slim(uint8x16_t corner1, uint8x16_t corner2) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t compose(cube_t c1, cube_t c2) { cube_t ret = {0}; @@ -159,7 +159,7 @@ compose(cube_t c1, cube_t c2) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t inverse(cube_t cube) { uint8_t i, piece, orien; @@ -180,16 +180,16 @@ inverse(cube_t cube) for (i = 0; i < 12; i++) { piece = edges[i]; - orien = piece & _eobit; - edge_result[piece & _pbits] = i | orien; + orien = piece & EOBIT; + edge_result[piece & PBITS] = i | orien; } // Process the corners for (i = 0; i < 8; i++) { piece = corners[i]; - orien = ((piece << 1) | (piece >> 1)) & _cobits2; - corner_result[piece & _pbits] = i | orien; + orien = ((piece << 1) | (piece >> 1)) & COBITS_2; + corner_result[piece & PBITS] = i | orien; } // Copy the results back to the NEON vectors @@ -199,7 +199,7 @@ inverse(cube_t cube) return ret; } -_static_inline int64_t +STATIC_INLINE int64_t coord_co(cube_t c) { // Temp array to store the NEON vector @@ -210,12 +210,12 @@ coord_co(cube_t c) int64_t ret; for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) - ret += p * (mem[i] >> _coshift); + ret += p * (mem[i] >> COSHIFT); return ret; } -_static_inline int64_t +STATIC_INLINE int64_t coord_csep(cube_t c) { // Temp array to store the NEON vector @@ -225,19 +225,19 @@ coord_csep(cube_t c) int64_t ret = 0; int i, p; for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 2) - ret += p * ((mem[i] & _csepbit) >> 2); + ret += p * ((mem[i] & CSEPBIT) >> 2); return ret; return 0; } -_static_inline int64_t +STATIC_INLINE int64_t coord_cocsep(cube_t c) { return (coord_co(c) << 7) + coord_csep(c); } -_static_inline int64_t +STATIC_INLINE int64_t coord_eo(cube_t c) { int64_t ret = 0; @@ -249,13 +249,13 @@ coord_eo(cube_t c) for (int i = 1; i < 12; i++, p *= 2) { - ret += p * (mem[i] >> _eoshift); + ret += p * (mem[i] >> EOSHIFT); } return ret; } -_static_inline int64_t +STATIC_INLINE int64_t coord_esep(cube_t c) { int64_t i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; @@ -266,8 +266,8 @@ coord_esep(cube_t c) for (i = 0, j = 0, k = 4, l = 4, ret1 = 0, ret2 = 0; i < 12; i++) { - bit1 = (mem[i] & _esepbit1) >> 2; - bit2 = (mem[i] & _esepbit2) >> 3; + bit1 = (mem[i] & ESEPBIT_1) >> 2; + bit2 = (mem[i] & ESEPBIT_2) >> 3; is1 = (1 - bit2) * bit1; ret1 += bit2 * binomial[11 - i][k]; @@ -282,19 +282,19 @@ coord_esep(cube_t c) return ret1 * 70 + ret2; } -_static_inline void +STATIC_INLINE void copy_corners(cube_t *dst, cube_t src) { dst->corner = src.corner; } -_static_inline void +STATIC_INLINE void copy_edges(cube_t *dst, cube_t src) { dst->edge = src.edge; } -_static_inline void +STATIC_INLINE void set_eo(cube_t *cube, int64_t eo) { // Temp array to store the NEON vector @@ -306,16 +306,16 @@ set_eo(cube_t *cube, int64_t eo) { flip = eo % 2; sum += flip; - mem[i] = (mem[i] & ~_eobit) | (_eobit * flip); + mem[i] = (mem[i] & ~EOBIT) | (EOBIT * flip); } - mem[0] = (mem[0] & ~_eobit) | (_eobit * (sum % 2)); + mem[0] = (mem[0] & ~EOBIT) | (EOBIT * (sum % 2)); // Copy the results back to the NEON vector cube->edge = vld1q_u8(mem); return; } -_static_inline cube_t +STATIC_INLINE cube_t invcoord_esep(int64_t esep) { cube_t ret; diff --git a/src/arch/portable.h b/src/arch/portable.h @@ -9,14 +9,14 @@ #define solved static_cube( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -_static void +STATIC void pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) { memcpy(c, cube->corner, 8); memcpy(e, cube->edge, 12); } -_static_inline bool +STATIC_INLINE bool equal(cube_t c1, cube_t c2) { uint8_t i; @@ -31,7 +31,7 @@ equal(cube_t c1, cube_t c2) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t invertco(cube_t c) { uint8_t i, piece, orien; @@ -40,44 +40,44 @@ invertco(cube_t c) ret = c; for (i = 0; i < 8; i++) { piece = c.corner[i]; - orien = ((piece << 1) | (piece >> 1)) & _cobits2; - ret.corner[i] = (piece & _pbits) | orien; + orien = ((piece << 1) | (piece >> 1)) & COBITS_2; + ret.corner[i] = (piece & PBITS) | orien; } return ret; } -_static_inline void +STATIC_INLINE void compose_edges_inplace(cube_t c1, cube_t c2, cube_t *ret) { uint8_t i, piece1, piece2, p, orien; for (i = 0; i < 12; i++) { piece2 = c2.edge[i]; - p = piece2 & _pbits; + p = piece2 & PBITS; piece1 = c1.edge[p]; - orien = (piece2 ^ piece1) & _eobit; - ret->edge[i] = (piece1 & _pbits) | orien; + orien = (piece2 ^ piece1) & EOBIT; + ret->edge[i] = (piece1 & PBITS) | orien; } } -_static_inline void +STATIC_INLINE void compose_corners_inplace(cube_t c1, cube_t c2, cube_t *ret) { uint8_t i, piece1, piece2, p, orien, aux, auy; for (i = 0; i < 8; i++) { piece2 = c2.corner[i]; - p = piece2 & _pbits; + p = piece2 & PBITS; piece1 = c1.corner[p]; - aux = (piece2 & _cobits) + (piece1 & _cobits); - auy = (aux + _ctwist_cw) >> 2; - orien = (aux + auy) & _cobits2; - ret->corner[i] = (piece1 & _pbits) | orien; + aux = (piece2 & COBITS) + (piece1 & COBITS); + auy = (aux + CTWIST_CW) >> 2; + orien = (aux + auy) & COBITS_2; + ret->corner[i] = (piece1 & PBITS) | orien; } } -_static_inline cube_t +STATIC_INLINE cube_t compose_edges(cube_t c1, cube_t c2) { cube_t ret = zero; @@ -87,7 +87,7 @@ compose_edges(cube_t c1, cube_t c2) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t compose_corners(cube_t c1, cube_t c2) { cube_t ret = zero; @@ -97,7 +97,7 @@ compose_corners(cube_t c1, cube_t c2) return ret; } -_static_inline cube_t +STATIC_INLINE cube_t compose(cube_t c1, cube_t c2) { cube_t ret = zero; @@ -116,27 +116,27 @@ inverse(cube_t cube) for (i = 0; i < 12; i++) { piece = cube.edge[i]; - orien = piece & _eobit; - ret.edge[piece & _pbits] = i | orien; + orien = piece & EOBIT; + ret.edge[piece & PBITS] = i | orien; } for (i = 0; i < 8; i++) { piece = cube.corner[i]; - orien = ((piece << 1) | (piece >> 1)) & _cobits2; - ret.corner[piece & _pbits] = i | orien; + orien = ((piece << 1) | (piece >> 1)) & COBITS_2; + ret.corner[piece & PBITS] = i | orien; } return ret; } -_static_inline int64_t +STATIC_INLINE int64_t coord_co(cube_t c) { int i, p; int64_t ret; for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) - ret += p * (c.corner[i] >> _coshift); + ret += p * (c.corner[i] >> COSHIFT); return ret; } @@ -148,32 +148,32 @@ Ignoring the last bit, we have a value up to 2^7, but not all values are possible. Encoding this as a number from 0 to C(8,4) would save about 40% of space, but we are not going to use this coordinate in large tables. */ -_static_inline int64_t +STATIC_INLINE int64_t coord_csep(cube_t c) { int i, p; int64_t ret; for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 2) - ret += p * ((c.corner[i] & _csepbit) >> 2); + ret += p * ((c.corner[i] & CSEPBIT) >> 2); return ret; } -_static_inline int64_t +STATIC_INLINE int64_t coord_cocsep(cube_t c) { return (coord_co(c) << 7) + coord_csep(c); } -_static_inline int64_t +STATIC_INLINE int64_t coord_eo(cube_t c) { int i, p; int64_t ret; for (ret = 0, i = 1, p = 1; i < 12; i++, p *= 2) - ret += p * (c.edge[i] >> _eoshift); + ret += p * (c.edge[i] >> EOSHIFT); return ret; } @@ -182,24 +182,24 @@ coord_eo(cube_t c) We encode the edge separation as a number from 0 to C(12,4)*C(8,4). It can be seen as the composition of two "subset index" coordinates. */ -_static_inline int64_t +STATIC_INLINE int64_t coord_esep(cube_t c) { int64_t i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; for (i = 0, j = 0, k = 4, l = 4, ret1 = 0, ret2 = 0; i < 12; i++) { /* Simple version: - if (c.edge[i] & _esepbit2) { + if (c.edge[i] & ESEPBIT_2) { ret1 += binomial[11-i][k--]; } else { - if (c.edge[i] & _esepbit1) + if (c.edge[i] & ESEPBIT_1) ret2 += binomial[7-j][l--]; j++; } */ - bit1 = (c.edge[i] & _esepbit1) >> 2; - bit2 = (c.edge[i] & _esepbit2) >> 3; + bit1 = (c.edge[i] & ESEPBIT_1) >> 2; + bit2 = (c.edge[i] & ESEPBIT_2) >> 3; is1 = (1 - bit2) * bit1; ret1 += bit2 * binomial[11-i][k]; @@ -214,19 +214,19 @@ coord_esep(cube_t c) return ret1 * 70 + ret2; } -_static_inline void +STATIC_INLINE void copy_corners(cube_t *dest, cube_t src) { memcpy(&dest->corner, src.corner, sizeof(src.corner)); } -_static_inline void +STATIC_INLINE void copy_edges(cube_t *dest, cube_t src) { memcpy(&dest->edge, src.edge, sizeof(src.edge)); } -_static_inline void +STATIC_INLINE void set_eo(cube_t *cube, int64_t eo) { uint8_t i, sum, flip; @@ -234,12 +234,12 @@ set_eo(cube_t *cube, int64_t eo) for (sum = 0, i = 1; i < 12; i++, eo >>= 1) { flip = eo % 2; sum += flip; - cube->edge[i] = (cube->edge[i] & ~_eobit) | (_eobit * flip); + cube->edge[i] = (cube->edge[i] & ~EOBIT) | (EOBIT * flip); } - cube->edge[0] = (cube->edge[0] & ~_eobit) | (_eobit * (sum % 2)); + cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); } -_static_inline cube_t +STATIC_INLINE cube_t invcoord_esep(int64_t esep) { cube_t ret; diff --git a/src/core/constant_cubes.h b/src/core/constant_cubes.h @@ -1,229 +1,229 @@ -#define _move_cube_U static_cube( \ +#define MOVE_CUBE_U static_cube( \ 5, 4, 2, 3, 0, 1, 6, 7, 4, 5, 2, 3, 1, 0, 6, 7, 8, 9, 10, 11) -#define _move_cube_U2 static_cube( \ +#define MOVE_CUBE_U2 static_cube( \ 1, 0, 2, 3, 5, 4, 6, 7, 1, 0, 2, 3, 5, 4, 6, 7, 8, 9, 10, 11) -#define _move_cube_U3 static_cube( \ +#define MOVE_CUBE_U3 static_cube( \ 4, 5, 2, 3, 1, 0, 6, 7, 5, 4, 2, 3, 0, 1, 6, 7, 8, 9, 10, 11) -#define _move_cube_D static_cube( \ +#define MOVE_CUBE_D static_cube( \ 0, 1, 7, 6, 4, 5, 2, 3, 0, 1, 7, 6, 4, 5, 2, 3, 8, 9, 10, 11) -#define _move_cube_D2 static_cube( \ +#define MOVE_CUBE_D2 static_cube( \ 0, 1, 3, 2, 4, 5, 7, 6, 0, 1, 3, 2, 4, 5, 7, 6, 8, 9, 10, 11) -#define _move_cube_D3 static_cube( \ +#define MOVE_CUBE_D3 static_cube( \ 0, 1, 6, 7, 4, 5, 3, 2, 0, 1, 6, 7, 4, 5, 3, 2, 8, 9, 10, 11) -#define _move_cube_R static_cube( \ +#define MOVE_CUBE_R static_cube( \ 70, 1, 2, 69, 4, 32, 35, 7, 0, 1, 2, 3, 8, 5, 6, 11, 7, 9, 10, 4) -#define _move_cube_R2 static_cube( \ +#define MOVE_CUBE_R2 static_cube( \ 3, 1, 2, 0, 4, 6, 5, 7, 0, 1, 2, 3, 7, 5, 6, 4, 11, 9, 10, 8) -#define _move_cube_R3 static_cube( \ +#define MOVE_CUBE_R3 static_cube( \ 69, 1, 2, 70, 4, 35, 32, 7, 0, 1, 2, 3, 11, 5, 6, 8, 4, 9, 10, 7) -#define _move_cube_L static_cube( \ +#define MOVE_CUBE_L static_cube( \ 0, 71, 68, 3, 33, 5, 6, 34, 0, 1, 2, 3, 4, 10, 9, 7, 8, 5, 6, 11) -#define _move_cube_L2 static_cube( \ +#define MOVE_CUBE_L2 static_cube( \ 0, 2, 1, 3, 7, 5, 6, 4, 0, 1, 2, 3, 4, 6, 5, 7, 8, 10, 9, 11) -#define _move_cube_L3 static_cube( \ +#define MOVE_CUBE_L3 static_cube( \ 0, 68, 71, 3, 34, 5, 6, 33, 0, 1, 2, 3, 4, 9, 10, 7, 8, 6, 5, 11) -#define _move_cube_F static_cube( \ +#define MOVE_CUBE_F static_cube( \ 36, 1, 38, 3, 66, 5, 64, 7, 25, 1, 2, 24, 4, 5, 6, 7, 16, 19, 10, 11) -#define _move_cube_F2 static_cube( \ +#define MOVE_CUBE_F2 static_cube( \ 2, 1, 0, 3, 6, 5, 4, 7, 3, 1, 2, 0, 4, 5, 6, 7, 9, 8, 10, 11) -#define _move_cube_F3 static_cube( \ +#define MOVE_CUBE_F3 static_cube( \ 38, 1, 36, 3, 64, 5, 66, 7, 24, 1, 2, 25, 4, 5, 6, 7, 19, 16, 10, 11) -#define _move_cube_B static_cube( \ +#define MOVE_CUBE_B static_cube( \ 0, 37, 2, 39, 4, 67, 6, 65, 0, 27, 26, 3, 4, 5, 6, 7, 8, 9, 17, 18) -#define _move_cube_B2 static_cube( \ +#define MOVE_CUBE_B2 static_cube( \ 0, 3, 2, 1, 4, 7, 6, 5, 0, 2, 1, 3, 4, 5, 6, 7, 8, 9, 11, 10) -#define _move_cube_B3 static_cube( \ +#define MOVE_CUBE_B3 static_cube( \ 0, 39, 2, 37, 4, 65, 6, 67, 0, 26, 27, 3, 4, 5, 6, 7, 8, 9, 18, 17) -#define _trans_cube_UFr static_cube( \ +#define TRANS_CUBE_UFr static_cube( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -#define _trans_cube_UFr_inverse static_cube( \ +#define TRANS_CUBE_UFr_INVERSE static_cube( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -#define _trans_cube_ULr static_cube( \ +#define TRANS_CUBE_ULr static_cube( \ 4, 5, 7, 6, 1, 0, 2, 3, 5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24) -#define _trans_cube_ULr_inverse static_cube( \ +#define TRANS_CUBE_ULr_INVERSE static_cube( \ 5, 4, 6, 7, 0, 1, 3, 2, 4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26) -#define _trans_cube_UBr static_cube( \ +#define TRANS_CUBE_UBr static_cube( \ 1, 0, 3, 2, 5, 4, 7, 6, 1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9) -#define _trans_cube_UBr_inverse static_cube( \ +#define TRANS_CUBE_UBr_INVERSE static_cube( \ 1, 0, 3, 2, 5, 4, 7, 6, 1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9) -#define _trans_cube_URr static_cube( \ +#define TRANS_CUBE_URr static_cube( \ 5, 4, 6, 7, 0, 1, 3, 2, 4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26) -#define _trans_cube_URr_inverse static_cube( \ +#define TRANS_CUBE_URr_INVERSE static_cube( \ 4, 5, 7, 6, 1, 0, 2, 3, 5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24) -#define _trans_cube_DFr static_cube( \ +#define TRANS_CUBE_DFr static_cube( \ 2, 3, 0, 1, 6, 7, 4, 5, 3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10) -#define _trans_cube_DFr_inverse static_cube( \ +#define TRANS_CUBE_DFr_INVERSE static_cube( \ 2, 3, 0, 1, 6, 7, 4, 5, 3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10) -#define _trans_cube_DLr static_cube( \ +#define TRANS_CUBE_DLr static_cube( \ 7, 6, 4, 5, 2, 3, 1, 0, 6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27) -#define _trans_cube_DLr_inverse static_cube( \ +#define TRANS_CUBE_DLr_INVERSE static_cube( \ 7, 6, 4, 5, 2, 3, 1, 0, 6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27) -#define _trans_cube_DBr static_cube( \ +#define TRANS_CUBE_DBr static_cube( \ 3, 2, 1, 0, 7, 6, 5, 4, 2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8) -#define _trans_cube_DBr_inverse static_cube( \ +#define TRANS_CUBE_DBr_INVERSE static_cube( \ 3, 2, 1, 0, 7, 6, 5, 4, 2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8) -#define _trans_cube_DRr static_cube( \ +#define TRANS_CUBE_DRr static_cube( \ 6, 7, 5, 4, 3, 2, 0, 1, 7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25) -#define _trans_cube_DRr_inverse static_cube( \ +#define TRANS_CUBE_DRr_INVERSE static_cube( \ 6, 7, 5, 4, 3, 2, 0, 1, 7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25) -#define _trans_cube_RUr static_cube( \ +#define TRANS_CUBE_RUr static_cube( \ 64, 67, 65, 66, 37, 38, 36, 39, 20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3) -#define _trans_cube_RUr_inverse static_cube( \ +#define TRANS_CUBE_RUr_INVERSE static_cube( \ 32, 34, 35, 33, 70, 68, 69, 71, 8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21) -#define _trans_cube_RFr static_cube( \ +#define TRANS_CUBE_RFr static_cube( \ 38, 37, 36, 39, 64, 67, 66, 65, 24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18) -#define _trans_cube_RFr_inverse static_cube( \ +#define TRANS_CUBE_RFr_INVERSE static_cube( \ 36, 39, 38, 37, 66, 65, 64, 67, 25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17) -#define _trans_cube_RDr static_cube( \ +#define TRANS_CUBE_RDr static_cube( \ 67, 64, 66, 65, 38, 37, 39, 36, 23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1) -#define _trans_cube_RDr_inverse static_cube( \ +#define TRANS_CUBE_RDr_INVERSE static_cube( \ 33, 35, 34, 32, 71, 69, 68, 70, 10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20) -#define _trans_cube_RBr static_cube( \ +#define TRANS_CUBE_RBr static_cube( \ 37, 38, 39, 36, 67, 64, 65, 66, 27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16) -#define _trans_cube_RBr_inverse static_cube( \ +#define TRANS_CUBE_RBr_INVERSE static_cube( \ 37, 38, 39, 36, 67, 64, 65, 66, 27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16) -#define _trans_cube_LUr static_cube( \ +#define TRANS_CUBE_LUr static_cube( \ 65, 66, 64, 67, 36, 39, 37, 38, 21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2) -#define _trans_cube_LUr_inverse static_cube( \ +#define TRANS_CUBE_LUr_INVERSE static_cube( \ 34, 32, 33, 35, 68, 70, 71, 69, 9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23) -#define _trans_cube_LFr static_cube( \ +#define TRANS_CUBE_LFr static_cube( \ 36, 39, 38, 37, 66, 65, 64, 67, 25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17) -#define _trans_cube_LFr_inverse static_cube( \ +#define TRANS_CUBE_LFr_INVERSE static_cube( \ 38, 37, 36, 39, 64, 67, 66, 65, 24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18) -#define _trans_cube_LDr static_cube( \ +#define TRANS_CUBE_LDr static_cube( \ 66, 65, 67, 64, 39, 36, 38, 37, 22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0) -#define _trans_cube_LDr_inverse static_cube( \ +#define TRANS_CUBE_LDr_INVERSE static_cube( \ 35, 33, 32, 34, 69, 71, 70, 68, 11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22) -#define _trans_cube_LBr static_cube( \ +#define TRANS_CUBE_LBr static_cube( \ 39, 36, 37, 38, 65, 66, 67, 64, 26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19) -#define _trans_cube_LBr_inverse static_cube( \ +#define TRANS_CUBE_LBr_INVERSE static_cube( \ 39, 36, 37, 38, 65, 66, 67, 64, 26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19) -#define _trans_cube_FUr static_cube( \ +#define TRANS_CUBE_FUr static_cube( \ 68, 70, 69, 71, 32, 34, 33, 35, 16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6) -#define _trans_cube_FUr_inverse static_cube( \ +#define TRANS_CUBE_FUr_INVERSE static_cube( \ 68, 70, 69, 71, 32, 34, 33, 35, 16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6) -#define _trans_cube_FRr static_cube( \ +#define TRANS_CUBE_FRr static_cube( \ 32, 34, 35, 33, 70, 68, 69, 71, 8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21) -#define _trans_cube_FRr_inverse static_cube( \ +#define TRANS_CUBE_FRr_INVERSE static_cube( \ 64, 67, 65, 66, 37, 38, 36, 39, 20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3) -#define _trans_cube_FDr static_cube( \ +#define TRANS_CUBE_FDr static_cube( \ 70, 68, 71, 69, 34, 32, 35, 33, 19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4) -#define _trans_cube_FDr_inverse static_cube( \ +#define TRANS_CUBE_FDr_INVERSE static_cube( \ 69, 71, 68, 70, 33, 35, 32, 34, 17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7) -#define _trans_cube_FLr static_cube( \ +#define TRANS_CUBE_FLr static_cube( \ 34, 32, 33, 35, 68, 70, 71, 69, 9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23) -#define _trans_cube_FLr_inverse static_cube( \ +#define TRANS_CUBE_FLr_INVERSE static_cube( \ 65, 66, 64, 67, 36, 39, 37, 38, 21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2) -#define _trans_cube_BUr static_cube( \ +#define TRANS_CUBE_BUr static_cube( \ 69, 71, 68, 70, 33, 35, 32, 34, 17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7) -#define _trans_cube_BUr_inverse static_cube( \ +#define TRANS_CUBE_BUr_INVERSE static_cube( \ 70, 68, 71, 69, 34, 32, 35, 33, 19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4) -#define _trans_cube_BRr static_cube( \ +#define TRANS_CUBE_BRr static_cube( \ 35, 33, 32, 34, 69, 71, 70, 68, 11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22) -#define _trans_cube_BRr_inverse static_cube( \ +#define TRANS_CUBE_BRr_INVERSE static_cube( \ 66, 65, 67, 64, 39, 36, 38, 37, 22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0) -#define _trans_cube_BDr static_cube( \ +#define TRANS_CUBE_BDr static_cube( \ 71, 69, 70, 68, 35, 33, 34, 32, 18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5) -#define _trans_cube_BDr_inverse static_cube( \ +#define TRANS_CUBE_BDr_INVERSE static_cube( \ 71, 69, 70, 68, 35, 33, 34, 32, 18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5) -#define _trans_cube_BLr static_cube( \ +#define TRANS_CUBE_BLr static_cube( \ 33, 35, 34, 32, 71, 69, 68, 70, 10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20) -#define _trans_cube_BLr_inverse static_cube( \ +#define TRANS_CUBE_BLr_INVERSE static_cube( \ 67, 64, 66, 65, 38, 37, 39, 36, 23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1) -#define _trans_cube_UFm static_cube( \ +#define TRANS_CUBE_UFm static_cube( \ 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10) -#define _trans_cube_UFm_inverse static_cube( \ +#define TRANS_CUBE_UFm_INVERSE static_cube( \ 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10) -#define _trans_cube_ULm static_cube( \ +#define TRANS_CUBE_ULm static_cube( \ 0, 1, 3, 2, 5, 4, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25) -#define _trans_cube_ULm_inverse static_cube( \ +#define TRANS_CUBE_ULm_INVERSE static_cube( \ 0, 1, 3, 2, 5, 4, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25) -#define _trans_cube_UBm static_cube( \ +#define TRANS_CUBE_UBm static_cube( \ 5, 4, 7, 6, 1, 0, 3, 2, 1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8) -#define _trans_cube_UBm_inverse static_cube( \ +#define TRANS_CUBE_UBm_INVERSE static_cube( \ 5, 4, 7, 6, 1, 0, 3, 2, 1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8) -#define _trans_cube_URm static_cube( \ +#define TRANS_CUBE_URm static_cube( \ 1, 0, 2, 3, 4, 5, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27) -#define _trans_cube_URm_inverse static_cube( \ +#define TRANS_CUBE_URm_INVERSE static_cube( \ 1, 0, 2, 3, 4, 5, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27) -#define _trans_cube_DFm static_cube( \ +#define TRANS_CUBE_DFm static_cube( \ 6, 7, 4, 5, 2, 3, 0, 1, 3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11) -#define _trans_cube_DFm_inverse static_cube( \ +#define TRANS_CUBE_DFm_INVERSE static_cube( \ 6, 7, 4, 5, 2, 3, 0, 1, 3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11) -#define _trans_cube_DLm static_cube( \ +#define TRANS_CUBE_DLm static_cube( \ 3, 2, 0, 1, 6, 7, 5, 4, 7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26) -#define _trans_cube_DLm_inverse static_cube( \ +#define TRANS_CUBE_DLm_INVERSE static_cube( \ 2, 3, 1, 0, 7, 6, 4, 5, 6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24) -#define _trans_cube_DBm static_cube( \ +#define TRANS_CUBE_DBm static_cube( \ 7, 6, 5, 4, 3, 2, 1, 0, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9) -#define _trans_cube_DBm_inverse static_cube( \ +#define TRANS_CUBE_DBm_INVERSE static_cube( \ 7, 6, 5, 4, 3, 2, 1, 0, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9) -#define _trans_cube_DRm static_cube( \ +#define TRANS_CUBE_DRm static_cube( \ 2, 3, 1, 0, 7, 6, 4, 5, 6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24) -#define _trans_cube_DRm_inverse static_cube( \ +#define TRANS_CUBE_DRm_INVERSE static_cube( \ 3, 2, 0, 1, 6, 7, 5, 4, 7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26) -#define _trans_cube_RUm static_cube( \ +#define TRANS_CUBE_RUm static_cube( \ 68, 71, 69, 70, 33, 34, 32, 35, 21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3) -#define _trans_cube_RUm_inverse static_cube( \ +#define TRANS_CUBE_RUm_INVERSE static_cube( \ 70, 68, 69, 71, 32, 34, 35, 33, 8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22) -#define _trans_cube_RFm static_cube( \ +#define TRANS_CUBE_RFm static_cube( \ 34, 33, 32, 35, 68, 71, 70, 69, 25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18) -#define _trans_cube_RFm_inverse static_cube( \ +#define TRANS_CUBE_RFm_INVERSE static_cube( \ 66, 65, 64, 67, 36, 39, 38, 37, 25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18) -#define _trans_cube_RDm static_cube( \ +#define TRANS_CUBE_RDm static_cube( \ 71, 68, 70, 69, 34, 33, 35, 32, 22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1) -#define _trans_cube_RDm_inverse static_cube( \ +#define TRANS_CUBE_RDm_INVERSE static_cube( \ 71, 69, 68, 70, 33, 35, 34, 32, 10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23) -#define _trans_cube_RBm static_cube( \ +#define TRANS_CUBE_RBm static_cube( \ 33, 34, 35, 32, 71, 68, 69, 70, 26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16) -#define _trans_cube_RBm_inverse static_cube( \ +#define TRANS_CUBE_RBm_INVERSE static_cube( \ 67, 64, 65, 66, 37, 38, 39, 36, 27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19) -#define _trans_cube_LUm static_cube( \ +#define TRANS_CUBE_LUm static_cube( \ 69, 70, 68, 71, 32, 35, 33, 34, 20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2) -#define _trans_cube_LUm_inverse static_cube( \ +#define TRANS_CUBE_LUm_INVERSE static_cube( \ 68, 70, 71, 69, 34, 32, 33, 35, 9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20) -#define _trans_cube_LFm static_cube( \ +#define TRANS_CUBE_LFm static_cube( \ 32, 35, 34, 33, 70, 69, 68, 71, 24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17) -#define _trans_cube_LFm_inverse static_cube( \ +#define TRANS_CUBE_LFm_INVERSE static_cube( \ 64, 67, 66, 65, 38, 37, 36, 39, 24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17) -#define _trans_cube_LDm static_cube( \ +#define TRANS_CUBE_LDm static_cube( \ 70, 69, 71, 68, 35, 32, 34, 33, 23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0) -#define _trans_cube_LDm_inverse static_cube( \ +#define TRANS_CUBE_LDm_INVERSE static_cube( \ 69, 71, 70, 68, 35, 33, 32, 34, 11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21) -#define _trans_cube_LBm static_cube( \ +#define TRANS_CUBE_LBm static_cube( \ 35, 32, 33, 34, 69, 70, 71, 68, 27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19) -#define _trans_cube_LBm_inverse static_cube( \ +#define TRANS_CUBE_LBm_INVERSE static_cube( \ 65, 66, 67, 64, 39, 36, 37, 38, 26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16) -#define _trans_cube_FUm static_cube( \ +#define TRANS_CUBE_FUm static_cube( \ 64, 66, 65, 67, 36, 38, 37, 39, 16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7) -#define _trans_cube_FUm_inverse static_cube( \ +#define TRANS_CUBE_FUm_INVERSE static_cube( \ 32, 34, 33, 35, 68, 70, 69, 71, 16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7) -#define _trans_cube_FRm static_cube( \ +#define TRANS_CUBE_FRm static_cube( \ 36, 38, 39, 37, 66, 64, 65, 67, 9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20) -#define _trans_cube_FRm_inverse static_cube( \ +#define TRANS_CUBE_FRm_INVERSE static_cube( \ 37, 38, 36, 39, 64, 67, 65, 66, 20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2) -#define _trans_cube_FDm static_cube( \ +#define TRANS_CUBE_FDm static_cube( \ 66, 64, 67, 65, 38, 36, 39, 37, 19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5) -#define _trans_cube_FDm_inverse static_cube( \ +#define TRANS_CUBE_FDm_INVERSE static_cube( \ 33, 35, 32, 34, 69, 71, 68, 70, 17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6) -#define _trans_cube_FLm static_cube( \ +#define TRANS_CUBE_FLm static_cube( \ 38, 36, 37, 39, 64, 66, 67, 65, 8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22) -#define _trans_cube_FLm_inverse static_cube( \ +#define TRANS_CUBE_FLm_INVERSE static_cube( \ 36, 39, 37, 38, 65, 66, 64, 67, 21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3) -#define _trans_cube_BUm static_cube( \ +#define TRANS_CUBE_BUm static_cube( \ 65, 67, 64, 66, 37, 39, 36, 38, 17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6) -#define _trans_cube_BUm_inverse static_cube( \ +#define TRANS_CUBE_BUm_INVERSE static_cube( \ 34, 32, 35, 33, 70, 68, 71, 69, 19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5) -#define _trans_cube_BRm static_cube( \ +#define TRANS_CUBE_BRm static_cube( \ 39, 37, 36, 38, 65, 67, 66, 64, 10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23) -#define _trans_cube_BRm_inverse static_cube( \ +#define TRANS_CUBE_BRm_INVERSE static_cube( \ 39, 36, 38, 37, 66, 65, 67, 64, 22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1) -#define _trans_cube_BDm static_cube( \ +#define TRANS_CUBE_BDm static_cube( \ 67, 65, 66, 64, 39, 37, 38, 36, 18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4) -#define _trans_cube_BDm_inverse static_cube( \ +#define TRANS_CUBE_BDm_INVERSE static_cube( \ 35, 33, 34, 32, 71, 69, 70, 68, 18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4) -#define _trans_cube_BLm static_cube( \ +#define TRANS_CUBE_BLm static_cube( \ 37, 39, 38, 36, 67, 65, 64, 66, 11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21) -#define _trans_cube_BLm_inverse static_cube( \ +#define TRANS_CUBE_BLm_INVERSE static_cube( \ 38, 37, 39, 36, 67, 64, 66, 65, 23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0) diff --git a/src/core/cube.h b/src/core/cube.h @@ -1,13 +1,13 @@ -_static cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]); -_static cube_t solvedcube(void); -_static bool isconsistent(cube_t); -_static bool issolvable(cube_t); -_static bool issolved(cube_t); -_static bool iserror(cube_t); -_static void getcube_fix(int64_t *, int64_t *, int64_t *, int64_t *); -_static cube_t getcube(int64_t, int64_t, int64_t, int64_t); - -_static cube_t +STATIC cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]); +STATIC cube_t solvedcube(void); +STATIC bool isconsistent(cube_t); +STATIC bool issolvable(cube_t); +STATIC bool issolved(cube_t); +STATIC bool iserror(cube_t); +STATIC void getcube_fix(int64_t *, int64_t *, int64_t *, int64_t *); +STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); + +STATIC cube_t cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) { return static_cube( @@ -16,13 +16,13 @@ cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) e[8], e[9], e[10], e[11]); } -_static cube_t +STATIC cube_t solvedcube(void) { return solved; } -_static bool +STATIC bool isconsistent(cube_t cube) { uint8_t i, p, e, piece, corner[8], edge[12]; @@ -34,11 +34,11 @@ isconsistent(cube_t cube) found[i] = false; for (i = 0; i < 12; i++) { piece = edge[i]; - p = piece & _pbits; - e = piece & _eobit; + p = piece & PBITS; + e = piece & EOBIT; if (p >= 12) goto inconsistent_ep; - if (e != 0 && e != _eobit) + if (e != 0 && e != EOBIT) goto inconsistent_eo; found[p] = true; } @@ -50,11 +50,11 @@ isconsistent(cube_t cube) found[i] = false; for (i = 0; i < 8; i++) { piece = corner[i]; - p = piece & _pbits; - e = piece & _cobits; + p = piece & PBITS; + e = piece & COBITS; if (p >= 8) goto inconsistent_cp; - if (e != 0 && e != _ctwist_cw && e != _ctwist_ccw) + if (e != 0 && e != CTWIST_CW && e != CTWIST_CCW) goto inconsistent_co; found[p] = true; } @@ -78,7 +78,7 @@ inconsistent_co: return false; } -_static bool +STATIC bool issolvable(cube_t cube) { uint8_t i, eo, co, piece, edge[12], corner[8], ep[12], cp[8]; @@ -88,9 +88,9 @@ issolvable(cube_t cube) pieces(&cube, corner, edge); for (i = 0; i < 12; i++) - ep[i] = edge[i] & _pbits; + ep[i] = edge[i] & PBITS; for (i = 0; i < 8; i++) - cp[i] = corner[i] & _pbits; + cp[i] = corner[i] & PBITS; if (permsign(ep, 12) != permsign(cp, 8)) goto issolvable_parity; @@ -98,7 +98,7 @@ issolvable(cube_t cube) eo = 0; for (i = 0; i < 12; i++) { piece = edge[i]; - eo += (piece & _eobit) >> _eoshift; + eo += (piece & EOBIT) >> EOSHIFT; } if (eo % 2 != 0) goto issolvable_eo; @@ -106,7 +106,7 @@ issolvable(cube_t cube) co = 0; for (i = 0; i < 8; i++) { piece = corner[i]; - co += (piece & _cobits) >> _coshift; + co += (piece & COBITS) >> COSHIFT; } if (co % 3 != 0) goto issolvable_co; @@ -136,15 +136,15 @@ iserror(cube_t cube) return equal(cube, zero); } -_static void +STATIC void getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) { uint8_t e[12], c[8], coarr[8]; - *ep = (*ep % _12f + _12f) % _12f; - *eo = (*eo % _2p11 + _2p11) % _2p11; - *cp = (*cp % _8f + _8f) % _8f; - *co = (*cp % _3p7 + _3p7) % _3p7; + *ep = (*ep % FACT_12 + FACT_12) % FACT_12; + *eo = (*eo % POW_2_11 + POW_2_11) % POW_2_11; + *cp = (*cp % FACT_8 + FACT_8) % FACT_8; + *co = (*cp % POW_3_7 + POW_3_7) % POW_3_7; indextoperm(*ep, 12, e); indextoperm(*cp, 8, c); @@ -158,24 +158,24 @@ getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) } } -_static cube_t +STATIC cube_t getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co) { uint8_t i, earr[12], carr[8], eoarr[12], coarr[8]; sumzerotodigits(eo, 12, 2, eoarr); - DBG_ASSERT(eoarr[0] != _error, zero, "Error making EO"); + DBG_ASSERT(eoarr[0] != UINT8_ERROR, zero, "Error making EO"); indextoperm(ep, 12, earr); - DBG_ASSERT(earr[0] != _error, zero, "Error making EP"); + DBG_ASSERT(earr[0] != UINT8_ERROR, zero, "Error making EP"); for (i = 0; i < 12; i++) - earr[i] |= eoarr[i] << _eoshift; + earr[i] |= eoarr[i] << EOSHIFT; sumzerotodigits(co, 8, 3, coarr); - DBG_ASSERT(coarr[0] != _error, zero, "Error making CO"); + DBG_ASSERT(coarr[0] != UINT8_ERROR, zero, "Error making CO"); indextoperm(cp, 8, carr); - DBG_ASSERT(carr[0] != _error, zero, "Error making CP"); + DBG_ASSERT(carr[0] != UINT8_ERROR, zero, "Error making CP"); for (i = 0; i < 8; i++) - carr[i] |= coarr[i] << _coshift; + carr[i] |= coarr[i] << COSHIFT; return cubefromarray(carr, earr); } diff --git a/src/core/io_cube.h b/src/core/io_cube.h @@ -1,23 +1,23 @@ -_static uint8_t readco(const char *); -_static uint8_t readcp(const char *); -_static uint8_t readeo(const char *); -_static uint8_t readep(const char *); -_static cube_t readcube_B32(const char *); -_static cube_t readcube_H48(const char *); -_static uint8_t readpiece_LST(const char **); -_static cube_t readcube_LST(const char *); - -_static int writepiece_LST(uint8_t, char *); -_static void writecube_B32(cube_t, char *); -_static void writecube_H48(cube_t, char *); -_static void writecube_LST(cube_t, char *); - -_static uint8_t b32toedge(char); -_static uint8_t b32tocorner(char); -_static char edgetob32(uint8_t); -_static char cornertob32(uint8_t); - -_static struct { +STATIC uint8_t readco(const char *); +STATIC uint8_t readcp(const char *); +STATIC uint8_t readeo(const char *); +STATIC uint8_t readep(const char *); +STATIC cube_t readcube_B32(const char *); +STATIC cube_t readcube_H48(const char *); +STATIC uint8_t readpiece_LST(const char **); +STATIC cube_t readcube_LST(const char *); + +STATIC int writepiece_LST(uint8_t, char *); +STATIC void writecube_B32(cube_t, char *); +STATIC void writecube_H48(cube_t, char *); +STATIC void writecube_LST(cube_t, char *); + +STATIC uint8_t b32toedge(char); +STATIC uint8_t b32tocorner(char); +STATIC char edgetob32(uint8_t); +STATIC char cornertob32(uint8_t); + +STATIC struct { const char *name; cube_t (*read)(const char *); void (*write)(cube_t, char *); @@ -72,21 +72,21 @@ writecube_error: buf[len+1] = '\0'; } -_static uint8_t +STATIC uint8_t readco(const char *str) { if (*str == '0') return 0; if (*str == '1') - return _ctwist_cw; + return CTWIST_CW; if (*str == '2') - return _ctwist_ccw; + return CTWIST_CCW; LOG("Error reading CO\n"); - return _error; + return UINT8_ERROR; } -_static uint8_t +STATIC uint8_t readcp(const char *str) { uint8_t c; @@ -97,22 +97,22 @@ readcp(const char *str) return c; LOG("Error reading CP\n"); - return _error; + return UINT8_ERROR; } -_static uint8_t +STATIC uint8_t readeo(const char *str) { if (*str == '0') return 0; if (*str == '1') - return _eflip; + return EFLIP; LOG("Error reading EO\n"); - return _error; + return UINT8_ERROR; } -_static uint8_t +STATIC uint8_t readep(const char *str) { uint8_t e; @@ -122,10 +122,10 @@ readep(const char *str) return e; LOG("Error reading EP\n"); - return _error; + return UINT8_ERROR; } -_static cube_t +STATIC cube_t readcube_B32(const char *buf) { int i; @@ -146,7 +146,7 @@ readcube_B32(const char *buf) return cubefromarray(c, e); } -_static cube_t +STATIC cube_t readcube_H48(const char *buf) { int i; @@ -158,10 +158,10 @@ readcube_H48(const char *buf) for (i = 0; i < 12; i++) { while (*b == ' ' || *b == '\t' || *b == '\n') b++; - if ((piece = readep(b)) == _error) + if ((piece = readep(b)) == UINT8_ERROR) return zero; b += 2; - if ((orient = readeo(b)) == _error) + if ((orient = readeo(b)) == UINT8_ERROR) return zero; b++; e[i] = piece | orient; @@ -169,10 +169,10 @@ readcube_H48(const char *buf) for (i = 0; i < 8; i++) { while (*b == ' ' || *b == '\t' || *b == '\n') b++; - if ((piece = readcp(b)) == _error) + if ((piece = readcp(b)) == UINT8_ERROR) return zero; b += 3; - if ((orient = readco(b)) == _error) + if ((orient = readco(b)) == UINT8_ERROR) return zero; b++; c[i] = piece | orient; @@ -181,7 +181,7 @@ readcube_H48(const char *buf) return cubefromarray(c, e); } -_static uint8_t +STATIC uint8_t readpiece_LST(const char **b) { uint8_t ret; @@ -195,10 +195,10 @@ readpiece_LST(const char **b) ret = ret * 10 + (**b) - '0'; } - return read ? ret : _error; + return read ? ret : UINT8_ERROR; } -_static cube_t +STATIC cube_t readcube_LST(const char *buf) { int i; @@ -213,7 +213,7 @@ readcube_LST(const char *buf) return cubefromarray(c, e); } -_static int +STATIC int writepiece_LST(uint8_t piece, char *buf) { char digits[3]; @@ -237,7 +237,7 @@ writepiece_LST(uint8_t piece, char *buf) return len+2; } -_static void +STATIC void writecube_B32(cube_t cube, char *buf) { int i; @@ -256,7 +256,7 @@ writecube_B32(cube_t cube, char *buf) buf[21] = '\0'; } -_static void +STATIC void writecube_H48(cube_t cube, char *buf) { uint8_t piece, perm, orient, corner[8], edge[12]; @@ -266,8 +266,8 @@ writecube_H48(cube_t cube, char *buf) for (i = 0; i < 12; i++) { piece = edge[i]; - perm = piece & _pbits; - orient = (piece & _eobit) >> _eoshift; + perm = piece & PBITS; + orient = (piece & EOBIT) >> EOSHIFT; buf[4*i ] = edgestr[perm][0]; buf[4*i + 1] = edgestr[perm][1]; buf[4*i + 2] = orient + '0'; @@ -275,8 +275,8 @@ writecube_H48(cube_t cube, char *buf) } for (i = 0; i < 8; i++) { piece = corner[i]; - perm = piece & _pbits; - orient = (piece & _cobits) >> _coshift; + perm = piece & PBITS; + orient = (piece & COBITS) >> COSHIFT; buf[48 + 5*i ] = cornerstr[perm][0]; buf[48 + 5*i + 1] = cornerstr[perm][1]; buf[48 + 5*i + 2] = cornerstr[perm][2]; @@ -287,7 +287,7 @@ writecube_H48(cube_t cube, char *buf) buf[48+39] = '\0'; } -_static void +STATIC void writecube_LST(cube_t cube, char *buf) { int i; @@ -310,7 +310,7 @@ writecube_LST(cube_t cube, char *buf) *(buf+ptr-2) = 0; } -_static uint8_t +STATIC uint8_t b32toedge(char c) { if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) @@ -319,7 +319,7 @@ b32toedge(char c) return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; } -_static uint8_t +STATIC uint8_t b32tocorner(char c) { uint8_t val; @@ -331,13 +331,13 @@ b32tocorner(char c) { return (val & 7) | ((val & 24) << 2); } -_static char +STATIC char edgetob32(uint8_t edge) { return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26); } -_static char +STATIC char cornertob32(uint8_t corner) { uint8_t val; diff --git a/src/core/io_moves.h b/src/core/io_moves.h @@ -1,29 +1,29 @@ -_static uint8_t readmove(char); -_static uint8_t readmodifier(char); -_static int writemoves(uint8_t *, int, char *); +STATIC uint8_t readmove(char); +STATIC uint8_t readmodifier(char); +STATIC int writemoves(uint8_t *, int, char *); -_static uint8_t +STATIC uint8_t readmove(char c) { switch (c) { case 'U': - return _move_U; + return MOVE_U; case 'D': - return _move_D; + return MOVE_D; case 'R': - return _move_R; + return MOVE_R; case 'L': - return _move_L; + return MOVE_L; case 'F': - return _move_F; + return MOVE_F; case 'B': - return _move_B; + return MOVE_B; default: - return _error; + return UINT8_ERROR; } } -_static uint8_t +STATIC uint8_t readmodifier(char c) { switch (c) { @@ -38,7 +38,7 @@ readmodifier(char c) } } -_static int +STATIC int writemoves(uint8_t *m, int n, char *buf) { int i; diff --git a/src/core/io_trans.h b/src/core/io_trans.h @@ -1,7 +1,7 @@ -_static uint8_t readtrans(const char *); -_static void writetrans(uint8_t, char *); +STATIC uint8_t readtrans(const char *); +STATIC void writetrans(uint8_t, char *); -_static uint8_t +STATIC uint8_t readtrans(const char *buf) { uint8_t t; @@ -11,10 +11,10 @@ readtrans(const char *buf) return t; LOG("readtrans error\n"); - return _error; + return UINT8_ERROR; } -_static void +STATIC void writetrans(uint8_t t, char *buf) { if (t >= 48) diff --git a/src/core/moves.h b/src/core/moves.h @@ -1,22 +1,22 @@ -#define _move(M, c) compose(c, _move_cube_ ## M) -#define _premove(M, c) compose(_move_cube_ ## M, c) +#define _move(M, c) compose(c, MOVE_CUBE_ ## M) +#define _premove(M, c) compose(MOVE_CUBE_ ## M, c) -_static_inline bool allowednextmove(uint8_t *, uint8_t); +STATIC_INLINE bool allowednextmove(uint8_t *, uint8_t); -_static_inline uint8_t inverse_trans(uint8_t); -_static_inline uint8_t movebase(uint8_t); -_static_inline uint8_t moveaxis(uint8_t); -_static_inline uint32_t disable_moves(uint32_t, uint8_t); +STATIC_INLINE uint8_t inverse_trans(uint8_t); +STATIC_INLINE uint8_t movebase(uint8_t); +STATIC_INLINE uint8_t moveaxis(uint8_t); +STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); -_static cube_t move(cube_t, uint8_t); -_static cube_t premove(cube_t, uint8_t); -_static uint8_t inverse_move(uint8_t); -_static void invertmoves(uint8_t *, uint8_t, uint8_t *); +STATIC cube_t move(cube_t, uint8_t); +STATIC cube_t premove(cube_t, uint8_t); +STATIC uint8_t inverse_move(uint8_t); +STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); -_static cube_t applymoves(cube_t, const char *); -_static cube_t frommoves(const char *); +STATIC cube_t applymoves(cube_t, const char *); +STATIC cube_t frommoves(const char *); -_static bool +STATIC bool allowednextmove(uint8_t *moves, uint8_t n) { uint8_t base[3], axis[3]; @@ -41,69 +41,69 @@ allowednextmove(uint8_t *moves, uint8_t n) return axis[1] != axis[2] || base[0] != base[2]; } -_static_inline uint32_t +STATIC_INLINE uint32_t disable_moves(uint32_t current_result, uint8_t base_index) { return current_result & ~(7 << base_index); } -_static_inline uint8_t +STATIC_INLINE uint8_t inverse_trans(uint8_t t) { return inverse_trans_table[t]; } -_static_inline uint8_t +STATIC_INLINE uint8_t movebase(uint8_t move) { return move / 3; } -_static_inline uint8_t +STATIC_INLINE uint8_t moveaxis(uint8_t move) { return move / 6; } -_static cube_t +STATIC cube_t move(cube_t c, uint8_t m) { switch (m) { - case _move_U: + case MOVE_U: return _move(U, c); - case _move_U2: + case MOVE_U2: return _move(U2, c); - case _move_U3: + case MOVE_U3: return _move(U3, c); - case _move_D: + case MOVE_D: return _move(D, c); - case _move_D2: + case MOVE_D2: return _move(D2, c); - case _move_D3: + case MOVE_D3: return _move(D3, c); - case _move_R: + case MOVE_R: return _move(R, c); - case _move_R2: + case MOVE_R2: return _move(R2, c); - case _move_R3: + case MOVE_R3: return _move(R3, c); - case _move_L: + case MOVE_L: return _move(L, c); - case _move_L2: + case MOVE_L2: return _move(L2, c); - case _move_L3: + case MOVE_L3: return _move(L3, c); - case _move_F: + case MOVE_F: return _move(F, c); - case _move_F2: + case MOVE_F2: return _move(F2, c); - case _move_F3: + case MOVE_F3: return _move(F3, c); - case _move_B: + case MOVE_B: return _move(B, c); - case _move_B2: + case MOVE_B2: return _move(B2, c); - case _move_B3: + case MOVE_B3: return _move(B3, c); default: LOG("move error, unknown move\n"); @@ -111,45 +111,45 @@ move(cube_t c, uint8_t m) } } -_static cube_t +STATIC cube_t premove(cube_t c, uint8_t m) { switch (m) { - case _move_U: + case MOVE_U: return _premove(U3, c); - case _move_U2: + case MOVE_U2: return _premove(U2, c); - case _move_U3: + case MOVE_U3: return _premove(U, c); - case _move_D: + case MOVE_D: return _premove(D3, c); - case _move_D2: + case MOVE_D2: return _premove(D2, c); - case _move_D3: + case MOVE_D3: return _premove(D, c); - case _move_R: + case MOVE_R: return _premove(R3, c); - case _move_R2: + case MOVE_R2: return _premove(R2, c); - case _move_R3: + case MOVE_R3: return _premove(R, c); - case _move_L: + case MOVE_L: return _premove(L3, c); - case _move_L2: + case MOVE_L2: return _premove(L2, c); - case _move_L3: + case MOVE_L3: return _premove(L, c); - case _move_F: + case MOVE_F: return _premove(F3, c); - case _move_F2: + case MOVE_F2: return _premove(F2, c); - case _move_F3: + case MOVE_F3: return _premove(F, c); - case _move_B: + case MOVE_B: return _premove(B3, c); - case _move_B2: + case MOVE_B2: return _premove(B2, c); - case _move_B3: + case MOVE_B3: return _premove(B, c); default: LOG("move error, unknown move\n"); @@ -157,13 +157,13 @@ premove(cube_t c, uint8_t m) } } -_static uint8_t +STATIC uint8_t inverse_move(uint8_t m) { return m - 2 * (m % 3) + 2; } -_static void +STATIC void invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret) { uint8_t i; @@ -172,7 +172,7 @@ invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret) ret[i] = inverse_move(moves[nmoves - i - 1]); } -_static cube_t +STATIC cube_t applymoves(cube_t cube, const char *buf) { uint8_t r, m; @@ -186,7 +186,7 @@ applymoves(cube_t cube, const char *buf) b++; if (*b == '\0') goto applymoves_finish; - if ((r = readmove(*b)) == _error) + if ((r = readmove(*b)) == UINT8_ERROR) goto applymoves_error; if ((m = readmodifier(*(b+1))) != 0) b++; @@ -201,7 +201,7 @@ applymoves_error: return zero; } -_static cube_t +STATIC cube_t frommoves(const char *buf) { return applymoves(solved, buf); diff --git a/src/core/transform.h b/src/core/transform.h @@ -1,132 +1,111 @@ -/* TODO: remove these macros, if the below works */ - -#define _trans_edges_rotation(T, c) \ - compose_edges(compose_edges(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse) -#define _trans_edges_mirrored(T, c) _trans_edges_rotation(T, c) - -#define _trans_corners_rotation(T, c) \ - compose_corners(compose_corners(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse) -#define _trans_corners_mirrored(T, c) \ - invertco(compose_corners( \ - compose_corners(_trans_cube_ ## T, c), _trans_cube_ ## T ## _inverse)) - -#define _trans_rotation(T, c) \ - compose(compose(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse) -#define _trans_mirrored(T, c) \ - invertco(compose(compose(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse)) - -_static cube_t transform_edges(cube_t, uint8_t); -_static cube_t transform_corners(cube_t, uint8_t); -_static cube_t transform(cube_t, uint8_t); -_static cube_t applytrans(cube_t, const char *); +STATIC cube_t transform_edges(cube_t, uint8_t); +STATIC cube_t transform_corners(cube_t, uint8_t); +STATIC cube_t transform(cube_t, uint8_t); +STATIC cube_t applytrans(cube_t, const char *); static cube_t cube_trans_table[48] = { - [_trans_UFr] = _trans_cube_UFr, - [_trans_UFm] = _trans_cube_UFm, - [_trans_ULr] = _trans_cube_URr, - [_trans_ULm] = _trans_cube_ULm, - [_trans_UBr] = _trans_cube_UBr, - [_trans_UBm] = _trans_cube_UBm, - [_trans_URr] = _trans_cube_ULr, - [_trans_URm] = _trans_cube_URm, - [_trans_DFr] = _trans_cube_DFr, - [_trans_DFm] = _trans_cube_DFm, - [_trans_DLr] = _trans_cube_DLr, - [_trans_DLm] = _trans_cube_DRm, - [_trans_DBr] = _trans_cube_DBr, - [_trans_DBm] = _trans_cube_DBm, - [_trans_DRr] = _trans_cube_DRr, - [_trans_DRm] = _trans_cube_DLm, - [_trans_RUr] = _trans_cube_FRr, - [_trans_RUm] = _trans_cube_FLm, - [_trans_RFr] = _trans_cube_LFr, - [_trans_RFm] = _trans_cube_RFm, - [_trans_RDr] = _trans_cube_BLr, - [_trans_RDm] = _trans_cube_BRm, - [_trans_RBr] = _trans_cube_RBr, - [_trans_RBm] = _trans_cube_LBm, - [_trans_LUr] = _trans_cube_FLr, - [_trans_LUm] = _trans_cube_FRm, - [_trans_LFr] = _trans_cube_RFr, - [_trans_LFm] = _trans_cube_LFm, - [_trans_LDr] = _trans_cube_BRr, - [_trans_LDm] = _trans_cube_BLm, - [_trans_LBr] = _trans_cube_LBr, - [_trans_LBm] = _trans_cube_RBm, - [_trans_FUr] = _trans_cube_FUr, - [_trans_FUm] = _trans_cube_FUm, - [_trans_FRr] = _trans_cube_RUr, - [_trans_FRm] = _trans_cube_LUm, - [_trans_FDr] = _trans_cube_BUr, - [_trans_FDm] = _trans_cube_BUm, - [_trans_FLr] = _trans_cube_LUr, - [_trans_FLm] = _trans_cube_RUm, - [_trans_BUr] = _trans_cube_FDr, - [_trans_BUm] = _trans_cube_FDm, - [_trans_BRr] = _trans_cube_LDr, - [_trans_BRm] = _trans_cube_RDm, - [_trans_BDr] = _trans_cube_BDr, - [_trans_BDm] = _trans_cube_BDm, - [_trans_BLr] = _trans_cube_RDr, - [_trans_BLm] = _trans_cube_LDm, + [TRANS_UFr] = TRANS_CUBE_UFr, + [TRANS_UFm] = TRANS_CUBE_UFm, + [TRANS_ULr] = TRANS_CUBE_URr, + [TRANS_ULm] = TRANS_CUBE_ULm, + [TRANS_UBr] = TRANS_CUBE_UBr, + [TRANS_UBm] = TRANS_CUBE_UBm, + [TRANS_URr] = TRANS_CUBE_ULr, + [TRANS_URm] = TRANS_CUBE_URm, + [TRANS_DFr] = TRANS_CUBE_DFr, + [TRANS_DFm] = TRANS_CUBE_DFm, + [TRANS_DLr] = TRANS_CUBE_DLr, + [TRANS_DLm] = TRANS_CUBE_DRm, + [TRANS_DBr] = TRANS_CUBE_DBr, + [TRANS_DBm] = TRANS_CUBE_DBm, + [TRANS_DRr] = TRANS_CUBE_DRr, + [TRANS_DRm] = TRANS_CUBE_DLm, + [TRANS_RUr] = TRANS_CUBE_FRr, + [TRANS_RUm] = TRANS_CUBE_FLm, + [TRANS_RFr] = TRANS_CUBE_LFr, + [TRANS_RFm] = TRANS_CUBE_RFm, + [TRANS_RDr] = TRANS_CUBE_BLr, + [TRANS_RDm] = TRANS_CUBE_BRm, + [TRANS_RBr] = TRANS_CUBE_RBr, + [TRANS_RBm] = TRANS_CUBE_LBm, + [TRANS_LUr] = TRANS_CUBE_FLr, + [TRANS_LUm] = TRANS_CUBE_FRm, + [TRANS_LFr] = TRANS_CUBE_RFr, + [TRANS_LFm] = TRANS_CUBE_LFm, + [TRANS_LDr] = TRANS_CUBE_BRr, + [TRANS_LDm] = TRANS_CUBE_BLm, + [TRANS_LBr] = TRANS_CUBE_LBr, + [TRANS_LBm] = TRANS_CUBE_RBm, + [TRANS_FUr] = TRANS_CUBE_FUr, + [TRANS_FUm] = TRANS_CUBE_FUm, + [TRANS_FRr] = TRANS_CUBE_RUr, + [TRANS_FRm] = TRANS_CUBE_LUm, + [TRANS_FDr] = TRANS_CUBE_BUr, + [TRANS_FDm] = TRANS_CUBE_BUm, + [TRANS_FLr] = TRANS_CUBE_LUr, + [TRANS_FLm] = TRANS_CUBE_RUm, + [TRANS_BUr] = TRANS_CUBE_FDr, + [TRANS_BUm] = TRANS_CUBE_FDm, + [TRANS_BRr] = TRANS_CUBE_LDr, + [TRANS_BRm] = TRANS_CUBE_RDm, + [TRANS_BDr] = TRANS_CUBE_BDr, + [TRANS_BDm] = TRANS_CUBE_BDm, + [TRANS_BLr] = TRANS_CUBE_RDr, + [TRANS_BLm] = TRANS_CUBE_LDm, }; static cube_t cube_trans_table_inverse[48] = { - [_trans_UFr] = _trans_cube_UFr_inverse, - [_trans_UFm] = _trans_cube_UFm_inverse, - [_trans_ULr] = _trans_cube_URr_inverse, - [_trans_ULm] = _trans_cube_ULm_inverse, - [_trans_UBr] = _trans_cube_UBr_inverse, - [_trans_UBm] = _trans_cube_UBm_inverse, - [_trans_URr] = _trans_cube_ULr_inverse, - [_trans_URm] = _trans_cube_URm_inverse, - [_trans_DFr] = _trans_cube_DFr_inverse, - [_trans_DFm] = _trans_cube_DFm_inverse, - [_trans_DLr] = _trans_cube_DLr_inverse, - [_trans_DLm] = _trans_cube_DRm_inverse, - [_trans_DBr] = _trans_cube_DBr_inverse, - [_trans_DBm] = _trans_cube_DBm_inverse, - [_trans_DRr] = _trans_cube_DRr_inverse, - [_trans_DRm] = _trans_cube_DLm_inverse, - [_trans_RUr] = _trans_cube_FRr_inverse, - [_trans_RUm] = _trans_cube_FLm_inverse, - [_trans_RFr] = _trans_cube_LFr_inverse, - [_trans_RFm] = _trans_cube_RFm_inverse, - [_trans_RDr] = _trans_cube_BLr_inverse, - [_trans_RDm] = _trans_cube_BRm_inverse, - [_trans_RBr] = _trans_cube_RBr_inverse, - [_trans_RBm] = _trans_cube_LBm_inverse, - [_trans_LUr] = _trans_cube_FLr_inverse, - [_trans_LUm] = _trans_cube_FRm_inverse, - [_trans_LFr] = _trans_cube_RFr_inverse, - [_trans_LFm] = _trans_cube_LFm_inverse, - [_trans_LDr] = _trans_cube_BRr_inverse, - [_trans_LDm] = _trans_cube_BLm_inverse, - [_trans_LBr] = _trans_cube_LBr_inverse, - [_trans_LBm] = _trans_cube_RBm_inverse, - [_trans_FUr] = _trans_cube_FUr_inverse, - [_trans_FUm] = _trans_cube_FUm_inverse, - [_trans_FRr] = _trans_cube_RUr_inverse, - [_trans_FRm] = _trans_cube_LUm_inverse, - [_trans_FDr] = _trans_cube_BUr_inverse, - [_trans_FDm] = _trans_cube_BUm_inverse, - [_trans_FLr] = _trans_cube_LUr_inverse, - [_trans_FLm] = _trans_cube_RUm_inverse, - [_trans_BUr] = _trans_cube_FDr_inverse, - [_trans_BUm] = _trans_cube_FDm_inverse, - [_trans_BRr] = _trans_cube_LDr_inverse, - [_trans_BRm] = _trans_cube_RDm_inverse, - [_trans_BDr] = _trans_cube_BDr_inverse, - [_trans_BDm] = _trans_cube_BDm_inverse, - [_trans_BLr] = _trans_cube_RDr_inverse, - [_trans_BLm] = _trans_cube_LDm_inverse, + [TRANS_UFr] = TRANS_CUBE_UFr_inverse, + [TRANS_UFm] = TRANS_CUBE_UFm_inverse, + [TRANS_ULr] = TRANS_CUBE_URr_inverse, + [TRANS_ULm] = TRANS_CUBE_ULm_inverse, + [TRANS_UBr] = TRANS_CUBE_UBr_inverse, + [TRANS_UBm] = TRANS_CUBE_UBm_inverse, + [TRANS_URr] = TRANS_CUBE_ULr_inverse, + [TRANS_URm] = TRANS_CUBE_URm_inverse, + [TRANS_DFr] = TRANS_CUBE_DFr_inverse, + [TRANS_DFm] = TRANS_CUBE_DFm_inverse, + [TRANS_DLr] = TRANS_CUBE_DLr_inverse, + [TRANS_DLm] = TRANS_CUBE_DRm_inverse, + [TRANS_DBr] = TRANS_CUBE_DBr_inverse, + [TRANS_DBm] = TRANS_CUBE_DBm_inverse, + [TRANS_DRr] = TRANS_CUBE_DRr_inverse, + [TRANS_DRm] = TRANS_CUBE_DLm_inverse, + [TRANS_RUr] = TRANS_CUBE_FRr_inverse, + [TRANS_RUm] = TRANS_CUBE_FLm_inverse, + [TRANS_RFr] = TRANS_CUBE_LFr_inverse, + [TRANS_RFm] = TRANS_CUBE_RFm_inverse, + [TRANS_RDr] = TRANS_CUBE_BLr_inverse, + [TRANS_RDm] = TRANS_CUBE_BRm_inverse, + [TRANS_RBr] = TRANS_CUBE_RBr_inverse, + [TRANS_RBm] = TRANS_CUBE_LBm_inverse, + [TRANS_LUr] = TRANS_CUBE_FLr_inverse, + [TRANS_LUm] = TRANS_CUBE_FRm_inverse, + [TRANS_LFr] = TRANS_CUBE_RFr_inverse, + [TRANS_LFm] = TRANS_CUBE_LFm_inverse, + [TRANS_LDr] = TRANS_CUBE_BRr_inverse, + [TRANS_LDm] = TRANS_CUBE_BLm_inverse, + [TRANS_LBr] = TRANS_CUBE_LBr_inverse, + [TRANS_LBm] = TRANS_CUBE_RBm_inverse, + [TRANS_FUr] = TRANS_CUBE_FUr_inverse, + [TRANS_FUm] = TRANS_CUBE_FUm_inverse, + [TRANS_FRr] = TRANS_CUBE_RUr_inverse, + [TRANS_FRm] = TRANS_CUBE_LUm_inverse, + [TRANS_FDr] = TRANS_CUBE_BUr_inverse, + [TRANS_FDm] = TRANS_CUBE_BUm_inverse, + [TRANS_FLr] = TRANS_CUBE_LUr_inverse, + [TRANS_FLm] = TRANS_CUBE_RUm_inverse, + [TRANS_BUr] = TRANS_CUBE_FDr_inverse, + [TRANS_BUm] = TRANS_CUBE_FDm_inverse, + [TRANS_BRr] = TRANS_CUBE_LDr_inverse, + [TRANS_BRm] = TRANS_CUBE_RDm_inverse, + [TRANS_BDr] = TRANS_CUBE_BDr_inverse, + [TRANS_BDm] = TRANS_CUBE_BDm_inverse, + [TRANS_BLr] = TRANS_CUBE_RDr_inverse, + [TRANS_BLm] = TRANS_CUBE_LDm_inverse, }; -_static cube_t +STATIC cube_t transform_edges(cube_t c, uint8_t t) { cube_t ret, trans_cube, trans_inv; @@ -144,7 +123,7 @@ transform_edges(cube_t c, uint8_t t) return ret; } -_static cube_t +STATIC cube_t transform_corners(cube_t c, uint8_t t) { cube_t ret, trans_cube, trans_inv; @@ -162,7 +141,7 @@ transform_corners(cube_t c, uint8_t t) return t < 24 ? ret : invertco(ret); } -_static cube_t +STATIC cube_t transform(cube_t c, uint8_t t) { cube_t ret, trans_cube, trans_inv; @@ -180,7 +159,7 @@ transform(cube_t c, uint8_t t) return t < 24 ? ret : invertco(ret); } -_static cube_t +STATIC cube_t applytrans(cube_t cube, const char *buf) { uint8_t t; diff --git a/src/core/transform_with_switch.h b/src/core/transform_with_switch.h @@ -1,346 +1,346 @@ -#define _trans_edges_rotation(T, c) \ - compose_edges(compose_edges(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse) -#define _trans_edges_mirrored(T, c) _trans_edges_rotation(T, c) +#define TRANS_EDGES_ROTATION(T, c) \ + compose_edges(compose_edges(TRANS_CUBE_ ## T, c), \ + TRANS_CUBE_ ## T ## _INVERSE) +#define TRANS_EDGES_MIRRORED(T, c) TRANS_EDGES_ROTATION(T, c) -#define _trans_corners_rotation(T, c) \ - compose_corners(compose_corners(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse) -#define _trans_corners_mirrored(T, c) \ +#define TRANS_CORNERS_ROTATION(T, c) \ + compose_corners(compose_corners(TRANS_CUBE_ ## T, c), \ + TRANS_CUBE_ ## T ## _INVERSE) +#define TRANS_CORNERS_MIRRORED(T, c) \ invertco(compose_corners( \ - compose_corners(_trans_cube_ ## T, c), _trans_cube_ ## T ## _inverse)) + compose_corners(TRANS_CUBE_ ## T, c), TRANS_CUBE_ ## T ## _INVERSE)) -#define _trans_rotation(T, c) \ - compose(compose(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse) -#define _trans_mirrored(T, c) \ - invertco(compose(compose(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse)) +#define TRANS_ROTATION(T, c) \ + compose(compose(TRANS_CUBE_ ## T, c), \ + TRANS_CUBE_ ## T ## _INVERSE) +#define TRANS_MIRRORED(T, c) \ + invertco(compose(compose(TRANS_CUBE_ ## T, c), \ + TRANS_CUBE_ ## T ## _INVERSE)) -_static cube_t transform_edges(cube_t, uint8_t); -_static cube_t transform_corners(cube_t, uint8_t); -_static cube_t transform(cube_t, uint8_t); -_static cube_t applytrans(cube_t, const char *); +STATIC cube_t transform_edges(cube_t, uint8_t); +STATIC cube_t transform_corners(cube_t, uint8_t); +STATIC cube_t transform(cube_t, uint8_t); +STATIC cube_t applytrans(cube_t, const char *); -_static cube_t +STATIC cube_t transform_edges(cube_t c, uint8_t t) { switch (t) { - case _trans_UFr: + case TRANS_UFr: return c; - case _trans_ULr: - return _trans_edges_rotation(ULr, c); - case _trans_UBr: - return _trans_edges_rotation(UBr, c); - case _trans_URr: - return _trans_edges_rotation(URr, c); - case _trans_DFr: - return _trans_edges_rotation(DFr, c); - case _trans_DLr: - return _trans_edges_rotation(DLr, c); - case _trans_DBr: - return _trans_edges_rotation(DBr, c); - case _trans_DRr: - return _trans_edges_rotation(DRr, c); - case _trans_RUr: - return _trans_edges_rotation(RUr, c); - case _trans_RFr: - return _trans_edges_rotation(RFr, c); - case _trans_RDr: - return _trans_edges_rotation(RDr, c); - case _trans_RBr: - return _trans_edges_rotation(RBr, c); - case _trans_LUr: - return _trans_edges_rotation(LUr, c); - case _trans_LFr: - return _trans_edges_rotation(LFr, c); - case _trans_LDr: - return _trans_edges_rotation(LDr, c); - case _trans_LBr: - return _trans_edges_rotation(LBr, c); - case _trans_FUr: - return _trans_edges_rotation(FUr, c); - case _trans_FRr: - return _trans_edges_rotation(FRr, c); - case _trans_FDr: - return _trans_edges_rotation(FDr, c); - case _trans_FLr: - return _trans_edges_rotation(FLr, c); - case _trans_BUr: - return _trans_edges_rotation(BUr, c); - case _trans_BRr: - return _trans_edges_rotation(BRr, c); - case _trans_BDr: - return _trans_edges_rotation(BDr, c); - case _trans_BLr: - return _trans_edges_rotation(BLr, c); - case _trans_UFm: - return _trans_edges_mirrored(UFm, c); - case _trans_ULm: - return _trans_edges_mirrored(ULm, c); - case _trans_UBm: - return _trans_edges_mirrored(UBm, c); - case _trans_URm: - return _trans_edges_mirrored(URm, c); - case _trans_DFm: - return _trans_edges_mirrored(DFm, c); - case _trans_DLm: - return _trans_edges_mirrored(DLm, c); - case _trans_DBm: - return _trans_edges_mirrored(DBm, c); - case _trans_DRm: - return _trans_edges_mirrored(DRm, c); - case _trans_RUm: - return _trans_edges_mirrored(RUm, c); - case _trans_RFm: - return _trans_edges_mirrored(RFm, c); - case _trans_RDm: - return _trans_edges_mirrored(RDm, c); - case _trans_RBm: - return _trans_edges_mirrored(RBm, c); - case _trans_LUm: - return _trans_edges_mirrored(LUm, c); - case _trans_LFm: - return _trans_edges_mirrored(LFm, c); - case _trans_LDm: - return _trans_edges_mirrored(LDm, c); - case _trans_LBm: - return _trans_edges_mirrored(LBm, c); - case _trans_FUm: - return _trans_edges_mirrored(FUm, c); - case _trans_FRm: - return _trans_edges_mirrored(FRm, c); - case _trans_FDm: - return _trans_edges_mirrored(FDm, c); - case _trans_FLm: - return _trans_edges_mirrored(FLm, c); - case _trans_BUm: - return _trans_edges_mirrored(BUm, c); - case _trans_BRm: - return _trans_edges_mirrored(BRm, c); - case _trans_BDm: - return _trans_edges_mirrored(BDm, c); - case _trans_BLm: - return _trans_edges_mirrored(BLm, c); + case TRANS_ULr: + return TRANS_EDGES_ROTATION(ULr, c); + case TRANS_UBr: + return TRANS_EDGES_ROTATION(UBr, c); + case TRANS_URr: + return TRANS_EDGES_ROTATION(URr, c); + case TRANS_DFr: + return TRANS_EDGES_ROTATION(DFr, c); + case TRANS_DLr: + return TRANS_EDGES_ROTATION(DLr, c); + case TRANS_DBr: + return TRANS_EDGES_ROTATION(DBr, c); + case TRANS_DRr: + return TRANS_EDGES_ROTATION(DRr, c); + case TRANS_RUr: + return TRANS_EDGES_ROTATION(RUr, c); + case TRANS_RFr: + return TRANS_EDGES_ROTATION(RFr, c); + case TRANS_RDr: + return TRANS_EDGES_ROTATION(RDr, c); + case TRANS_RBr: + return TRANS_EDGES_ROTATION(RBr, c); + case TRANS_LUr: + return TRANS_EDGES_ROTATION(LUr, c); + case TRANS_LFr: + return TRANS_EDGES_ROTATION(LFr, c); + case TRANS_LDr: + return TRANS_EDGES_ROTATION(LDr, c); + case TRANS_LBr: + return TRANS_EDGES_ROTATION(LBr, c); + case TRANS_FUr: + return TRANS_EDGES_ROTATION(FUr, c); + case TRANS_FRr: + return TRANS_EDGES_ROTATION(FRr, c); + case TRANS_FDr: + return TRANS_EDGES_ROTATION(FDr, c); + case TRANS_FLr: + return TRANS_EDGES_ROTATION(FLr, c); + case TRANS_BUr: + return TRANS_EDGES_ROTATION(BUr, c); + case TRANS_BRr: + return TRANS_EDGES_ROTATION(BRr, c); + case TRANS_BDr: + return TRANS_EDGES_ROTATION(BDr, c); + case TRANS_BLr: + return TRANS_EDGES_ROTATION(BLr, c); + case TRANS_UFm: + return TRANS_EDGES_MIRRORED(UFm, c); + case TRANS_ULm: + return TRANS_EDGES_MIRRORED(ULm, c); + case TRANS_UBm: + return TRANS_EDGES_MIRRORED(UBm, c); + case TRANS_URm: + return TRANS_EDGES_MIRRORED(URm, c); + case TRANS_DFm: + return TRANS_EDGES_MIRRORED(DFm, c); + case TRANS_DLm: + return TRANS_EDGES_MIRRORED(DLm, c); + case TRANS_DBm: + return TRANS_EDGES_MIRRORED(DBm, c); + case TRANS_DRm: + return TRANS_EDGES_MIRRORED(DRm, c); + case TRANS_RUm: + return TRANS_EDGES_MIRRORED(RUm, c); + case TRANS_RFm: + return TRANS_EDGES_MIRRORED(RFm, c); + case TRANS_RDm: + return TRANS_EDGES_MIRRORED(RDm, c); + case TRANS_RBm: + return TRANS_EDGES_MIRRORED(RBm, c); + case TRANS_LUm: + return TRANS_EDGES_MIRRORED(LUm, c); + case TRANS_LFm: + return TRANS_EDGES_MIRRORED(LFm, c); + case TRANS_LDm: + return TRANS_EDGES_MIRRORED(LDm, c); + case TRANS_LBm: + return TRANS_EDGES_MIRRORED(LBm, c); + case TRANS_FUm: + return TRANS_EDGES_MIRRORED(FUm, c); + case TRANS_FRm: + return TRANS_EDGES_MIRRORED(FRm, c); + case TRANS_FDm: + return TRANS_EDGES_MIRRORED(FDm, c); + case TRANS_FLm: + return TRANS_EDGES_MIRRORED(FLm, c); + case TRANS_BUm: + return TRANS_EDGES_MIRRORED(BUm, c); + case TRANS_BRm: + return TRANS_EDGES_MIRRORED(BRm, c); + case TRANS_BDm: + return TRANS_EDGES_MIRRORED(BDm, c); + case TRANS_BLm: + return TRANS_EDGES_MIRRORED(BLm, c); default: LOG("transform error, unknown transformation %" PRIu8 "\n", t); return zero; } } -_static cube_t +STATIC cube_t transform_corners(cube_t c, uint8_t t) { switch (t) { - case _trans_UFr: + case TRANS_UFr: return c; - case _trans_ULr: - return _trans_corners_rotation(ULr, c); - case _trans_UBr: - return _trans_corners_rotation(UBr, c); - case _trans_URr: - return _trans_corners_rotation(URr, c); - case _trans_DFr: - return _trans_corners_rotation(DFr, c); - case _trans_DLr: - return _trans_corners_rotation(DLr, c); - case _trans_DBr: - return _trans_corners_rotation(DBr, c); - case _trans_DRr: - return _trans_corners_rotation(DRr, c); - case _trans_RUr: - return _trans_corners_rotation(RUr, c); - case _trans_RFr: - return _trans_corners_rotation(RFr, c); - case _trans_RDr: - return _trans_corners_rotation(RDr, c); - case _trans_RBr: - return _trans_corners_rotation(RBr, c); - case _trans_LUr: - return _trans_corners_rotation(LUr, c); - case _trans_LFr: - return _trans_corners_rotation(LFr, c); - case _trans_LDr: - return _trans_corners_rotation(LDr, c); - case _trans_LBr: - return _trans_corners_rotation(LBr, c); - case _trans_FUr: - return _trans_corners_rotation(FUr, c); - case _trans_FRr: - return _trans_corners_rotation(FRr, c); - case _trans_FDr: - return _trans_corners_rotation(FDr, c); - case _trans_FLr: - return _trans_corners_rotation(FLr, c); - case _trans_BUr: - return _trans_corners_rotation(BUr, c); - case _trans_BRr: - return _trans_corners_rotation(BRr, c); - case _trans_BDr: - return _trans_corners_rotation(BDr, c); - case _trans_BLr: - return _trans_corners_rotation(BLr, c); - case _trans_UFm: - return _trans_corners_mirrored(UFm, c); - case _trans_ULm: - return _trans_corners_mirrored(ULm, c); - case _trans_UBm: - return _trans_corners_mirrored(UBm, c); - case _trans_URm: - return _trans_corners_mirrored(URm, c); - case _trans_DFm: - return _trans_corners_mirrored(DFm, c); - case _trans_DLm: - return _trans_corners_mirrored(DLm, c); - case _trans_DBm: - return _trans_corners_mirrored(DBm, c); - case _trans_DRm: - return _trans_corners_mirrored(DRm, c); - case _trans_RUm: - return _trans_corners_mirrored(RUm, c); - case _trans_RFm: - return _trans_corners_mirrored(RFm, c); - case _trans_RDm: - return _trans_corners_mirrored(RDm, c); - case _trans_RBm: - return _trans_corners_mirrored(RBm, c); - case _trans_LUm: - return _trans_corners_mirrored(LUm, c); - case _trans_LFm: - return _trans_corners_mirrored(LFm, c); - case _trans_LDm: - return _trans_corners_mirrored(LDm, c); - case _trans_LBm: - return _trans_corners_mirrored(LBm, c); - case _trans_FUm: - return _trans_corners_mirrored(FUm, c); - case _trans_FRm: - return _trans_corners_mirrored(FRm, c); - case _trans_FDm: - return _trans_corners_mirrored(FDm, c); - case _trans_FLm: - return _trans_corners_mirrored(FLm, c); - case _trans_BUm: - return _trans_corners_mirrored(BUm, c); - case _trans_BRm: - return _trans_corners_mirrored(BRm, c); - case _trans_BDm: - return _trans_corners_mirrored(BDm, c); - case _trans_BLm: - return _trans_corners_mirrored(BLm, c); + case TRANS_ULr: + return TRANS_CORNERS_ROTATION(ULr, c); + case TRANS_UBr: + return TRANS_CORNERS_ROTATION(UBr, c); + case TRANS_URr: + return TRANS_CORNERS_ROTATION(URr, c); + case TRANS_DFr: + return TRANS_CORNERS_ROTATION(DFr, c); + case TRANS_DLr: + return TRANS_CORNERS_ROTATION(DLr, c); + case TRANS_DBr: + return TRANS_CORNERS_ROTATION(DBr, c); + case TRANS_DRr: + return TRANS_CORNERS_ROTATION(DRr, c); + case TRANS_RUr: + return TRANS_CORNERS_ROTATION(RUr, c); + case TRANS_RFr: + return TRANS_CORNERS_ROTATION(RFr, c); + case TRANS_RDr: + return TRANS_CORNERS_ROTATION(RDr, c); + case TRANS_RBr: + return TRANS_CORNERS_ROTATION(RBr, c); + case TRANS_LUr: + return TRANS_CORNERS_ROTATION(LUr, c); + case TRANS_LFr: + return TRANS_CORNERS_ROTATION(LFr, c); + case TRANS_LDr: + return TRANS_CORNERS_ROTATION(LDr, c); + case TRANS_LBr: + return TRANS_CORNERS_ROTATION(LBr, c); + case TRANS_FUr: + return TRANS_CORNERS_ROTATION(FUr, c); + case TRANS_FRr: + return TRANS_CORNERS_ROTATION(FRr, c); + case TRANS_FDr: + return TRANS_CORNERS_ROTATION(FDr, c); + case TRANS_FLr: + return TRANS_CORNERS_ROTATION(FLr, c); + case TRANS_BUr: + return TRANS_CORNERS_ROTATION(BUr, c); + case TRANS_BRr: + return TRANS_CORNERS_ROTATION(BRr, c); + case TRANS_BDr: + return TRANS_CORNERS_ROTATION(BDr, c); + case TRANS_BLr: + return TRANS_CORNERS_ROTATION(BLr, c); + case TRANS_UFm: + return TRANS_CORNERS_MIRRORED(UFm, c); + case TRANS_ULm: + return TRANS_CORNERS_MIRRORED(ULm, c); + case TRANS_UBm: + return TRANS_CORNERS_MIRRORED(UBm, c); + case TRANS_URm: + return TRANS_CORNERS_MIRRORED(URm, c); + case TRANS_DFm: + return TRANS_CORNERS_MIRRORED(DFm, c); + case TRANS_DLm: + return TRANS_CORNERS_MIRRORED(DLm, c); + case TRANS_DBm: + return TRANS_CORNERS_MIRRORED(DBm, c); + case TRANS_DRm: + return TRANS_CORNERS_MIRRORED(DRm, c); + case TRANS_RUm: + return TRANS_CORNERS_MIRRORED(RUm, c); + case TRANS_RFm: + return TRANS_CORNERS_MIRRORED(RFm, c); + case TRANS_RDm: + return TRANS_CORNERS_MIRRORED(RDm, c); + case TRANS_RBm: + return TRANS_CORNERS_MIRRORED(RBm, c); + case TRANS_LUm: + return TRANS_CORNERS_MIRRORED(LUm, c); + case TRANS_LFm: + return TRANS_CORNERS_MIRRORED(LFm, c); + case TRANS_LDm: + return TRANS_CORNERS_MIRRORED(LDm, c); + case TRANS_LBm: + return TRANS_CORNERS_MIRRORED(LBm, c); + case TRANS_FUm: + return TRANS_CORNERS_MIRRORED(FUm, c); + case TRANS_FRm: + return TRANS_CORNERS_MIRRORED(FRm, c); + case TRANS_FDm: + return TRANS_CORNERS_MIRRORED(FDm, c); + case TRANS_FLm: + return TRANS_CORNERS_MIRRORED(FLm, c); + case TRANS_BUm: + return TRANS_CORNERS_MIRRORED(BUm, c); + case TRANS_BRm: + return TRANS_CORNERS_MIRRORED(BRm, c); + case TRANS_BDm: + return TRANS_CORNERS_MIRRORED(BDm, c); + case TRANS_BLm: + return TRANS_CORNERS_MIRRORED(BLm, c); default: LOG("transform error, unknown transformation %" PRIu8 "\n", t); return zero; } } -_static cube_t +STATIC cube_t transform(cube_t c, uint8_t t) { switch (t) { - case _trans_UFr: + case TRANS_UFr: return c; - case _trans_ULr: - return _trans_rotation(ULr, c); - case _trans_UBr: - return _trans_rotation(UBr, c); - case _trans_URr: - return _trans_rotation(URr, c); - case _trans_DFr: - return _trans_rotation(DFr, c); - case _trans_DLr: - return _trans_rotation(DLr, c); - case _trans_DBr: - return _trans_rotation(DBr, c); - case _trans_DRr: - return _trans_rotation(DRr, c); - case _trans_RUr: - return _trans_rotation(RUr, c); - case _trans_RFr: - return _trans_rotation(RFr, c); - case _trans_RDr: - return _trans_rotation(RDr, c); - case _trans_RBr: - return _trans_rotation(RBr, c); - case _trans_LUr: - return _trans_rotation(LUr, c); - case _trans_LFr: - return _trans_rotation(LFr, c); - case _trans_LDr: - return _trans_rotation(LDr, c); - case _trans_LBr: - return _trans_rotation(LBr, c); - case _trans_FUr: - return _trans_rotation(FUr, c); - case _trans_FRr: - return _trans_rotation(FRr, c); - case _trans_FDr: - return _trans_rotation(FDr, c); - case _trans_FLr: - return _trans_rotation(FLr, c); - case _trans_BUr: - return _trans_rotation(BUr, c); - case _trans_BRr: - return _trans_rotation(BRr, c); - case _trans_BDr: - return _trans_rotation(BDr, c); - case _trans_BLr: - return _trans_rotation(BLr, c); - case _trans_UFm: - return _trans_mirrored(UFm, c); - case _trans_ULm: - return _trans_mirrored(ULm, c); - case _trans_UBm: - return _trans_mirrored(UBm, c); - case _trans_URm: - return _trans_mirrored(URm, c); - case _trans_DFm: - return _trans_mirrored(DFm, c); - case _trans_DLm: - return _trans_mirrored(DLm, c); - case _trans_DBm: - return _trans_mirrored(DBm, c); - case _trans_DRm: - return _trans_mirrored(DRm, c); - case _trans_RUm: - return _trans_mirrored(RUm, c); - case _trans_RFm: - return _trans_mirrored(RFm, c); - case _trans_RDm: - return _trans_mirrored(RDm, c); - case _trans_RBm: - return _trans_mirrored(RBm, c); - case _trans_LUm: - return _trans_mirrored(LUm, c); - case _trans_LFm: - return _trans_mirrored(LFm, c); - case _trans_LDm: - return _trans_mirrored(LDm, c); - case _trans_LBm: - return _trans_mirrored(LBm, c); - case _trans_FUm: - return _trans_mirrored(FUm, c); - case _trans_FRm: - return _trans_mirrored(FRm, c); - case _trans_FDm: - return _trans_mirrored(FDm, c); - case _trans_FLm: - return _trans_mirrored(FLm, c); - case _trans_BUm: - return _trans_mirrored(BUm, c); - case _trans_BRm: - return _trans_mirrored(BRm, c); - case _trans_BDm: - return _trans_mirrored(BDm, c); - case _trans_BLm: - return _trans_mirrored(BLm, c); + case TRANS_ULr: + return TRANS_ROTATION(ULr, c); + case TRANS_UBr: + return TRANS_ROTATION(UBr, c); + case TRANS_URr: + return TRANS_ROTATION(URr, c); + case TRANS_DFr: + return TRANS_ROTATION(DFr, c); + case TRANS_DLr: + return TRANS_ROTATION(DLr, c); + case TRANS_DBr: + return TRANS_ROTATION(DBr, c); + case TRANS_DRr: + return TRANS_ROTATION(DRr, c); + case TRANS_RUr: + return TRANS_ROTATION(RUr, c); + case TRANS_RFr: + return TRANS_ROTATION(RFr, c); + case TRANS_RDr: + return TRANS_ROTATION(RDr, c); + case TRANS_RBr: + return TRANS_ROTATION(RBr, c); + case TRANS_LUr: + return TRANS_ROTATION(LUr, c); + case TRANS_LFr: + return TRANS_ROTATION(LFr, c); + case TRANS_LDr: + return TRANS_ROTATION(LDr, c); + case TRANS_LBr: + return TRANS_ROTATION(LBr, c); + case TRANS_FUr: + return TRANS_ROTATION(FUr, c); + case TRANS_FRr: + return TRANS_ROTATION(FRr, c); + case TRANS_FDr: + return TRANS_ROTATION(FDr, c); + case TRANS_FLr: + return TRANS_ROTATION(FLr, c); + case TRANS_BUr: + return TRANS_ROTATION(BUr, c); + case TRANS_BRr: + return TRANS_ROTATION(BRr, c); + case TRANS_BDr: + return TRANS_ROTATION(BDr, c); + case TRANS_BLr: + return TRANS_ROTATION(BLr, c); + case TRANS_UFm: + return TRANS_MIRRORED(UFm, c); + case TRANS_ULm: + return TRANS_MIRRORED(ULm, c); + case TRANS_UBm: + return TRANS_MIRRORED(UBm, c); + case TRANS_URm: + return TRANS_MIRRORED(URm, c); + case TRANS_DFm: + return TRANS_MIRRORED(DFm, c); + case TRANS_DLm: + return TRANS_MIRRORED(DLm, c); + case TRANS_DBm: + return TRANS_MIRRORED(DBm, c); + case TRANS_DRm: + return TRANS_MIRRORED(DRm, c); + case TRANS_RUm: + return TRANS_MIRRORED(RUm, c); + case TRANS_RFm: + return TRANS_MIRRORED(RFm, c); + case TRANS_RDm: + return TRANS_MIRRORED(RDm, c); + case TRANS_RBm: + return TRANS_MIRRORED(RBm, c); + case TRANS_LUm: + return TRANS_MIRRORED(LUm, c); + case TRANS_LFm: + return TRANS_MIRRORED(LFm, c); + case TRANS_LDm: + return TRANS_MIRRORED(LDm, c); + case TRANS_LBm: + return TRANS_MIRRORED(LBm, c); + case TRANS_FUm: + return TRANS_MIRRORED(FUm, c); + case TRANS_FRm: + return TRANS_MIRRORED(FRm, c); + case TRANS_FDm: + return TRANS_MIRRORED(FDm, c); + case TRANS_FLm: + return TRANS_MIRRORED(FLm, c); + case TRANS_BUm: + return TRANS_MIRRORED(BUm, c); + case TRANS_BRm: + return TRANS_MIRRORED(BRm, c); + case TRANS_BDm: + return TRANS_MIRRORED(BDm, c); + case TRANS_BLm: + return TRANS_MIRRORED(BLm, c); default: LOG("transform error, unknown transformation %" PRIu8 "\n", t); return zero; } } -_static cube_t +STATIC cube_t applytrans(cube_t cube, const char *buf) { uint8_t t; diff --git a/src/nissy.c b/src/nissy.c @@ -10,8 +10,8 @@ #include "nissy.h" -_static int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); -_static int64_t write_result(cube_t, char [static 22]); +STATIC int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); +STATIC int64_t write_result(cube_t, char [static 22]); /* TODO: add option to get DR, maybe C-only, E-only, eo... */ #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } @@ -23,7 +23,7 @@ struct { GETCUBE_OPTIONS(NULL, NULL) }; -_static int +STATIC int parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) { bool h_valid, k_valid, maxdepth_valid; @@ -61,7 +61,7 @@ parse_h48_options_error: return -1; } -_static int64_t +STATIC int64_t write_result(cube_t cube, char result[static 22]) { if (!isconsistent(cube)) { diff --git a/src/solvers/generic/generic.h b/src/solvers/generic/generic.h @@ -9,14 +9,14 @@ typedef struct { uint8_t (*estimate)(cube_t); } dfsarg_generic_t; -_static void solve_generic_appendsolution(dfsarg_generic_t *); -_static int solve_generic_dfs(dfsarg_generic_t *); -_static int64_t solve_generic(cube_t, const char *, int8_t, int8_t, int64_t, +STATIC void solve_generic_appendsolution(dfsarg_generic_t *); +STATIC int solve_generic_dfs(dfsarg_generic_t *); +STATIC int64_t solve_generic(cube_t, const char *, int8_t, int8_t, int64_t, int8_t, char *, uint8_t (*)(cube_t)); -_static uint8_t estimate_simple(cube_t); -_static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); +STATIC uint8_t estimate_simple(cube_t); +STATIC int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); -_static void +STATIC void solve_generic_appendsolution(dfsarg_generic_t *arg) { int strl; @@ -29,7 +29,7 @@ solve_generic_appendsolution(dfsarg_generic_t *arg) (*arg->nsols)++; } -_static int +STATIC int solve_generic_dfs(dfsarg_generic_t *arg) { dfsarg_generic_t nextarg; @@ -64,7 +64,7 @@ solve_generic_dfs(dfsarg_generic_t *arg) return ret; } -_static int64_t +STATIC int64_t solve_generic( cube_t cube, const char *nisstype, @@ -128,13 +128,13 @@ solve_generic( return ret; } -_static uint8_t +STATIC uint8_t estimate_simple(cube_t cube) { return issolved(cube) ? 0 : 1; } -_static int64_t +STATIC int64_t solve_simple( cube_t cube, int8_t minmoves, diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h @@ -1,15 +1,15 @@ -#define H48_ESIZE(h) ((_12c4 * _8c4) << (int64_t)(h)) +#define H48_ESIZE(h) ((COMB_12_4 * COMB_8_4) << (int64_t)(h)) #define COCLASS_MASK (UINT32_C(0xFFFF) << UINT32_C(16)) #define COCLASS(x) (((x) & COCLASS_MASK) >> UINT32_C(16)) #define TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) #define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) -_static_inline int64_t coord_h48(cube_t, const uint32_t *, uint8_t); -_static_inline int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); -_static_inline cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); +STATIC_INLINE int64_t coord_h48(cube_t, const uint32_t *, uint8_t); +STATIC_INLINE int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); +STATIC_INLINE cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); -_static_inline int64_t +STATIC_INLINE int64_t coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) { int64_t cocsep, coclass; @@ -26,7 +26,7 @@ coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) return coord_h48_edges(c, coclass, ttrep, h); } -_static_inline int64_t +STATIC_INLINE int64_t coord_h48_edges(cube_t c, int64_t coclass, uint8_t ttrep, uint8_t h) { cube_t d; @@ -45,7 +45,7 @@ This function does not necessarily return a cube whose coordinate is the given value, because it works up to symmetry. This means that the returned cube is a transformed cube of one that gives the correct value. */ -_static_inline cube_t +STATIC_INLINE cube_t invcoord_h48(int64_t i, const cube_t *crep, uint8_t h) { cube_t ret; diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h @@ -1,5 +1,5 @@ #define COCSEP_CLASSES ((size_t)3393) -#define COCSEP_TABLESIZE ((size_t)_3p7 << (size_t)7) +#define COCSEP_TABLESIZE ((size_t)POW_3_7 << (size_t)7) #define COCSEP_VISITEDSIZE ((COCSEP_TABLESIZE + (size_t)7) / (size_t)8) #define COCSEP_FULLSIZE ((size_t)4 * (COCSEP_TABLESIZE + (size_t)12)) @@ -20,13 +20,13 @@ typedef struct { cube_t *rep; } cocsep_dfs_arg_t; -_static_inline bool get_visited(const uint8_t *, int64_t); -_static_inline void set_visited(uint8_t *, int64_t); +STATIC_INLINE bool get_visited(const uint8_t *, int64_t); +STATIC_INLINE void set_visited(uint8_t *, int64_t); -_static size_t gendata_cocsep(void *, uint64_t *, cube_t *); -_static uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); +STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *); +STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); -_static_inline int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); +STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); /* Each element of the cocsep table is a uint32_t used as follows: @@ -39,7 +39,7 @@ After the data as described above, more auxiliary information is appended: - One uint32_t for each "line" of the pruning table, representing the number of positions having that pruning value. */ -_static size_t +STATIC size_t gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep) { uint32_t *buf32, *info, cc; @@ -91,7 +91,7 @@ gendata_cocsep_return_size: return COCSEP_FULLSIZE; } -_static uint32_t +STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) { uint8_t m; @@ -145,19 +145,19 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) return cc; } -_static_inline bool +STATIC_INLINE bool get_visited(const uint8_t *a, int64_t i) { return a[VISITED_IND(i)] & VISITED_MASK(i); } -_static_inline void +STATIC_INLINE void set_visited(uint8_t *a, int64_t i) { a[VISITED_IND(i)] |= VISITED_MASK(i); } -_static_inline int8_t +STATIC_INLINE int8_t get_h48_cdata(cube_t cube, uint32_t *cocsepdata, uint32_t *cdata) { int64_t coord; diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -1,4 +1,4 @@ -#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * _12c4 * _8c4)) +#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * COMB_12_4 * COMB_8_4)) #define H48_COORDMAX(h) ((int64_t)(H48_COORDMAX_NOEO << (int64_t)(h))) #define H48_DIV(k) ((size_t)8 / (size_t)(k)) #define H48_TABLESIZE(h, k) _div_round_up((size_t)H48_COORDMAX((h)), H48_DIV(k)) @@ -6,7 +6,7 @@ #define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k)) #define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k)) #define H48_SHIFT(i, k) ((uint32_t)(k) * ((uint32_t)(i) % H48_COEFF(k))) -#define H48_MASK(i, k) ((_bit_u32(k) - (uint32_t)(1)) << H48_SHIFT(i, k)) +#define H48_MASK(i, k) ((UINT32_BIT(k) - (uint32_t)(1)) << H48_SHIFT(i, k)) #define MAXLEN 20 @@ -74,21 +74,21 @@ typedef struct { h48map_t *shortcubes; } h48k2_dfs_arg_t; -_static_inline uint8_t get_esep_pval(const uint32_t *, int64_t, uint8_t); -_static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t, uint8_t); +STATIC_INLINE uint8_t get_esep_pval(const uint32_t *, int64_t, uint8_t); +STATIC_INLINE void set_esep_pval(uint32_t *, int64_t, uint8_t, uint8_t); -_static uint64_t gen_h48short(gendata_h48short_arg_t *); -_static size_t gendata_h48(gendata_h48_arg_t *); -_static size_t gendata_h48h0k4(gendata_h48_arg_t *); -_static int64_t gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *); -_static int64_t gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *); -_static int64_t gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *); -_static size_t gendata_h48k2(gendata_h48_arg_t *); -_static void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); +STATIC uint64_t gen_h48short(gendata_h48short_arg_t *); +STATIC size_t gendata_h48(gendata_h48_arg_t *); +STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); +STATIC int64_t gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *); +STATIC int64_t gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *); +STATIC int64_t gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *); +STATIC size_t gendata_h48k2(gendata_h48_arg_t *); +STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); -_static_inline int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint32_t *); +STATIC_INLINE int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint32_t *); -_static uint64_t +STATIC uint64_t gen_h48short(gendata_h48short_arg_t *arg) { uint8_t i, m; @@ -129,7 +129,7 @@ gen_h48short(gendata_h48short_arg_t *arg) } /* Generic function that dispatches to the data generators */ -_static size_t +STATIC size_t gendata_h48(gendata_h48_arg_t *arg) { static const size_t infosize = 88; /* TODO: change to e.g. 1024 */ @@ -164,7 +164,7 @@ gendata_h48(gendata_h48_arg_t *arg) TODO description generating fixed table with h=0, k=4 */ -_static size_t +STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *arg) { uint32_t j; @@ -208,7 +208,7 @@ gendata_h48h0k4_return_size: return H48_TABLESIZE(0, 4); } -_static int64_t +STATIC int64_t gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *arg) { const uint8_t breakpoint = 10; /* Hand-picked optimal */ @@ -219,7 +219,7 @@ gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *arg) return gendata_h48h0k4_bfs_fromnew(arg); } -_static int64_t +STATIC int64_t gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg) { uint8_t c, m, x; @@ -249,7 +249,7 @@ gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg) return cc; } -_static int64_t +STATIC int64_t gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg) { uint8_t c, m, x; @@ -281,7 +281,7 @@ gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg) return cc; } -_static size_t +STATIC size_t gendata_h48k2(gendata_h48_arg_t *arg) { static const uint8_t shortdepth = 8; @@ -363,7 +363,7 @@ gendata_h48k2_return_size: return H48_TABLESIZE(arg->h, 2); } -_static void +STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) { cube_t ccc; @@ -406,20 +406,20 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) } } -_static_inline uint8_t +STATIC_INLINE uint8_t get_esep_pval(const uint32_t *buf32, int64_t i, uint8_t k) { return (buf32[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); } -_static_inline void +STATIC_INLINE void set_esep_pval(uint32_t *buf32, int64_t i, uint8_t k, uint8_t val) { buf32[H48_INDEX(i, k)] = (buf32[H48_INDEX(i, k)] & (~H48_MASK(i, k))) | (val << H48_SHIFT(i, k)); } -_static_inline int8_t +STATIC_INLINE int8_t get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint32_t *h48data) { int64_t coord; diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h @@ -15,15 +15,15 @@ typedef struct { uint64_t val; } kvpair_t; -_static void h48map_create(h48map_t *, uint64_t, uint64_t); -_static void h48map_clear(h48map_t *); -_static void h48map_destroy(h48map_t *); -_static uint64_t h48map_lookup(h48map_t *, uint64_t); -_static void h48map_insertmin(h48map_t *, uint64_t, uint64_t); -_static uint64_t h48map_value(h48map_t *, uint64_t); -_static kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); - -_static void +STATIC void h48map_create(h48map_t *, uint64_t, uint64_t); +STATIC void h48map_clear(h48map_t *); +STATIC void h48map_destroy(h48map_t *); +STATIC uint64_t h48map_lookup(h48map_t *, uint64_t); +STATIC void h48map_insertmin(h48map_t *, uint64_t, uint64_t); +STATIC uint64_t h48map_value(h48map_t *, uint64_t); +STATIC kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); + +STATIC void h48map_create(h48map_t *map, uint64_t capacity, uint64_t randomizer) { map->capacity = capacity; @@ -33,20 +33,20 @@ h48map_create(h48map_t *map, uint64_t capacity, uint64_t randomizer) h48map_clear(map); } -_static void +STATIC void h48map_clear(h48map_t *map) { memset(map->table, 0xFF, map->capacity * sizeof(uint64_t)); map->n = 0; } -_static void +STATIC void h48map_destroy(h48map_t *map) { free(map->table); } -_static_inline uint64_t +STATIC_INLINE uint64_t h48map_lookup(h48map_t *map, uint64_t x) { uint64_t hash, i; @@ -60,7 +60,7 @@ h48map_lookup(h48map_t *map, uint64_t x) return i; } -_static_inline void +STATIC_INLINE void h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val) { uint64_t i, oldval, min; @@ -73,13 +73,13 @@ h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val) map->table[i] = (key & MAP_KEYMASK) | (min << MAP_KEYSHIFT); } -_static_inline uint64_t +STATIC_INLINE uint64_t h48map_value(h48map_t *map, uint64_t key) { return map->table[h48map_lookup(map, key)] >> MAP_KEYSHIFT; } -_static kvpair_t +STATIC kvpair_t h48map_nextkvpair(h48map_t *map, uint64_t *p) { kvpair_t kv; diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -26,22 +26,22 @@ typedef struct { char *s; } dfsarg_solveh48stats_t; -_static uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint32_t); +STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint32_t); -_static void solve_h48_appendsolution(dfsarg_solveh48_t *); -_static_inline bool solve_h48_stop(dfsarg_solveh48_t *); -_static int64_t solve_h48_dfs(dfsarg_solveh48_t *); -_static int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, const void *, char *); +STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); +STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); +STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); +STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, const void *, char *); -_static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); -_static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); +STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); +STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); -_static uint32_t +STATIC uint32_t allowednextmove_h48(uint8_t *moves, uint8_t n, uint32_t h48branch) { - uint32_t result = _mm_allmoves; - if (h48branch & _mm_normalbranch) - result &= _mm_nohalfturns; + uint32_t result = MM_ALLMOVES; + if (h48branch & MM_NORMALBRANCH) + result &= MM_NOHALFTURNS; if (n < 1) return result; @@ -64,7 +64,7 @@ allowednextmove_h48(uint8_t *moves, uint8_t n, uint32_t h48branch) return result; } -_static void +STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *arg) { int strl; @@ -89,13 +89,13 @@ solve_h48_appendsolution(dfsarg_solveh48_t *arg) (*arg->nsols)++; } -_static_inline bool +STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *arg) { uint32_t data, data_inv; int8_t bound; - arg->nissbranch = _mm_normal; + arg->nissbranch = MM_NORMAL; bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); if (bound + arg->nmoves + arg->npremoves > arg->depth) return true; @@ -109,18 +109,18 @@ solve_h48_stop(dfsarg_solveh48_t *arg) if (bound + arg->nmoves + arg->npremoves > arg->depth) return true; if (bound + arg->nmoves + arg->npremoves == arg->depth) - arg->nissbranch = _mm_inversebranch; + arg->nissbranch = MM_INVERSEBRANCH; bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); if (bound + arg->nmoves + arg->npremoves > arg->depth) return true; if (bound + arg->nmoves + arg->npremoves == arg->depth) - arg->nissbranch = _mm_normalbranch; + arg->nissbranch = MM_NORMALBRANCH; return false; } -_static int64_t +STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *arg) { dfsarg_solveh48_t nextarg; @@ -144,7 +144,7 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) nextarg = *arg; ret = 0; uint32_t allowed; - if(arg->nissbranch & _mm_inverse) { + if(arg->nissbranch & MM_INVERSE) { allowed = allowednextmove_h48(arg->premoves, arg->npremoves, arg->nissbranch); for (m = 0; m < 18; m++) { if(allowed & (1 << m)) { @@ -171,7 +171,7 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) return ret; } -_static int64_t +STATIC int64_t solve_h48( cube_t cube, int8_t minmoves, @@ -219,7 +219,7 @@ each of the 12 h48 coordinates, one for each value of h from 0 to 11. The solutions array is filled with the length of the solutions. The solution array is therefore not a printable string. */ -_static int64_t +STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *arg) { const int64_t limit = 11; @@ -268,7 +268,7 @@ solve_h48stats_dfs(dfsarg_solveh48stats_t *arg) return 0; } -_static int64_t +STATIC int64_t solve_h48stats( cube_t cube, int8_t maxmoves, diff --git a/src/utils/constants.h b/src/utils/constants.h @@ -1,19 +1,15 @@ -#define _bit_u8(i) (UINT8_C(1) << (uint8_t)(i)) -#define _bit_u32(i) (UINT32_C(1) << (uint32_t)(i)) -#define _bit_u64(i) (UINT64_C(1) << (uint64_t)(i)) +#define UINT32_BIT(i) (UINT32_C(1) << (uint32_t)(i)) -#define _max_factorial INT64_C(12) +#define FACTORIAL_MAX INT64_C(12) -#define _2p11 INT64_C(2048) -#define _2p12 INT64_C(4096) -#define _3p7 INT64_C(2187) -#define _3p8 INT64_C(6561) -#define _12f INT64_C(479001600) -#define _8f INT64_C(40320) -#define _12c4 INT64_C(495) -#define _8c4 INT64_C(70) +#define POW_2_11 INT64_C(2048) +#define POW_3_7 INT64_C(2187) +#define FACT_12 INT64_C(479001600) +#define FACT_8 INT64_C(40320) +#define COMB_12_4 INT64_C(495) +#define COMB_8_4 INT64_C(70) -_static int64_t binomial[12][12] = { +STATIC int64_t binomial[12][12] = { {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, @@ -28,275 +24,275 @@ _static int64_t binomial[12][12] = { {1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1}, }; -#define _move_U UINT8_C(0) -#define _move_U2 UINT8_C(1) -#define _move_U3 UINT8_C(2) -#define _move_D UINT8_C(3) -#define _move_D2 UINT8_C(4) -#define _move_D3 UINT8_C(5) -#define _move_R UINT8_C(6) -#define _move_R2 UINT8_C(7) -#define _move_R3 UINT8_C(8) -#define _move_L UINT8_C(9) -#define _move_L2 UINT8_C(10) -#define _move_L3 UINT8_C(11) -#define _move_F UINT8_C(12) -#define _move_F2 UINT8_C(13) -#define _move_F3 UINT8_C(14) -#define _move_B UINT8_C(15) -#define _move_B2 UINT8_C(16) -#define _move_B3 UINT8_C(17) +#define MOVE_U UINT8_C(0) +#define MOVE_U2 UINT8_C(1) +#define MOVE_U3 UINT8_C(2) +#define MOVE_D UINT8_C(3) +#define MOVE_D2 UINT8_C(4) +#define MOVE_D3 UINT8_C(5) +#define MOVE_R UINT8_C(6) +#define MOVE_R2 UINT8_C(7) +#define MOVE_R3 UINT8_C(8) +#define MOVE_L UINT8_C(9) +#define MOVE_L2 UINT8_C(10) +#define MOVE_L3 UINT8_C(11) +#define MOVE_F UINT8_C(12) +#define MOVE_F2 UINT8_C(13) +#define MOVE_F3 UINT8_C(14) +#define MOVE_B UINT8_C(15) +#define MOVE_B2 UINT8_C(16) +#define MOVE_B3 UINT8_C(17) -#define _trans_UFr UINT8_C(0) -#define _trans_ULr UINT8_C(1) -#define _trans_UBr UINT8_C(2) -#define _trans_URr UINT8_C(3) -#define _trans_DFr UINT8_C(4) -#define _trans_DLr UINT8_C(5) -#define _trans_DBr UINT8_C(6) -#define _trans_DRr UINT8_C(7) -#define _trans_RUr UINT8_C(8) -#define _trans_RFr UINT8_C(9) -#define _trans_RDr UINT8_C(10) -#define _trans_RBr UINT8_C(11) -#define _trans_LUr UINT8_C(12) -#define _trans_LFr UINT8_C(13) -#define _trans_LDr UINT8_C(14) -#define _trans_LBr UINT8_C(15) -#define _trans_FUr UINT8_C(16) -#define _trans_FRr UINT8_C(17) -#define _trans_FDr UINT8_C(18) -#define _trans_FLr UINT8_C(19) -#define _trans_BUr UINT8_C(20) -#define _trans_BRr UINT8_C(21) -#define _trans_BDr UINT8_C(22) -#define _trans_BLr UINT8_C(23) +#define TRANS_UFr UINT8_C(0) +#define TRANS_ULr UINT8_C(1) +#define TRANS_UBr UINT8_C(2) +#define TRANS_URr UINT8_C(3) +#define TRANS_DFr UINT8_C(4) +#define TRANS_DLr UINT8_C(5) +#define TRANS_DBr UINT8_C(6) +#define TRANS_DRr UINT8_C(7) +#define TRANS_RUr UINT8_C(8) +#define TRANS_RFr UINT8_C(9) +#define TRANS_RDr UINT8_C(10) +#define TRANS_RBr UINT8_C(11) +#define TRANS_LUr UINT8_C(12) +#define TRANS_LFr UINT8_C(13) +#define TRANS_LDr UINT8_C(14) +#define TRANS_LBr UINT8_C(15) +#define TRANS_FUr UINT8_C(16) +#define TRANS_FRr UINT8_C(17) +#define TRANS_FDr UINT8_C(18) +#define TRANS_FLr UINT8_C(19) +#define TRANS_BUr UINT8_C(20) +#define TRANS_BRr UINT8_C(21) +#define TRANS_BDr UINT8_C(22) +#define TRANS_BLr UINT8_C(23) -#define _trans_UFm UINT8_C(24) -#define _trans_ULm UINT8_C(25) -#define _trans_UBm UINT8_C(26) -#define _trans_URm UINT8_C(27) -#define _trans_DFm UINT8_C(28) -#define _trans_DLm UINT8_C(29) -#define _trans_DBm UINT8_C(30) -#define _trans_DRm UINT8_C(31) -#define _trans_RUm UINT8_C(32) -#define _trans_RFm UINT8_C(33) -#define _trans_RDm UINT8_C(34) -#define _trans_RBm UINT8_C(35) -#define _trans_LUm UINT8_C(36) -#define _trans_LFm UINT8_C(37) -#define _trans_LDm UINT8_C(38) -#define _trans_LBm UINT8_C(39) -#define _trans_FUm UINT8_C(40) -#define _trans_FRm UINT8_C(41) -#define _trans_FDm UINT8_C(42) -#define _trans_FLm UINT8_C(43) -#define _trans_BUm UINT8_C(44) -#define _trans_BRm UINT8_C(45) -#define _trans_BDm UINT8_C(46) -#define _trans_BLm UINT8_C(47) +#define TRANS_UFm UINT8_C(24) +#define TRANS_ULm UINT8_C(25) +#define TRANS_UBm UINT8_C(26) +#define TRANS_URm UINT8_C(27) +#define TRANS_DFm UINT8_C(28) +#define TRANS_DLm UINT8_C(29) +#define TRANS_DBm UINT8_C(30) +#define TRANS_DRm UINT8_C(31) +#define TRANS_RUm UINT8_C(32) +#define TRANS_RFm UINT8_C(33) +#define TRANS_RDm UINT8_C(34) +#define TRANS_RBm UINT8_C(35) +#define TRANS_LUm UINT8_C(36) +#define TRANS_LFm UINT8_C(37) +#define TRANS_LDm UINT8_C(38) +#define TRANS_LBm UINT8_C(39) +#define TRANS_FUm UINT8_C(40) +#define TRANS_FRm UINT8_C(41) +#define TRANS_FDm UINT8_C(42) +#define TRANS_FLm UINT8_C(43) +#define TRANS_BUm UINT8_C(44) +#define TRANS_BRm UINT8_C(45) +#define TRANS_BDm UINT8_C(46) +#define TRANS_BLm UINT8_C(47) -#define _mm_normal UINT32_C(0x00) -#define _mm_inverse UINT32_C(0x01) -#define _mm_inversebranch UINT32_C(0x03) -#define _mm_normalbranch UINT32_C(0x02) -#define _mm_allmoves UINT32_C(0x3FFFF) -#define _mm_nohalfturns UINT32_C(0x2DB6D) +#define MM_NORMAL UINT32_C(0x00) +#define MM_INVERSE UINT32_C(0x01) +#define MM_INVERSEBRANCH UINT32_C(0x03) +#define MM_NORMALBRANCH UINT32_C(0x02) +#define MM_ALLMOVES UINT32_C(0x3FFFF) +#define MM_NOHALFTURNS UINT32_C(0x2DB6D) -#define _c_ufr UINT8_C(0) -#define _c_ubl UINT8_C(1) -#define _c_dfl UINT8_C(2) -#define _c_dbr UINT8_C(3) -#define _c_ufl UINT8_C(4) -#define _c_ubr UINT8_C(5) -#define _c_dfr UINT8_C(6) -#define _c_dbl UINT8_C(7) +#define CORNER_UFR UINT8_C(0) +#define CORNER_UBL UINT8_C(1) +#define CORNER_DFL UINT8_C(2) +#define CORNER_DBR UINT8_C(3) +#define CORNER_UFL UINT8_C(4) +#define CORNER_UBR UINT8_C(5) +#define CORNER_DFR UINT8_C(6) +#define CORNER_DBL UINT8_C(7) -#define _e_uf UINT8_C(0) -#define _e_ub UINT8_C(1) -#define _e_db UINT8_C(2) -#define _e_df UINT8_C(3) -#define _e_ur UINT8_C(4) -#define _e_ul UINT8_C(5) -#define _e_dl UINT8_C(6) -#define _e_dr UINT8_C(7) -#define _e_fr UINT8_C(8) -#define _e_fl UINT8_C(9) -#define _e_bl UINT8_C(10) -#define _e_br UINT8_C(11) +#define EDGE_UF UINT8_C(0) +#define EDGE_UB UINT8_C(1) +#define EDGE_DB UINT8_C(2) +#define EDGE_DF UINT8_C(3) +#define EDGE_UR UINT8_C(4) +#define EDGE_UL UINT8_C(5) +#define EDGE_DL UINT8_C(6) +#define EDGE_DR UINT8_C(7) +#define EDGE_FR UINT8_C(8) +#define EDGE_FL UINT8_C(9) +#define EDGE_BL UINT8_C(10) +#define EDGE_BR UINT8_C(11) -#define _eoshift UINT8_C(4) -#define _coshift UINT8_C(5) +#define EOSHIFT UINT8_C(4) +#define COSHIFT UINT8_C(5) -#define _pbits UINT8_C(0xF) -#define _esepbit1 UINT8_C(0x4) -#define _esepbit2 UINT8_C(0x8) -#define _csepbit UINT8_C(0x4) -#define _eobit UINT8_C(0x10) -#define _cobits UINT8_C(0xF0) -#define _cobits2 UINT8_C(0x60) -#define _ctwist_cw UINT8_C(0x20) -#define _ctwist_ccw UINT8_C(0x40) -#define _eflip UINT8_C(0x10) -#define _error UINT8_C(0xFF) +#define PBITS UINT8_C(0xF) +#define ESEPBIT_1 UINT8_C(0x4) +#define ESEPBIT_2 UINT8_C(0x8) +#define CSEPBIT UINT8_C(0x4) +#define EOBIT UINT8_C(0x10) +#define COBITS UINT8_C(0xF0) +#define COBITS_2 UINT8_C(0x60) +#define CTWIST_CW UINT8_C(0x20) +#define CTWIST_CCW UINT8_C(0x40) +#define EFLIP UINT8_C(0x10) +#define UINT8_ERROR UINT8_C(0xFF) -_static const 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 const char *cornerstr[] = { + [CORNER_UFR] = "UFR", + [CORNER_UBL] = "UBL", + [CORNER_DFL] = "DFL", + [CORNER_DBR] = "DBR", + [CORNER_UFL] = "UFL", + [CORNER_UBR] = "UBR", + [CORNER_DFR] = "DFR", + [CORNER_DBL] = "DBL" }; -_static const 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 const char *cornerstralt[] = { + [CORNER_UFR] = "URF", + [CORNER_UBL] = "ULB", + [CORNER_DFL] = "DLF", + [CORNER_DBR] = "DRB", + [CORNER_UFL] = "ULF", + [CORNER_UBR] = "URB", + [CORNER_DFR] = "DRF", + [CORNER_DBL] = "DLB" }; -_static const 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 const char *edgestr[] = { + [EDGE_UF] = "UF", + [EDGE_UB] = "UB", + [EDGE_DB] = "DB", + [EDGE_DF] = "DF", + [EDGE_UR] = "UR", + [EDGE_UL] = "UL", + [EDGE_DL] = "DL", + [EDGE_DR] = "DR", + [EDGE_FR] = "FR", + [EDGE_FL] = "FL", + [EDGE_BL] = "BL", + [EDGE_BR] = "BR" }; -_static const char *movestr[] = { - [_move_U] = "U", - [_move_U2] = "U2", - [_move_U3] = "U'", - [_move_D] = "D", - [_move_D2] = "D2", - [_move_D3] = "D'", - [_move_R] = "R", - [_move_R2] = "R2", - [_move_R3] = "R'", - [_move_L] = "L", - [_move_L2] = "L2", - [_move_L3] = "L'", - [_move_F] = "F", - [_move_F2] = "F2", - [_move_F3] = "F'", - [_move_B] = "B", - [_move_B2] = "B2", - [_move_B3] = "B'", +STATIC const char *movestr[] = { + [MOVE_U] = "U", + [MOVE_U2] = "U2", + [MOVE_U3] = "U'", + [MOVE_D] = "D", + [MOVE_D2] = "D2", + [MOVE_D3] = "D'", + [MOVE_R] = "R", + [MOVE_R2] = "R2", + [MOVE_R3] = "R'", + [MOVE_L] = "L", + [MOVE_L2] = "L2", + [MOVE_L3] = "L'", + [MOVE_F] = "F", + [MOVE_F2] = "F2", + [MOVE_F3] = "F'", + [MOVE_B] = "B", + [MOVE_B2] = "B2", + [MOVE_B3] = "B'", }; -_static const char *transstr[] = { - [_trans_UFr] = "rotation UF", - [_trans_UFm] = "mirrored UF", - [_trans_ULr] = "rotation UL", - [_trans_ULm] = "mirrored UL", - [_trans_UBr] = "rotation UB", - [_trans_UBm] = "mirrored UB", - [_trans_URr] = "rotation UR", - [_trans_URm] = "mirrored UR", - [_trans_DFr] = "rotation DF", - [_trans_DFm] = "mirrored DF", - [_trans_DLr] = "rotation DL", - [_trans_DLm] = "mirrored DL", - [_trans_DBr] = "rotation DB", - [_trans_DBm] = "mirrored DB", - [_trans_DRr] = "rotation DR", - [_trans_DRm] = "mirrored DR", - [_trans_RUr] = "rotation RU", - [_trans_RUm] = "mirrored RU", - [_trans_RFr] = "rotation RF", - [_trans_RFm] = "mirrored RF", - [_trans_RDr] = "rotation RD", - [_trans_RDm] = "mirrored RD", - [_trans_RBr] = "rotation RB", - [_trans_RBm] = "mirrored RB", - [_trans_LUr] = "rotation LU", - [_trans_LUm] = "mirrored LU", - [_trans_LFr] = "rotation LF", - [_trans_LFm] = "mirrored LF", - [_trans_LDr] = "rotation LD", - [_trans_LDm] = "mirrored LD", - [_trans_LBr] = "rotation LB", - [_trans_LBm] = "mirrored LB", - [_trans_FUr] = "rotation FU", - [_trans_FUm] = "mirrored FU", - [_trans_FRr] = "rotation FR", - [_trans_FRm] = "mirrored FR", - [_trans_FDr] = "rotation FD", - [_trans_FDm] = "mirrored FD", - [_trans_FLr] = "rotation FL", - [_trans_FLm] = "mirrored FL", - [_trans_BUr] = "rotation BU", - [_trans_BUm] = "mirrored BU", - [_trans_BRr] = "rotation BR", - [_trans_BRm] = "mirrored BR", - [_trans_BDr] = "rotation BD", - [_trans_BDm] = "mirrored BD", - [_trans_BLr] = "rotation BL", - [_trans_BLm] = "mirrored BL", +STATIC const char *transstr[] = { + [TRANS_UFr] = "rotation UF", + [TRANS_UFm] = "mirrored UF", + [TRANS_ULr] = "rotation UL", + [TRANS_ULm] = "mirrored UL", + [TRANS_UBr] = "rotation UB", + [TRANS_UBm] = "mirrored UB", + [TRANS_URr] = "rotation UR", + [TRANS_URm] = "mirrored UR", + [TRANS_DFr] = "rotation DF", + [TRANS_DFm] = "mirrored DF", + [TRANS_DLr] = "rotation DL", + [TRANS_DLm] = "mirrored DL", + [TRANS_DBr] = "rotation DB", + [TRANS_DBm] = "mirrored DB", + [TRANS_DRr] = "rotation DR", + [TRANS_DRm] = "mirrored DR", + [TRANS_RUr] = "rotation RU", + [TRANS_RUm] = "mirrored RU", + [TRANS_RFr] = "rotation RF", + [TRANS_RFm] = "mirrored RF", + [TRANS_RDr] = "rotation RD", + [TRANS_RDm] = "mirrored RD", + [TRANS_RBr] = "rotation RB", + [TRANS_RBm] = "mirrored RB", + [TRANS_LUr] = "rotation LU", + [TRANS_LUm] = "mirrored LU", + [TRANS_LFr] = "rotation LF", + [TRANS_LFm] = "mirrored LF", + [TRANS_LDr] = "rotation LD", + [TRANS_LDm] = "mirrored LD", + [TRANS_LBr] = "rotation LB", + [TRANS_LBm] = "mirrored LB", + [TRANS_FUr] = "rotation FU", + [TRANS_FUm] = "mirrored FU", + [TRANS_FRr] = "rotation FR", + [TRANS_FRm] = "mirrored FR", + [TRANS_FDr] = "rotation FD", + [TRANS_FDm] = "mirrored FD", + [TRANS_FLr] = "rotation FL", + [TRANS_FLm] = "mirrored FL", + [TRANS_BUr] = "rotation BU", + [TRANS_BUm] = "mirrored BU", + [TRANS_BRr] = "rotation BR", + [TRANS_BRm] = "mirrored BR", + [TRANS_BDr] = "rotation BD", + [TRANS_BDm] = "mirrored BD", + [TRANS_BLr] = "rotation BL", + [TRANS_BLm] = "mirrored BL", }; static uint8_t inverse_trans_table[48] = { - [_trans_UFr] = _trans_UFr, - [_trans_UFm] = _trans_UFm, - [_trans_ULr] = _trans_URr, - [_trans_ULm] = _trans_ULm, - [_trans_UBr] = _trans_UBr, - [_trans_UBm] = _trans_UBm, - [_trans_URr] = _trans_ULr, - [_trans_URm] = _trans_URm, - [_trans_DFr] = _trans_DFr, - [_trans_DFm] = _trans_DFm, - [_trans_DLr] = _trans_DLr, - [_trans_DLm] = _trans_DRm, - [_trans_DBr] = _trans_DBr, - [_trans_DBm] = _trans_DBm, - [_trans_DRr] = _trans_DRr, - [_trans_DRm] = _trans_DLm, - [_trans_RUr] = _trans_FRr, - [_trans_RUm] = _trans_FLm, - [_trans_RFr] = _trans_LFr, - [_trans_RFm] = _trans_RFm, - [_trans_RDr] = _trans_BLr, - [_trans_RDm] = _trans_BRm, - [_trans_RBr] = _trans_RBr, - [_trans_RBm] = _trans_LBm, - [_trans_LUr] = _trans_FLr, - [_trans_LUm] = _trans_FRm, - [_trans_LFr] = _trans_RFr, - [_trans_LFm] = _trans_LFm, - [_trans_LDr] = _trans_BRr, - [_trans_LDm] = _trans_BLm, - [_trans_LBr] = _trans_LBr, - [_trans_LBm] = _trans_RBm, - [_trans_FUr] = _trans_FUr, - [_trans_FUm] = _trans_FUm, - [_trans_FRr] = _trans_RUr, - [_trans_FRm] = _trans_LUm, - [_trans_FDr] = _trans_BUr, - [_trans_FDm] = _trans_BUm, - [_trans_FLr] = _trans_LUr, - [_trans_FLm] = _trans_RUm, - [_trans_BUr] = _trans_FDr, - [_trans_BUm] = _trans_FDm, - [_trans_BRr] = _trans_LDr, - [_trans_BRm] = _trans_RDm, - [_trans_BDr] = _trans_BDr, - [_trans_BDm] = _trans_BDm, - [_trans_BLr] = _trans_RDr, - [_trans_BLm] = _trans_LDm, + [TRANS_UFr] = TRANS_UFr, + [TRANS_UFm] = TRANS_UFm, + [TRANS_ULr] = TRANS_URr, + [TRANS_ULm] = TRANS_ULm, + [TRANS_UBr] = TRANS_UBr, + [TRANS_UBm] = TRANS_UBm, + [TRANS_URr] = TRANS_ULr, + [TRANS_URm] = TRANS_URm, + [TRANS_DFr] = TRANS_DFr, + [TRANS_DFm] = TRANS_DFm, + [TRANS_DLr] = TRANS_DLr, + [TRANS_DLm] = TRANS_DRm, + [TRANS_DBr] = TRANS_DBr, + [TRANS_DBm] = TRANS_DBm, + [TRANS_DRr] = TRANS_DRr, + [TRANS_DRm] = TRANS_DLm, + [TRANS_RUr] = TRANS_FRr, + [TRANS_RUm] = TRANS_FLm, + [TRANS_RFr] = TRANS_LFr, + [TRANS_RFm] = TRANS_RFm, + [TRANS_RDr] = TRANS_BLr, + [TRANS_RDm] = TRANS_BRm, + [TRANS_RBr] = TRANS_RBr, + [TRANS_RBm] = TRANS_LBm, + [TRANS_LUr] = TRANS_FLr, + [TRANS_LUm] = TRANS_FRm, + [TRANS_LFr] = TRANS_RFr, + [TRANS_LFm] = TRANS_LFm, + [TRANS_LDr] = TRANS_BRr, + [TRANS_LDm] = TRANS_BLm, + [TRANS_LBr] = TRANS_LBr, + [TRANS_LBm] = TRANS_RBm, + [TRANS_FUr] = TRANS_FUr, + [TRANS_FUm] = TRANS_FUm, + [TRANS_FRr] = TRANS_RUr, + [TRANS_FRm] = TRANS_LUm, + [TRANS_FDr] = TRANS_BUr, + [TRANS_FDm] = TRANS_BUm, + [TRANS_FLr] = TRANS_LUr, + [TRANS_FLm] = TRANS_RUm, + [TRANS_BUr] = TRANS_FDr, + [TRANS_BUm] = TRANS_FDm, + [TRANS_BRr] = TRANS_LDr, + [TRANS_BRm] = TRANS_RDm, + [TRANS_BDr] = TRANS_BDr, + [TRANS_BDm] = TRANS_BDm, + [TRANS_BLr] = TRANS_RDr, + [TRANS_BLm] = TRANS_LDm, }; diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h @@ -3,14 +3,14 @@ void (*nissy_log)(const char *, ...); #define LOG(...) if (nissy_log != NULL) nissy_log(__VA_ARGS__); #ifdef DEBUG -#define _static -#define _static_inline +#define STATIC +#define STATIC_INLINE #define DBG_WARN(condition, ...) if (!(condition)) LOG(__VA_ARGS__); #define DBG_ASSERT(condition, retval, ...) \ if (!(condition)) { LOG(__VA_ARGS__); return retval; } #else -#define _static static -#define _static_inline static inline +#define STATIC static +#define STATIC_INLINE static inline #define DBG_WARN(condition, ...) #define DBG_ASSERT(condition, retval, ...) #endif diff --git a/src/utils/math.h b/src/utils/math.h @@ -3,22 +3,22 @@ #define _max(x, y) ((x) > (y) ? (x) : (y)) #define _div_round_up(n, d) (((n) + (d) - 1) / (d)) -_static int64_t factorial(int64_t); -_static bool isperm(uint8_t *, int64_t); -_static int64_t permtoindex(uint8_t *, int64_t); -_static void indextoperm(int64_t, int64_t, uint8_t *); -_static int permsign(uint8_t *, int64_t); -_static int64_t digitstosumzero(uint8_t *, uint8_t, uint8_t); -_static void sumzerotodigits(int64_t, uint8_t, uint8_t, uint8_t *); - -_static int64_t +STATIC int64_t factorial(int64_t); +STATIC bool isperm(uint8_t *, int64_t); +STATIC int64_t permtoindex(uint8_t *, int64_t); +STATIC void indextoperm(int64_t, int64_t, uint8_t *); +STATIC int permsign(uint8_t *, int64_t); +STATIC int64_t digitstosumzero(uint8_t *, uint8_t, uint8_t); +STATIC void sumzerotodigits(int64_t, uint8_t, uint8_t, uint8_t *); + +STATIC int64_t factorial(int64_t n) { int64_t i, ret; - if (n > _max_factorial) { + if (n > FACTORIAL_MAX) { LOG("Error: won't compute factorial for n=%" PRId64 " because" - " it is larger than %" PRId64 "\n", n, _max_factorial); + " it is larger than %" PRId64 "\n", n, FACTORIAL_MAX); return -1; } @@ -31,15 +31,15 @@ factorial(int64_t n) return ret; } -_static bool +STATIC bool isperm(uint8_t *a, int64_t n) { int64_t i; - bool aux[_max_factorial+1]; + bool aux[FACTORIAL_MAX+1]; - if (n > _max_factorial) { + if (n > FACTORIAL_MAX) { LOG("Error: won't compute 'isperm()' for n=%" PRId64 " because" - " it is larger than %" PRId64 "\n", n, _max_factorial); + " it is larger than %" PRId64 "\n", n, FACTORIAL_MAX); return false; } @@ -59,15 +59,15 @@ isperm(uint8_t *a, int64_t n) return true; } -_static int64_t +STATIC int64_t permtoindex(uint8_t *a, int64_t n) { int64_t i, j, c, ret; - if (n > _max_factorial) { + if (n > FACTORIAL_MAX) { LOG("Error: won't compute 'permtoindex()' for n=%" PRId64 " because it is larger than %" PRId64 "\n", - n, _max_factorial); + n, FACTORIAL_MAX); return -1; } @@ -83,16 +83,16 @@ permtoindex(uint8_t *a, int64_t n) return ret; } -_static void +STATIC void indextoperm(int64_t p, int64_t n, uint8_t *r) { int64_t i, j, c; - uint8_t a[_max_factorial+1]; + uint8_t a[FACTORIAL_MAX+1]; - if (n > _max_factorial) { + if (n > FACTORIAL_MAX) { LOG("Error: won't compute 'permtoindex()' for n=%" PRId64 " because it is larger than %" PRId64 "\n", - n, _max_factorial); + n, FACTORIAL_MAX); goto indextoperm_error; } @@ -115,10 +115,10 @@ indextoperm(int64_t p, int64_t n, uint8_t *r) return; indextoperm_error: - memset(r, _error, n); + memset(r, UINT8_ERROR, n); } -_static int +STATIC int permsign(uint8_t *a, int64_t n) { int i, j; @@ -131,7 +131,7 @@ permsign(uint8_t *a, int64_t n) return ret % 2; } -_static int64_t +STATIC int64_t digitstosumzero(uint8_t *a, uint8_t n, uint8_t b) { int64_t ret, p; @@ -161,7 +161,7 @@ digitstosumzero(uint8_t *a, uint8_t n, uint8_t b) return ret; } -_static void +STATIC void sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a) { uint8_t sum; @@ -182,5 +182,5 @@ sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a) return; digitstosumzero_error: - memset(a, _error, n); + memset(a, UINT8_ERROR, n); }