nissy-fmc

A Rubik's cube FMC assistant
git clone https://git.tronto.net/nissy-fmc
Download | Log | Files | Refs | README | LICENSE

commit 6e22349757cd7fb40f8524cd81308010d04bb97c
parent 4cad5c413b4a89b331f96f6e905c6f94b030cccb
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Fri, 21 Apr 2023 18:48:47 +0200

Fixes; also, weird gcc -O3 bug?

Diffstat:
Msrc/coord.c | 24+++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/coord.c b/src/coord.c @@ -12,6 +12,7 @@ static uint64_t indexers_getind(Indexer **is, Cube *c); static uint64_t indexers_getmax(Indexer **is); static void indexers_makecube(Indexer **is, uint64_t ind, Cube *c); +static int coord_base_number(Coordinate *coord); static void gen_coord_comp(Coordinate *coord); static void gen_coord_sym(Coordinate *coord); static bool read_coord_mtable(Coordinate *coord); @@ -76,6 +77,16 @@ indexers_makecube(Indexer **is, uint64_t ind, Cube *c) } } +static int +coord_base_number(Coordinate *coord) +{ + int j; + + for (j = 0; coord->base[j] != NULL; j++) ; + + return j; +} + static void gen_coord_comp(Coordinate *coord) { @@ -547,14 +558,15 @@ genptable(Coordinate *coord) int d, i; uint64_t oldn, sz; - compact = coord->base[1] != NULL; - sz = ptablesize(coord) * (compact ? 2 : 1); + coord->compact = coord->base[1] != NULL; + sz = ptablesize(coord) * (coord->compact ? 2 : 1); coord->ptable = malloc(sz * sizeof(entry_group_t)); if (read_ptable_file(coord)) return; /* For the first steps we proceed the same way for compact and not */ + compact = coord->compact; coord->compact = false; fprintf(stderr, "Generating pt_%s\n", coord->name); @@ -726,10 +738,9 @@ ptableval(Coordinate *coord, uint64_t ind) e = ENTRIES_PER_GROUP_COMPACT; sh = (ind % e) * 2; ret = (coord->ptable[ind/e] & (3 << sh)) >> sh; - if (ret != coord->ptablebase) - return ret; - for (j = 0; coord->base[j] != NULL; j++) ; - for ( ; j >= 0; j--) { + if (ret != 0) + return ret + coord->ptablebase; + for (j = coord_base_number(coord); j >= 0; j--) { ii = ind % coord->base[j]->max; ret = MAX(ret, ptableval(coord->base[j], ii)); ind /= coord->base[j]->max; @@ -760,7 +771,6 @@ read_ptable_file(Coordinate *coord) for (i = 0; i < 16; i++) r += fread(&(coord->count[i]), sizeof(uint64_t), 1, f); r += fread(coord->ptable, sizeof(entry_group_t), ptablesize(coord), f); - fclose(f); return r == 17 + ptablesize(coord);