nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit ea0387796a349c91032fbcb10f50c6ad8607b0f6
parent 52c21640508c3fc668107778ae027ff4428ebd89
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Tue, 29 Jul 2025 12:12:43 +0200

All coordinates unsigned

Diffstat:
Msrc/arch/avx2.h | 60++++++++++++++++++++++++++++++------------------------------
Msrc/arch/common.h | 36++++++++++++++++++------------------
Msrc/arch/neon.h | 59+++++++++++++++++++++++++++++------------------------------
Msrc/arch/portable.h | 32++++++++++++++++----------------
Msrc/core/cube.h | 24++++++++++++------------
Msrc/solvers/coord/dr.h | 8++------
Msrc/solvers/coord/dreo.h | 6+++---
Msrc/solvers/coord/eo.h | 2+-
Msrc/solvers/coord/gendata.h | 2+-
Msrc/solvers/h48/coordinate.h | 28++++++++++++++--------------
Msrc/solvers/h48/coordinate_types_macros.h | 2+-
Msrc/solvers/h48/gendata_cocsep.h | 12++++++------
Msrc/solvers/h48/gendata_eoesep.h | 42+++++++++++++++++++++---------------------
Msrc/solvers/h48/gendata_h48.h | 42+++++++++++++++++++++---------------------
Msrc/solvers/h48/gendata_types_macros.h | 10+++++-----
Msrc/solvers/h48/map.h | 2+-
Msrc/solvers/h48/solve.h | 10+++++-----
Msrc/utils/constants.h | 18+++++++++---------
Msrc/utils/math.h | 39++++++++++++++++++++-------------------
Mtest/010_math_permtoindex/permtoindex_tests.c | 6+++---
Mtest/011_math_indextoperm/indextoperm_tests.c | 4++--
Mtest/012_math_permsign/permsign_tests.c | 2+-
Mtest/013_math_digitstosumzero/digitstosumzero_tests.c | 6+++---
Mtest/014_math_sumzerotodigits/sumzerotodigits.c | 4++--
Mtest/071_coord_eo/coord_eo_tests.c | 6+++---
Mtest/072_coord_co/coord_co_tests.c | 6+++---
Mtest/073_coord_csep/coord_csep_tests.c | 6+++---
Mtest/074_coord_esep/coord_esep_tests.c | 6+++---
Mtest/075_set_eo/set_eo_tests.c | 6+++---
Mtest/078_invcoord_esep/invcoord_esep_tests.c | 8++++----
Mtest/079_invcoord_co/invcoord_co_tests.c | 10+++++-----
Mtest/080_invcoord_cp/invcoord_cp_tests.c | 10+++++-----
Mtest/081_invcoord_epud/invcoord_epud_tests.c | 10+++++-----
Mtest/091_getcube/getcube_tests.c | 4++--
Mtest/111_cocsep_transform_invariant/cocsep_transform_invariant.c | 12++++++------
Mtest/112_cocsep_selfsim/cocsep_selfsim_tests.c | 6+++---
Mtest/113_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c | 1-
Mtest/114_cocsep_ttrep/cocsep_ttrep_tests.c | 8++++----
Mtest/120_coord_invcoord_h48/coord_invcoord_h48_tests.c | 6+++---
39 files changed, 278 insertions(+), 283 deletions(-)

diff --git a/src/arch/avx2.h b/src/arch/avx2.h @@ -25,8 +25,8 @@ #define SOLVED_CUBE _mm256_set_epi64x(SOLVED_H, SOLVED_L, 0, SOLVED_L) -STATIC_INLINE int64_t permtoindex_8x8(int64_t); -STATIC_INLINE int64_t indextoperm_8x8(int64_t); +STATIC_INLINE uint64_t permtoindex_8x8(int64_t); +STATIC_INLINE int64_t indextoperm_8x8(uint64_t); STATIC_INLINE int popcount_u32(uint32_t x) @@ -144,11 +144,11 @@ inverse(cube_t c) return invertco(ret); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_co(cube_t c) { cube_t co; - int64_t mem[4], ret, i, p; + uint64_t mem[4], ret, i, p; co = _mm256_and_si256(c, CO2_AVX2); _mm256_storeu_si256((__m256i *)mem, co); @@ -161,15 +161,15 @@ coord_co(cube_t c) } STATIC_INLINE cube_t -invcoord_co(int64_t coord) +invcoord_co(uint64_t coord) { - int64_t i, c, p, co, mem[4] = {0}; + uint64_t i, c, p, co, mem[4] = {0}; cube_t cube, cc; for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) { co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3); p += co; - mem[0] |= (int64_t)(i + (co << COSHIFT)) << (int64_t)(8 * i); + mem[0] |= (uint64_t)(i + (co << COSHIFT)) << (uint64_t)(8 * i); } cc = _mm256_loadu_si256((const __m256i *)mem); @@ -179,43 +179,43 @@ invcoord_co(int64_t coord) return cube; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_csep(cube_t c) { cube_t cp, shifted; - int64_t mask; + int mask; cp = _mm256_and_si256(c, CP_AVX2); shifted = _mm256_slli_epi32(cp, 5); mask = _mm256_movemask_epi8(shifted); - return mask & 0x7F; + return (uint64_t)(mask & 0x7F); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_cocsep(cube_t c) { - return (coord_co(c) << 7) + coord_csep(c); + return (coord_co(c) << UINT8_C(7)) + coord_csep(c); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_eo(cube_t c) { cube_t eo, shifted; - int64_t mask; + int mask; eo = _mm256_and_si256(c, EO_AVX2); shifted = _mm256_slli_epi32(eo, 3); mask = _mm256_movemask_epi8(shifted); - return mask >> 17; + return (uint64_t)(mask >> 17); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_esep(cube_t c) { cube_t ep; - int64_t e, mem[4], i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; + uint64_t e, mem[4], i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; ep = _mm256_and_si256(c, EP_AVX2); _mm256_storeu_si256((__m256i *)mem, ep); @@ -243,12 +243,12 @@ coord_esep(cube_t c) } STATIC_INLINE cube_t -invcoord_esep(int64_t esep) +invcoord_esep(uint64_t esep) { cube_t eee, ret; uint8_t mem[32] = {0}; - invcoord_esep_array(esep % 70, esep / 70, mem+16); + invcoord_esep_array(esep % UINT64_C(70), esep / UINT64_C(70), mem+16); ret = SOLVED_CUBE; eee = _mm256_loadu_si256((__m256i_u *)&mem); @@ -270,9 +270,9 @@ copy_edges(cube_t dest[static 1], cube_t src) } STATIC_INLINE void -set_eo(cube_t cube[static 1], int64_t eo) +set_eo(cube_t cube[static 1], uint64_t eo) { - int64_t eo12, eotop, eobot; + uint64_t eo12, eotop, eobot; __m256i veo; eo12 = (eo << 1) + (_mm_popcnt_u64(eo) % 2); @@ -294,17 +294,17 @@ set_eo(cube_t cube[static 1], int64_t eo) *cube = _mm256_or_si256(*cube, veo); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t permtoindex_8x8(int64_t a) { - int64_t i, c, ret; + uint64_t i, c, ret; __m64 cmp; for (i = 0, ret = 0; i < 8; i++) { cmp = _mm_set1_pi8(a & INT64_C(0xFF)); a = (a >> INT64_C(8)) | INT64_C(0x0F00000000000000); cmp = _mm_cmpgt_pi8(cmp, _mm_cvtsi64_m64(a)); - c = _mm_popcnt_u64(_mm_cvtm64_si64(cmp)) >> INT64_C(3); + c = _mm_popcnt_u64(_mm_cvtm64_si64(cmp)) >> UINT64_C(3); ret += c * factorial[7-i]; } @@ -312,10 +312,10 @@ permtoindex_8x8(int64_t a) } STATIC_INLINE int64_t -indextoperm_8x8(int64_t p) +indextoperm_8x8(uint64_t p) { int used; - int64_t c, k, i, j, ret; + uint64_t c, k, i, j, ret; for (i = 0, ret = 0, used = 0; i < 8; i++) { k = p / factorial[7-i]; @@ -332,7 +332,7 @@ indextoperm_8x8(int64_t p) return ret; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_cp(cube_t cube) { cube_t cp; @@ -345,12 +345,12 @@ coord_cp(cube_t cube) } STATIC_INLINE cube_t -invcoord_cp(int64_t i) +invcoord_cp(uint64_t i) { return _mm256_set_epi64x(SOLVED_H, SOLVED_L, 0, indextoperm_8x8(i)); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_epud(cube_t cube) { cube_t ep; @@ -363,7 +363,7 @@ coord_epud(cube_t cube) } STATIC_INLINE cube_t -invcoord_epud(int64_t i) +invcoord_epud(uint64_t i) { return _mm256_set_epi64x(SOLVED_H, indextoperm_8x8(i), 0, SOLVED_L); } diff --git a/src/arch/common.h b/src/arch/common.h @@ -22,30 +22,30 @@ 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 cube_t invcoord_co(int64_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 cube_t invcoord_esep(int64_t); +STATIC_INLINE uint64_t coord_co(cube_t); +STATIC_INLINE cube_t invcoord_co(uint64_t); +STATIC_INLINE uint64_t coord_csep(cube_t); +STATIC_INLINE uint64_t coord_cocsep(cube_t); +STATIC_INLINE uint64_t coord_eo(cube_t); +STATIC_INLINE uint64_t coord_esep(cube_t); +STATIC_INLINE cube_t invcoord_esep(uint64_t); STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); -STATIC_INLINE void set_eo(cube_t [static 1], int64_t); +STATIC_INLINE void set_eo(cube_t [static 1], uint64_t); -STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); -STATIC_INLINE cube_t invcoord_eoesep(int64_t); +STATIC_INLINE void invcoord_esep_array(uint64_t, uint64_t, uint8_t[static 12]); +STATIC_INLINE cube_t invcoord_eoesep(uint64_t); -STATIC_INLINE int64_t coord_cp(cube_t); -STATIC_INLINE cube_t invcoord_cp(int64_t); -STATIC_INLINE int64_t coord_epud(cube_t); -STATIC_INLINE cube_t invcoord_epud(int64_t); +STATIC_INLINE uint64_t coord_cp(cube_t); +STATIC_INLINE cube_t invcoord_cp(uint64_t); +STATIC_INLINE uint64_t coord_epud(cube_t); +STATIC_INLINE cube_t invcoord_epud(uint64_t); STATIC_INLINE void -invcoord_esep_array(int64_t set1, int64_t set2, uint8_t mem[static 12]) +invcoord_esep_array(uint64_t set1, uint64_t set2, uint8_t mem[static 12]) { - int64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1; + uint64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1; uint8_t slice[3] = {0}; for (i = 0, j = 0, k = 4, l = 4; i < 12; i++) @@ -69,10 +69,10 @@ invcoord_esep_array(int64_t set1, int64_t set2, uint8_t mem[static 12]) } STATIC_INLINE cube_t -invcoord_eoesep(int64_t i) +invcoord_eoesep(uint64_t i) { cube_t c; - int64_t esep, eo; + uint64_t esep, eo; esep = i >> INT64_C(11); eo = i % POW_2_11; diff --git a/src/arch/neon.h b/src/arch/neon.h @@ -29,8 +29,8 @@ STATIC_INLINE uint8x8_t compose_corners_slim(uint8x8_t, uint8x8_t); const uint8_t SOLVED_L[8] = {0, 1, 2, 3, 4, 5, 6, 7}; const uint8_t SOLVED_H[8] = {8, 9, 10, 11, 0, 0, 0}; -STATIC_INLINE int64_t permtoindex_8x8(uint8x8_t); -STATIC_INLINE uint8x8_t indextoperm_8x8(int64_t); +STATIC_INLINE uint64_t permtoindex_8x8(uint8x8_t); +STATIC_INLINE uint8x8_t indextoperm_8x8(uint64_t); STATIC_INLINE int popcount_u32(uint32_t x) @@ -215,16 +215,15 @@ inverse(cube_t cube) return ret; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_co(cube_t c) { + uint64_t i, p, ret; + // Temp array to store the NEON vector uint8_t mem[8]; vst1_u8(mem, c.corner); - int i, p; - int64_t ret; - for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) ret += p * (mem[i] >> COSHIFT); @@ -232,9 +231,9 @@ coord_co(cube_t c) } STATIC_INLINE cube_t -invcoord_co(int64_t coord) +invcoord_co(uint64_t coord) { - int64_t co, c, i, p; + uint64_t co, c, i, p; uint8_t mem[8]; cube_t cube; @@ -250,15 +249,15 @@ invcoord_co(int64_t coord) return cube; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_csep(cube_t c) { + uint64_t ret, i, p; + // Temp array to store the NEON vector uint8_t mem[8]; vst1_u8(mem, c.corner); - 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); @@ -266,23 +265,23 @@ coord_csep(cube_t c) return 0; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_cocsep(cube_t c) { - return (coord_co(c) << 7) + coord_csep(c); + return (coord_co(c) << UINT64_C(7)) + coord_csep(c); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_eo(cube_t c) { - int64_t ret = 0; - int64_t p = 1; + uint64_t ret, p; + int i; // Temp array to store the NEON vector uint8_t mem[16]; vst1q_u8(mem, c.edge); - for (int i = 1; i < 12; i++, p *= 2) + for (i = 1, ret = 0, p = 1; i < 12; i++, p *= 2) { ret += p * (mem[i] >> EOSHIFT); } @@ -290,10 +289,10 @@ coord_eo(cube_t c) return ret; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_esep(cube_t c) { - int64_t i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; + uint64_t i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; // Temp array to store the NEON vector uint8_t mem[16]; @@ -330,7 +329,7 @@ copy_edges(cube_t dst[static 1], cube_t src) } STATIC_INLINE void -set_eo(cube_t cube[static 1], int64_t eo) +set_eo(cube_t cube[static 1], uint64_t eo) { // Temp array to store the NEON vector uint8_t mem[16]; @@ -351,12 +350,12 @@ set_eo(cube_t cube[static 1], int64_t eo) } STATIC_INLINE cube_t -invcoord_esep(int64_t esep) +invcoord_esep(uint64_t esep) { cube_t ret; uint8_t mem[16] = {0}; - invcoord_esep_array(esep % 70, esep / 70, mem); + invcoord_esep_array(esep % UINT64_C(70), esep / UINT64_C(70), mem); ret = SOLVED_CUBE; ret.edge = vld1q_u8(mem); @@ -364,10 +363,10 @@ invcoord_esep(int64_t esep) return ret; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t permtoindex_8x8(uint8x8_t a) { - int64_t i, c, ret; + uint64_t i, c, ret; uint8x8_t cmp; uint64x1_t anum; uint8_t or[8] = {0, 0, 0, 0, 0, 0, 0, 0x0F}; @@ -387,10 +386,10 @@ permtoindex_8x8(uint8x8_t a) } STATIC_INLINE uint8x8_t -indextoperm_8x8(int64_t p) +indextoperm_8x8(uint64_t p) { int used; - int64_t c, k, i, j; + uint64_t c, k, i, j; uint8_t ret[8]; for (i = 0, used = 0; i < 8; i++) { @@ -408,14 +407,14 @@ indextoperm_8x8(int64_t p) return vld1_u8(ret); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_cp(cube_t cube) { return permtoindex_8x8(vand_u8(cube.corner, PBITS8_NEON)); } STATIC_INLINE cube_t -invcoord_cp(int64_t i) +invcoord_cp(uint64_t i) { return (cube_t) { .corner = indextoperm_8x8(i), @@ -423,14 +422,14 @@ invcoord_cp(int64_t i) }; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_epud(cube_t cube) { return permtoindex_8x8(vand_u8(vget_low_u8(cube.edge), PBITS8_NEON)); } STATIC_INLINE cube_t -invcoord_epud(int64_t i) +invcoord_epud(uint64_t i) { return (cube_t) { .corner = vld1_u8(SOLVED_L), diff --git a/src/arch/portable.h b/src/arch/portable.h @@ -154,7 +154,7 @@ inverse(cube_t cube) return ret; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_co(cube_t c) { int i, p, ret; @@ -166,9 +166,9 @@ coord_co(cube_t c) } STATIC_INLINE cube_t -invcoord_co(int64_t coord) +invcoord_co(uint64_t coord) { - int64_t i, c, p; + uint64_t i, c, p; cube_t cube; cube = SOLVED_CUBE; @@ -189,11 +189,11 @@ 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 uint64_t coord_csep(cube_t c) { int i, p; - int64_t ret; + uint64_t ret; for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 2) ret += p * ((c.corner[i] & CSEPBIT) >> 2); @@ -201,17 +201,17 @@ coord_csep(cube_t c) return ret; } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_cocsep(cube_t c) { return (coord_co(c) << 7) + coord_csep(c); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_eo(cube_t c) { int i, p; - int64_t ret; + uint64_t ret; for (ret = 0, i = 1, p = 1; i < 12; i++, p *= 2) ret += p * (c.edge[i] >> EOSHIFT); @@ -223,10 +223,10 @@ 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 uint64_t coord_esep(cube_t c) { - int64_t i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; + uint64_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: @@ -256,7 +256,7 @@ coord_esep(cube_t c) } STATIC_INLINE cube_t -invcoord_esep(int64_t esep) +invcoord_esep(uint64_t esep) { cube_t ret; @@ -279,7 +279,7 @@ copy_edges(cube_t dest[static 1], cube_t src) } STATIC_INLINE void -set_eo(cube_t cube[static 1], int64_t eo) +set_eo(cube_t cube[static 1], uint64_t eo) { uint8_t i, sum, flip; @@ -291,7 +291,7 @@ set_eo(cube_t cube[static 1], int64_t eo) cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_cp(cube_t cube) { int i; @@ -303,7 +303,7 @@ coord_cp(cube_t cube) } STATIC_INLINE cube_t -invcoord_cp(int64_t i) +invcoord_cp(uint64_t i) { uint8_t c[8]; @@ -313,7 +313,7 @@ invcoord_cp(int64_t i) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); } -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_epud(cube_t cube) { int i; @@ -325,7 +325,7 @@ coord_epud(cube_t cube) } STATIC_INLINE cube_t -invcoord_epud(int64_t i) +invcoord_epud(uint64_t i) { uint8_t e[8]; diff --git a/src/core/cube.h b/src/core/cube.h @@ -5,7 +5,7 @@ STATIC bool issolved(oriented_cube_t); STATIC bool iserror(oriented_cube_t); STATIC void getcube_fix(long long *, long long *, long long *, long long *, long long *); -STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); +STATIC cube_t getcube(uint64_t, uint64_t, uint64_t, uint64_t); STATIC oriented_cube_t readcube(const char *); STATIC int64_t writecube(oriented_cube_t, size_t n, char [n]); @@ -150,26 +150,26 @@ getcube_fix( { uint8_t e[12], c[8], coarr[8]; - *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; - *orien = (*orien % 24 + 24) % 24; + *ep = POSITIVE_MOD(*ep, (long long)FACT_12); + *eo = POSITIVE_MOD(*eo, (long long)POW_2_11); + *cp = POSITIVE_MOD(*cp, (long long)FACT_8); + *co = POSITIVE_MOD(*co, (long long)POW_3_7); + *orien = POSITIVE_MOD(*orien, 24LL); - indextoperm(*ep, 12, e); - indextoperm(*cp, 8, c); + indextoperm((uint64_t)*ep, 12, e); + indextoperm((uint64_t)*cp, 8, c); if (permsign(12, e) != permsign(8, c)) { SWAP(c[0], c[1]); - *cp = permtoindex(8, c); + *cp = (long long)permtoindex(8, c); - sumzerotodigits(*co, 8, 3, coarr); + sumzerotodigits((uint64_t)*co, 8, 3, coarr); SWAP(coarr[0], coarr[1]); - *co = digitstosumzero(8, coarr, 3); + *co = (uint64_t)digitstosumzero(8, coarr, 3); } } STATIC cube_t -getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co) +getcube(uint64_t ep, uint64_t eo, uint64_t cp, uint64_t co) { uint8_t i, earr[12], carr[8], eoarr[12], coarr[8]; diff --git a/src/solvers/coord/dr.h b/src/solvers/coord/dr.h @@ -12,10 +12,6 @@ STATIC size_t coordinate_dr_gendata(unsigned char *); STATIC bool is_eoco_solvable(cube_t); -/* TODO: remove the following two when all coordinates are converted to unsigned */ -STATIC uint64_t coord_co_u(cube_t c) { return (uint64_t)coord_co(c); } -STATIC cube_t invcoord_co_u(uint64_t i) { return invcoord_co((int64_t)i); } - STATIC coord_t coordinate_dr = { .name = "DR", .coord = &coordinate_dr_coord, @@ -54,8 +50,8 @@ STATIC coord_t coordinate_dr = { .coord = &coord_dreoesep_nosym, .cube = &invcoord_dreoesep_nosym, .max2 = POW_3_7, - .coord2 = &coord_co_u, - .cube2 = &invcoord_co_u, + .coord2 = &coord_co, + .cube2 = &invcoord_co, .merge = &coordinate_dr_merge, }, }; diff --git a/src/solvers/coord/dreo.h b/src/solvers/coord/dreo.h @@ -47,8 +47,8 @@ STATIC coord_t coordinate_dreo = { .coord = &coord_dresep_nosym, .cube = &invcoord_dresep_nosym, .max2 = POW_3_7, - .coord2 = &coord_co_u, - .cube2 = &invcoord_co_u, + .coord2 = &coord_co, + .cube2 = &invcoord_co, .merge = &coordinate_dreo_merge, }, }; @@ -56,7 +56,7 @@ STATIC coord_t coordinate_dreo = { STATIC uint64_t coord_dresep_nosym(cube_t cube) { - return (uint64_t)coord_esep(cube) / COMB_8_4; + return coord_esep(cube) / COMB_8_4; } STATIC cube_t diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h @@ -44,7 +44,7 @@ STATIC cube_t coordinate_eo_cube(uint64_t c, const unsigned char *data) { cube_t cube = SOLVED_CUBE; - set_eo(&cube, (int64_t)c); + set_eo(&cube, c); return cube; } diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h @@ -29,7 +29,7 @@ gendata_coord_dispatch( return NISSY_ERROR_INVALID_SOLVER; } - return (int64_t)gendata_coord(coord, buf); + return gendata_coord(coord, buf); } STATIC size_t diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h @@ -1,17 +1,17 @@ -STATIC_INLINE int64_t coord_h48( +STATIC_INLINE uint64_t coord_h48( cube_t, const uint32_t [static COCSEP_TABLESIZE], uint8_t); -STATIC_INLINE int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); +STATIC_INLINE uint64_t coord_h48_edges(cube_t, uint64_t, uint8_t, uint8_t); STATIC_INLINE cube_t invcoord_h48( - int64_t, const cube_t [static COCSEP_CLASSES], uint8_t); + uint64_t, const cube_t [static COCSEP_CLASSES], uint8_t); -STATIC_INLINE int64_t +STATIC_INLINE uint64_t coord_h48( cube_t c, const uint32_t cocsepdata[static COCSEP_TABLESIZE], uint8_t h ) { - int64_t cocsep, coclass; + uint64_t cocsep, coclass; uint32_t data; uint8_t ttrep; @@ -19,24 +19,24 @@ coord_h48( cocsep = coord_cocsep(c); data = cocsepdata[cocsep]; - coclass = (int64_t)COCLASS(data); - ttrep = (int64_t)TTREP(data); + coclass = COCLASS(data); + ttrep = TTREP(data); return coord_h48_edges(c, coclass, ttrep, h); } -STATIC_INLINE int64_t -coord_h48_edges(cube_t c, int64_t coclass, uint8_t ttrep, uint8_t h) +STATIC_INLINE uint64_t +coord_h48_edges(cube_t c, uint64_t coclass, uint8_t ttrep, uint8_t h) { cube_t d; - int64_t esep, eo, edges; + uint64_t esep, eo, edges; d = transform_edges(c, ttrep); esep = coord_esep(d); eo = coord_eo(d); edges = (esep << 11) + eo; - return (coclass * H48_ESIZE(11) + edges) >> (11 - (int64_t)h); + return (coclass * H48_ESIZE(11) + edges) >> (11 - (uint64_t)h); } /* @@ -46,17 +46,17 @@ returned cube is a transformed cube of one that gives the correct value. */ STATIC_INLINE cube_t invcoord_h48( - int64_t i, + uint64_t i, const cube_t crep[static COCSEP_CLASSES], uint8_t h ) { cube_t ret; - int64_t hh, coclass, ee, esep, eo; + uint64_t hh, coclass, ee, esep, eo; DBG_ASSERT(h <= 11, "invcoord_h48: h must be between 0 and 11\n"); - hh = (int64_t)h; + hh = (uint64_t)h; coclass = i / H48_ESIZE(h); ee = i % H48_ESIZE(h); esep = ee >> hh; diff --git a/src/solvers/h48/coordinate_types_macros.h b/src/solvers/h48/coordinate_types_macros.h @@ -1,4 +1,4 @@ -#define H48_ESIZE(h) ((COMB_12_4 * COMB_8_4) << (int64_t)(h)) +#define H48_ESIZE(h) ((COMB_12_4 * COMB_8_4) << (uint64_t)(h)) #define COCLASS_MASK (UINT32_C(0xFFFF) << UINT32_C(16)) #define COCLASS(x) (((x) & COCLASS_MASK) >> UINT32_C(16)) diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h @@ -2,9 +2,9 @@ STATIC size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t [static 1]); STATIC_INLINE bool gendata_cocsep_get_visited( - const uint8_t [static COCSEP_VISITEDSIZE], int64_t); + const uint8_t [static COCSEP_VISITEDSIZE], uint64_t); STATIC_INLINE void gendata_cocsep_set_visited( - uint8_t [static COCSEP_VISITEDSIZE], int64_t); + uint8_t [static COCSEP_VISITEDSIZE], uint64_t); STATIC_INLINE int8_t get_h48_cdata( cube_t, const uint32_t [static COCSEP_TABLESIZE], uint32_t *); @@ -84,7 +84,7 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t arg[static 1]) uint8_t m; uint32_t cc, class, ttrep, depth, olddepth, tinv; uint64_t t; - int64_t i, j; + uint64_t i, j; cube_t d; cocsep_dfs_arg_t nextarg; @@ -136,7 +136,7 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t arg[static 1]) STATIC_INLINE bool gendata_cocsep_get_visited( const uint8_t a[static COCSEP_VISITEDSIZE], - int64_t i + uint64_t i ) { return a[VISITED_IND(i)] & VISITED_MASK(i); @@ -145,7 +145,7 @@ gendata_cocsep_get_visited( STATIC_INLINE void gendata_cocsep_set_visited( uint8_t a[static COCSEP_VISITEDSIZE], - int64_t i + uint64_t i ) { a[VISITED_IND(i)] |= VISITED_MASK(i); @@ -158,7 +158,7 @@ get_h48_cdata( uint32_t *cdata ) { - int64_t coord; + uint64_t coord; coord = coord_cocsep(cube); *cdata = cocsepdata[coord]; diff --git a/src/solvers/h48/gendata_eoesep.h b/src/solvers/h48/gendata_eoesep.h @@ -1,4 +1,4 @@ -STATIC int64_t coord_eoesep_sym(cube_t, const uint32_t [static ESEP_MAX]); +STATIC uint64_t coord_eoesep_sym(cube_t, const uint32_t [static ESEP_MAX]); STATIC size_t gendata_esep_classes( uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); STATIC size_t gendata_eoesep(unsigned char *, uint8_t); @@ -8,22 +8,22 @@ STATIC uint32_t gendata_eoesep_fromnew(uint8_t, uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); STATIC uint32_t gendata_eoesep_fromdone(uint8_t, uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); -STATIC uint32_t gendata_eoesep_marksim(int64_t, uint8_t, +STATIC uint32_t gendata_eoesep_marksim(uint64_t, uint8_t, uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]); STATIC bool gendata_eoesep_next(cube_t, uint8_t, uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]); STATIC uint8_t get_eoesep_pval( - const uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t); + const uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], uint64_t); STATIC uint8_t get_eoesep_pval_cube(const unsigned char *, cube_t); STATIC void set_eoesep_pval( - uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t, uint8_t); + uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], uint64_t, uint8_t); -STATIC int64_t +STATIC uint64_t coord_eoesep_sym(cube_t c, const uint32_t esep_classes[static ESEP_MAX]) { uint8_t ttrep; uint32_t edata, class; - int64_t esep, eo; + uint64_t esep, eo; esep = coord_esep(c); edata = esep_classes[esep]; @@ -43,7 +43,7 @@ gendata_esep_classes( bool visited[ESEP_MAX]; uint8_t t; uint32_t class, cl, ti; - int64_t i, j; + uint64_t i, j; cube_t c; memset(visited, 0, ESEP_MAX * sizeof(bool)); @@ -73,7 +73,7 @@ gendata_eoesep(unsigned char *buf, uint8_t maxdepth) unsigned char *buf8; uint16_t rep[ESEP_CLASSES]; uint32_t *esep_classes, done, level; - int64_t coord; + uint64_t coord; tableinfo_t info; if (buf == NULL) @@ -140,18 +140,18 @@ gendata_eoesep_fromdone( ) { uint8_t pval; - int64_t i, esep, eo, coord, done; + uint64_t i, esep, eo, coord, done; done = 0; - for (i = 0; i < (int64_t)ESEP_CLASSES; i++) { + for (i = 0; i < ESEP_CLASSES; i++) { esep = rep[i]; for (eo = 0; eo < POW_2_11; eo++) { - coord = (i << INT64_C(11)) + eo; + coord = (i << UINT64_C(11)) + eo; pval = get_eoesep_pval(buf8, coord); if (pval != d-1) continue; - coord = (esep << INT64_C(11)) + eo; + coord = (esep << UINT64_C(11)) + eo; done += gendata_eoesep_marksim( coord, d, buf8, esep_classes); } @@ -169,19 +169,19 @@ gendata_eoesep_fromnew( ) { uint8_t pval; - int64_t i, esep, eo, coord, done; + uint64_t i, esep, eo, coord, done; cube_t c; done = 0; - for (i = 0; i < (int64_t)ESEP_CLASSES; i++) { + for (i = 0; i < ESEP_CLASSES; i++) { esep = rep[i]; for (eo = 0; eo < POW_2_11; eo++) { - coord = (i << INT64_C(11)) + eo; + coord = (i << UINT64_C(11)) + eo; pval = get_eoesep_pval(buf8, coord); if (pval != 15) continue; - c = invcoord_eoesep((esep << INT64_C(11)) + eo); + c = invcoord_eoesep((esep << UINT64_C(11)) + eo); if (gendata_eoesep_next(c, d, buf8, esep_classes)) { set_eoesep_pval(buf8, coord, d); done++; @@ -194,7 +194,7 @@ gendata_eoesep_fromnew( STATIC uint32_t gendata_eoesep_marksim( - int64_t i, + uint64_t i, uint8_t d, uint8_t buf8[static EOESEP_BUF], uint32_t esep_classes[static ESEP_MAX] @@ -232,7 +232,7 @@ gendata_eoesep_next( ) { uint8_t m, t, pval; - int64_t coord; + uint64_t coord; cube_t moved, transformed; for (t = 0; t < NTRANS; t++) { @@ -252,7 +252,7 @@ gendata_eoesep_next( STATIC uint8_t get_eoesep_pval( const uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], - int64_t i + uint64_t i ) { return (table[EOESEP_INDEX(i)] & EOESEP_MASK(i)) >> EOESEP_SHIFT(i); @@ -261,7 +261,7 @@ get_eoesep_pval( STATIC uint8_t get_eoesep_pval_cube(const unsigned char *data, cube_t c) { - int64_t coord; + uint64_t coord; coord = coord_eoesep_sym(c, (const uint32_t *)data); @@ -271,7 +271,7 @@ get_eoesep_pval_cube(const unsigned char *data, cube_t c) STATIC void set_eoesep_pval( uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], - int64_t i, + uint64_t i, uint8_t val ) { diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -18,12 +18,12 @@ STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]); STATIC const uint32_t *get_cocsepdata_constptr(const unsigned char *); STATIC const unsigned char *get_h48data_constptr(const unsigned char *); -STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, int64_t, uint8_t); -STATIC_INLINE void set_h48_pval(unsigned char *, int64_t, uint8_t, uint8_t); +STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, uint64_t, uint8_t); +STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t, uint8_t); STATIC_INLINE uint8_t get_h48_pval_atomic( - _Atomic const unsigned char *, int64_t, uint8_t); + _Atomic const unsigned char *, uint64_t, uint8_t); STATIC_INLINE void set_h48_pval_atomic( - _Atomic unsigned char *, int64_t, uint8_t, uint8_t); + _Atomic unsigned char *, uint64_t, uint8_t, uint8_t); STATIC long long gendata_h48_dispatch( @@ -50,7 +50,7 @@ STATIC uint64_t gendata_h48short(gendata_h48short_arg_t arg[static 1]) { uint8_t i, m; - int64_t coord; + uint64_t coord; uint64_t j; kvpair_t kv; cube_t cube, d; @@ -106,7 +106,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) if (arg->buf_size < size) { LOG("[H48 gendata] Error: buffer is too small " - "(needed %" PRId64 " bytes but received %" PRId64 ")\n", + "(needed %" PRId64 " bytes but received %" PRIu64 ")\n", size, arg->buf_size); return NISSY_ERROR_BUFFER_SIZE; } @@ -209,7 +209,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) { _Atomic unsigned char *table; uint8_t val; - int64_t i, sc, done, d, h48max; + uint64_t i, sc, done, d, h48max; uint64_t t, tt, isize, cc, bufsize; h48h0k4_bfs_arg_t bfsarg[THREADS]; pthread_t thread[THREADS]; @@ -233,7 +233,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) table = arg->h48buf + INFOSIZE; memset(table, 0xFF, H48_TABLESIZE(0, 4)); - h48max = (int64_t)H48_COORDMAX(0); + h48max = H48_COORDMAX(0); sc = coord_h48(SOLVED_CUBE, arg->cocsepdata, 0); set_h48_pval_atomic(table, sc, 4, 0); arg->info.distribution[0] = 1; @@ -249,13 +249,13 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) .selfsim = arg->selfsim, .crep = arg->crep, .start = isize * t, - .end = t == THREADS-1 ? (uint64_t)h48max : isize * (t+1), + .end = t == THREADS-1 ? h48max : isize * (t+1), }; for (tt = 0; tt < CHUNKS; tt++) bfsarg[t].table_mutex[tt] = &table_mutex[tt]; } for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) { - LOG("[H48 gendata] Generating depth %" PRId64 "\n", d); + LOG("[H48 gendata] Generating depth %" PRIu64 "\n", d); for (t = 0; t < THREADS; t++) { bfsarg[t].depth = d; @@ -274,7 +274,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) done += cc; arg->info.distribution[d] = cc; - LOG("[H48 gendata] Found %" PRId64 "\n", cc); + LOG("[H48 gendata] Found %" PRIu64 "\n", cc); } arg->info.maxvalue = d - 1; @@ -289,7 +289,7 @@ gendata_h48h0k4_runthread(void *arg) uint8_t c, m; uint64_t i; - int64_t j; + uint64_t j; cube_t cube, moved; gendata_h48_mark_t markarg; h48h0k4_bfs_arg_t *bfsarg; @@ -394,7 +394,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) uint8_t t; int sleeptime; unsigned char *table; - int64_t j; + uint64_t j; _Atomic uint64_t count; uint64_t i, ii, inext, bufsize, done, nshort, velocity; h48map_t shortcubes; @@ -510,7 +510,7 @@ gendata_h48k2_runthread(void *arg) pthread_mutex_unlock(dfsarg->shortcubes_mutex); if (kv.val < dfsarg->shortdepth) { - coord = kv.key >> (int64_t)(11 - dfsarg->h); + coord = kv.key >> (uint64_t)(11 - dfsarg->h); mutex = H48_INDEX(coord, dfsarg->k) % CHUNKS; pthread_mutex_lock(dfsarg->table_mutex[mutex]); set_h48_pval(dfsarg->table, coord, dfsarg->k, 0); @@ -607,7 +607,7 @@ STATIC_INLINE void gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) { uint8_t oldval, newval; - int64_t coord, mutex; + uint64_t coord, mutex; FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); @@ -627,7 +627,7 @@ STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t arg[static 1]) { uint8_t oldval, newval; - int64_t coord, mutex; + uint64_t coord, mutex; FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); @@ -644,7 +644,7 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) { uint64_t val; - int64_t coord, mutex; + uint64_t coord, mutex; int8_t oldval; if (arg->h == 0 || arg->h == 11) { @@ -705,19 +705,19 @@ get_h48data_constptr(const unsigned char *data) } STATIC_INLINE uint8_t -get_h48_pval(const unsigned char *table, int64_t i, uint8_t k) +get_h48_pval(const unsigned char *table, uint64_t i, uint8_t k) { return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); } STATIC_INLINE uint8_t -get_h48_pval_atomic(_Atomic const unsigned char *table, int64_t i, uint8_t k) +get_h48_pval_atomic(_Atomic const unsigned char *table, uint64_t i, uint8_t k) { return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); } STATIC_INLINE void -set_h48_pval(unsigned char *table, int64_t i, uint8_t k, uint8_t val) +set_h48_pval(unsigned char *table, uint64_t i, uint8_t k, uint8_t val) { table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) | (val << H48_SHIFT(i, k)); @@ -726,7 +726,7 @@ set_h48_pval(unsigned char *table, int64_t i, uint8_t k, uint8_t val) STATIC_INLINE void set_h48_pval_atomic( _Atomic unsigned char *table, - int64_t i, + uint64_t i, uint8_t k, uint8_t val ) diff --git a/src/solvers/h48/gendata_types_macros.h b/src/solvers/h48/gendata_types_macros.h @@ -18,12 +18,12 @@ #define CBOUND_MASK UINT32_C(0xFF) #define CBOUND(x) ((x) & CBOUND_MASK) -#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * ESEP_MAX)) -#define H48_COORDMAX(h) (H48_COORDMAX_NOEO << (int64_t)(h)) +#define H48_COORDMAX_NOEO (COCSEP_CLASSES * ESEP_MAX) +#define H48_COORDMAX(h) (H48_COORDMAX_NOEO << (uint64_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_COEFF(k) (INT64_C(8) / (int64_t)(k)) +#define H48_COEFF(k) (UINT64_C(8) / (uint64_t)(k)) #define H48_INDEX(i, k) ((i) / H48_COEFF(k)) #define H48_SHIFT(i, k) ((uint8_t)(k) * (uint8_t)((i) % H48_COEFF(k))) #define H48_MASK(i, k) ((UINT8_BIT(k) - UINT8_C(1)) << H48_SHIFT(i, k)) @@ -36,10 +36,10 @@ transforming edges, but we need to compose transformations (i.e. conjugate VAR_T by VAR_TTREP). */ #define FOREACH_H48SIM(ARG_CUBE, ARG_COCSEPDATA, ARG_SELFSIM, ARG_ACTION) \ - int64_t VAR_COCSEP = coord_cocsep(ARG_CUBE); \ + uint64_t VAR_COCSEP = coord_cocsep(ARG_CUBE); \ uint8_t VAR_TTREP = TTREP(ARG_COCSEPDATA[VAR_COCSEP]); \ uint8_t VAR_INVERSE_TTREP = inverse_trans(VAR_TTREP); \ - int64_t VAR_COCLASS = COCLASS(ARG_COCSEPDATA[VAR_COCSEP]); \ + uint64_t VAR_COCLASS = COCLASS(ARG_COCSEPDATA[VAR_COCSEP]); \ cube_t VAR_REP = transform(ARG_CUBE, VAR_TTREP); \ uint64_t VAR_S = ARG_SELFSIM[VAR_COCLASS]; \ for (uint8_t VAR_T = 0; VAR_T < NTRANS && VAR_S; VAR_T++, VAR_S >>= 1) { \ diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h @@ -12,7 +12,7 @@ h48map_create(h48map_t map[static 1], uint64_t capacity, uint64_t randomizer) map->capacity = capacity; map->randomizer = randomizer; - map->table = malloc(map->capacity * sizeof(int64_t)); + map->table = malloc(map->capacity * sizeof(uint64_t)); h48map_clear(map); } diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -36,9 +36,9 @@ typedef struct { const unsigned char *h48data_fallback_eoesep; uint64_t movemask_normal; uint64_t movemask_inverse; - int64_t nodes_visited; - int64_t table_fallbacks; - int64_t table_lookups; + uint64_t nodes_visited; + uint64_t table_fallbacks; + uint64_t table_lookups; int8_t threads; int ntasks; solve_h48_task_t *tasks; @@ -463,7 +463,7 @@ solve_h48( dfsarg_solve_h48_maketasks_t maketasks_arg; long double fallback_rate, lookups_per_node; uint64_t offset; - int64_t nodes_visited, table_lookups, table_fallbacks; + uint64_t nodes_visited, table_lookups, table_fallbacks; tableinfo_t info, fbinfo, fbinfo2; const uint32_t *cocsepdata; const unsigned char *fallback, *h48data; @@ -579,7 +579,7 @@ solve_h48( d++ ) { if (d >= H48_LOG_PROGRESS_MIN_DEPTH) { - LOG("[H48 solve] Found %" PRId64 " solutions, " + LOG("[H48 solve] Found %" PRIu64 " solutions, " "searching at depth %" PRId8 "\n", sollist.nsols, d); } diff --git a/src/utils/constants.h b/src/utils/constants.h @@ -1,17 +1,17 @@ #define UINT8_BIT(i) (UINT8_C(1) << (uint8_t)(i)) -#define FACTORIAL_MAX INT64_C(12) +#define FACTORIAL_MAX UINT64_C(12) -#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) +#define POW_2_11 UINT64_C(2048) +#define POW_3_7 UINT64_C(2187) +#define FACT_12 UINT64_C(479001600) +#define FACT_8 UINT64_C(40320) +#define COMB_12_4 UINT64_C(495) +#define COMB_8_4 UINT64_C(70) #define UINT8_ERROR UINT8_MAX -STATIC int64_t factorial[FACTORIAL_MAX+1] = { +STATIC uint64_t factorial[FACTORIAL_MAX+1] = { [0] = 1, [1] = 1, [2] = 2, @@ -27,7 +27,7 @@ STATIC int64_t factorial[FACTORIAL_MAX+1] = { [12] = 479001600, }; -STATIC int64_t binomial[12][12] = { +STATIC uint64_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}, diff --git a/src/utils/math.h b/src/utils/math.h @@ -2,12 +2,13 @@ #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 POSITIVE_MOD(x, y) (((x) % (y) + (y)) % (y)) -STATIC int64_t permtoindex(size_t, const uint8_t *); -STATIC void indextoperm(int64_t, size_t, uint8_t *); +STATIC uint64_t permtoindex(size_t, const uint8_t *); +STATIC void indextoperm(uint64_t, size_t, uint8_t *); STATIC int permsign(size_t, const uint8_t *); -STATIC int64_t digitstosumzero(size_t, const uint8_t *, uint8_t); -STATIC void sumzerotodigits(int64_t, size_t, uint8_t, uint8_t *); +STATIC uint64_t digitstosumzero(size_t, const uint8_t *, uint8_t); +STATIC void sumzerotodigits(uint64_t, size_t, uint8_t, uint8_t *); STATIC double intpow(double, uint64_t); /* This code is only used for assertions in debug mode */ @@ -36,14 +37,14 @@ isperm(size_t n, const uint8_t *a) } #endif -STATIC int64_t +STATIC uint64_t permtoindex(size_t n, const uint8_t *a) { size_t i, j; - int64_t c, ret; + uint64_t c, ret; DBG_ASSERT(n <= FACTORIAL_MAX, "Error: cannot compute permtoindex() " - "for set of size %zu > %" PRId64 "\n", n, FACTORIAL_MAX); + "for set of size %zu > %" PRIu64 "\n", n, FACTORIAL_MAX); DBG_ASSERT(isperm(n, a), "Error: cannot compute permtoindex() for " "invalid permutation\n"); @@ -57,15 +58,15 @@ permtoindex(size_t n, const uint8_t *a) } STATIC void -indextoperm(int64_t p, size_t n, uint8_t *r) +indextoperm(uint64_t p, size_t n, uint8_t *r) { - int64_t c, k; + uint64_t c, k; size_t i, j, used; DBG_ASSERT(n <= FACTORIAL_MAX, "Error: cannot compute indextoperm() " - "for set of size %zu > %" PRId64 "\n", n, FACTORIAL_MAX); - DBG_ASSERT(p >= 0 && p < factorial[n], "Error: invalid permutation " - "index %" PRId64 " for set of size %zu\n", p, n); + "for set of size %zu > %" PRIu64 "\n", n, FACTORIAL_MAX); + DBG_ASSERT(p < factorial[n], "Error: invalid permutation index %" + PRIu64 " for set of size %zu\n", p, n); for (i = 0, used = 0; i < n; i++) { k = p / factorial[n-i-1]; @@ -94,28 +95,28 @@ permsign(size_t n, const uint8_t *a) return ret % 2; } -STATIC int64_t +STATIC uint64_t digitstosumzero(size_t n, const uint8_t *a, uint8_t b) { - int64_t ret, p; + uint64_t ret, p; size_t i, sum; DBG_ASSERT((n == 8 && b == 3 ) || (n == 12 && b == 2), "Error: digitstosumzero() called with n=%zu and b=%" PRIu8 " (use n=8 b=3 or n=12 b=2)\n", n, b); - for (i = 1, ret = 0, p = 1, sum = 0; i < n; i++, p *= (int64_t)b) { + for (i = 1, ret = 0, p = 1, sum = 0; i < n; i++, p *= (uint64_t)b) { DBG_ASSERT(a[i] < b, "Error: digit %" PRIu8 " > %" PRIu8 "in digitstosumzero()\n", a[i], b); sum += a[i]; - ret += p * (int64_t)a[i]; + ret += p * (uint64_t)a[i]; } return ret; } STATIC void -sumzerotodigits(int64_t d, size_t n, uint8_t b, uint8_t *a) +sumzerotodigits(uint64_t d, size_t n, uint8_t b, uint8_t *a) { uint8_t sum; size_t i; @@ -124,8 +125,8 @@ sumzerotodigits(int64_t d, size_t n, uint8_t b, uint8_t *a) "Error: sumzerotodigits() called with n=%zu and b=%" PRIu8 " (use n=8 b=3 or n=12 b=2)\n", n, b); - for (i = 1, sum = 0; i < n; i++, d /= (int64_t)b) { - a[i] = (uint8_t)(d % (int64_t)b); + for (i = 1, sum = 0; i < n; i++, d /= (uint64_t)b) { + a[i] = (uint8_t)(d % (uint64_t)b); sum += a[i]; } a[0] = (b - (sum % b)) % b; diff --git a/test/010_math_permtoindex/permtoindex_tests.c b/test/010_math_permtoindex/permtoindex_tests.c @@ -1,11 +1,11 @@ #include "../test.h" -int64_t permtoindex(size_t n, const uint8_t [n]); +uint64_t permtoindex(size_t n, const uint8_t [n]); void run(void) { char str[STRLENMAX]; uint8_t a[100]; - int64_t n, i, p; + uint64_t n, i, p; fgets(str, STRLENMAX, stdin); n = atoll(str); @@ -15,5 +15,5 @@ void run(void) { } p = permtoindex(n, a); - printf("%" PRId64 "\n", p); + printf("%" PRIu64 "\n", p); } diff --git a/test/011_math_indextoperm/indextoperm_tests.c b/test/011_math_indextoperm/indextoperm_tests.c @@ -1,11 +1,11 @@ #include "../test.h" -void indextoperm(int64_t, size_t n, uint8_t [n]); +void indextoperm(uint64_t, size_t n, uint8_t [n]); void run(void) { char str[STRLENMAX]; uint8_t a[100]; - int64_t n, p, i; + uint64_t n, p, i; fgets(str, STRLENMAX, stdin); n = atoll(str); diff --git a/test/012_math_permsign/permsign_tests.c b/test/012_math_permsign/permsign_tests.c @@ -6,7 +6,7 @@ void run(void) { char str[STRLENMAX]; uint8_t a[100]; int p; - int64_t n, i; + uint64_t n, i; fgets(str, STRLENMAX, stdin); n = atoll(str); diff --git a/test/013_math_digitstosumzero/digitstosumzero_tests.c b/test/013_math_digitstosumzero/digitstosumzero_tests.c @@ -1,12 +1,12 @@ #include "../test.h" -int64_t digitstosumzero(size_t n, uint8_t [n], uint8_t); +uint64_t digitstosumzero(size_t n, uint8_t [n], uint8_t); void run(void) { char str[STRLENMAX]; uint8_t i, b, a[100]; size_t n; - int64_t p; + uint64_t p; fgets(str, STRLENMAX, stdin); n = atoi(str); @@ -18,5 +18,5 @@ void run(void) { } p = digitstosumzero(n, a, b); - printf("%" PRId64 "\n", p); + printf("%" PRIu64 "\n", p); } diff --git a/test/014_math_sumzerotodigits/sumzerotodigits.c b/test/014_math_sumzerotodigits/sumzerotodigits.c @@ -1,11 +1,11 @@ #include "../test.h" -void sumzerotodigits(int64_t, size_t n, uint8_t, uint8_t [n]); +void sumzerotodigits(uint64_t, size_t n, uint8_t, uint8_t [n]); void run(void) { char str[STRLENMAX]; uint8_t i, n, b, a[100]; - int64_t d; + uint64_t d; fgets(str, STRLENMAX, stdin); n = atoi(str); diff --git a/test/071_coord_eo/coord_eo_tests.c b/test/071_coord_eo/coord_eo_tests.c @@ -1,16 +1,16 @@ #include "../test.h" -int64_t coord_eo(cube_t); +uint64_t coord_eo(cube_t); void run(void) { char str[STRLENMAX]; oriented_cube_t cube; - int64_t result; + uint64_t result; fgets(str, STRLENMAX, stdin); cube = readcube(str); result = coord_eo(cube.cube); - printf("%" PRId64 "\n", result); + printf("%" PRIu64 "\n", result); } diff --git a/test/072_coord_co/coord_co_tests.c b/test/072_coord_co/coord_co_tests.c @@ -1,16 +1,16 @@ #include "../test.h" -int64_t coord_co(cube_t); +uint64_t coord_co(cube_t); void run(void) { char str[STRLENMAX]; oriented_cube_t cube; - int64_t result; + uint64_t result; fgets(str, STRLENMAX, stdin); cube = readcube(str); result = coord_co(cube.cube); - printf("%" PRId64 "\n", result); + printf("%" PRIu64 "\n", result); } diff --git a/test/073_coord_csep/coord_csep_tests.c b/test/073_coord_csep/coord_csep_tests.c @@ -1,16 +1,16 @@ #include "../test.h" -int64_t coord_csep(cube_t); +uint64_t coord_csep(cube_t); void run(void) { char str[STRLENMAX]; oriented_cube_t cube; - int64_t result; + uint64_t result; fgets(str, STRLENMAX, stdin); cube = readcube(str); result = coord_csep(cube.cube); - printf("%" PRId64 "\n", result); + printf("%" PRIu64 "\n", result); } diff --git a/test/074_coord_esep/coord_esep_tests.c b/test/074_coord_esep/coord_esep_tests.c @@ -1,16 +1,16 @@ #include "../test.h" -int64_t coord_esep(cube_t); +uint64_t coord_esep(cube_t); void run(void) { char str[STRLENMAX]; oriented_cube_t cube; - int64_t result; + uint64_t result; fgets(str, STRLENMAX, stdin); cube = readcube(str); result = coord_esep(cube.cube); - printf("%" PRId64 "\n", result); + printf("%" PRIu64 "\n", result); } diff --git a/test/075_set_eo/set_eo_tests.c b/test/075_set_eo/set_eo_tests.c @@ -1,14 +1,14 @@ #include "../test.h" -int64_t coord_eo(cube_t); -void set_eo(cube_t *, int64_t); +uint64_t coord_eo(cube_t); +void set_eo(cube_t *, uint64_t); void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]); void run(void) { char str[STRLENMAX]; oriented_cube_t cube; uint8_t edge[12], corner[8]; - int64_t eo; + uint64_t eo; fgets(str, STRLENMAX, stdin); cube = readcube(str); diff --git a/test/078_invcoord_esep/invcoord_esep_tests.c b/test/078_invcoord_esep/invcoord_esep_tests.c @@ -1,12 +1,12 @@ #include "../test.h" -int64_t coord_esep(cube_t); -cube_t invcoord_esep(int64_t); +uint64_t coord_esep(cube_t); +cube_t invcoord_esep(uint64_t); void run(void) { char str[STRLENMAX]; oriented_cube_t cube; - int64_t i; + uint64_t i; fgets(str, STRLENMAX, stdin); cube = readcube(str); @@ -15,5 +15,5 @@ void run(void) { cube.cube = invcoord_esep(i); i = coord_esep(cube.cube); - printf("%" PRId64 "\n", i); + printf("%" PRIu64 "\n", i); } diff --git a/test/079_invcoord_co/invcoord_co_tests.c b/test/079_invcoord_co/invcoord_co_tests.c @@ -2,12 +2,12 @@ #define POW_3_7 2187 -int64_t coord_co(cube_t); -cube_t invcoord_co(int64_t); +uint64_t coord_co(cube_t); +cube_t invcoord_co(uint64_t); void run(void) { oriented_cube_t cube; - int64_t coord, coord2; + uint64_t coord, coord2; cube.orientation = 0; @@ -26,8 +26,8 @@ void run(void) { coord2 = coord_co(cube.cube); if (coord != coord2) { - printf("Error: invcoord of %" PRId64 - " returns %" PRId64 "\n", coord, coord2); + printf("Error: invcoord of %" PRIu64 + " returns %" PRIu64 "\n", coord, coord2); return; } } diff --git a/test/080_invcoord_cp/invcoord_cp_tests.c b/test/080_invcoord_cp/invcoord_cp_tests.c @@ -2,12 +2,12 @@ #define FACT_8 40320 -int64_t coord_cp(cube_t); -cube_t invcoord_cp(int64_t); +uint64_t coord_cp(cube_t); +cube_t invcoord_cp(uint64_t); void run(void) { oriented_cube_t cube; - int64_t coord, coord2; + uint64_t coord, coord2; cube.orientation = 0; @@ -22,8 +22,8 @@ void run(void) { coord2 = coord_cp(cube.cube); if (coord != coord2) { - printf("Error: invcoord of %" PRId64 - " returns %" PRId64 "\n", coord, coord2); + printf("Error: invcoord of %" PRIu64 + " returns %" PRIu64 "\n", coord, coord2); return; } } diff --git a/test/081_invcoord_epud/invcoord_epud_tests.c b/test/081_invcoord_epud/invcoord_epud_tests.c @@ -2,12 +2,12 @@ #define FACT_8 40320 -int64_t coord_epud(cube_t); -cube_t invcoord_epud(int64_t); +uint64_t coord_epud(cube_t); +cube_t invcoord_epud(uint64_t); void run(void) { oriented_cube_t cube; - int64_t coord, coord2; + uint64_t coord, coord2; cube.orientation = 0; @@ -22,8 +22,8 @@ void run(void) { coord2 = coord_epud(cube.cube); if (coord != coord2) { - printf("Error: invcoord of %" PRId64 - " returns %" PRId64 "\n", coord, coord2); + printf("Error: invcoord of %" PRIu64 + " returns %" PRIu64 "\n", coord, coord2); return; } } diff --git a/test/091_getcube/getcube_tests.c b/test/091_getcube/getcube_tests.c @@ -1,11 +1,11 @@ #include "../test.h" -cube_t getcube(int64_t, int64_t, int64_t, int64_t); +cube_t getcube(uint64_t, uint64_t, uint64_t, uint64_t); void run(void) { char str[STRLENMAX]; oriented_cube_t cube; - int64_t ep, eo, cp, co; + uint64_t ep, eo, cp, co; fgets(str, STRLENMAX, stdin); ep = atoll(str); diff --git a/test/111_cocsep_transform_invariant/cocsep_transform_invariant.c b/test/111_cocsep_transform_invariant/cocsep_transform_invariant.c @@ -2,14 +2,14 @@ size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); cube_t transform(cube_t, uint8_t); -int64_t coord_cocsep(cube_t); +uint64_t coord_cocsep(cube_t); void run(void) { uint8_t t; unsigned char buf[2000000]; uint32_t *cocsepdata; uint64_t selfsim[COCSEP_CLASSES]; - int64_t coord, tcoord; + uint64_t coord, tcoord; char str[STRLENMAX]; oriented_cube_t cube; cube_t rep[COCSEP_CLASSES], transd; @@ -20,12 +20,12 @@ void run(void) { gendata_cocsep(buf, selfsim, rep); cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); - coord = (int64_t)COCLASS(cocsepdata[coord_cocsep(cube.cube)]); + coord = COCLASS(cocsepdata[coord_cocsep(cube.cube)]); for (t = 0; t < 48; t++) { transd = transform(cube.cube, t); - tcoord = (int64_t)COCLASS(cocsepdata[coord_cocsep(transd)]); + tcoord = COCLASS(cocsepdata[coord_cocsep(transd)]); if (coord != tcoord) - printf("Error: expected %" PRId64 - " but got %" PRId64 "\n", coord, tcoord); + printf("Error: expected %" PRIu64 + " but got %" PRIu64 "\n", coord, tcoord); } } diff --git a/test/112_cocsep_selfsim/cocsep_selfsim_tests.c b/test/112_cocsep_selfsim/cocsep_selfsim_tests.c @@ -8,13 +8,13 @@ #include "../test.h" size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); -int64_t coord_cocsep(cube_t); +uint64_t coord_cocsep(cube_t); void run(void) { char str[STRLENMAX]; unsigned char buf[2000000]; uint32_t *cocsepdata, data; - int64_t coord, coclass; + uint64_t coord, coclass; uint64_t selfsim[COCSEP_CLASSES], sim, t; oriented_cube_t cube; cube_t rep[COCSEP_CLASSES]; @@ -32,7 +32,7 @@ void run(void) { sim = selfsim[coclass]; for (t = 0; t < 48 && sim; t++, sim >>= 1) { if (sim & 1) - printf("%" PRId64 " ", t); + printf("%" PRIu64 " ", t); } printf("\n"); } diff --git a/test/113_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c b/test/113_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c @@ -1,7 +1,6 @@ #include "../test.h" size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); -int64_t coord_cocsep(cube_t); int bcount(uint64_t x) { int ret; diff --git a/test/114_cocsep_ttrep/cocsep_ttrep_tests.c b/test/114_cocsep_ttrep/cocsep_ttrep_tests.c @@ -2,7 +2,7 @@ uint8_t inverse_trans(uint8_t); cube_t transform_corners(cube_t, uint8_t); -int64_t coord_cocsep(cube_t); +uint64_t coord_cocsep(cube_t); size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); void run(void) { @@ -10,7 +10,7 @@ void run(void) { unsigned char buf[2000000]; uint32_t *cocsepdata, tt; uint64_t i, selfsim[COCSEP_CLASSES]; - int64_t j, k, l; + uint64_t j, k, l; cube_t rep[COCSEP_CLASSES], c, d; gendata_cocsep(buf, selfsim, rep); @@ -26,8 +26,8 @@ void run(void) { k = coord_cocsep(d); l = coord_cocsep(c); if (k != l) - printf("cocsep %" PRId64 " (%" PRId64 "): " - "%" PRId64 " ttrep %" PRIu32 + printf("cocsep %" PRIu64 " (%" PRIu64 "): " + "%" PRIu64 " ttrep %" PRIu32 " -> %" PRId64 "\n", i, l, j, tt, k); } } diff --git a/test/120_coord_invcoord_h48/coord_invcoord_h48_tests.c b/test/120_coord_invcoord_h48/coord_invcoord_h48_tests.c @@ -1,8 +1,8 @@ #include "../test.h" size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); -int64_t coord_h48(cube_t, const uint32_t *, uint8_t); -cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); +uint64_t coord_h48(cube_t, const uint32_t *, uint8_t); +cube_t invcoord_h48(uint64_t, const cube_t *, uint8_t); cube_t transform(cube_t, uint8_t); void run(void) { @@ -13,7 +13,7 @@ void run(void) { unsigned char buf[2000000]; uint32_t *cocsepdata; uint64_t selfsim[COCSEP_CLASSES]; - int64_t c, cc; + uint64_t c, cc; oriented_cube_t cube; cube_t invc, rep[COCSEP_CLASSES];