nissy-fmc

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

commit a133071ccc9fef628541a31fd68723ad34e751ce
parent 4d4d6282431c50ce6066ffc796e9d1978cb91d83
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Mon,  8 May 2023 19:16:05 +0200

Change coordinate values from 64 to 32 bits

Diffstat:
Mbuild/build.c | 48++++++++++++++++++++++++------------------------
Msrc/coord.c | 58+++++++++++++++++++++++++++++-----------------------------
Msrc/coord.h | 37+++++++++++++++++++------------------
Msrc/solve.h | 2+-
Msrc/steps.c | 76++++++++++++++++++++++++++++++++++++++--------------------------------------
5 files changed, 111 insertions(+), 110 deletions(-)

diff --git a/build/build.c b/build/build.c @@ -14,7 +14,7 @@ static void gen_coord_comp(Coordinate *); static void gen_coord_sym(Coordinate *); static void gen_ptable(Coordinate *); static void gen_ptable_bfs(Coordinate *, int); -static void gen_ptable_fixnasty(Coordinate *, uint64_t, int); +static void gen_ptable_fixnasty(Coordinate *, coord_value_t, int); static void gen_ptable_compress(Coordinate *); static void gen_ptable_setbase(Coordinate *); @@ -23,7 +23,7 @@ static char buf[TABLESFILESIZE]; static void gen_coord_comp(Coordinate *coord) { - uint64_t ui; + coord_value_t ui; Cube c, mvd; Move m; Trans t; @@ -32,13 +32,13 @@ gen_coord_comp(Coordinate *coord) coord->max = indexers_getmax(coord->i); - fprintf(stderr, "%s: size is %" PRIu64 "\n", coord->name, coord->max); + fprintf(stderr, "%s: size is %" PRIu32 "\n", coord->name, coord->max); fprintf(stderr, "%s: generating mtable\n", coord->name); alloc_mtable(coord); for (ui = 0; ui < coord->max; ui++) { if (ui % 100000 == 0) - fprintf(stderr, "\t(%" PRIu64 " done)\n", ui); + fprintf(stderr, "\t(%" PRIu32 " done)\n", ui); indexers_makecube(coord->i, ui, &c); for (m = 0; m < NMOVES_HTM; m++) { copy_cube(&c, &mvd); @@ -46,13 +46,13 @@ gen_coord_comp(Coordinate *coord) coord->mtable[m][ui] = indexers_getind(coord->i, &mvd); } } - fprintf(stderr, "\t(%" PRIu64 " done)\n", coord->max); + fprintf(stderr, "\t(%" PRIu32 " done)\n", coord->max); fprintf(stderr, "%s: generating ttable\n", coord->name); alloc_ttable(coord); for (ui = 0; ui < coord->max; ui++) { if (ui % 100000 == 0) - fprintf(stderr, "\t(%" PRIu64 " done)\n", ui); + fprintf(stderr, "\t(%" PRIu32 " done)\n", ui); indexers_makecube(coord->i, ui, &c); for (t = 0; t < NTRANS; t++) { copy_cube(&c, &mvd); @@ -60,13 +60,13 @@ gen_coord_comp(Coordinate *coord) coord->ttable[t][ui] = indexers_getind(coord->i, &mvd); } } - fprintf(stderr, "\t(%" PRIu64 " done)\n", coord->max); + fprintf(stderr, "\t(%" PRIu32 " done)\n", coord->max); } static void gen_coord_sym(Coordinate *coord) { - uint64_t i, in, ui, uj, uu, nr; + coord_value_t i, in, ui, uj, uu, nr; int j; Move m; Trans t; @@ -84,13 +84,13 @@ gen_coord_sym(Coordinate *coord) coord->symrep[nr] = i; coord->transtorep[i] = uf; - coord->selfsim[nr] = (uint64_t)0; + coord->selfsim[nr] = (coord_value_t)0; for (j = 0; j < coord->tgrp->n; j++) { t = coord->tgrp->t[j]; in = trans_coord(coord->base[0], t, i); coord->symclass[in] = nr; if (in == i) - coord->selfsim[nr] |= ((uint64_t)1<<t); + coord->selfsim[nr] |= ((coord_value_t)1<<t); else coord->transtorep[in] = inverse_trans(t); } @@ -99,14 +99,14 @@ gen_coord_sym(Coordinate *coord) coord->max = nr; - fprintf(stderr, "%s: number of classes is %" PRIu64 "\n", + fprintf(stderr, "%s: number of classes is %" PRIu32 "\n", coord->name, coord->max); /* Reallocating for maximum number of classes found */ /* TODO: remove, not needed anymore because not writing to file */ /* - coord->symrep = realloc(coord->symrep, coord->max*sizeof(uint64_t)); - coord->selfsim = realloc(coord->selfsim, coord->max*sizeof(uint64_t)); + coord->symrep = realloc(coord->symrep, coord->max*sizeof(coord_value_t)); + coord->selfsim = realloc(coord->selfsim, coord->max*sizeof(coord_value_t)); */ fprintf(stderr, "%s: generating mtable and ttrep_move\n", coord->name); @@ -114,7 +114,7 @@ gen_coord_sym(Coordinate *coord) alloc_ttrep_move(coord); for (ui = 0; ui < coord->max; ui++) { if (ui % 100000 == 0) - fprintf(stderr, "\t(%" PRIu64 " done)\n", ui); + fprintf(stderr, "\t(%" PRIu32 " done)\n", ui); uu = coord->symrep[ui]; for (m = 0; m < NMOVES_HTM; m++) { uj = move_coord(coord->base[0], m, uu, NULL); @@ -122,7 +122,7 @@ gen_coord_sym(Coordinate *coord) coord->ttrep_move[m][ui] = coord->transtorep[uj]; } } - fprintf(stderr, "\t(%" PRIu64 " done)\n", coord->max); + fprintf(stderr, "\t(%" PRIu32 " done)\n", coord->max); } void @@ -179,7 +179,7 @@ gen_ptable(Coordinate *coord) { bool compact; int d, i; - uint64_t oldn, sz; + coord_value_t oldn, sz; alloc_ptable(coord, true); @@ -199,14 +199,14 @@ gen_ptable(Coordinate *coord) ptableupdate(coord, 0, 0); gen_ptable_fixnasty(coord, 0, 0); fprintf(stderr, "\tDepth %d done, generated %" - PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", + PRIu32 "\t(%" PRIu32 "/%" PRIu32 ")\n", 0, coord->updated - oldn, coord->updated, coord->max); oldn = coord->updated; coord->count[0] = coord->updated; for (d = 0; d < 15 && coord->updated < coord->max; d++) { gen_ptable_bfs(coord, d); fprintf(stderr, "\tDepth %d done, generated %" - PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", + PRIu32 "\t(%" PRIu32 "/%" PRIu32 ")\n", d+1, coord->updated-oldn, coord->updated, coord->max); coord->count[d+1] = coord->updated - oldn; oldn = coord->updated; @@ -225,7 +225,7 @@ gen_ptable(Coordinate *coord) static void gen_ptable_bfs(Coordinate *coord, int d) { - uint64_t i, ii; + coord_value_t i, ii; int pval; Move m; @@ -244,9 +244,9 @@ gen_ptable_bfs(Coordinate *coord, int d) } static void -gen_ptable_fixnasty(Coordinate *coord, uint64_t i, int d) +gen_ptable_fixnasty(Coordinate *coord, coord_value_t i, int d) { - uint64_t ii, ss, M; + coord_value_t ii, ss, M; int j; Trans t; @@ -257,7 +257,7 @@ gen_ptable_fixnasty(Coordinate *coord, uint64_t i, int d) ss = coord->base[0]->selfsim[i/M]; for (j = 0; j < coord->base[0]->tgrp->n; j++) { t = coord->base[0]->tgrp->t[j]; - if (t == uf || !(ss & ((uint64_t)1<<t))) + if (t == uf || !(ss & ((coord_value_t)1<<t))) continue; ii = trans_coord(coord, t, i); ptableupdate(coord, ii, d); @@ -268,7 +268,7 @@ static void gen_ptable_compress(Coordinate *coord) { int val; - uint64_t i, j; + coord_value_t i, j; entry_group_t mask, v; fprintf(stderr, "Compressing table to 2 bits per entry\n"); @@ -298,7 +298,7 @@ static void gen_ptable_setbase(Coordinate *coord) { int i; - uint64_t sum, newsum; + coord_value_t sum, newsum; coord->ptablebase = 0; sum = coord->count[0] + coord->count[1] + coord->count[2]; diff --git a/src/coord.c b/src/coord.c @@ -17,11 +17,11 @@ static size_t copy_ptable(Coordinate *, char *, Copier *); static void readin (void *t, void *b, size_t n) { memcpy(t, b, n); } static void writeout(void *t, void *b, size_t n) { memcpy(b, t, n); } -uint64_t +coord_value_t indexers_getmax(Indexer **is) { int i; - uint64_t max = 1; + coord_value_t max = 1; for (i = 0; is[i] != NULL; i++) max *= is[i]->n; @@ -29,11 +29,11 @@ indexers_getmax(Indexer **is) return max; } -uint64_t +coord_value_t indexers_getind(Indexer **is, Cube *c) { int i; - uint64_t max = 0; + coord_value_t max = 0; for (i = 0; is[i] != NULL; i++) { max *= is[i]->n; @@ -44,14 +44,14 @@ indexers_getind(Indexer **is, Cube *c) } void -indexers_makecube(Indexer **is, uint64_t ind, Cube *c) +indexers_makecube(Indexer **is, coord_value_t ind, Cube *c) { /* Warning: anti-indexers are applied in the same order as indexers. */ /* We assume order does not matter, but it would make more sense to */ /* Apply them in reverse. */ int i; - uint64_t m; + coord_value_t m; make_solved(c); m = indexers_getmax(is); @@ -68,11 +68,11 @@ alloc_sd(Coordinate *coord, bool gen) size_t M; M = coord->base[0]->max; - coord->symclass = malloc(M * sizeof(uint64_t)); + coord->symclass = malloc(M * sizeof(coord_value_t)); coord->transtorep = malloc(M * sizeof(Trans)); if (gen) { - coord->selfsim = malloc(M * sizeof(uint64_t)); - coord->symrep = malloc(M * sizeof(uint64_t)); + coord->selfsim = malloc(M * sizeof(coord_value_t)); + coord->symrep = malloc(M * sizeof(coord_value_t)); } } @@ -82,7 +82,7 @@ alloc_mtable(Coordinate *coord) Move m; for (m = 0; m < NMOVES_HTM; m++) - coord->mtable[m] = malloc(coord->max * sizeof(uint64_t)); + coord->mtable[m] = malloc(coord->max * sizeof(coord_value_t)); } void @@ -100,7 +100,7 @@ alloc_ttable(Coordinate *coord) Trans t; for (t = 0; t < NTRANS; t++) - coord->ttable[t] = malloc(coord->max * sizeof(uint64_t)); + coord->ttable[t] = malloc(coord->max * sizeof(coord_value_t)); } void @@ -120,7 +120,7 @@ copy_coord_mtable(Coordinate *coord, char *buf, Copier *copy) size_t b, rowsize; b = 0; - rowsize = coord->max * sizeof(uint64_t); + rowsize = coord->max * sizeof(coord_value_t); for (m = 0; m < NMOVES_HTM; m++) { copy(coord->mtable[m], &buf[b], rowsize); b += rowsize; @@ -152,7 +152,7 @@ copy_coord_sd(Coordinate *coord, char *buf, Copier *copy) b = 0; - size_max = sizeof(uint64_t); + size_max = sizeof(coord_value_t); copy(&coord->max, &buf[b], size_max); b += size_max; @@ -160,7 +160,7 @@ copy_coord_sd(Coordinate *coord, char *buf, Copier *copy) copy(coord->transtorep, &buf[b], rowsize_ttr); b += rowsize_ttr; - rowsize_symc = coord->base[0]->max * sizeof(uint64_t); + rowsize_symc = coord->base[0]->max * sizeof(coord_value_t); copy(coord->symclass, &buf[b], rowsize_symc); b += rowsize_symc; @@ -174,7 +174,7 @@ copy_coord_ttable(Coordinate *coord, char *buf, Copier *copy) size_t b, rowsize; b = 0; - rowsize = coord->max * sizeof(uint64_t); + rowsize = coord->max * sizeof(coord_value_t); for (t = 0; t < NTRANS; t++) { copy(coord->ttable[t], &buf[b], rowsize); b += rowsize; @@ -194,7 +194,7 @@ copy_ptable(Coordinate *coord, char *buf, Copier *copy) copy(&coord->ptablebase, &buf[b], size_base); b += size_base; - size_count = 16 * sizeof(uint64_t); + size_count = 16 * sizeof(coord_value_t); copy(&coord->count, &buf[b], size_count); b += size_count; @@ -205,10 +205,10 @@ copy_ptable(Coordinate *coord, char *buf, Copier *copy) return b; } -uint64_t +coord_value_t index_coord(Coordinate *coord, Cube *cube, Trans *offtrans) { - uint64_t c[2], cnosym; + coord_value_t c[2], cnosym; Trans ttr; switch (coord->type) { @@ -243,10 +243,10 @@ index_coord(Coordinate *coord, Cube *cube, Trans *offtrans) return coord->max; /* Only reached in case of error */ } -uint64_t -move_coord(Coordinate *coord, Move m, uint64_t ind, Trans *offtrans) +coord_value_t +move_coord(Coordinate *coord, Move m, coord_value_t ind, Trans *offtrans) { - uint64_t i[2], M; + coord_value_t i[2], M; Trans ttr; /* Some safety checks should be done here, but for performance * @@ -286,10 +286,10 @@ move_coord(Coordinate *coord, Move m, uint64_t ind, Trans *offtrans) return coord->max; /* Only reached in case of error */ } -uint64_t -trans_coord(Coordinate *coord, Trans t, uint64_t ind) +coord_value_t +trans_coord(Coordinate *coord, Trans t, coord_value_t ind) { - uint64_t i[2], M; + coord_value_t i[2], M; /* Some safety checks should be done here, but for performance * * reasons we'd rather do them before calling this function. * @@ -316,7 +316,7 @@ trans_coord(Coordinate *coord, Trans t, uint64_t ind) size_t ptablesize(Coordinate *coord) { - uint64_t e; + coord_value_t e; e = coord->compact ? ENTRIES_PER_GROUP_COMPACT : ENTRIES_PER_GROUP; @@ -324,11 +324,11 @@ ptablesize(Coordinate *coord) } void -ptableupdate(Coordinate *coord, uint64_t ind, int n) +ptableupdate(Coordinate *coord, coord_value_t ind, int n) { int sh; entry_group_t mask; - uint64_t i; + coord_value_t i; if (ptableval(coord, ind) <= n) return; @@ -343,10 +343,10 @@ ptableupdate(Coordinate *coord, uint64_t ind, int n) } int -ptableval(Coordinate *coord, uint64_t ind) +ptableval(Coordinate *coord, coord_value_t ind) { int ret, j, sh; - uint64_t e, ii; + coord_value_t e, ii; if (coord->compact) { e = ENTRIES_PER_GROUP_COMPACT; diff --git a/src/coord.h b/src/coord.h @@ -2,42 +2,43 @@ #define ENTRIES_PER_GROUP_COMPACT (4*sizeof(entry_group_t)) typedef uint8_t entry_group_t; +typedef uint32_t coord_value_t; typedef bool (Moveset)(Move); typedef enum { COMP_COORD, SYM_COORD, SYMCOMP_COORD } CoordType; typedef struct { int n; - uint64_t (*index)(Cube *); - void (*to_cube)(uint64_t, Cube *); + coord_value_t (*index)(Cube *); + void (*to_cube)(coord_value_t, Cube *); } Indexer; typedef struct coordinate { char *name; CoordType type; - uint64_t max; - uint64_t *mtable[NMOVES_HTM]; - uint64_t *ttable[NTRANS]; + coord_value_t max; + coord_value_t *mtable[NMOVES_HTM]; + coord_value_t *ttable[NTRANS]; TransGroup *tgrp; struct coordinate *base[2]; - uint64_t *symclass; - uint64_t *symrep; + coord_value_t *symclass; + coord_value_t *symrep; Trans *transtorep; Trans *ttrep_move[NMOVES_HTM]; bool generated; Indexer *i[99]; - uint64_t *selfsim; + coord_value_t *selfsim; Moveset *moveset; - uint64_t updated; + coord_value_t updated; entry_group_t *ptable; int8_t ptablebase; bool compact; - uint64_t count[16]; + coord_value_t count[16]; } Coordinate; -uint64_t indexers_getind(Indexer **, Cube *); -uint64_t indexers_getmax(Indexer **); -void indexers_makecube(Indexer **, uint64_t, Cube *); +coord_value_t indexers_getind(Indexer **, Cube *); +coord_value_t indexers_getmax(Indexer **); +void indexers_makecube(Indexer **, coord_value_t, Cube *); void alloc_sd(Coordinate *, bool); void alloc_mtable(Coordinate *); @@ -45,13 +46,13 @@ void alloc_ttrep_move(Coordinate *); void alloc_ttable(Coordinate *); void alloc_ptable(Coordinate *, bool); -uint64_t index_coord(Coordinate *, Cube *, Trans *); -uint64_t move_coord(Coordinate *, Move, uint64_t, Trans *); -uint64_t trans_coord(Coordinate *, Trans, uint64_t); +coord_value_t index_coord(Coordinate *, Cube *, Trans *); +coord_value_t move_coord(Coordinate *, Move, coord_value_t, Trans *); +coord_value_t trans_coord(Coordinate *, Trans, coord_value_t); -int ptableval(Coordinate *, uint64_t); +int ptableval(Coordinate *, coord_value_t); size_t ptablesize(Coordinate *); -void ptableupdate(Coordinate *, uint64_t, int); +void ptableupdate(Coordinate *, coord_value_t, int); size_t read_coord(Coordinate *, char *); size_t write_coord(Coordinate *, char *); diff --git a/src/solve.h b/src/solve.h @@ -1,7 +1,7 @@ #define MAX_N_COORD 3 typedef enum { NORMAL, INVERSE, NISS } SolutionType; -typedef struct { uint64_t val; Trans t; } CubeState; +typedef struct { coord_value_t val; Trans t; } CubeState; typedef struct { char *shortname; Moveset *moveset; diff --git a/src/steps.c b/src/steps.c @@ -29,56 +29,56 @@ static void int_to_digit_array(int, int, int, int *); static void int_to_sum_zero_array(int, int, int, int *); static int perm_sign(int *, int); -static uint64_t index_eofb(Cube *cube); -static void invindex_eofb(uint64_t ind, Cube *ret); +static coord_value_t index_eofb(Cube *cube); +static void invindex_eofb(coord_value_t ind, Cube *ret); Indexer i_eofb = { .n = POW2TO11, .index = index_eofb, .to_cube = invindex_eofb, }; -static uint64_t index_coud(Cube *cube); -static void invindex_coud(uint64_t ind, Cube *ret); +static coord_value_t index_coud(Cube *cube); +static void invindex_coud(coord_value_t ind, Cube *ret); Indexer i_coud = { .n = POW3TO7, .index = index_coud, .to_cube = invindex_coud, }; -static uint64_t index_cp(Cube *cube); -static void invindex_cp(uint64_t ind, Cube *ret); +static coord_value_t index_cp(Cube *cube); +static void invindex_cp(coord_value_t ind, Cube *ret); Indexer i_cp = { .n = FACTORIAL8, .index = index_cp, .to_cube = invindex_cp, }; -static uint64_t index_epos(Cube *cube); -static void invindex_epos(uint64_t ind, Cube *ret); +static coord_value_t index_epos(Cube *cube); +static void invindex_epos(coord_value_t ind, Cube *ret); Indexer i_epos = { .n = BINOM12ON4, .index = index_epos, .to_cube = invindex_epos, }; -static uint64_t index_epe(Cube *cube); -static void invindex_epe(uint64_t ind, Cube *ret); +static coord_value_t index_epe(Cube *cube); +static void invindex_epe(coord_value_t ind, Cube *ret); Indexer i_epe = { .n = FACTORIAL4, .index = index_epe, .to_cube = invindex_epe, }; -static uint64_t index_eposepe(Cube *cube); -static void invindex_eposepe(uint64_t ind, Cube *ret); +static coord_value_t index_eposepe(Cube *cube); +static void invindex_eposepe(coord_value_t ind, Cube *ret); Indexer i_eposepe = { .n = BINOM12ON4 * FACTORIAL4, .index = index_eposepe, .to_cube = invindex_eposepe, }; -static uint64_t index_epud(Cube *cube); -static void invindex_epud(uint64_t ind, Cube *ret); +static coord_value_t index_epud(Cube *cube); +static void invindex_epud(coord_value_t ind, Cube *ret); Indexer i_epud = { .n = FACTORIAL8, .index = index_epud, @@ -384,25 +384,25 @@ perm_sign(int *a, int n) return ret % 2; } -static uint64_t +static coord_value_t index_eofb(Cube *cube) { - return (uint64_t)digit_array_to_int(cube->eo, 11, 2); + return (coord_value_t)digit_array_to_int(cube->eo, 11, 2); } -static uint64_t +static coord_value_t index_coud(Cube *cube) { - return (uint64_t)digit_array_to_int(cube->co, 7, 3); + return (coord_value_t)digit_array_to_int(cube->co, 7, 3); } -static uint64_t +static coord_value_t index_cp(Cube *cube) { - return (uint64_t)perm_to_index(cube->cp, 8); + return (coord_value_t)perm_to_index(cube->cp, 8); } -static uint64_t +static coord_value_t index_epe(Cube *cube) { int i, e[4]; @@ -410,16 +410,16 @@ index_epe(Cube *cube) for (i = 0; i < 4; i++) e[i] = cube->ep[i+8] - 8; - return (uint64_t)perm_to_index(e, 4); + return (coord_value_t)perm_to_index(e, 4); } -static uint64_t +static coord_value_t index_epud(Cube *cube) { - return (uint64_t)perm_to_index(cube->ep, 8); + return (coord_value_t)perm_to_index(cube->ep, 8); } -static uint64_t +static coord_value_t index_epos(Cube *cube) { int i, a[12]; @@ -427,44 +427,44 @@ index_epos(Cube *cube) for (i = 0; i < 12; i++) a[i] = (cube->ep[i] < 8) ? 0 : 1; - return (uint64_t)subset_to_index(a, 12, 4); + return (coord_value_t)subset_to_index(a, 12, 4); } -static uint64_t +static coord_value_t index_eposepe(Cube *cube) { int i, j, e[4]; - uint64_t epos, epe; + coord_value_t epos, epe; - epos = (uint64_t)index_epos(cube); + epos = (coord_value_t)index_epos(cube); for (i = 0, j = 0; i < 12; i++) if (cube->ep[i] >= 8) e[j++] = cube->ep[i] - 8; - epe = (uint64_t)perm_to_index(e, 4); + epe = (coord_value_t)perm_to_index(e, 4); return epos * FACTORIAL4 + epe; } static void -invindex_eofb(uint64_t ind, Cube *cube) +invindex_eofb(coord_value_t ind, Cube *cube) { int_to_sum_zero_array(ind, 2, 12, cube->eo); } static void -invindex_coud(uint64_t ind, Cube *cube) +invindex_coud(coord_value_t ind, Cube *cube) { int_to_sum_zero_array(ind, 3, 8, cube->co); } static void -invindex_cp(uint64_t ind, Cube *cube) +invindex_cp(coord_value_t ind, Cube *cube) { index_to_perm(ind, 8, cube->cp); } static void -invindex_epe(uint64_t ind, Cube *cube) +invindex_epe(coord_value_t ind, Cube *cube) { int i; @@ -474,13 +474,13 @@ invindex_epe(uint64_t ind, Cube *cube) } static void -invindex_epud(uint64_t ind, Cube *cube) +invindex_epud(coord_value_t ind, Cube *cube) { index_to_perm(ind, 8, cube->ep); } static void -invindex_epos(uint64_t ind, Cube *cube) +invindex_epos(coord_value_t ind, Cube *cube) { int i, j, k; @@ -493,10 +493,10 @@ invindex_epos(uint64_t ind, Cube *cube) } static void -invindex_eposepe(uint64_t ind, Cube *cube) +invindex_eposepe(coord_value_t ind, Cube *cube) { int i, j, k, e[4]; - uint64_t epos, epe; + coord_value_t epos, epe; epos = ind / FACTORIAL4; epe = ind % FACTORIAL4;