aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-11-19 22:03:17 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2023-11-19 22:03:17 +0100
commit2c8ad86805516211103df1ef7552d882f54748c3 (patch)
treefd3b1927a94c8aea02e6090cb9b441997fd7206d
parentbb5abea645a31832e9d6a94cea09714a9b1632e3 (diff)
downloadnissy-core-2c8ad86805516211103df1ef7552d882f54748c3.tar.gz
nissy-core-2c8ad86805516211103df1ef7552d882f54748c3.zip
Removed src cube type, kept only H48 and LST (for now)
-rw-r--r--TODO.txt6
-rw-r--r--cube.c72
-rw-r--r--cube.h14
-rw-r--r--test/021_io_SRC_write/01_solved.out4
-rw-r--r--test/021_io_SRC_write/02_scrambled.out4
-rw-r--r--test/023_io_LST_write/io_LST_tests.c7
-rw-r--r--test/024_io_LST_read/01_solved.in1
-rw-r--r--test/024_io_LST_read/01_solved.out (renamed from test/021_io_SRC_write/01_solved.in)0
-rw-r--r--test/024_io_LST_read/02_scrambled.in1
-rw-r--r--test/024_io_LST_read/02_scrambled.out (renamed from test/021_io_SRC_write/02_scrambled.in)0
-rw-r--r--test/024_io_LST_read/io_LST_tests.c (renamed from test/021_io_SRC_write/io_SRC_tests.c)4
11 files changed, 53 insertions, 60 deletions
diff --git a/TODO.txt b/TODO.txt
index f6a0b10..c507479 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -39,6 +39,12 @@ switch. Here NISS may be useful.
39* improve light solver with no table; consider using a small, hard-coded 39* improve light solver with no table; consider using a small, hard-coded
40 table, e.g. H48 corner table? 40 table, e.g. H48 corner table?
41 41
42## ARM NEON intrinsics and other architectures
43
44* For ARM: use two uint8x16_t (or uint8x16x2_t) and vqtbl* instructions;
45 see https://developer.arm.com/architectures/instruction-sets/intrinsics
46* Implement also SSE? Why not...
47
42## Optimizations 48## Optimizations
43 49
44### General things 50### General things
diff --git a/cube.c b/cube.c
index 895c088..e9a063d 100644
--- a/cube.c
+++ b/cube.c
@@ -849,9 +849,10 @@ _static uint8_t readcp(char *);
849_static uint8_t readeo(char *); 849_static uint8_t readeo(char *);
850_static uint8_t readep(char *); 850_static uint8_t readep(char *);
851_static cube_t readcube_H48(char *); 851_static cube_t readcube_H48(char *);
852_static int writepiece_SRC(uint8_t, char *); 852_static uint8_t readpiece_LST(char **);
853_static cube_t readcube_LST(char *);
854_static int writepiece_LST(uint8_t, char *);
853_static void writecube_H48(cube_t, char *); 855_static void writecube_H48(cube_t, char *);
854_static void writecube_SRC(cube_t, char *);
855_static void writecube_LST(cube_t, char *); 856_static void writecube_LST(cube_t, char *);
856_static uint8_t readmove(char); 857_static uint8_t readmove(char);
857_static uint8_t readmodifier(char); 858_static uint8_t readmodifier(char);
@@ -1083,6 +1084,8 @@ readcube(char *format, char *buf)
1083 1084
1084 if (!strcmp(format, "H48")) { 1085 if (!strcmp(format, "H48")) {
1085 cube = readcube_H48(buf); 1086 cube = readcube_H48(buf);
1087 } else if (!strcmp(format, "LST")) {
1088 cube = readcube_LST(buf);
1086 } else { 1089 } else {
1087 DBG_LOG("Cannot read cube in the given format\n"); 1090 DBG_LOG("Cannot read cube in the given format\n");
1088 cube = zero; 1091 cube = zero;
@@ -1104,8 +1107,6 @@ writecube(char *format, cube_t cube, char *buf)
1104 1107
1105 if (!strcmp(format, "H48")) { 1108 if (!strcmp(format, "H48")) {
1106 writecube_H48(cube, buf); 1109 writecube_H48(cube, buf);
1107 } else if (!strcmp(format, "SRC")) {
1108 writecube_SRC(cube, buf);
1109 } else if (!strcmp(format, "LST")) { 1110 } else if (!strcmp(format, "LST")) {
1110 writecube_LST(cube, buf); 1111 writecube_LST(cube, buf);
1111 } else { 1112 } else {
@@ -1225,8 +1226,40 @@ readcube_H48(char *buf)
1225 return ret; 1226 return ret;
1226} 1227}
1227 1228
1229_static uint8_t
1230readpiece_LST(char **b)
1231{
1232 uint8_t ret;
1233 bool read;
1234
1235 while (**b == ',' || **b == ' ' || **b == '\t' || **b == '\n')
1236 (*b)++;
1237
1238 for (ret = 0, read = false; **b >= '0' && **b <= '9'; (*b)++) {
1239 read = true;
1240 ret = ret * 10 + (**b) - '0';
1241 }
1242
1243 return read ? ret : _error;
1244}
1245
1246_static cube_t
1247readcube_LST(char *buf)
1248{
1249 int i;
1250 cube_t ret = {0};
1251
1252 for (i = 0; i < 8; i++)
1253 ret.corner[i] = readpiece_LST(&buf);
1254
1255 for (i = 0; i < 12; i++)
1256 ret.edge[i] = readpiece_LST(&buf);
1257
1258 return ret;
1259}
1260
1228_static int 1261_static int
1229writepiece_SRC(uint8_t piece, char *buf) 1262writepiece_LST(uint8_t piece, char *buf)
1230{ 1263{
1231 char digits[3]; 1264 char digits[3];
1232 int i, len = 0; 1265 int i, len = 0;
@@ -1278,31 +1311,6 @@ writecube_H48(cube_t cube, char *buf)
1278} 1311}
1279 1312
1280_static void 1313_static void
1281writecube_SRC(cube_t cube, char *buf)
1282{
1283 int i, ptr;
1284 uint8_t piece;
1285
1286 memcpy(buf, "{\n\t.corner = {", 14);
1287 ptr = 14;
1288
1289 for (i = 0; i < 8; i++) {
1290 piece = cube.corner[i];
1291 ptr += writepiece_SRC(piece, buf + ptr);
1292 }
1293
1294 memcpy(buf+ptr-2, "},\n\t.edge = {", 13);
1295 ptr += 11;
1296
1297 for (i = 0; i < 12; i++) {
1298 piece = cube.edge[i];
1299 ptr += writepiece_SRC(piece, buf + ptr);
1300 }
1301
1302 memcpy(buf+ptr-2, "}\n}\0", 4);
1303}
1304
1305_static void
1306writecube_LST(cube_t cube, char *buf) 1314writecube_LST(cube_t cube, char *buf)
1307{ 1315{
1308 int i, ptr; 1316 int i, ptr;
@@ -1312,12 +1320,12 @@ writecube_LST(cube_t cube, char *buf)
1312 1320
1313 for (i = 0; i < 8; i++) { 1321 for (i = 0; i < 8; i++) {
1314 piece = cube.corner[i]; 1322 piece = cube.corner[i];
1315 ptr += writepiece_SRC(piece, buf + ptr); 1323 ptr += writepiece_LST(piece, buf + ptr);
1316 } 1324 }
1317 1325
1318 for (i = 0; i < 12; i++) { 1326 for (i = 0; i < 12; i++) {
1319 piece = cube.edge[i]; 1327 piece = cube.edge[i];
1320 ptr += writepiece_SRC(piece, buf + ptr); 1328 ptr += writepiece_LST(piece, buf + ptr);
1321 } 1329 }
1322 1330
1323 *(buf+ptr-2) = 0; 1331 *(buf+ptr-2) = 0;
diff --git a/cube.h b/cube.h
index 6d701b4..f2d7300 100644
--- a/cube.h
+++ b/cube.h
@@ -86,20 +86,12 @@ Multiple representations of the cube as text are supported:
86 If OUT is the output in SRC format, one can use `cube_t cube = OUT` to 86 If OUT is the output in SRC format, one can use `cube_t cube = OUT` to
87 declare a new cube object. 87 declare a new cube object.
88 88
89- LST: similar to SRC, but only a list of comma-separated numbers is printed. 89- LST: a format for internal use and generating code.
90 90 The cube is printed as a comma-separated list of 20 integers, as they appear
91Not all formats are supported for both reading and writing. More formats 91 in cube_t. Corners come first, followed by edge (unlike H48).
92may be supported in the future.
93******************************************************************************/ 92******************************************************************************/
94 93
95/* Reads a cube from buf in the specified format, and return it.
96 * Supported formats: "H48".
97 */
98cube_t readcube(char *format, char *buf); 94cube_t readcube(char *format, char *buf);
99
100/* Write the given cube to buf in the specified format.
101 * Supported formats: "H48", "SRC", "LST".
102 */
103void writecube(char *format, cube_t cube, char *buf); 95void writecube(char *format, cube_t cube, char *buf);
104 96
105/****************************************************************************** 97/******************************************************************************
diff --git a/test/021_io_SRC_write/01_solved.out b/test/021_io_SRC_write/01_solved.out
deleted file mode 100644
index 3c21bcc..0000000
--- a/test/021_io_SRC_write/01_solved.out
+++ /dev/null
@@ -1,4 +0,0 @@
1{
2 .corner = {0, 1, 2, 3, 4, 5, 6, 7},
3 .edge = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
4}
diff --git a/test/021_io_SRC_write/02_scrambled.out b/test/021_io_SRC_write/02_scrambled.out
deleted file mode 100644
index b899386..0000000
--- a/test/021_io_SRC_write/02_scrambled.out
+++ /dev/null
@@ -1,4 +0,0 @@
1{
2 .corner = {38, 32, 37, 68, 67, 2, 71, 1},
3 .edge = {9, 2, 17, 8, 4, 3, 0, 27, 21, 26, 6, 7}
4}
diff --git a/test/023_io_LST_write/io_LST_tests.c b/test/023_io_LST_write/io_LST_tests.c
index 45cc203..df35632 100644
--- a/test/023_io_LST_write/io_LST_tests.c
+++ b/test/023_io_LST_write/io_LST_tests.c
@@ -1,12 +1,5 @@
1#include "../test.h" 1#include "../test.h"
2 2
3#define STRLENMAX 10000
4
5bool iserror(cube_t);
6bool issolvable(cube_t);
7cube_t readcube(char *, char *);
8void writecube(char *, cube_t, char *);
9
10int main(void) { 3int main(void) {
11 char str[STRLENMAX], *aux; 4 char str[STRLENMAX], *aux;
12 cube_t cube; 5 cube_t cube;
diff --git a/test/024_io_LST_read/01_solved.in b/test/024_io_LST_read/01_solved.in
new file mode 100644
index 0000000..c5b394b
--- /dev/null
+++ b/test/024_io_LST_read/01_solved.in
@@ -0,0 +1 @@
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
diff --git a/test/021_io_SRC_write/01_solved.in b/test/024_io_LST_read/01_solved.out
index dff224d..dff224d 100644
--- a/test/021_io_SRC_write/01_solved.in
+++ b/test/024_io_LST_read/01_solved.out
diff --git a/test/024_io_LST_read/02_scrambled.in b/test/024_io_LST_read/02_scrambled.in
new file mode 100644
index 0000000..9fcb603
--- /dev/null
+++ b/test/024_io_LST_read/02_scrambled.in
@@ -0,0 +1 @@
38, 32, 37, 68, 67, 2, 71, 1, 9, 2, 17, 8, 4, 3, 0, 27, 21, 26, 6, 7
diff --git a/test/021_io_SRC_write/02_scrambled.in b/test/024_io_LST_read/02_scrambled.out
index 6a05bbc..6a05bbc 100644
--- a/test/021_io_SRC_write/02_scrambled.in
+++ b/test/024_io_LST_read/02_scrambled.out
diff --git a/test/021_io_SRC_write/io_SRC_tests.c b/test/024_io_LST_read/io_LST_tests.c
index c427c6c..506a23d 100644
--- a/test/021_io_SRC_write/io_SRC_tests.c
+++ b/test/024_io_LST_read/io_LST_tests.c
@@ -9,14 +9,14 @@ int main(void) {
9 while (*aux != '\n') 9 while (*aux != '\n')
10 aux++; 10 aux++;
11 11
12 cube = readcube("H48", str); 12 cube = readcube("LST", str);
13 13
14 if (iserror(cube)) { 14 if (iserror(cube)) {
15 printf("Error reading cube\n"); 15 printf("Error reading cube\n");
16 } else if (!issolvable(cube)) { 16 } else if (!issolvable(cube)) {
17 printf("Cube is not solvable\n"); 17 printf("Cube is not solvable\n");
18 } else { 18 } else {
19 writecube("SRC", cube, str); 19 writecube("H48", cube, str);
20 printf("%s\n", str); 20 printf("%s\n", str);
21 } 21 }
22 22

Generated with cgit - Back to sebastiano.tronto.net