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 a21959e7edf523e6660023851f73426d8897783a
parent 99b746a01c11e061c4bd42cf096d27be9507ae21
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Mon, 16 Dec 2024 17:27:35 +0100

Fixed alignment bug

Diffstat:
M.gitignore | 2+-
Msrc/nissy.c | 22++++++++++++++++++++++
Msrc/nissy.h | 6++++++
Msrc/solvers/h48/gendata_h48.h | 6++++++
Msrc/solvers/h48/solve.h | 1+
5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -12,7 +12,7 @@ debugrun shell/lasttest.out shell/lasttest.err tables/* -tables-old/* +tables-old*/* test/*/runtest test/.DS_Store test/run diff --git a/src/nissy.c b/src/nissy.c @@ -79,6 +79,8 @@ checkdata(const char *buf, const tableinfo_t *info) } else if (!strncmp(info->solver, "h48", 3)) { getdistribution_h48((uint8_t *)buf + INFOSIZE, distr, info->h48h, info->bits); + } else if (!strncmp(info->solver, "eoesep data for h48", 19)) { + return true; } else { LOG("checkdata: unknown solver %s\n", info->solver); return false; @@ -367,6 +369,11 @@ nissy_datainfo( tableinfo_t info; long long ret; + if ((size_t)data % 8 != 0) { + LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + return NISSY_ERROR_DATA; + } + ret = readtableinfo(data_size, data, &info); if (ret != 0) return ret; @@ -439,6 +446,11 @@ nissy_gendata_unsafe( return NISSY_ERROR_NULL_POINTER; } + if ((size_t)data % 8 != 0) { + LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + return NISSY_ERROR_DATA; + } + arg.buf_size = data_size; arg.buf = data; if (!strncmp(solver, "h48", 3)) { @@ -463,6 +475,11 @@ nissy_checkdata( tableinfo_t info; int64_t err; + if ((size_t)data % 8 != 0) { + LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + return NISSY_ERROR_DATA; + } + for (buf = (char *)data; (err = readtableinfo(data_size, buf, &info)) == NISSY_OK; buf += info.next, data_size -= info.next) @@ -538,6 +555,11 @@ nissy_solve( return NISSY_ERROR_OPTIONS; } + if ((size_t)data % 8 != 0) { + LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + return NISSY_ERROR_DATA; + } + if (!strncmp(solver, "h48", 3)) { parse_ret = parse_h48_solver(solver, &h, &k); if (parse_ret == NISSY_OK) diff --git a/src/nissy.h b/src/nissy.h @@ -216,11 +216,14 @@ Parameters: data_size - The size of the data buffer. It is advised to use nissy_datasize to check how much memory is needed. data - The return parameter for the generated data. + This buffer must have 8-byte alignment. Return values: NISSY_ERROR_INVALID_SOLVER - The given solver is not known. NISSY_ERROR_NULL_POINTER - The 'solver' argument is null. NISSY_ERROR_UNKNOWN - An error occurred while generating the data. + NISSY_ERROR_DATA - The data buffer is invalid, for example because + it is not 8-byte aligned. Any value >= 0 - The size of the data, in bytes. */ long long @@ -236,6 +239,7 @@ Check that the data is a valid data table for a solver. Parameters: data_size - The size of the data buffer. data - The data for the solver. Can be computed with gendata. + This buffer must have 8-byte alignment. Return values: NISSY_OK - The data is valid. @@ -264,6 +268,7 @@ Parameters: the default value THREADS will be used. data_size - The size of the data buffer. data - The data for the solver. Can be computed with gendata. + This buffer must have 8-byte alignment. sols_size - The size of the solutions buffer. sols - The return parameter for the solutions. The solutions are separated by a '\n' (newline) and a '\0' (NULL character) @@ -278,6 +283,7 @@ Return values: NISSY_ERROR_OPTIONS - One or more of the given options are invalid. NISSY_ERROR_INVALID_SOLVER - The given solver is not known. NISSY_ERROR_NULL_POINTER - The 'solver' argument is null. + NISSY_ERROR_DATA - The data buffer is invalid. Any value >= 0 - The number of solutions found. */ long long diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -79,6 +79,12 @@ gendata_h48(gendata_h48_arg_t *arg) h48size = INFOSIZE + H48_TABLESIZE(arg->h, arg->k); fallbacksize = arg->k == 2 ? INFOSIZE + H48_TABLESIZE(0, 4) : 0; fallback2size = EOESEP_FULLSIZE; + + /* Add padding for 8-bit alignment */ + h48size = 8 * DIV_ROUND_UP(h48size, 8); + fallbacksize = 8 * DIV_ROUND_UP(fallbacksize, 8); + fallback2size = 8 * DIV_ROUND_UP(fallback2size, 8); + size = cocsepsize + h48size + fallbacksize + fallback2size; if (arg->buf == NULL) diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -129,6 +129,7 @@ solve_h48_appendallsym(dfsarg_solve_h48_t *arg) } /* The solutions are appended */ + ret = 0; for (k = 0; k < j && *arg->nsols < arg->maxsolutions; k++) { l = arg->solutions_size - *arg->solutions_used; m = *arg->solutions + *arg->solutions_used;