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 b17411249b17133f35833c202e6c2e4bf43b3298
parent fd5ddb3db9f50411ca579d84f225f265ca35b56a
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Thu,  5 Sep 2024 10:04:34 +0200

More renaming

Diffstat:
Msrc/arch/avx2.h | 48++++++++++++++++++++++++------------------------
Msrc/arch/neon.h | 22+++++++++++-----------
Msrc/arch/portable.h | 14+++++++-------
Msrc/core/constant_cubes.h | 228++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/core/cube.h | 33+++++++++++++++++----------------
Msrc/core/io_cube.h | 14+++++++-------
Msrc/core/moves.h | 86++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/core/transform.h | 8++++----
Msrc/core/transform_with_switch.h | 8++++----
Msrc/nissy.c | 4++--
Msrc/solvers/h48/coordinate.h | 2+-
Msrc/solvers/h48/gendata_cocsep.h | 2+-
Msrc/solvers/h48/gendata_h48.h | 10+++++-----
Msrc/solvers/h48/map.h | 2+-
Msrc/utils/math.h | 8++++----
15 files changed, 245 insertions(+), 244 deletions(-)

diff --git a/src/arch/avx2.h b/src/arch/avx2.h @@ -1,19 +1,19 @@ -#define _co2_avx2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x6060606060606060)) -#define _cocw_avx2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x2020202020202020)) -#define _cp_avx2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x0707070707070707)) -#define _ep_avx2 \ +#define CO2_AVX2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x6060606060606060)) +#define COCW_AVX2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x2020202020202020)) +#define CP_AVX2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x0707070707070707)) +#define EP_AVX2 \ _mm256_set_epi64x(INT64_C(0x0F0F0F0F), INT64_C(0x0F0F0F0F0F0F0F0F), 0, 0) -#define _eo_avx2 \ +#define EO_AVX2 \ _mm256_set_epi64x(INT64_C(0x10101010), INT64_C(0x1010101010101010), 0, 0) -#define static_cube(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ +#define STATIC_CUBE(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ e_uf, e_ub, e_db, e_df, e_ur, e_ul, e_dl, e_dr, e_fr, e_fl, e_bl, e_br) \ _mm256_set_epi8(0, 0, 0, 0, e_br, e_bl, e_fl, e_fr, \ e_dr, e_dl, e_ul, e_ur, e_df, e_db, e_ub, e_uf, \ 0, 0, 0, 0, 0, 0, 0, 0, \ c_dbl, c_dfr, c_ubr, c_ufl, c_dbr, c_dfl, c_ubl, c_ufr) -#define zero _mm256_set_epi64x(0, 0, 0, 0) -#define solved static_cube( \ +#define ZERO_CUBE _mm256_set_epi64x(0, 0, 0, 0) +#define SOLVED_CUBE STATIC_CUBE( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) STATIC void @@ -43,11 +43,11 @@ invertco(cube_t c) { cube_t co, shleft, shright, summed, newco, cleanco, ret; - co = _mm256_and_si256(c, _co2_avx2); + co = _mm256_and_si256(c, CO2_AVX2); shleft = _mm256_slli_epi32(co, 1); shright = _mm256_srli_epi32(co, 1); summed = _mm256_or_si256(shleft, shright); - newco = _mm256_and_si256(summed, _co2_avx2); + newco = _mm256_and_si256(summed, CO2_AVX2); cleanco = _mm256_xor_si256(c, co); ret = _mm256_or_si256(cleanco, newco); @@ -68,7 +68,7 @@ compose_epcpeo(cube_t c1, cube_t c2) s = _mm256_andnot_si256(b, s); /* Change EO */ - eo2 = _mm256_and_si256(c2, _eo_avx2); + eo2 = _mm256_and_si256(c2, EO_AVX2); s = _mm256_xor_si256(s, eo2); return s; @@ -99,16 +99,16 @@ compose(cube_t c1, cube_t c2) s = compose_epcpeo(c1, c2); /* Change CO */ - co1 = _mm256_and_si256(s, _co2_avx2); - co2 = _mm256_and_si256(c2, _co2_avx2); + co1 = _mm256_and_si256(s, CO2_AVX2); + co2 = _mm256_and_si256(c2, CO2_AVX2); aux = _mm256_add_epi8(co1, co2); - auy1 = _mm256_add_epi8(aux, _cocw_avx2); + auy1 = _mm256_add_epi8(aux, COCW_AVX2); auy2 = _mm256_srli_epi32(auy1, 2); auz1 = _mm256_add_epi8(aux, auy2); - auz2 = _mm256_and_si256(auz1, _co2_avx2); + auz2 = _mm256_and_si256(auz1, CO2_AVX2); /* Put together */ - s = _mm256_andnot_si256(_co2_avx2, s); + s = _mm256_andnot_si256(CO2_AVX2, s); s = _mm256_or_si256(s, auz2); return s; @@ -157,9 +157,9 @@ inverse(cube_t c) vi = _mm256_shuffle_epi8(vi, vi); vi = _mm256_shuffle_epi8(vi, c); - vo = _mm256_and_si256(c, _mm256_or_si256(_eo_avx2, _co2_avx2)); + vo = _mm256_and_si256(c, _mm256_or_si256(EO_AVX2, CO2_AVX2)); vo = _mm256_shuffle_epi8(vo, vi); - vp = _mm256_andnot_si256(_mm256_or_si256(_eo_avx2, _co2_avx2), vi); + vp = _mm256_andnot_si256(_mm256_or_si256(EO_AVX2, CO2_AVX2), vi); ret = _mm256_or_si256(vp, vo); ret = cleanaftershuffle(ret); @@ -172,7 +172,7 @@ coord_co(cube_t c) cube_t co; int64_t mem[4], ret, i, p; - co = _mm256_and_si256(c, _co2_avx2); + co = _mm256_and_si256(c, CO2_AVX2); _mm256_storeu_si256((__m256i *)mem, co); mem[0] >>= 5; @@ -188,7 +188,7 @@ coord_csep(cube_t c) cube_t cp, shifted; int64_t mask; - cp = _mm256_and_si256(c, _cp_avx2); + cp = _mm256_and_si256(c, CP_AVX2); shifted = _mm256_slli_epi32(cp, 5); mask = _mm256_movemask_epi8(shifted); @@ -207,7 +207,7 @@ coord_eo(cube_t c) cube_t eo, shifted; int64_t mask; - eo = _mm256_and_si256(c, _eo_avx2); + eo = _mm256_and_si256(c, EO_AVX2); shifted = _mm256_slli_epi32(eo, 3); mask = _mm256_movemask_epi8(shifted); @@ -220,7 +220,7 @@ coord_esep(cube_t c) cube_t ep; int64_t e, mem[4], i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; - ep = _mm256_and_si256(c, _ep_avx2); + ep = _mm256_and_si256(c, EP_AVX2); _mm256_storeu_si256((__m256i *)mem, ep); mem[3] <<= 8; @@ -278,7 +278,7 @@ set_eo(cube_t *cube, int64_t eo) (eo12 & 1) << 4; veo = _mm256_set_epi64x(eotop, eobot, 0, 0); - *cube = _mm256_andnot_si256(_eo_avx2, *cube); + *cube = _mm256_andnot_si256(EO_AVX2, *cube); *cube = _mm256_or_si256(*cube, veo); } @@ -290,7 +290,7 @@ invcoord_esep(int64_t esep) invcoord_esep_array(esep % 70, esep / 70, mem+16); - ret = solved; + ret = SOLVED_CUBE; eee = _mm256_loadu_si256((__m256i_u *)&mem); copy_edges(&ret, eee); diff --git a/src/arch/neon.h b/src/arch/neon.h @@ -1,21 +1,21 @@ -#define _co2_neon vdupq_n_u8(0x60) -#define _cocw_neon vdupq_n_u8(0x20) -#define _cp_neon vdupq_n_u8(0x07) -#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)) +#define CO2_NEON vdupq_n_u8(0x60) +#define COCW_NEON vdupq_n_u8(0x20) +#define CP_NEON vdupq_n_u8(0x07) +#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 cube -#define static_cube(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ +#define STATIC_CUBE(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ e_uf, e_ub, e_db, e_df, e_ur, e_ul, e_dl, e_dr, e_fr, e_fl, e_bl, e_br) \ ((cube_t){ \ .corner = {c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, 0, 0, 0, 0, 0, 0, 0, 0}, \ .edge = {e_uf, e_ub, e_db, e_df, e_ur, e_ul, e_dl, e_dr, e_fr, e_fl, e_bl, e_br, 0, 0, 0, 0}}) // zero cube -#define zero \ +#define ZERO_CUBE \ (cube_t) \ { \ .corner = vdupq_n_u8(0), \ @@ -23,7 +23,7 @@ STATIC_INLINE uint8x16_t compose_corners_slim(uint8x16_t, uint8x16_t); } // solved cube -#define solved static_cube( \ +#define SOLVED_CUBE STATIC_CUBE( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) STATIC void @@ -68,11 +68,11 @@ invertco(cube_t c) cube_t ret; uint8x16_t co, shleft, shright, summed, newco, cleanco; - co = vandq_u8(c.corner, _co2_neon); + co = vandq_u8(c.corner, CO2_NEON); shleft = vshlq_n_u8(co, 1); shright = vshrq_n_u8(co, 1); summed = vorrq_u8(shleft, shright); - newco = vandq_u8(summed, _co2_neon); + newco = vandq_u8(summed, CO2_NEON); cleanco = veorq_u8(c.corner, co); ret.corner = vorrq_u8(cleanco, newco); ret.edge = c.edge; @@ -323,7 +323,7 @@ invcoord_esep(int64_t esep) invcoord_esep_array(esep % 70, esep / 70, mem); - ret = solved; + ret = SOLVED_CUBE; ret.edge = vld1q_u8(mem); return ret; diff --git a/src/arch/portable.h b/src/arch/portable.h @@ -1,12 +1,12 @@ -#define static_cube(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ +#define STATIC_CUBE(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \ e_uf, e_ub, e_db, e_df, e_ur, e_ul, e_dl, e_dr, e_fr, e_fl, e_bl, e_br) \ ((cube_t) { \ .corner = { c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl }, \ .edge = { e_uf, e_ub, e_db, e_df, e_ur, e_ul, \ e_dl, e_dr, e_fr, e_fl, e_bl, e_br } }) -#define zero static_cube( \ +#define ZERO_CUBE STATIC_CUBE( \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) -#define solved static_cube( \ +#define SOLVED_CUBE STATIC_CUBE( \ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) STATIC void @@ -80,7 +80,7 @@ compose_corners_inplace(cube_t c1, cube_t c2, cube_t *ret) STATIC_INLINE cube_t compose_edges(cube_t c1, cube_t c2) { - cube_t ret = zero; + cube_t ret = ZERO_CUBE; compose_edges_inplace(c1, c2, &ret); @@ -90,7 +90,7 @@ compose_edges(cube_t c1, cube_t c2) STATIC_INLINE cube_t compose_corners(cube_t c1, cube_t c2) { - cube_t ret = zero; + cube_t ret = ZERO_CUBE; compose_corners_inplace(c1, c2, &ret); @@ -100,7 +100,7 @@ compose_corners(cube_t c1, cube_t c2) STATIC_INLINE cube_t compose(cube_t c1, cube_t c2) { - cube_t ret = zero; + cube_t ret = ZERO_CUBE; compose_edges_inplace(c1, c2, &ret); compose_corners_inplace(c1, c2, &ret); @@ -244,7 +244,7 @@ invcoord_esep(int64_t esep) { cube_t ret; - ret = solved; + ret = SOLVED_CUBE; invcoord_esep_array(esep % 70, esep / 70, ret.edge); return 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,5 +1,5 @@ +STATIC cube_t solvecube(void); 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); @@ -7,19 +7,20 @@ 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); +/* This is used only in tests, use SOLVED_CUBE directly everywhere else */ STATIC cube_t -cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) +solvedcube(void) { - return static_cube( - c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], - e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], - e[8], e[9], e[10], e[11]); + return SOLVED_CUBE; } STATIC cube_t -solvedcube(void) +cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) { - return solved; + return STATIC_CUBE( + c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], + e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], + e[8], e[9], e[10], e[11]); } STATIC bool @@ -127,13 +128,13 @@ issolvable_co: bool issolved(cube_t cube) { - return equal(cube, solved); + return equal(cube, SOLVED_CUBE); } bool iserror(cube_t cube) { - return equal(cube, zero); + return equal(cube, ZERO_CUBE); } STATIC void @@ -149,11 +150,11 @@ getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) indextoperm(*ep, 12, e); indextoperm(*cp, 8, c); if (permsign(e, 12) != permsign(c, 8)) { - _swap(c[0], c[1]); + SWAP(c[0], c[1]); *cp = permtoindex(c, 8); sumzerotodigits(*co, 8, 3, coarr); - _swap(coarr[0], coarr[1]); + SWAP(coarr[0], coarr[1]); *co = digitstosumzero(coarr, 8, 3); } } @@ -164,16 +165,16 @@ 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] != UINT8_ERROR, zero, "Error making EO"); + DBG_ASSERT(eoarr[0] != UINT8_ERROR, ZERO_CUBE, "Error making EO"); indextoperm(ep, 12, earr); - DBG_ASSERT(earr[0] != UINT8_ERROR, zero, "Error making EP"); + DBG_ASSERT(earr[0] != UINT8_ERROR, ZERO_CUBE, "Error making EP"); for (i = 0; i < 12; i++) earr[i] |= eoarr[i] << EOSHIFT; sumzerotodigits(co, 8, 3, coarr); - DBG_ASSERT(coarr[0] != UINT8_ERROR, zero, "Error making CO"); + DBG_ASSERT(coarr[0] != UINT8_ERROR, ZERO_CUBE, "Error making CO"); indextoperm(cp, 8, carr); - DBG_ASSERT(carr[0] != UINT8_ERROR, zero, "Error making CP"); + DBG_ASSERT(carr[0] != UINT8_ERROR, ZERO_CUBE, "Error making CP"); for (i = 0; i < 8; i++) carr[i] |= coarr[i] << COSHIFT; diff --git a/src/core/io_cube.h b/src/core/io_cube.h @@ -39,7 +39,7 @@ readcube(const char *format, const char *buf) return ioformat[i].read(buf); LOG("Cannot read cube in the given format\n"); - return zero; + return ZERO_CUBE; } void @@ -133,13 +133,13 @@ readcube_B32(const char *buf) for (i = 0; i < 8; i++) { c[i] = b32tocorner(buf[i]); - DBG_ASSERT(c[i] < 255, zero, + DBG_ASSERT(c[i] < 255, ZERO_CUBE, "Error reading B32 corner %d (char %d)\n", i, i); } for (i = 0; i < 12; i++) { e[i] = b32toedge(buf[i+9]); - DBG_ASSERT(e[i] < 255, zero, + DBG_ASSERT(e[i] < 255, ZERO_CUBE, "Error reading B32 edge %d (char %d)\n", i, i+9); } @@ -159,10 +159,10 @@ readcube_H48(const char *buf) while (*b == ' ' || *b == '\t' || *b == '\n') b++; if ((piece = readep(b)) == UINT8_ERROR) - return zero; + return ZERO_CUBE; b += 2; if ((orient = readeo(b)) == UINT8_ERROR) - return zero; + return ZERO_CUBE; b++; e[i] = piece | orient; } @@ -170,10 +170,10 @@ readcube_H48(const char *buf) while (*b == ' ' || *b == '\t' || *b == '\n') b++; if ((piece = readcp(b)) == UINT8_ERROR) - return zero; + return ZERO_CUBE; b += 3; if ((orient = readco(b)) == UINT8_ERROR) - return zero; + return ZERO_CUBE; b++; c[i] = piece | orient; } diff --git a/src/core/moves.h b/src/core/moves.h @@ -1,5 +1,5 @@ -#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); @@ -70,44 +70,44 @@ move(cube_t c, uint8_t m) { switch (m) { case MOVE_U: - return _move(U, c); + return MOVE(U, c); case MOVE_U2: - return _move(U2, c); + return MOVE(U2, c); case MOVE_U3: - return _move(U3, c); + return MOVE(U3, c); case MOVE_D: - return _move(D, c); + return MOVE(D, c); case MOVE_D2: - return _move(D2, c); + return MOVE(D2, c); case MOVE_D3: - return _move(D3, c); + return MOVE(D3, c); case MOVE_R: - return _move(R, c); + return MOVE(R, c); case MOVE_R2: - return _move(R2, c); + return MOVE(R2, c); case MOVE_R3: - return _move(R3, c); + return MOVE(R3, c); case MOVE_L: - return _move(L, c); + return MOVE(L, c); case MOVE_L2: - return _move(L2, c); + return MOVE(L2, c); case MOVE_L3: - return _move(L3, c); + return MOVE(L3, c); case MOVE_F: - return _move(F, c); + return MOVE(F, c); case MOVE_F2: - return _move(F2, c); + return MOVE(F2, c); case MOVE_F3: - return _move(F3, c); + return MOVE(F3, c); case MOVE_B: - return _move(B, c); + return MOVE(B, c); case MOVE_B2: - return _move(B2, c); + return MOVE(B2, c); case MOVE_B3: - return _move(B3, c); + return MOVE(B3, c); default: LOG("move error, unknown move\n"); - return zero; + return ZERO_CUBE; } } @@ -116,44 +116,44 @@ premove(cube_t c, uint8_t m) { switch (m) { case MOVE_U: - return _premove(U3, c); + return PREMOVE(U3, c); case MOVE_U2: - return _premove(U2, c); + return PREMOVE(U2, c); case MOVE_U3: - return _premove(U, c); + return PREMOVE(U, c); case MOVE_D: - return _premove(D3, c); + return PREMOVE(D3, c); case MOVE_D2: - return _premove(D2, c); + return PREMOVE(D2, c); case MOVE_D3: - return _premove(D, c); + return PREMOVE(D, c); case MOVE_R: - return _premove(R3, c); + return PREMOVE(R3, c); case MOVE_R2: - return _premove(R2, c); + return PREMOVE(R2, c); case MOVE_R3: - return _premove(R, c); + return PREMOVE(R, c); case MOVE_L: - return _premove(L3, c); + return PREMOVE(L3, c); case MOVE_L2: - return _premove(L2, c); + return PREMOVE(L2, c); case MOVE_L3: - return _premove(L, c); + return PREMOVE(L, c); case MOVE_F: - return _premove(F3, c); + return PREMOVE(F3, c); case MOVE_F2: - return _premove(F2, c); + return PREMOVE(F2, c); case MOVE_F3: - return _premove(F, c); + return PREMOVE(F, c); case MOVE_B: - return _premove(B3, c); + return PREMOVE(B3, c); case MOVE_B2: - return _premove(B2, c); + return PREMOVE(B2, c); case MOVE_B3: - return _premove(B, c); + return PREMOVE(B, c); default: LOG("move error, unknown move\n"); - return zero; + return ZERO_CUBE; } } @@ -178,7 +178,7 @@ applymoves(cube_t cube, const char *buf) uint8_t r, m; const char *b; - DBG_ASSERT(isconsistent(cube), zero, + DBG_ASSERT(isconsistent(cube), ZERO_CUBE, "move error: inconsistent cube\n"); for (b = buf; *b != '\0'; b++) { @@ -198,11 +198,11 @@ applymoves_finish: applymoves_error: LOG("applymoves error\n"); - return zero; + return ZERO_CUBE; } STATIC cube_t frommoves(const char *buf) { - return applymoves(solved, buf); + return applymoves(SOLVED_CUBE, buf); } diff --git a/src/core/transform.h b/src/core/transform.h @@ -110,7 +110,7 @@ transform_edges(cube_t c, uint8_t t) { cube_t ret, trans_cube, trans_inv; - DBG_ASSERT(t < 48, zero, + DBG_ASSERT(t < 48, ZERO_CUBE, "transform: invalid transformation %" PRIu8 ", must be between 0 and 47\n", t); @@ -128,7 +128,7 @@ transform_corners(cube_t c, uint8_t t) { cube_t ret, trans_cube, trans_inv; - DBG_ASSERT(t < 48, zero, + DBG_ASSERT(t < 48, ZERO_CUBE, "transform: invalid transformation %" PRIu8 ", must be between 0 and 47\n", t); @@ -146,7 +146,7 @@ transform(cube_t c, uint8_t t) { cube_t ret, trans_cube, trans_inv; - DBG_ASSERT(t < 48, zero, + DBG_ASSERT(t < 48, ZERO_CUBE, "transform: invalid transformation %" PRIu8 ", must be between 0 and 47\n", t); @@ -164,7 +164,7 @@ applytrans(cube_t cube, const char *buf) { uint8_t t; - DBG_ASSERT(isconsistent(cube), zero, + DBG_ASSERT(isconsistent(cube), ZERO_CUBE, "transformation error: inconsistent cube\n"); t = readtrans(buf); diff --git a/src/core/transform_with_switch.h b/src/core/transform_with_switch.h @@ -124,7 +124,7 @@ transform_edges(cube_t c, uint8_t t) return TRANS_EDGES_MIRRORED(BLm, c); default: LOG("transform error, unknown transformation %" PRIu8 "\n", t); - return zero; + return ZERO_CUBE; } } @@ -230,7 +230,7 @@ transform_corners(cube_t c, uint8_t t) return TRANS_CORNERS_MIRRORED(BLm, c); default: LOG("transform error, unknown transformation %" PRIu8 "\n", t); - return zero; + return ZERO_CUBE; } } @@ -336,7 +336,7 @@ transform(cube_t c, uint8_t t) return TRANS_MIRRORED(BLm, c); default: LOG("transform error, unknown transformation %" PRIu8 "\n", t); - return zero; + return ZERO_CUBE; } } @@ -345,7 +345,7 @@ applytrans(cube_t cube, const char *buf) { uint8_t t; - DBG_ASSERT(isconsistent(cube), zero, + DBG_ASSERT(isconsistent(cube), ZERO_CUBE, "transformation error: inconsistent cube\n"); t = readtrans(buf); diff --git a/src/nissy.c b/src/nissy.c @@ -65,7 +65,7 @@ STATIC int64_t write_result(cube_t cube, char result[static 22]) { if (!isconsistent(cube)) { - writecube("B32", zero, result); + writecube("B32", ZERO_CUBE, result); return 2; } @@ -142,7 +142,7 @@ nissy_frommoves( { cube_t res; - res = applymoves(solved, moves); + res = applymoves(SOLVED_CUBE, moves); return write_result(res, result); } diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h @@ -51,7 +51,7 @@ invcoord_h48(int64_t i, const cube_t *crep, uint8_t h) cube_t ret; int64_t hh, coclass, ee, esep, eo; - DBG_ASSERT(h <= 11, zero, + DBG_ASSERT(h <= 11, ZERO_CUBE, "invcoord_h48: h must be between 0 and 11\n"); hh = (int64_t)h; diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h @@ -57,7 +57,7 @@ gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep) memset(selfsim, 0, sizeof(uint64_t) * COCSEP_CLASSES); arg = (cocsep_dfs_arg_t) { - .cube = solved, + .cube = SOLVED_CUBE, .n = &n, .buf32 = buf32, .visited = visited, diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -1,7 +1,7 @@ #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)) +#define H48_TABLESIZE(h, k) DIV_ROUND_UP((size_t)H48_COORDMAX((h)), H48_DIV(k)) #define H48_COEFF(k) (UINT32_C(32) / (uint32_t)(k)) #define H48_INDEX(i, k) ((uint32_t)(i) / H48_COEFF(k)) @@ -97,7 +97,7 @@ gen_h48short(gendata_h48short_arg_t *arg) kvpair_t kv; cube_t cube, d; - cube = solvedcube(); + cube = SOLVED_CUBE; coord = coord_h48(cube, arg->cocsepdata, 11); h48map_insertmin(arg->map, coord, 0); oldn = 0; @@ -175,7 +175,7 @@ gendata_h48h0k4(gendata_h48_arg_t *arg) goto gendata_h48h0k4_return_size; esep_max = (int64_t)H48_COORDMAX(0); - sc = coord_h48(solved, arg->cocsepdata, 0); + sc = coord_h48(SOLVED_CUBE, arg->cocsepdata, 0); set_esep_pval(arg->h48data, sc, 4, 0); arg->info[1] = 1; bfsarg = (h48h0k4_bfs_arg_t) { @@ -331,7 +331,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) .base = base[arg->h], .depth = shortdepth, .shortdepth = shortdepth, - .maxdepth = _min(arg->maxdepth, base[arg->h]+2), + .maxdepth = MIN(arg->maxdepth, base[arg->h]+2), .cocsepdata = arg->cocsepdata, .h48data = arg->h48data, .selfsim = arg->selfsim, @@ -381,7 +381,7 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) oldval = get_esep_pval(arg->h48data, coord, arg->k); newval = arg->depth >= arg->base ? arg->depth - arg->base : 0; set_esep_pval( - arg->h48data, coord, arg->k, _min(oldval, newval)); + arg->h48data, coord, arg->k, MIN(oldval, newval)); ) fullcoord = coord_h48(arg->cube, arg->cocsepdata, 11); /* Necessary? */ diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h @@ -67,7 +67,7 @@ h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val) i = h48map_lookup(map, key); oldval = map->table[i] >> MAP_KEYSHIFT; - min = _min(val, oldval); + min = MIN(val, oldval); map->n += map->table[i] == MAP_UNSET; map->table[i] = (key & MAP_KEYMASK) | (min << MAP_KEYSHIFT); diff --git a/src/utils/math.h b/src/utils/math.h @@ -1,7 +1,7 @@ -#define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) -#define _min(x, y) ((x) < (y) ? (x) : (y)) -#define _max(x, y) ((x) > (y) ? (x) : (y)) -#define _div_round_up(n, d) (((n) + (d) - 1) / (d)) +#define SWAP(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) +#define MIN(x, y) ((x) < (y) ? (x) : (y)) +#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);