From 83338a2f753ebbb7ba7b154cc60b2f427b6121b0 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 26 Mar 2025 19:22:50 +0100 Subject: Added inverse coordinate for CO this is necessary for DR coordinate --- src/arch/avx2.h | 49 ++++++++++++++++++++++++++++++++++--------------- src/arch/common.h | 3 ++- src/arch/neon.h | 19 +++++++++++++++++++ src/arch/portable.h | 42 +++++++++++++++++++++++++++++------------- src/core/cube.h | 2 +- src/core/io_moves.h | 16 ++++++++++++++++ src/nissy.c | 2 +- 7 files changed, 102 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/arch/avx2.h b/src/arch/avx2.h index ebcf84f..4682e33 100644 --- a/src/arch/avx2.h +++ b/src/arch/avx2.h @@ -188,6 +188,25 @@ coord_co(cube_t c) return ret; } +STATIC_INLINE cube_t +invcoord_co(int64_t coord) +{ + int64_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); + } + + cc = _mm256_loadu_si256((const __m256i *)mem); + cube = SOLVED_CUBE; + copy_corners(&cube, cc); + + return cube; +} + STATIC_INLINE int64_t coord_csep(cube_t c) { @@ -251,6 +270,21 @@ coord_esep(cube_t c) return ret1 * 70 + ret2; } +STATIC_INLINE cube_t +invcoord_esep(int64_t esep) +{ + cube_t eee, ret; + uint8_t mem[32] = {0}; + + invcoord_esep_array(esep % 70, esep / 70, mem+16); + + ret = SOLVED_CUBE; + eee = _mm256_loadu_si256((__m256i_u *)&mem); + copy_edges(&ret, eee); + + return ret; +} + STATIC_INLINE void copy_corners(cube_t dest[static 1], cube_t src) { @@ -287,18 +321,3 @@ set_eo(cube_t cube[static 1], int64_t eo) *cube = _mm256_andnot_si256(EO_AVX2, *cube); *cube = _mm256_or_si256(*cube, veo); } - -STATIC_INLINE cube_t -invcoord_esep(int64_t esep) -{ - cube_t eee, ret; - uint8_t mem[32] = {0}; - - invcoord_esep_array(esep % 70, esep / 70, mem+16); - - ret = SOLVED_CUBE; - eee = _mm256_loadu_si256((__m256i_u *)&mem); - copy_edges(&ret, eee); - - return ret; -} diff --git a/src/arch/common.h b/src/arch/common.h index 5c1efde..e57fba9 100644 --- a/src/arch/common.h +++ b/src/arch/common.h @@ -9,15 +9,16 @@ 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 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 cube_t invcoord_esep(int64_t); STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); STATIC_INLINE cube_t invcoord_eoesep(int64_t); diff --git a/src/arch/neon.h b/src/arch/neon.h index d5f5f8b..fc0e612 100644 --- a/src/arch/neon.h +++ b/src/arch/neon.h @@ -219,6 +219,25 @@ coord_co(cube_t c) return ret; } +STATIC_INLINE cube_t +invcoord_co(int64_t coord) +{ + int64_t co, c, i, p; + uint8_t mem[8]; + cube_t cube; + + for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) { + co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3); + p += co; + mem[i] = i + (co << COSHIFT); + } + + cube.corner = vld1_u8(mem); + cube.edge = SOLVED_CUBE.edge; + + return cube; +} + STATIC_INLINE int64_t coord_csep(cube_t c) { diff --git a/src/arch/portable.h b/src/arch/portable.h index 4ac5fe7..56d3074 100644 --- a/src/arch/portable.h +++ b/src/arch/portable.h @@ -144,8 +144,7 @@ inverse(cube_t cube) STATIC_INLINE int64_t coord_co(cube_t c) { - int i, p; - int64_t ret; + int i, p, ret; for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) ret += p * (c.corner[i] >> COSHIFT); @@ -153,6 +152,23 @@ coord_co(cube_t c) return ret; } +STATIC_INLINE cube_t +invcoord_co(int64_t coord) +{ + int64_t i, c, p; + cube_t cube; + + cube = SOLVED_CUBE; + for (i = 0, p = 0, c = coord; i < 7; i++, c /= 3) { + p += c % 3; + cube.corner[i] |= (c % 3) << COSHIFT; + } + + cube.corner[7] |= ((3 - (p % 3)) % 3) << COSHIFT; + + return cube; +} + /* For corner separation, we consider the axis (a.k.a. tetrad) each corner belongs to as 0 or 1 and we translate this sequence into binary. @@ -226,6 +242,17 @@ coord_esep(cube_t c) return ret1 * 70 + ret2; } +STATIC_INLINE cube_t +invcoord_esep(int64_t esep) +{ + cube_t ret; + + ret = SOLVED_CUBE; + invcoord_esep_array(esep % 70, esep / 70, ret.edge); + + return ret; +} + STATIC_INLINE void copy_corners(cube_t dest[static 1], cube_t src) { @@ -250,14 +277,3 @@ set_eo(cube_t cube[static 1], int64_t eo) } cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); } - -STATIC_INLINE cube_t -invcoord_esep(int64_t esep) -{ - cube_t ret; - - ret = SOLVED_CUBE; - invcoord_esep_array(esep % 70, esep / 70, ret.edge); - - return ret; -} diff --git a/src/core/cube.h b/src/core/cube.h index 7a68fb2..3dd3ccb 100644 --- a/src/core/cube.h +++ b/src/core/cube.h @@ -61,7 +61,7 @@ isconsistent(cube_t cube) } for (i = 0; i < 8; i++) if (!found[i]) - goto inconsistent_co; + goto inconsistent_cp; return true; diff --git a/src/core/io_moves.h b/src/core/io_moves.h index b00682b..c94b6b7 100644 --- a/src/core/io_moves.h +++ b/src/core/io_moves.h @@ -1,5 +1,6 @@ STATIC uint8_t readmove(char); STATIC int64_t readmoves(const char *, size_t n, uint8_t [n]); +STATIC int64_t countmoves(const char *); STATIC uint8_t readmodifier(char); STATIC int64_t writemoves(size_t n, const uint8_t [n], size_t m, char [m]); @@ -71,6 +72,21 @@ readmoves(const char *buf, size_t n, uint8_t ret[n]) return (int64_t)c; } +STATIC int64_t +countmoves(const char *buf) +{ + uint8_t m; + uint64_t c; + + FOREACH_READMOVE(buf, m, c, INT_MAX, NISSY_ERROR_INVALID_MOVES, + {} + ) + + (void)m; /* Ignore "variable set but not used" warning */ + + return (int64_t)c; +} + STATIC int64_t writemoves( size_t nmoves, diff --git a/src/nissy.c b/src/nissy.c index e8a6550..738d6e1 100644 --- a/src/nissy.c +++ b/src/nissy.c @@ -620,7 +620,7 @@ nissy_countmoves( if (moves == NULL) return NISSY_ERROR_NULL_POINTER; - return readmoves(moves, INT_MAX, NULL); + return countmoves(moves); } long long -- cgit v1.3