aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-11-08 10:48:56 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2023-11-08 10:48:56 +0100
commit41d6b7aea5f1c9abddf5377dc6f37d8d197e548b (patch)
treed573235ae68f2bcd8c1b5d95326e8b601163a675
parent61ae2bd88751a291f97e6f0ee36563e898cacac8 (diff)
downloadnissy-core-41d6b7aea5f1c9abddf5377dc6f37d8d197e548b.tar.gz
nissy-core-41d6b7aea5f1c9abddf5377dc6f37d8d197e548b.zip
Fixes
-rw-r--r--README.md2
-rw-r--r--cube.c35
-rw-r--r--cube.h4
3 files changed, 23 insertions, 18 deletions
diff --git a/README.md b/README.md
index fc33ef7..444d037 100644
--- a/README.md
+++ b/README.md
@@ -84,6 +84,8 @@ Implement the following solvers:
84 84
85### cube.h changes 85### cube.h changes
86 86
87* better documentation: add parameter names, one-line comment
88 for each function
87* prefix public functions with nissy_ or something similar 89* prefix public functions with nissy_ or something similar
88* move() that takes a string (alg) as input 90* move() that takes a string (alg) as input
89* Add single moves and transformations to the interface? (performance!) 91* Add single moves and transformations to the interface? (performance!)
diff --git a/cube.c b/cube.c
index ba00ce8..b485a0f 100644
--- a/cube.c
+++ b/cube.c
@@ -246,8 +246,8 @@ state of the cube that are used in debugging.
246******************************************************************************/ 246******************************************************************************/
247 247
248typedef struct { 248typedef struct {
249 uint8_t c[16]; 249 uint8_t c[8];
250 uint8_t e[16]; 250 uint8_t e[12];
251} cube_array_t; 251} cube_array_t;
252 252
253#define get_edge(cube, i) (cube).e[(i)] 253#define get_edge(cube, i) (cube).e[(i)]
@@ -255,7 +255,6 @@ typedef struct {
255#define set_edge(cube, i, p) (cube).e[(i)] = (p) 255#define set_edge(cube, i, p) (cube).e[(i)] = (p)
256#define set_corner(cube, i, p) (cube).c[(i)] = (p) 256#define set_corner(cube, i, p) (cube).c[(i)] = (p)
257 257
258static void setzero_array(cube_array_t *);
259static bool equal_array(cube_array_t, cube_array_t); 258static bool equal_array(cube_array_t, cube_array_t);
260static bool iserror_array(cube_array_t); 259static bool iserror_array(cube_array_t);
261static bool isconsistent_array(cube_array_t); 260static bool isconsistent_array(cube_array_t);
@@ -275,17 +274,11 @@ static uint8_t readmove(char);
275static uint8_t readmodifier(char); 274static uint8_t readmodifier(char);
276 275
277cube_array_t _solvedcube_array = { 276cube_array_t _solvedcube_array = {
278 .c = {0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0}, 277 .c = {0, 1, 2, 3, 4, 5, 6, 7},
279 .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0} 278 .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
280}; 279};
281cube_array_t _zerocube_array = { .e = {0}, .c = {0} }; 280cube_array_t _zerocube_array = { .e = {0}, .c = {0} };
282 281
283static void
284setzero_array(cube_array_t *arr)
285{
286 memset(arr, 0, 32);
287}
288
289static bool 282static bool
290equal_array(cube_array_t c1, cube_array_t c2) 283equal_array(cube_array_t c1, cube_array_t c2)
291{ 284{
@@ -407,7 +400,7 @@ readcube_array(format_t format, char *buf)
407 break; 400 break;
408 default: 401 default:
409 DBG_LOG("Cannot read cube in the given format\n"); 402 DBG_LOG("Cannot read cube in the given format\n");
410 setzero_array(&arr); 403 return _zerocube_array;
411 } 404 }
412 405
413 DBG_ASSERT(!iserror_array(arr), arr, "readcube error\n"); 406 DBG_ASSERT(!iserror_array(arr), arr, "readcube error\n");
@@ -1984,13 +1977,23 @@ _trans_BLm(cube_t c)
1984static cube_t 1977static cube_t
1985_arraytocube(cube_array_t a) 1978_arraytocube(cube_array_t a)
1986{ 1979{
1987 return _mm256_loadu_si256((__m256i_u *)&a); 1980 uint8_t aux[32];
1981
1982 memset(aux, 0, 32);
1983 memcpy(aux, &a.c, 8);
1984 memcpy(aux + 16, &a.e, 12);
1985
1986 return _mm256_loadu_si256((__m256i_u *)&aux);
1988} 1987}
1989 1988
1990static void 1989static void
1991_cubetoarray(cube_t c, cube_array_t *a) 1990_cubetoarray(cube_t c, cube_array_t *a)
1992{ 1991{
1993 _mm256_storeu_si256((__m256i_u *)a, c); 1992 uint8_t aux[32];
1993
1994 _mm256_storeu_si256((__m256i_u *)aux, c);
1995 memcpy(&a->c, aux, 8);
1996 memcpy(&a->e, aux + 16, 12);
1994} 1997}
1995 1998
1996static inline bool 1999static inline bool
@@ -2136,8 +2139,8 @@ in the previous section(s) for unsupported architectures.
2136 r[l] ^= _eobit; 2139 r[l] ^= _eobit;
2137 2140
2138static const cube_t _solvedcube = { 2141static const cube_t _solvedcube = {
2139 .c = {0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0}, 2142 .c = {0, 1, 2, 3, 4, 5, 6, 7},
2140 .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0} 2143 .e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
2141}; 2144};
2142static const cube_t _zerocube = { .e = {0}, .c = {0} }; 2145static const cube_t _zerocube = { .e = {0}, .c = {0} };
2143 2146
diff --git a/cube.h b/cube.h
index a588ba4..925ea36 100644
--- a/cube.h
+++ b/cube.h
@@ -3,8 +3,8 @@
3typedef __m256i cube_t; 3typedef __m256i cube_t;
4#else 4#else
5typedef struct { 5typedef struct {
6 uint8_t c[16]; /* Only the first 8 are used, the rest is padding */ 6 uint8_t c[8];
7 uint8_t e[16]; /* Only the first 12 are used, the rest is padding */ 7 uint8_t e[12];
8} cube_t; 8} cube_t;
9#endif 9#endif
10 10

Generated with cgit - Back to sebastiano.tronto.net