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 56048d13b73ec6e6a9c59d62e82f41e69a3994bd
parent 0f4931c8de298b0f97aba1757c9538f48adb30c6
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Tue, 25 Mar 2025 18:35:47 +0100

More safety with pointers using VLA function parameters

Diffstat:
Msrc/arch/avx2.h | 8++++----
Msrc/arch/common.h | 8++++----
Msrc/arch/neon.h | 8++++----
Msrc/arch/portable.h | 8++++----
Msrc/core/cube.h | 2+-
Msrc/nissy.c | 6+++---
Msrc/solvers/coord/gendata.h | 32++++++++++++++++++++++++--------
Msrc/solvers/coord/utils.h | 3++-
Msrc/solvers/h48/coordinate.h | 21++++++++++++++-------
Rsrc/solvers/h48/coordinate_macros.h -> src/solvers/h48/coordinate_types_macros.h | 0
Msrc/solvers/h48/gendata_cocsep.h | 39++++++++++++++++++++++++++++-----------
Msrc/solvers/h48/gendata_eoesep.h | 17+++++++++++++----
Msrc/solvers/h48/gendata_h48.h | 61++++++++++++++++++++-----------------------------------------
Msrc/solvers/h48/gendata_types_macros.h | 2+-
Msrc/solvers/h48/h48.h | 4+++-
Msrc/solvers/h48/map.h | 31++++++++++++++-----------------
Msrc/solvers/h48/solve.h | 18+++++++++---------
Msrc/solvers/tables.h | 49++++++++++++++++++++++---------------------------
Mtest/111_h48map/h48map_tests.c | 10+++++-----
Mtest/112_gendata_h48short/gendata_h48short_tests.c | 8++++----
Mtest/test.h | 2+-
Mtools/expected_distributions.h | 4++--
22 files changed, 182 insertions(+), 159 deletions(-)

diff --git a/src/arch/avx2.h b/src/arch/avx2.h @@ -23,7 +23,7 @@ popcount_u32(uint32_t x) } STATIC void -pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) +pieces(cube_t cube[static 1], uint8_t c[static 8], uint8_t e[static 12]) { uint8_t aux[32]; @@ -252,19 +252,19 @@ coord_esep(cube_t c) } STATIC_INLINE void -copy_corners(cube_t *dest, cube_t src) +copy_corners(cube_t dest[static 1], cube_t src) { *dest = _mm256_blend_epi32(*dest, src, 0x0F); } STATIC_INLINE void -copy_edges(cube_t *dest, cube_t src) +copy_edges(cube_t dest[static 1], cube_t src) { *dest = _mm256_blend_epi32(*dest, src, 0xF0); } STATIC_INLINE void -set_eo(cube_t *cube, int64_t eo) +set_eo(cube_t cube[static 1], int64_t eo) { int64_t eo12, eotop, eobot; __m256i veo; diff --git a/src/arch/common.h b/src/arch/common.h @@ -1,6 +1,6 @@ STATIC_INLINE int popcount_u32(uint32_t); -STATIC void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]); +STATIC void pieces(cube_t [static 1], uint8_t [static 8], uint8_t [static 12]); STATIC_INLINE bool equal(cube_t, cube_t); STATIC_INLINE cube_t invertco(cube_t); STATIC_INLINE cube_t compose_edges(cube_t, cube_t); @@ -14,9 +14,9 @@ STATIC_INLINE int64_t coord_cocsep(cube_t); STATIC_INLINE int64_t coord_eo(cube_t); STATIC_INLINE int64_t coord_esep(cube_t); -STATIC_INLINE void copy_corners(cube_t *, cube_t); -STATIC_INLINE void copy_edges(cube_t *, cube_t); -STATIC_INLINE void set_eo(cube_t *, int64_t); +STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); +STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); +STATIC_INLINE void set_eo(cube_t [static 1], int64_t); STATIC_INLINE cube_t invcoord_esep(int64_t); STATIC_INLINE void invcoord_esep_array(int64_t, int64_t, uint8_t[static 12]); diff --git a/src/arch/neon.h b/src/arch/neon.h @@ -39,7 +39,7 @@ popcount_u32(uint32_t x) } STATIC void -pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) +pieces(cube_t cube[static 1], uint8_t c[static 8], uint8_t e[static 12]) { // First 8 bytes of the corner vector are copied from the c array vst1_u8(c, cube->corner); @@ -287,19 +287,19 @@ coord_esep(cube_t c) } STATIC_INLINE void -copy_corners(cube_t *dst, cube_t src) +copy_corners(cube_t dst[static 1], cube_t src) { dst->corner = src.corner; } STATIC_INLINE void -copy_edges(cube_t *dst, cube_t src) +copy_edges(cube_t dst[static 1], cube_t src) { dst->edge = src.edge; } STATIC_INLINE void -set_eo(cube_t *cube, int64_t eo) +set_eo(cube_t cube[static 1], int64_t eo) { // Temp array to store the NEON vector uint8_t mem[16]; diff --git a/src/arch/portable.h b/src/arch/portable.h @@ -22,7 +22,7 @@ popcount_u32(uint32_t x) } STATIC void -pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12]) +pieces(cube_t cube[static 1], uint8_t c[static 8], uint8_t e[static 12]) { memcpy(c, cube->corner, 8); memcpy(e, cube->edge, 12); @@ -227,19 +227,19 @@ coord_esep(cube_t c) } STATIC_INLINE void -copy_corners(cube_t *dest, cube_t src) +copy_corners(cube_t dest[static 1], cube_t src) { memcpy(&dest->corner, src.corner, sizeof(src.corner)); } STATIC_INLINE void -copy_edges(cube_t *dest, cube_t src) +copy_edges(cube_t dest[static 1], cube_t src) { memcpy(&dest->edge, src.edge, sizeof(src.edge)); } STATIC_INLINE void -set_eo(cube_t *cube, int64_t eo) +set_eo(cube_t cube[static 1], int64_t eo) { uint8_t i, sum, flip; diff --git a/src/core/cube.h b/src/core/cube.h @@ -1,4 +1,4 @@ -STATIC cube_t solvecube(void); +STATIC cube_t solvedcube(void); STATIC cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]); STATIC bool isconsistent(cube_t); STATIC bool issolvable(cube_t); diff --git a/src/nissy.c b/src/nissy.c @@ -14,7 +14,7 @@ long long parse_h48_solver( const char *, uint8_t [static 1], uint8_t [static 1]); -STATIC bool checkdata(const char *, const tableinfo_t *); +STATIC bool checkdata(const char *, const tableinfo_t [static 1]); STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); @@ -66,11 +66,11 @@ parse_h48_solver_error: } STATIC bool -checkdata(const char *buf, const tableinfo_t *info) +checkdata(const char *buf, const tableinfo_t info[static 1]) { uint64_t distr[INFO_DISTRIBUTION_LEN]; - if (info == NULL || my_strnlen(info->solver, INFO_SOLVER_STRLEN) + if (my_strnlen(info->solver, INFO_SOLVER_STRLEN) == INFO_SOLVER_STRLEN) { LOG("checkdata: error reading table info\n"); return false; diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h @@ -1,10 +1,13 @@ -STATIC size_t gendata_coord(const coord_t *, void *); +STATIC size_t gendata_coord(const coord_t [static 1], void *); STATIC int64_t gendata_coord_dispatch(const char *, void *); -STATIC tableinfo_t genptable_coord(const coord_t *, const void *, uint8_t *); +STATIC tableinfo_t genptable_coord( + const coord_t [static 1], const void *, uint8_t *); STATIC void getdistribution_coord( const uint8_t *, const char *, uint64_t [static INFO_DISTRIBUTION_LEN]); -STATIC uint8_t get_coord_pval(const coord_t *, const uint8_t *, uint64_t); -STATIC void set_coord_pval(const coord_t *, uint8_t *, uint64_t, uint8_t); +STATIC uint8_t get_coord_pval( + const coord_t [static 1], const uint8_t *, uint64_t); +STATIC void set_coord_pval( + const coord_t [static 1], uint8_t *, uint64_t, uint8_t); STATIC int64_t gendata_coord_dispatch(const char *coordstr, void *buf) @@ -22,7 +25,7 @@ gendata_coord_dispatch(const char *coordstr, void *buf) } STATIC size_t -gendata_coord(const coord_t *coord, void *buf) +gendata_coord(const coord_t coord[static 1], void *buf) { uint64_t coord_dsize, tablesize, ninfo; void *pruningbuf, *coord_data; @@ -72,7 +75,11 @@ gendata_coord_return_size: } STATIC tableinfo_t -genptable_coord(const coord_t *coord, const void *data, uint8_t *table) +genptable_coord( + const coord_t coord[static 1], + const void *data, + uint8_t *table +) { uint64_t tablesize, i, j, d, tot; tableinfo_t info; @@ -147,13 +154,22 @@ getdistribution_coord( } STATIC uint8_t -get_coord_pval(const coord_t *coord, const uint8_t *table, uint64_t i) +get_coord_pval( + const coord_t coord[static 1], + const uint8_t *table, + uint64_t i +) { return (table[COORD_INDEX(i)] & COORD_MASK(i)) >> COORD_SHIFT(i); } STATIC void -set_coord_pval(const coord_t *coord, uint8_t *table, uint64_t i, uint8_t val) +set_coord_pval( + const coord_t coord[static 1], + uint8_t *table, + uint64_t i, + uint8_t val +) { table[COORD_INDEX(i)] = (table[COORD_INDEX(i)] & (~COORD_MASK(i))) | (val << COORD_SHIFT(i)); diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h @@ -1,6 +1,7 @@ STATIC coord_t *parse_coord(size_t n, const char [n]); STATIC uint8_t parse_axis(size_t n, const char [n]); -STATIC void parse_coord_and_axis(size_t n, const char [n], coord_t **, uint8_t *); +STATIC void parse_coord_and_axis( + size_t n, const char [n], coord_t **, uint8_t *); STATIC int64_t dataid_coord(const char *, char [static NISSY_DATAID_SIZE]); STATIC coord_t * diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h @@ -1,12 +1,15 @@ -/* Macros defined in a separate file for easier testing */ -#include "coordinate_macros.h" - -STATIC_INLINE int64_t coord_h48(cube_t, const uint32_t *, uint8_t); +STATIC_INLINE int64_t coord_h48( + cube_t, const uint32_t [static COCSEP_TABLESIZE], uint8_t); STATIC_INLINE int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); -STATIC_INLINE cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); +STATIC_INLINE cube_t invcoord_h48( + int64_t, const cube_t [static COCSEP_CLASSES], uint8_t); STATIC_INLINE int64_t -coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) +coord_h48( + cube_t c, + const uint32_t cocsepdata[static COCSEP_TABLESIZE], + uint8_t h +) { int64_t cocsep, coclass; uint32_t data; @@ -42,7 +45,11 @@ the given value, because it works up to symmetry. This means that the returned cube is a transformed cube of one that gives the correct value. */ STATIC_INLINE cube_t -invcoord_h48(int64_t i, const cube_t *crep, uint8_t h) +invcoord_h48( + int64_t i, + const cube_t crep[static COCSEP_CLASSES], + uint8_t h +) { cube_t ret; int64_t hh, coclass, ee, esep, eo; diff --git a/src/solvers/h48/coordinate_macros.h b/src/solvers/h48/coordinate_types_macros.h diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h @@ -1,11 +1,15 @@ -STATIC_INLINE bool gendata_cocsep_get_visited(const uint8_t *, int64_t); -STATIC_INLINE void gendata_cocsep_set_visited(uint8_t *, int64_t); - STATIC size_t gendata_cocsep(char *, uint64_t *, cube_t *); -STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); -STATIC void getdistribution_cocsep(const uint32_t *, uint64_t [static 21]); +STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t [static 1]); +STATIC void getdistribution_cocsep( + const uint32_t [static COCSEP_TABLESIZE], uint64_t [static 21]); + +STATIC_INLINE bool gendata_cocsep_get_visited( + const uint8_t [static COCSEP_VISITEDSIZE], int64_t); +STATIC_INLINE void gendata_cocsep_set_visited( + uint8_t [static COCSEP_VISITEDSIZE], int64_t); -STATIC_INLINE int8_t get_h48_cdata(cube_t, const uint32_t *, uint32_t *); +STATIC_INLINE int8_t get_h48_cdata( + cube_t, const uint32_t [static COCSEP_TABLESIZE], uint32_t *); STATIC size_t gendata_cocsep( @@ -78,7 +82,7 @@ gendata_cocsep_return_size: } STATIC uint32_t -gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) +gendata_cocsep_dfs(cocsep_dfs_arg_t arg[static 1]) { uint8_t m; uint32_t cc, class, ttrep, depth, olddepth, tinv; @@ -133,7 +137,10 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) } STATIC void -getdistribution_cocsep(const uint32_t *table, uint64_t distr[static 21]) +getdistribution_cocsep( + const uint32_t table[static COCSEP_TABLESIZE], + uint64_t distr[static 21] +) { size_t i; @@ -144,19 +151,29 @@ getdistribution_cocsep(const uint32_t *table, uint64_t distr[static 21]) } STATIC_INLINE bool -gendata_cocsep_get_visited(const uint8_t *a, int64_t i) +gendata_cocsep_get_visited( + const uint8_t a[static COCSEP_VISITEDSIZE], + int64_t i +) { return a[VISITED_IND(i)] & VISITED_MASK(i); } STATIC_INLINE void -gendata_cocsep_set_visited(uint8_t *a, int64_t i) +gendata_cocsep_set_visited( + uint8_t a[static COCSEP_VISITEDSIZE], + int64_t i +) { a[VISITED_IND(i)] |= VISITED_MASK(i); } STATIC_INLINE int8_t -get_h48_cdata(cube_t cube, const uint32_t *cocsepdata, uint32_t *cdata) +get_h48_cdata( + cube_t cube, + const uint32_t cocsepdata[static COCSEP_TABLESIZE], + uint32_t *cdata +) { int64_t coord; diff --git a/src/solvers/h48/gendata_eoesep.h b/src/solvers/h48/gendata_eoesep.h @@ -12,9 +12,11 @@ STATIC uint32_t gendata_eoesep_marksim(int64_t, uint8_t, uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]); STATIC bool gendata_eoesep_next(cube_t, uint8_t, uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX]); -STATIC uint8_t get_eoesep_pval(const uint8_t *, int64_t); +STATIC uint8_t get_eoesep_pval( + const uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t); STATIC uint8_t get_eoesep_pval_cube(const void *, cube_t); -STATIC void set_eoesep_pval(uint8_t *, int64_t, uint8_t); +STATIC void set_eoesep_pval( + uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t, uint8_t); STATIC int64_t coord_eoesep_sym(cube_t c, const uint32_t esep_classes[static ESEP_MAX]) @@ -247,7 +249,10 @@ gendata_eoesep_next( } STATIC uint8_t -get_eoesep_pval(const uint8_t *table, int64_t i) +get_eoesep_pval( + const uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], + int64_t i +) { return (table[EOESEP_INDEX(i)] & EOESEP_MASK(i)) >> EOESEP_SHIFT(i); } @@ -267,7 +272,11 @@ get_eoesep_pval_cube(const void *data, cube_t c) } STATIC void -set_eoesep_pval(uint8_t *table, int64_t i, uint8_t val) +set_eoesep_pval( + uint8_t table[static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], + int64_t i, + uint8_t val +) { table[EOESEP_INDEX(i)] = (table[EOESEP_INDEX(i)] & (~EOESEP_MASK(i))) | (val << EOESEP_SHIFT(i)); diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -1,17 +1,17 @@ -STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *); -STATIC int64_t gendata_h48(gendata_h48_arg_t *); -STATIC void gendata_h48h0k4(gendata_h48_arg_t *); -STATIC void gendata_h48k2(gendata_h48_arg_t *); -STATIC void gendata_h48k2_realcoord(gendata_h48_arg_t *); +STATIC uint64_t genddfggta_h48short(gendata_h48short_arg_t [static 1]); +STATIC int64_t gendata_h48(gendata_h48_arg_t [static 1]); +STATIC void gendata_h48h0k4(gendata_h48_arg_t [static 1]); +STATIC void gendata_h48k2(gendata_h48_arg_t [static 1]); STATIC void * gendata_h48h0k4_runthread(void *); STATIC void * gendata_h48k2_runthread(void *); -STATIC_INLINE void gendata_h48_mark_atomic(gendata_h48_mark_t *); -STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t *); -STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); -STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); -STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); +STATIC_INLINE void gendata_h48_mark_atomic(gendata_h48_mark_t [static 1]); +STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t [static 1]); +STATIC_INLINE bool gendata_h48k2_dfs_stop( + cube_t, int8_t, h48k2_dfs_arg_t [static 1]); +STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]); +STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]); STATIC void getdistribution_h48(const uint8_t *, uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); @@ -28,7 +28,7 @@ STATIC_INLINE void set_h48_pval_atomic( size_t gendata_h48_derive(uint8_t, const void *, void *); STATIC uint64_t -gendata_h48short(gendata_h48short_arg_t *arg) +gendata_h48short(gendata_h48short_arg_t arg[static 1]) { uint8_t i, m; int64_t coord; @@ -62,7 +62,7 @@ gendata_h48short(gendata_h48short_arg_t *arg) } STATIC int64_t -gendata_h48(gendata_h48_arg_t *arg) +gendata_h48(gendata_h48_arg_t arg[static 1]) { uint64_t size, cocsepsize, h48size, fallbacksize, fallback2size, of; long long r; @@ -70,11 +70,6 @@ gendata_h48(gendata_h48_arg_t *arg) tableinfo_t cocsepinfo, h48info, fallbackinfo; gendata_h48_arg_t arg_h0k4; - if (arg == NULL) { - LOG("Error computing H48 data: arg is NULL.\n"); - return NISSY_ERROR_UNKNOWN; - } - cocsepsize = COCSEP_FULLSIZE; h48size = INFOSIZE + H48_TABLESIZE(arg->h, arg->k); fallbacksize = arg->k == 2 ? INFOSIZE + H48_TABLESIZE(0, 4) : 0; @@ -107,8 +102,6 @@ gendata_h48(gendata_h48_arg_t *arg) if (arg->h == 0 && arg->k == 4) { gendata_h48h0k4(arg); - } else if ((arg->h == 0 || arg->h == 11) && arg->k == 2) { - gendata_h48k2_realcoord(arg); } else if (arg->k == 2) { gendata_h48k2(arg); } else { @@ -189,7 +182,7 @@ gendata_h48(gendata_h48_arg_t *arg) } STATIC void -gendata_h48h0k4(gendata_h48_arg_t *arg) +gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) { _Atomic uint8_t *table; uint8_t val; @@ -325,7 +318,7 @@ gendata_h48h0k4_runthread(void *arg) } STATIC void -gendata_h48k2(gendata_h48_arg_t *arg) +gendata_h48k2(gendata_h48_arg_t arg[static 1]) { static const uint8_t shortdepth = 8; static const uint64_t capacity = 10000019; @@ -483,7 +476,7 @@ gendata_h48k2_runthread(void *arg) } STATIC void -gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) +gendata_h48k2_dfs(h48k2_dfs_arg_t arg[static 1]) { int8_t d; uint8_t m[4]; @@ -562,7 +555,7 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) } STATIC_INLINE void -gendata_h48_mark_atomic(gendata_h48_mark_t *arg) +gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) { uint8_t oldval, newval; int64_t coord, mutex; @@ -582,7 +575,7 @@ gendata_h48_mark_atomic(gendata_h48_mark_t *arg) } STATIC_INLINE void -gendata_h48_mark(gendata_h48_mark_t *arg) +gendata_h48_mark(gendata_h48_mark_t arg[static 1]) { uint8_t oldval, newval; int64_t coord, mutex; @@ -599,7 +592,7 @@ gendata_h48_mark(gendata_h48_mark_t *arg) } STATIC_INLINE bool -gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) +gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) { uint64_t val; int64_t coord, mutex; @@ -613,7 +606,7 @@ gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) pthread_mutex_lock(arg->table_mutex[mutex]); oldval = get_h48_pval(arg->table, coord, arg->k); pthread_mutex_unlock(arg->table_mutex[mutex]); - return oldval <= depth; + return oldval <= d; } else { /* With 0 < k < 11 we do not have a "real coordinate". The best we can do is checking if we backtracked to @@ -624,22 +617,8 @@ gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) } } -STATIC void -gendata_h48k2_realcoord(gendata_h48_arg_t *arg) -{ - /* TODO */ - gendata_h48k2(arg); -} - -STATIC void * -gendata_h48k2_realcoord_runthread(void *arg) -{ - /* TODO */ - return NULL; -} - STATIC tableinfo_t -makeinfo_h48k2(gendata_h48_arg_t *arg) +makeinfo_h48k2(gendata_h48_arg_t arg[static 1]) { tableinfo_t info; diff --git a/src/solvers/h48/gendata_types_macros.h b/src/solvers/h48/gendata_types_macros.h @@ -33,7 +33,7 @@ /* TODO: This loop over similar h48 coordinates can be improved by only transforming edges, but we need to compose transformations (i.e. conjugate -_t by _ttrep). +VAR_T by VAR_TTREP). */ #define FOREACH_H48SIM(ARG_CUBE, ARG_COCSEPDATA, ARG_SELFSIM, ARG_ACTION) \ int64_t VAR_COCSEP = coord_cocsep(ARG_CUBE); \ diff --git a/src/solvers/h48/h48.h b/src/solvers/h48/h48.h @@ -1,6 +1,8 @@ +#include "coordinate_types_macros.h" +#include "map_types_macros.h" +#include "gendata_types_macros.h" #include "coordinate.h" #include "map.h" -#include "gendata_types_macros.h" #include "gendata_cocsep.h" #include "gendata_eoesep.h" #include "gendata_h48.h" diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h @@ -1,16 +1,13 @@ -/* Type definitions and macros are in a separate file for easier testing */ -#include "map_types_macros.h" - -STATIC void h48map_create(h48map_t *, uint64_t, uint64_t); -STATIC void h48map_clear(h48map_t *); -STATIC void h48map_destroy(h48map_t *); -STATIC uint64_t h48map_lookup(h48map_t *, uint64_t); -STATIC void h48map_insertmin(h48map_t *, uint64_t, uint64_t); -STATIC uint64_t h48map_value(h48map_t *, uint64_t); -STATIC kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); +STATIC void h48map_create(h48map_t [static 1], uint64_t, uint64_t); +STATIC void h48map_clear(h48map_t [static 1]); +STATIC void h48map_destroy(h48map_t [static 1]); +STATIC uint64_t h48map_lookup(h48map_t [static 1], uint64_t); +STATIC void h48map_insertmin(h48map_t [static 1], uint64_t, uint64_t); +STATIC uint64_t h48map_value(h48map_t [static 1], uint64_t); +STATIC kvpair_t h48map_nextkvpair(h48map_t [static 1], uint64_t [static 1]); STATIC void -h48map_create(h48map_t *map, uint64_t capacity, uint64_t randomizer) +h48map_create(h48map_t map[static 1], uint64_t capacity, uint64_t randomizer) { map->capacity = capacity; map->randomizer = randomizer; @@ -20,20 +17,20 @@ h48map_create(h48map_t *map, uint64_t capacity, uint64_t randomizer) } STATIC void -h48map_clear(h48map_t *map) +h48map_clear(h48map_t map[static 1]) { memset(map->table, 0xFF, map->capacity * sizeof(uint64_t)); map->n = 0; } STATIC void -h48map_destroy(h48map_t *map) +h48map_destroy(h48map_t map[static 1]) { free(map->table); } STATIC_INLINE uint64_t -h48map_lookup(h48map_t *map, uint64_t x) +h48map_lookup(h48map_t map[static 1], uint64_t x) { uint64_t hash, i; @@ -47,7 +44,7 @@ h48map_lookup(h48map_t *map, uint64_t x) } STATIC_INLINE void -h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val) +h48map_insertmin(h48map_t map[static 1], uint64_t key, uint64_t val) { uint64_t i, oldval, min; @@ -60,13 +57,13 @@ h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val) } STATIC_INLINE uint64_t -h48map_value(h48map_t *map, uint64_t key) +h48map_value(h48map_t map[static 1], uint64_t key) { return map->table[h48map_lookup(map, key)] >> MAP_KEYSHIFT; } STATIC kvpair_t -h48map_nextkvpair(h48map_t *map, uint64_t *p) +h48map_nextkvpair(h48map_t map[static 1], uint64_t p[static 1]) { kvpair_t kv; uint64_t pair; diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -46,18 +46,18 @@ typedef struct { int8_t *shortest_sol; } dfsarg_solve_h48_maketasks_t; -STATIC_INLINE bool solve_h48_stop(dfsarg_solve_h48_t *); +STATIC_INLINE bool solve_h48_stop(dfsarg_solve_h48_t [static 1]); STATIC int64_t solve_h48_maketasks( - dfsarg_solve_h48_t *, dfsarg_solve_h48_maketasks_t *, - solve_h48_task_t [static STARTING_CUBES], int *); + dfsarg_solve_h48_t [static 1], dfsarg_solve_h48_maketasks_t [static 1], + solve_h48_task_t [static STARTING_CUBES], int [static 1]); STATIC void *solve_h48_runthread(void *); -STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t *); +STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, int8_t, int8_t, uint64_t, const void *, size_t n, char [n], long long [static NISSY_SIZE_SOLVE_STATS]); STATIC_INLINE bool -solve_h48_stop(dfsarg_solve_h48_t *arg) +solve_h48_stop(dfsarg_solve_h48_t arg[static 1]) { uint32_t data, data_inv; int64_t coord; @@ -145,7 +145,7 @@ solve_h48_stop(dfsarg_solve_h48_t *arg) } STATIC int64_t -solve_h48_dfs(dfsarg_solve_h48_t *arg) +solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) { int64_t ret, n; uint8_t m, nm, lbn, lbi; @@ -261,10 +261,10 @@ solve_h48_runthread(void *arg) STATIC int64_t solve_h48_maketasks( - dfsarg_solve_h48_t *solve_arg, - dfsarg_solve_h48_maketasks_t *maketasks_arg, + dfsarg_solve_h48_t solve_arg[static 1], + dfsarg_solve_h48_maketasks_t maketasks_arg[static 1], solve_h48_task_t tasks[static STARTING_CUBES], - int *ntasks + int ntasks[static 1] ) { int r; diff --git a/src/solvers/tables.h b/src/solvers/tables.h @@ -1,11 +1,13 @@ -STATIC uint64_t read_unaligned_u64(const char *); -STATIC void write_unaligned_u64(char *, uint64_t); -STATIC int64_t readtableinfo(uint64_t, const char *, tableinfo_t *); -STATIC int64_t readtableinfo_n(uint64_t, const char *, uint8_t, tableinfo_t *); -STATIC int64_t writetableinfo(const tableinfo_t *, uint64_t, char *); +STATIC uint64_t read_unaligned_u64(const char [static sizeof(uint64_t)]); +STATIC void write_unaligned_u64(char [static sizeof(uint64_t)], uint64_t); +STATIC int64_t readtableinfo(size_t n, const char [n], tableinfo_t [static 1]); +STATIC int64_t readtableinfo_n( + size_t n, const char [n], uint8_t, tableinfo_t [static 1]); +STATIC int64_t writetableinfo( + const tableinfo_t [static 1], size_t n, char [n]); STATIC uint64_t -read_unaligned_u64(const char *buf) +read_unaligned_u64(const char buf[static sizeof(uint64_t)]) { uint64_t ret; @@ -15,13 +17,17 @@ read_unaligned_u64(const char *buf) } STATIC void -write_unaligned_u64(char *buf, uint64_t x) +write_unaligned_u64(char buf[static sizeof(uint64_t)], uint64_t x) { memcpy(buf, &x, sizeof(uint64_t)); } STATIC int64_t -readtableinfo(uint64_t buf_size, const char *buf, tableinfo_t *info) +readtableinfo( + size_t buf_size, + const char buf[buf_size], + tableinfo_t info[static 1] +) { size_t i; @@ -37,11 +43,6 @@ readtableinfo(uint64_t buf_size, const char *buf, tableinfo_t *info) return NISSY_ERROR_BUFFER_SIZE; } - if (info == NULL) { - LOG("Error reading table info: info struct is NULL\n"); - return NISSY_ERROR_UNKNOWN; - } - for (i = 0; i < INFO_DISTRIBUTION_LEN; i++) info->distribution[i] = read_unaligned_u64(OFFSET(buf, INFO_OFFSET_DISTRIBUTION + i * sizeof(uint64_t))); @@ -67,10 +68,10 @@ readtableinfo(uint64_t buf_size, const char *buf, tableinfo_t *info) STATIC int64_t readtableinfo_n( - uint64_t buf_size, - const char *buf, + size_t buf_size, + const char buf[buf_size], uint8_t n, - tableinfo_t *info + tableinfo_t info[static 1] ) { int64_t ret; @@ -83,22 +84,16 @@ readtableinfo_n( } STATIC int64_t -writetableinfo(const tableinfo_t *info, uint64_t data_size, char *buf) +writetableinfo( + const tableinfo_t info[static 1], + size_t data_size, + char buf[data_size] +) { size_t i; bool end; char *c; - if (buf == NULL) { - LOG("Error writing table: buffer is NULL\n"); - return NISSY_ERROR_NULL_POINTER; - } - - if (info == NULL) { - LOG("Error writing table info: provided info is NULL\n"); - return NISSY_ERROR_UNKNOWN; - } - if (data_size < info->fullsize) { LOG("Error writing table: buffer size is too small " "(given %" PRId64 " but table requires %" PRId64 ")\n", diff --git a/test/111_h48map/h48map_tests.c b/test/111_h48map/h48map_tests.c @@ -2,11 +2,11 @@ #define MAXPOS 1000 -void h48map_create(h48map_t *, uint64_t, uint64_t); -void h48map_destroy(h48map_t *); -void h48map_insertmin(h48map_t *, uint64_t, uint64_t); -uint64_t h48map_value(h48map_t *, uint64_t); -kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); +void h48map_create(h48map_t [static 1], uint64_t, uint64_t); +void h48map_destroy(h48map_t [static 1]); +void h48map_insertmin(h48map_t [static 1], uint64_t, uint64_t); +uint64_t h48map_value(h48map_t [static 1], uint64_t); +kvpair_t h48map_nextkvpair(h48map_t [static 1], uint64_t [static 1]); char str[STRLENMAX]; diff --git a/test/112_gendata_h48short/gendata_h48short_tests.c b/test/112_gendata_h48short/gendata_h48short_tests.c @@ -2,11 +2,11 @@ #define MAXPOS 200 -void h48map_create(h48map_t *, uint64_t, uint64_t); -void h48map_destroy(h48map_t *); -kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); +void h48map_create(h48map_t [static 1], uint64_t, uint64_t); +void h48map_destroy(h48map_t [static 1]); +kvpair_t h48map_nextkvpair(h48map_t [static 1], uint64_t [static 1]); size_t gendata_cocsep(void *, uint64_t *, cube_t *); -uint64_t gendata_h48short(gendata_h48short_arg_t *); +uint64_t gendata_h48short(gendata_h48short_arg_t [static 1]); char str[STRLENMAX]; diff --git a/test/test.h b/test/test.h @@ -12,7 +12,7 @@ #include "../src/arch/arch.h" #include "../src/solvers/solutions_types_macros.h" #include "../src/solvers/tables_types_macros.h" -#include "../src/solvers/h48/coordinate_macros.h" +#include "../src/solvers/h48/coordinate_types_macros.h" #include "../src/solvers/h48/map_types_macros.h" #include "../src/solvers/h48/gendata_types_macros.h" #include "../src/solvers/coord/types_macros.h" diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h @@ -167,7 +167,7 @@ check_table(uint64_t *exp, tableinfo_t *info) } static bool -check_cocsep(uint64_t data_size, const void *data) +check_cocsep(size_t data_size, const void *data) { tableinfo_t info; @@ -189,7 +189,7 @@ unknown_h48(uint8_t h, uint8_t k) } STATIC bool -check_distribution(const char *solver, uint64_t data_size, const void *data) +check_distribution(const char *solver, size_t data_size, const void *data) { const char *str; tableinfo_t info = {0};