diff options
Diffstat (limited to '')
| -rw-r--r-- | src/arch/avx2.h | 49 | ||||
| -rw-r--r-- | src/arch/common.h | 3 | ||||
| -rw-r--r-- | src/arch/neon.h | 19 | ||||
| -rw-r--r-- | src/arch/portable.h | 42 | ||||
| -rw-r--r-- | src/core/cube.h | 2 | ||||
| -rw-r--r-- | src/core/io_moves.h | 16 | ||||
| -rw-r--r-- | src/nissy.c | 2 |
7 files changed, 102 insertions, 31 deletions
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) | |||
| 188 | return ret; | 188 | return ret; |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | STATIC_INLINE cube_t | ||
| 192 | invcoord_co(int64_t coord) | ||
| 193 | { | ||
| 194 | int64_t i, c, p, co, mem[4] = {0}; | ||
| 195 | cube_t cube, cc; | ||
| 196 | |||
| 197 | for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) { | ||
| 198 | co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3); | ||
| 199 | p += co; | ||
| 200 | mem[0] |= (int64_t)(i + (co << COSHIFT)) << (int64_t)(8 * i); | ||
| 201 | } | ||
| 202 | |||
| 203 | cc = _mm256_loadu_si256((const __m256i *)mem); | ||
| 204 | cube = SOLVED_CUBE; | ||
| 205 | copy_corners(&cube, cc); | ||
| 206 | |||
| 207 | return cube; | ||
| 208 | } | ||
| 209 | |||
| 191 | STATIC_INLINE int64_t | 210 | STATIC_INLINE int64_t |
| 192 | coord_csep(cube_t c) | 211 | coord_csep(cube_t c) |
| 193 | { | 212 | { |
| @@ -251,6 +270,21 @@ coord_esep(cube_t c) | |||
| 251 | return ret1 * 70 + ret2; | 270 | return ret1 * 70 + ret2; |
| 252 | } | 271 | } |
| 253 | 272 | ||
| 273 | STATIC_INLINE cube_t | ||
| 274 | invcoord_esep(int64_t esep) | ||
| 275 | { | ||
| 276 | cube_t eee, ret; | ||
| 277 | uint8_t mem[32] = {0}; | ||
| 278 | |||
| 279 | invcoord_esep_array(esep % 70, esep / 70, mem+16); | ||
| 280 | |||
| 281 | ret = SOLVED_CUBE; | ||
| 282 | eee = _mm256_loadu_si256((__m256i_u *)&mem); | ||
| 283 | copy_edges(&ret, eee); | ||
| 284 | |||
| 285 | return ret; | ||
| 286 | } | ||
| 287 | |||
| 254 | STATIC_INLINE void | 288 | STATIC_INLINE void |
| 255 | copy_corners(cube_t dest[static 1], cube_t src) | 289 | copy_corners(cube_t dest[static 1], cube_t src) |
| 256 | { | 290 | { |
| @@ -287,18 +321,3 @@ set_eo(cube_t cube[static 1], int64_t eo) | |||
| 287 | *cube = _mm256_andnot_si256(EO_AVX2, *cube); | 321 | *cube = _mm256_andnot_si256(EO_AVX2, *cube); |
| 288 | *cube = _mm256_or_si256(*cube, veo); | 322 | *cube = _mm256_or_si256(*cube, veo); |
| 289 | } | 323 | } |
| 290 | |||
| 291 | STATIC_INLINE cube_t | ||
| 292 | invcoord_esep(int64_t esep) | ||
| 293 | { | ||
| 294 | cube_t eee, ret; | ||
| 295 | uint8_t mem[32] = {0}; | ||
| 296 | |||
| 297 | invcoord_esep_array(esep % 70, esep / 70, mem+16); | ||
| 298 | |||
| 299 | ret = SOLVED_CUBE; | ||
| 300 | eee = _mm256_loadu_si256((__m256i_u *)&mem); | ||
| 301 | copy_edges(&ret, eee); | ||
| 302 | |||
| 303 | return ret; | ||
| 304 | } | ||
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); | |||
| 9 | STATIC_INLINE cube_t inverse(cube_t); | 9 | STATIC_INLINE cube_t inverse(cube_t); |
| 10 | 10 | ||
| 11 | STATIC_INLINE int64_t coord_co(cube_t); | 11 | STATIC_INLINE int64_t coord_co(cube_t); |
| 12 | STATIC_INLINE cube_t invcoord_co(int64_t); | ||
| 12 | STATIC_INLINE int64_t coord_csep(cube_t); | 13 | STATIC_INLINE int64_t coord_csep(cube_t); |
| 13 | STATIC_INLINE int64_t coord_cocsep(cube_t); | 14 | STATIC_INLINE int64_t coord_cocsep(cube_t); |
| 14 | STATIC_INLINE int64_t coord_eo(cube_t); | 15 | STATIC_INLINE int64_t coord_eo(cube_t); |
| 15 | STATIC_INLINE int64_t coord_esep(cube_t); | 16 | STATIC_INLINE int64_t coord_esep(cube_t); |
| 17 | STATIC_INLINE cube_t invcoord_esep(int64_t); | ||
| 16 | 18 | ||
| 17 | STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); | 19 | STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); |
| 18 | STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); | 20 | STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); |
| 19 | STATIC_INLINE void set_eo(cube_t [static 1], int64_t); | 21 | STATIC_INLINE void set_eo(cube_t [static 1], int64_t); |
| 20 | STATIC_INLINE cube_t invcoord_esep(int64_t); | ||
| 21 | 22 | ||
| 22 | STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); | 23 | STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); |
| 23 | STATIC_INLINE cube_t invcoord_eoesep(int64_t); | 24 | 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) | |||
| 219 | return ret; | 219 | return ret; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | STATIC_INLINE cube_t | ||
| 223 | invcoord_co(int64_t coord) | ||
| 224 | { | ||
| 225 | int64_t co, c, i, p; | ||
| 226 | uint8_t mem[8]; | ||
| 227 | cube_t cube; | ||
| 228 | |||
| 229 | for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) { | ||
| 230 | co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3); | ||
| 231 | p += co; | ||
| 232 | mem[i] = i + (co << COSHIFT); | ||
| 233 | } | ||
| 234 | |||
| 235 | cube.corner = vld1_u8(mem); | ||
| 236 | cube.edge = SOLVED_CUBE.edge; | ||
| 237 | |||
| 238 | return cube; | ||
| 239 | } | ||
| 240 | |||
| 222 | STATIC_INLINE int64_t | 241 | STATIC_INLINE int64_t |
| 223 | coord_csep(cube_t c) | 242 | coord_csep(cube_t c) |
| 224 | { | 243 | { |
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) | |||
| 144 | STATIC_INLINE int64_t | 144 | STATIC_INLINE int64_t |
| 145 | coord_co(cube_t c) | 145 | coord_co(cube_t c) |
| 146 | { | 146 | { |
| 147 | int i, p; | 147 | int i, p, ret; |
| 148 | int64_t ret; | ||
| 149 | 148 | ||
| 150 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) | 149 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) |
| 151 | ret += p * (c.corner[i] >> COSHIFT); | 150 | ret += p * (c.corner[i] >> COSHIFT); |
| @@ -153,6 +152,23 @@ coord_co(cube_t c) | |||
| 153 | return ret; | 152 | return ret; |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 155 | STATIC_INLINE cube_t | ||
| 156 | invcoord_co(int64_t coord) | ||
| 157 | { | ||
| 158 | int64_t i, c, p; | ||
| 159 | cube_t cube; | ||
| 160 | |||
| 161 | cube = SOLVED_CUBE; | ||
| 162 | for (i = 0, p = 0, c = coord; i < 7; i++, c /= 3) { | ||
| 163 | p += c % 3; | ||
| 164 | cube.corner[i] |= (c % 3) << COSHIFT; | ||
| 165 | } | ||
| 166 | |||
| 167 | cube.corner[7] |= ((3 - (p % 3)) % 3) << COSHIFT; | ||
| 168 | |||
| 169 | return cube; | ||
| 170 | } | ||
| 171 | |||
| 156 | /* | 172 | /* |
| 157 | For corner separation, we consider the axis (a.k.a. tetrad) each | 173 | For corner separation, we consider the axis (a.k.a. tetrad) each |
| 158 | corner belongs to as 0 or 1 and we translate this sequence into binary. | 174 | corner belongs to as 0 or 1 and we translate this sequence into binary. |
| @@ -226,6 +242,17 @@ coord_esep(cube_t c) | |||
| 226 | return ret1 * 70 + ret2; | 242 | return ret1 * 70 + ret2; |
| 227 | } | 243 | } |
| 228 | 244 | ||
| 245 | STATIC_INLINE cube_t | ||
| 246 | invcoord_esep(int64_t esep) | ||
| 247 | { | ||
| 248 | cube_t ret; | ||
| 249 | |||
| 250 | ret = SOLVED_CUBE; | ||
| 251 | invcoord_esep_array(esep % 70, esep / 70, ret.edge); | ||
| 252 | |||
| 253 | return ret; | ||
| 254 | } | ||
| 255 | |||
| 229 | STATIC_INLINE void | 256 | STATIC_INLINE void |
| 230 | copy_corners(cube_t dest[static 1], cube_t src) | 257 | copy_corners(cube_t dest[static 1], cube_t src) |
| 231 | { | 258 | { |
| @@ -250,14 +277,3 @@ set_eo(cube_t cube[static 1], int64_t eo) | |||
| 250 | } | 277 | } |
| 251 | cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); | 278 | cube->edge[0] = (cube->edge[0] & ~EOBIT) | (EOBIT * (sum % 2)); |
| 252 | } | 279 | } |
| 253 | |||
| 254 | STATIC_INLINE cube_t | ||
| 255 | invcoord_esep(int64_t esep) | ||
| 256 | { | ||
| 257 | cube_t ret; | ||
| 258 | |||
| 259 | ret = SOLVED_CUBE; | ||
| 260 | invcoord_esep_array(esep % 70, esep / 70, ret.edge); | ||
| 261 | |||
| 262 | return ret; | ||
| 263 | } | ||
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) | |||
| 61 | } | 61 | } |
| 62 | for (i = 0; i < 8; i++) | 62 | for (i = 0; i < 8; i++) |
| 63 | if (!found[i]) | 63 | if (!found[i]) |
| 64 | goto inconsistent_co; | 64 | goto inconsistent_cp; |
| 65 | 65 | ||
| 66 | return true; | 66 | return true; |
| 67 | 67 | ||
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 @@ | |||
| 1 | STATIC uint8_t readmove(char); | 1 | STATIC uint8_t readmove(char); |
| 2 | STATIC int64_t readmoves(const char *, size_t n, uint8_t [n]); | 2 | STATIC int64_t readmoves(const char *, size_t n, uint8_t [n]); |
| 3 | STATIC int64_t countmoves(const char *); | ||
| 3 | STATIC uint8_t readmodifier(char); | 4 | STATIC uint8_t readmodifier(char); |
| 4 | STATIC int64_t writemoves(size_t n, const uint8_t [n], size_t m, char [m]); | 5 | STATIC int64_t writemoves(size_t n, const uint8_t [n], size_t m, char [m]); |
| 5 | 6 | ||
| @@ -72,6 +73,21 @@ readmoves(const char *buf, size_t n, uint8_t ret[n]) | |||
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | STATIC int64_t | 75 | STATIC int64_t |
| 76 | countmoves(const char *buf) | ||
| 77 | { | ||
| 78 | uint8_t m; | ||
| 79 | uint64_t c; | ||
| 80 | |||
| 81 | FOREACH_READMOVE(buf, m, c, INT_MAX, NISSY_ERROR_INVALID_MOVES, | ||
| 82 | {} | ||
| 83 | ) | ||
| 84 | |||
| 85 | (void)m; /* Ignore "variable set but not used" warning */ | ||
| 86 | |||
| 87 | return (int64_t)c; | ||
| 88 | } | ||
| 89 | |||
| 90 | STATIC int64_t | ||
| 75 | writemoves( | 91 | writemoves( |
| 76 | size_t nmoves, | 92 | size_t nmoves, |
| 77 | const uint8_t m[nmoves], | 93 | const uint8_t m[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( | |||
| 620 | if (moves == NULL) | 620 | if (moves == NULL) |
| 621 | return NISSY_ERROR_NULL_POINTER; | 621 | return NISSY_ERROR_NULL_POINTER; |
| 622 | 622 | ||
| 623 | return readmoves(moves, INT_MAX, NULL); | 623 | return countmoves(moves); |
| 624 | } | 624 | } |
| 625 | 625 | ||
| 626 | long long | 626 | long long |
