h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit f8d247c53c3c3bd94fed645b5b47a9096cadc123
parent 2e93de4ad102973961cb24d5b91f0c299763299f
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Thu, 10 Oct 2024 14:30:39 +0200

Removed "options" from solver selection

Now the solver name fully determines the solver (and options)
to be used. For example, now one must specify "h48h0k4" as the
name of the solver.

This PR also fixes a couple of things in tools.

Diffstat:
MREADME.md | 4++--
Mconfigure.sh | 1+
Mshell.c | 32+++++++++-----------------------
Msrc/nissy.c | 112+++++++++++++++++++++++++++++++++----------------------------------------------
Msrc/nissy.h | 7++-----
Mtools/000_gendata/gendata.c | 23+++++++++++++++--------
Mtools/001_derive_h48/derive_h48.c | 12++++++------
Mtools/100_checkdata/checkdata.c | 17+++++++++--------
Mtools/200_stats_tables_h48/stats_tables_h48.c | 30++++++++++++++++++++++--------
Mtools/300_solve_small/solve_small.c | 11++++++-----
Mtools/expected_distributions.h | 2+-
Mtools/nissy_extra.h | 2+-
Mtools/tool.h | 88+++++++++++++++++++++++++++++++++++++------------------------------------------
Mtools/tool.sh | 3---
14 files changed, 161 insertions(+), 183 deletions(-)

diff --git a/README.md b/README.md @@ -130,10 +130,10 @@ $ ./run convert -fin B32 -fout H48 -cubestr "WDSQREVX=VBKYDUCJXWAb" UL1 UB0 BL0 FR1 DF0 UR1 DB0 FL0 DR1 DL1 UF0 BR1 DFR2 DBR0 DFL2 UFR2 UBL2 UFL0 UBR2 DBL2 ``` -To solve a cube (experimental) you can use: +To solve a cube you can use: ``` -$ ./run solve -solver "h48" -options "0;20" -n 1 -M 4 -cube "JLQWSVUH=ZLCUABGIVTKH" +$ ./run solve -solver "h48h0k4" -n 1 -M 4 -cube "JLQWSVUH=ZLCUABGIVTKH" Found 0 solutions, searching at depth 0 Found 0 solutions, searching at depth 1 Found 0 solutions, searching at depth 2 diff --git a/configure.sh b/configure.sh @@ -71,6 +71,7 @@ validatearch() { ;; *) echo "Error: architecture '$ARCH' not supported" + echo "Supported architectures: AVX2, NEON, PORTABLE" exit 1 ;; esac diff --git a/shell.c b/shell.c @@ -23,7 +23,6 @@ #define FLAG_MOVES "-moves" #define FLAG_TRANS "-trans" #define FLAG_SOLVER "-solver" -#define FLAG_OPTIONS "-options" #define FLAG_NISSTYPE "-nisstype" #define FLAG_MINMOVES "-m" #define FLAG_MAXMOVES "-M" @@ -50,7 +49,6 @@ typedef struct { char *str_moves; char *str_trans; char *str_solver; - char *str_options; /* TODO: remove, use only solver */ char *str_nisstype; /* TODO: remove, use flags */ int8_t minmoves; int8_t maxmoves; @@ -87,7 +85,6 @@ static bool set_str_format_out(int, char **, args_t *); static bool set_str_moves(int, char **, args_t *); static bool set_str_trans(int, char **, args_t *); static bool set_str_solver(int, char **, args_t *); -static bool set_str_options(int, char **, args_t *); static bool set_str_nisstype(int, char **, args_t *); static bool set_minmoves(int, char **, args_t *); static bool set_maxmoves(int, char **, args_t *); @@ -113,7 +110,6 @@ struct { OPTION(FLAG_MOVES, 1, set_str_moves), OPTION(FLAG_TRANS, 1, set_str_trans), OPTION(FLAG_SOLVER, 1, set_str_solver), - OPTION(FLAG_OPTIONS, 1, set_str_options), /* TODO: remove, use only solver */ OPTION(FLAG_NISSTYPE, 1, set_str_nisstype), /* TODO: remove, use flags */ OPTION(FLAG_MINMOVES, 1, set_minmoves), OPTION(FLAG_MAXMOVES, 1, set_maxmoves), @@ -183,21 +179,21 @@ struct { ), COMMAND( "datasize", - "datasize " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS", + "datasize " FLAG_SOLVER " SOLVER", "Return the size in bytes of the data table used by " "SOLVER when called with the given OPTIONS.", datasize_exec ), COMMAND( "gendata", - "gendata " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS", + "gendata " FLAG_SOLVER " SOLVER", "Generate the data table used by " "SOLVER when called with the given OPTIONS.", gendata_exec ), COMMAND( "solve", - "solve " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS " + "solve " FLAG_SOLVER " SOLVER" "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " FLAG_CUBE " CUBE", "Solve the given CUBE using SOLVER with the given OPTIONS, " @@ -357,7 +353,7 @@ datasize_exec(args_t *args) { int64_t ret; - ret = nissy_datasize(args->str_solver, args->str_options); + ret = nissy_datasize(args->str_solver); if (ret < 0) fprintf(stderr, "Unknown error (make sure solver is valid)\n"); printf("%" PRId64 "\n", ret); @@ -389,7 +385,7 @@ gendata_exec(args_t *args) return -2; } - size = nissy_datasize(args->str_solver, args->str_options); + size = nissy_datasize(args->str_solver); if (size < 0) { fprintf(stderr, @@ -401,7 +397,7 @@ gendata_exec(args_t *args) buf = malloc(size); - ret = nissy_gendata(args->str_solver, args->str_options, buf); + ret = nissy_gendata(args->str_solver, buf); if (ret < 0) { fprintf(stderr, "Unknown error in generating data\n"); fclose(file); @@ -476,7 +472,7 @@ solve_exec(args_t *args) return -1; } - size = nissy_datasize(args->str_solver, args->str_options); + size = nissy_datasize(args->str_solver); buf = malloc(size); read = fread(buf, size, 1, file); fclose(file); @@ -488,9 +484,8 @@ solve_exec(args_t *args) } ret = nissy_solve( - args->cube, args->str_solver, args->str_options, args->str_nisstype, - args->minmoves, args->maxmoves, args->maxsolutions, args->optimal, - buf, solutions); + args->cube, args->str_solver, args->str_nisstype, args->minmoves, + args->maxmoves, args->maxsolutions, args->optimal, buf, solutions); free(buf); @@ -545,7 +540,6 @@ parse_args(int argc, char **argv, args_t *args) .str_moves = "", .str_trans = "", .str_solver = "", - .str_options = "", .str_nisstype = "", .minmoves = 0, .maxmoves = 20, @@ -703,14 +697,6 @@ set_str_solver(int argc, char **argv, args_t *args) } static bool -set_str_options(int argc, char **argv, args_t *args) -{ - args->str_options = argv[0]; - - return true; -} - -static bool set_str_nisstype(int argc, char **argv, args_t *args) { args->str_nisstype = argv[0]; diff --git a/src/nissy.c b/src/nissy.c @@ -12,13 +12,12 @@ #include "nissy.h" -int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); +int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); STATIC int64_t write_result(cube_t, char [static 22]); STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); STATIC bool checkdata(const void *, const tableinfo_t *); -/* TODO: add option to get DR, maybe C-only, E-only, eo... */ #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } struct { char *option; @@ -29,40 +28,41 @@ struct { }; int -parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) +parse_h48_solver(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) { - bool h_valid, k_valid, maxdepth_valid; - int i; + const char *fullbuf = buf; + + buf += 3; + + if (!strcmp(buf, "stats")) { + *h = 0; + *k = 4; + return 0; + } - /* TODO temporarily, options are in the form "h;k;maxdepth" */ - if (h != NULL) - *h = atoi(buf); - h_valid = h == NULL || *h <= 11; + if (*buf != 'h') + goto parse_h48_solver_error; + buf++; - for (i = 0; buf[i] != ';'; i++) - if (buf[i] == 0) - goto parse_h48_options_error; + *h = atoi(buf); - if (k != NULL) - *k = atoi(&buf[i+1]); - k_valid = k == NULL || (*k == 2 || *k == 4); + for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) + if (*buf == 0) + goto parse_h48_solver_error; - for (i = i+1; buf[i] != ';'; i++) - if (buf[i] == 0) - goto parse_h48_options_error; + if (*buf != 'k') + goto parse_h48_solver_error; + buf++; - if (maxdepth != NULL) - *maxdepth = atoi(&buf[i+1]); - maxdepth_valid = maxdepth == NULL || *maxdepth <= 20; + *k = atoi(buf); - return h_valid && k_valid && maxdepth_valid ? 0 : 1; + return *h < 12 && (*k == 2 || (*k == 4 && *h == 0)) ? 0 : 1; -parse_h48_options_error: +parse_h48_solver_error: *h = 0; *k = 0; - *maxdepth = 0; - LOG("Error parsing options: must be in \"h;k;maxdepth\" format " - " (instead it was \"%s\")\n", buf); + LOG("Error parsing solver: must be in \"h48h*k*\" format" + " or \"h48stats\", but got %s\n", fullbuf); return -1; } @@ -103,13 +103,7 @@ distribution_equal( } } - if (wrong > 0) { - LOG("checkdata: %d wrong values\n", wrong); - } else { - LOG("checkdata: table is consistent with info\n"); - } - - return wrong > 0; + return wrong == 0; } STATIC int64_t @@ -238,12 +232,11 @@ nissy_getcube( int64_t nissy_datasize( - const char *solver, - const char *options + const char *solver ) { /* gendata() handles a NULL *data as a "dryrun" request */ - return nissy_gendata(solver, options, NULL); + return nissy_gendata(solver, NULL); } int64_t @@ -294,7 +287,6 @@ nissy_datainfo( int64_t nissy_gendata( const char *solver, - const char *options, void *data ) { @@ -303,21 +295,12 @@ nissy_gendata( gendata_h48_arg_t arg; arg.buf = data; - if (!strcmp(solver, "h48")) { - p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth); - if (p != 0) { - LOG("gendata: could not parse options\n"); - ret = -1; - } else { - ret = gendata_h48(&arg); - } - } else if (!strcmp(solver, "h48stats")) { - arg.h = 0; - arg.k = 4; + if (!strncmp(solver, "h48", 3)) { + p = parse_h48_solver(solver, &arg.h, &arg.k); arg.maxdepth = 20; - ret = gendata_h48(&arg); + ret = p == 0 ? (int64_t)gendata_h48(&arg) : -1; } else { - LOG("gendata: implemented only for h48 solver\n"); + LOG("gendata: unknown solver %s\n", solver); ret = -1; } @@ -327,7 +310,6 @@ nissy_gendata( int64_t nissy_checkdata( const char *solver, - const char *options, const void *data ) { @@ -335,8 +317,11 @@ nissy_checkdata( tableinfo_t info; for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) { - if (!checkdata(buf, &info)) + if (!checkdata(buf, &info)) { + LOG("Error: data for %s is inconsistent with info!\n", + info.solver); return 1; + } if (info.next == 0) break; } @@ -348,7 +333,6 @@ int64_t nissy_solve( const char cube[static 22], const char *solver, - const char *options, const char *nisstype, int8_t minmoves, int8_t maxmoves, @@ -360,7 +344,6 @@ nissy_solve( { cube_t c; int p; - int64_t ret; uint8_t h, k; c = readcube_B32(cube); @@ -395,28 +378,25 @@ nissy_solve( return -1; } - /* TODO define and use solve_options_t */ - if (!strcmp(solver, "h48")) { - p = parse_h48_options(options, &h, &k, NULL); + if (!strncmp(solver, "h48", 3)) { + if (!strcmp(solver, "h48stats")) + return solve_h48stats(c, maxmoves, data, solutions); + + p = parse_h48_solver(solver, &h, &k); if (p != 0) { - LOG("gendata: could not parse options\n"); - ret = -1; + return -1; } else { - ret = THREADS > 1 ? + return THREADS > 1 ? solve_h48_multithread(c, minmoves, maxmoves, maxsolutions, data, solutions) : solve_h48(c, minmoves, maxmoves, maxsolutions, data, solutions); } - } else if (!strcmp(solver, "h48stats")) { - ret = solve_h48stats(c, maxmoves, data, solutions); } else if (!strcmp(solver, "simple")) { - ret = solve_simple( + return solve_simple( c, minmoves, maxmoves, maxsolutions, optimal, solutions); } else { LOG("solve: unknown solver '%s'\n", solver); - ret = -1; + return -1; } - - return ret; } void diff --git a/src/nissy.h b/src/nissy.h @@ -75,14 +75,12 @@ the same parameters, or -1 in case of error. The returned value can be slightly larger than the actual table size. */ int64_t nissy_datasize( - const char *solver, - const char *options /* TODO: remove options, use only solver name */ + const char *solver ); /* Returns the number of bytes written, or -1 in case of error */ int64_t nissy_gendata( const char *solver, - const char *options, /* TODO: remove options, use only solver name */ void *generated_data ); @@ -93,9 +91,9 @@ int64_t nissy_derivedata( void *generated_data ); +/* Returns 0 on positive check, 1 on error */ int64_t nissy_checkdata( const char *solver, - const char *options, const void *data ); @@ -109,7 +107,6 @@ int64_t nissy_datainfo( int64_t nissy_solve( const char cube[static 22], const char *solver, - const char *options, /* TODO: remove options, use only solver name */ const char *nisstype, /* TODO: remove, use flags */ int8_t minmoves, int8_t maxmoves, diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c @@ -1,16 +1,16 @@ #include "../tool.h" #include "../expected_distributions.h" -char *solver, *options; +char *solver; uint64_t *expected; static void run(void) { int64_t size; + bool consistent, expected; char *buf, filename[1024]; - getfilename(solver, options, filename); - size = generatetable(solver, options, &buf); + size = generatetable(solver, &buf); switch (size) { case -1: return; @@ -18,11 +18,19 @@ run(void) { goto gendata_run_finish; default: nissy_datainfo(buf, write_stdout); - if (check_distribution(solver, buf)) { + consistent = nissy_checkdata(solver, buf) == 0; + expected = check_distribution(solver, buf); + if (consistent && expected) { printf("\n"); printf("Generated %" PRId64 " bytes.\n", size); + sprintf(filename, "tables/%s", solver); writetable(buf, size, filename); } + if (!consistent) + printf("Error: table is not consistent with info" + " (nissy_checkdata() failed)\n"); + if (!expected) + printf("Error: distribution is not as expected\n"); break; } @@ -33,15 +41,14 @@ gendata_run_finish: int main(int argc, char **argv) { uint8_t h, k; - if (argc < 3) { + if (argc < 2) { fprintf(stderr, "Error: not enough arguments. " - "A solver and its options must be given.\n"); + "A solver must be given.\n"); return 1; } solver = argv[1]; - options = argv[2]; - parse_h48_options(options, &h, &k, NULL); + parse_h48_solver(solver, &h, &k); expected = expected_h48[h][k]; nissy_setlogger(log_stderr); diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c @@ -11,25 +11,25 @@ edit the base value in the source code and recompile. #include "../tool.h" -char *opts_large, *opts_small, *filename_large, *filename_small; +char *solver_large, *solver_small, *filename_large, *filename_small; void run(void) { - derivedata_run(opts_large, opts_small, filename_large, filename_small); + derivedata_run(solver_large, solver_small, filename_large, filename_small); } int main(int argc, char **argv) { if (argc < 5) { fprintf(stderr, "Error: not enough arguments. Required:\n" - "1. Options for large table\n" - "2. Options for derived table\n" + "1. Solver name for large table\n" + "2. Solver name for derived table\n" "3. Filename containing large table\n" "4. Filename for saving derived table\n"); return 1; } - opts_large = argv[1]; - opts_small = argv[2]; + solver_large = argv[1]; + solver_small = argv[2]; filename_large = argv[3]; filename_small = argv[4]; diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c @@ -1,15 +1,15 @@ #include "../tool.h" #include "../expected_distributions.h" -char *solver, *options, *filename; +char *solver, *filename; static void run(void) { - int64_t size; + int64_t size, result; char *buf; FILE *f; - size = nissy_datasize(solver, options); + size = nissy_datasize(solver); if (size <= 0) { fprintf(stderr, "Error in datasize\n"); @@ -24,22 +24,23 @@ run(void) { buf = malloc(size); fread(buf, size, 1, f); fclose(f); - nissy_checkdata(solver, options, buf); + result = nissy_checkdata(solver, buf); free(buf); + printf("checkdata %s\n", result == 0 ? "succeeded" : "failed"); + /* TODO: cross-check with expected distributions? */ } int main(int argc, char **argv) { - if (argc < 4) { + if (argc < 3) { fprintf(stderr, "Error: not enough arguments. " - "A solver, its options and a file name must be given.\n"); + "A solver and a file name must be given.\n"); return 1; } solver = argv[1]; - options = argv[2]; - filename = argv[3]; + filename = argv[2]; nissy_setlogger(log_stderr); timerun(run); diff --git a/tools/200_stats_tables_h48/stats_tables_h48.c b/tools/200_stats_tables_h48/stats_tables_h48.c @@ -3,11 +3,10 @@ #include "../tool.h" #define MAXMOVES 20 -#define NCUBES_PER_THREAD 10000 #define LOG_EVERY (NCUBES_PER_THREAD / 10) +int NCUBES_PER_THREAD; const char *solver = "h48stats"; -const char *options = ""; const char *filename = "tables/h48h0k4"; char *buf; @@ -29,7 +28,7 @@ uint64_t rand64(void) { static void * run_thread(void *arg) { - char sols[12], cube[22]; + char s[12], cube[22]; int64_t ep, eo, cp, co; int i, j; @@ -41,10 +40,9 @@ run_thread(void *arg) cp = rand64(); co = rand64(); nissy_getcube(ep, eo, cp, co, "fix", cube); - nissy_solve(cube, "h48stats", "", "", - 0, MAXMOVES, 1, -1, buf, sols); + nissy_solve(cube, "h48stats", "", 0, MAXMOVES, 1, -1, buf, s); for (j = 0; j < 12; j++) - a->v[j][(int)sols[j]]++; + a->v[j][(int)s[j]]++; if ((i+1) % LOG_EVERY == 0) fprintf(stderr, "[thread %d] %d cubes solved...\n", a->thread_id, i+1); @@ -85,11 +83,27 @@ void run(void) { } } -int main(void) { +int main(int argc, char **argv) { srand(time(NULL)); nissy_setlogger(log_stderr); - if (getdata(solver, options, &buf, filename) != 0) + if (argc < 2) { + fprintf(stderr, "Error: not enough arguments. " + "Number of cubes per thread must be provided.\n"); + return 1; + } + + NCUBES_PER_THREAD = atoi(argv[1]); + + if (NCUBES_PER_THREAD < 1 || NCUBES_PER_THREAD > 1000000) { + fprintf(stderr, "Invalid number of cubes: must be > 0 and " + "< 1000000, but %d was given.\n", NCUBES_PER_THREAD); + return 1; + } + + printf("Using %d cubes per thread (%d total)\n", + NCUBES_PER_THREAD, NCUBES_PER_THREAD * THREADS); + if (getdata(solver, &buf, filename) != 0) return 1; timerun(run); diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c @@ -1,8 +1,6 @@ #include "../tool.h" -const char *solver = "h48"; -const char *options = "0;4;20"; -const char *filename = "tables/h48h0k4"; +const char *solver = "h48h0k4"; char *buf; char *scrambles[] = { @@ -28,7 +26,7 @@ void run(void) { continue; } n = nissy_solve( - cube, "h48", options, "", 0, 20, 1, -1, buf, sol); + cube, solver, "", 0, 20, 1, -1, buf, sol); if (n == 0) { printf("No solution\n"); fprintf(stderr, "No solution found\n"); @@ -39,10 +37,13 @@ void run(void) { } int main(void) { + char filename[255]; + srand(time(NULL)); nissy_setlogger(log_stderr); - if (getdata(solver, options, &buf, filename) != 0) + sprintf(filename, "tables/%s", solver); + if (getdata(solver, &buf, filename) != 0) return 1; timerun(run); diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h @@ -155,7 +155,7 @@ check_distribution(const char *solver, const void *data) { tableinfo_t info = {0}; - if (!strcmp(solver, "h48")) { + if (!strncmp(solver, "h48", 3)) { readtableinfo(data, &info); if (!distribution_equal( expected_cocsep, info.distribution, info.maxvalue)) { diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h @@ -9,4 +9,4 @@ for testing purposes only. #include "../src/solvers/tables.h" size_t gendata_h48_derive(uint8_t, const void *, void *); -int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); +int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); diff --git a/tools/tool.h b/tools/tool.h @@ -12,12 +12,11 @@ static void log_stderr(const char *, ...); static void log_stdout(const char *, ...); static double timerun(void (*)(void)); -static void getfilename(const char *, const char *, char *); static void writetable(const char *, int64_t, const char *); -static int64_t generatetable(const char *, const char *, char **); +static int64_t generatetable(const char *, char **); static int64_t derivetable(const char *, const char *, const char *, char **); -static int getdata(const char *, const char *, char **, const char *); -static void gendata_run(const char *, const char *, uint64_t[static 21]); +static int getdata(const char *, char **, const char *); +static void gendata_run(const char *, uint64_t[static 21]); static void derivedata_run( const char *, const char *, const char *, const char *); @@ -71,50 +70,39 @@ timerun(void (*run)(void)) } static void -getfilename(const char *solver, const char *options, char *filename) -{ - uint8_t h, k; - - /* Only h48 supported for now */ - parse_h48_options(options, &h, &k, NULL); - - sprintf(filename, "tables/%sh%dk%d", solver, h, k); -} - -static void writetable(const char *buf, int64_t size, const char *filename) { FILE *f; if ((f = fopen(filename, "wb")) == NULL) { - fprintf(stderr, "Could not write tables to file %s" + printf("Could not write tables to file %s" ", will be regenerated next time.\n", filename); } else { fwrite(buf, size, 1, f); fclose(f); - fprintf(stderr, "Table written to %s.\n", filename); + printf("Table written to %s.\n", filename); } } static int64_t -generatetable(const char *solver, const char *options, char **buf) +generatetable(const char *solver, char **buf) { int64_t size, gensize; - size = nissy_datasize(solver, options); + size = nissy_datasize(solver); if (size == -1) { printf("Error getting table size.\n"); return -1; } *buf = malloc(size); - gensize = nissy_gendata(solver, options, *buf); + gensize = nissy_gendata(solver, *buf); if (gensize != size) { - fprintf(stderr, "Error generating table"); + printf("Error generating table"); if (gensize != -1) - fprintf(stderr, " (got %" PRId64 " bytes)", gensize); - fprintf(stderr, "\n"); + printf(" (got %" PRId64 " bytes)", gensize); + printf("\n"); return -2; } @@ -123,46 +111,53 @@ generatetable(const char *solver, const char *options, char **buf) static int64_t derivetable( - const char *opts_large, - const char *opts_small, + const char *solver_large, + const char *solver_small, const char *filename_large, char **buf ) { - uint8_t h; + uint8_t h, k; int64_t size, gensize; char *fulltable; - if (getdata("h48", opts_large, &fulltable, filename_large) != 0) { + if (getdata(solver_large, &fulltable, filename_large) != 0) { printf("Error reading full table.\n"); - return -1; + gensize = -1; + goto derivetable_error_nofree; } - size = nissy_datasize("h48", opts_small); + size = nissy_datasize(solver_small); if (size == -1) { printf("Error getting table size.\n"); - free(fulltable); - return -1; + gensize = -2; + goto derivetable_error; + } + + if (parse_h48_solver(solver_small, &h, &k) != 0) { + gensize = -3; + goto derivetable_error; } - h = atoi(opts_small); /* TODO: use option parser */ *buf = malloc(size); gensize = gendata_h48_derive(h, fulltable, *buf); if (gensize != size) { - fprintf(stderr, "Error deriving table\n"); - free(fulltable); - return -2; + printf("Error deriving table\n"); + gensize = -4; + goto derivetable_error; } +derivetable_error: free(fulltable); + +derivetable_error_nofree: return gensize; } static int getdata( const char *solver, - const char *options, char **buf, const char *filename ) { @@ -170,8 +165,8 @@ getdata( FILE *f; if ((f = fopen(filename, "rb")) == NULL) { - fprintf(stderr, "Table file not found, generating it.\n"); - size = generatetable(solver, options, buf); + printf("Table file not found, generating it.\n"); + size = generatetable(solver, buf); switch (size) { case -1: goto getdata_error_nofree; @@ -182,13 +177,13 @@ getdata( break; } } else { - fprintf(stderr, "Reading tables from file %s\n", filename); - size = nissy_datasize(solver, options); + printf("Reading tables from file %s\n", filename); + size = nissy_datasize(solver); *buf = malloc(size); sizeread = fread(*buf, size, 1, f); fclose(f); if (sizeread != 1) { - fprintf(stderr, "Error reading table, stopping\n"); + printf("Error reading table, stopping\n"); goto getdata_error; } } @@ -204,14 +199,13 @@ getdata_error_nofree: static void gendata_run( const char *solver, - const char *options, uint64_t expected[static 21] ) { int64_t size; char *buf, filename[1024]; - getfilename(solver, options, filename); - size = generatetable(solver, options, &buf); + sprintf(filename, "tables/%s", solver); + size = generatetable(solver, &buf); switch (size) { case -1: return; @@ -234,8 +228,8 @@ gendata_run_finish: static void derivedata_run( - const char *opts_large, - const char *opts_small, + const char *solver_large, + const char *solver_small, const char *filename_large, const char *filename_small ) @@ -243,7 +237,7 @@ derivedata_run( int64_t size; char *buf; - size = derivetable(opts_large, opts_small, filename_large, &buf); + size = derivetable(solver_large, solver_small, filename_large, &buf); switch (size) { case -1: return; diff --git a/tools/tool.sh b/tools/tool.sh @@ -29,15 +29,12 @@ date +'%Y-%m-%d %H:%M' echo "" echo "======== config.mk ========" cat config.mk -echo "===========================" echo "" echo "=== tool configuration ====" echo "TOOL=$toolname" echo "TOOLARGS=$TOOLARGS" echo "CC=$CC" -echo "===========================" echo "" echo "======= tool output =======" $BIN $TOOLARGS -echo "===========================" ) | tee "$file" "$LAST"