diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-08 10:48:56 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-08 10:48:56 +0100 |
| commit | 41d6b7aea5f1c9abddf5377dc6f37d8d197e548b (patch) | |
| tree | d573235ae68f2bcd8c1b5d95326e8b601163a675 /cube.c | |
| parent | 61ae2bd88751a291f97e6f0ee36563e898cacac8 (diff) | |
| download | nissy-core-41d6b7aea5f1c9abddf5377dc6f37d8d197e548b.tar.gz nissy-core-41d6b7aea5f1c9abddf5377dc6f37d8d197e548b.zip | |
Fixes
Diffstat (limited to '')
| -rw-r--r-- | cube.c | 35 |
1 files changed, 19 insertions, 16 deletions
| @@ -246,8 +246,8 @@ state of the cube that are used in debugging. | |||
| 246 | ******************************************************************************/ | 246 | ******************************************************************************/ |
| 247 | 247 | ||
| 248 | typedef struct { | 248 | typedef 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 | ||
| 258 | static void setzero_array(cube_array_t *); | ||
| 259 | static bool equal_array(cube_array_t, cube_array_t); | 258 | static bool equal_array(cube_array_t, cube_array_t); |
| 260 | static bool iserror_array(cube_array_t); | 259 | static bool iserror_array(cube_array_t); |
| 261 | static bool isconsistent_array(cube_array_t); | 260 | static bool isconsistent_array(cube_array_t); |
| @@ -275,17 +274,11 @@ static uint8_t readmove(char); | |||
| 275 | static uint8_t readmodifier(char); | 274 | static uint8_t readmodifier(char); |
| 276 | 275 | ||
| 277 | cube_array_t _solvedcube_array = { | 276 | cube_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 | }; |
| 281 | cube_array_t _zerocube_array = { .e = {0}, .c = {0} }; | 280 | cube_array_t _zerocube_array = { .e = {0}, .c = {0} }; |
| 282 | 281 | ||
| 283 | static void | ||
| 284 | setzero_array(cube_array_t *arr) | ||
| 285 | { | ||
| 286 | memset(arr, 0, 32); | ||
| 287 | } | ||
| 288 | |||
| 289 | static bool | 282 | static bool |
| 290 | equal_array(cube_array_t c1, cube_array_t c2) | 283 | equal_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) | |||
| 1984 | static cube_t | 1977 | static 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 | ||
| 1990 | static void | 1989 | static 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 | ||
| 1996 | static inline bool | 1999 | static inline bool |
| @@ -2136,8 +2139,8 @@ in the previous section(s) for unsupported architectures. | |||
| 2136 | r[l] ^= _eobit; | 2139 | r[l] ^= _eobit; |
| 2137 | 2140 | ||
| 2138 | static const cube_t _solvedcube = { | 2141 | static 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 | }; |
| 2142 | static const cube_t _zerocube = { .e = {0}, .c = {0} }; | 2145 | static const cube_t _zerocube = { .e = {0}, .c = {0} }; |
| 2143 | 2146 | ||
