From 56048d13b73ec6e6a9c59d62e82f41e69a3994bd Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 25 Mar 2025 18:35:47 +0100 Subject: More safety with pointers using VLA function parameters --- src/solvers/coord/gendata.h | 32 ++++++++++++---- src/solvers/coord/utils.h | 3 +- src/solvers/h48/coordinate.h | 21 +++++++---- src/solvers/h48/coordinate_macros.h | 7 ---- src/solvers/h48/coordinate_types_macros.h | 7 ++++ src/solvers/h48/gendata_cocsep.h | 39 ++++++++++++++------ src/solvers/h48/gendata_eoesep.h | 17 +++++++-- src/solvers/h48/gendata_h48.h | 61 ++++++++++--------------------- src/solvers/h48/gendata_types_macros.h | 2 +- src/solvers/h48/h48.h | 4 +- src/solvers/h48/map.h | 31 +++++++--------- src/solvers/h48/solve.h | 18 ++++----- src/solvers/tables.h | 49 +++++++++++-------------- 13 files changed, 157 insertions(+), 134 deletions(-) delete mode 100644 src/solvers/h48/coordinate_macros.h create mode 100644 src/solvers/h48/coordinate_types_macros.h (limited to 'src/solvers') diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index 5819608..ca058b0 100644 --- 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 index ab4aded..e9d0595 100644 --- 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 index 6caac2a..eb08fd8 100644 --- 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_macros.h deleted file mode 100644 index 04462d6..0000000 --- a/src/solvers/h48/coordinate_macros.h +++ /dev/null @@ -1,7 +0,0 @@ -#define H48_ESIZE(h) ((COMB_12_4 * COMB_8_4) << (int64_t)(h)) - -#define COCLASS_MASK (UINT32_C(0xFFFF) << UINT32_C(16)) -#define COCLASS(x) (((x) & COCLASS_MASK) >> UINT32_C(16)) -#define ECLASS(x) COCLASS(x) -#define TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) -#define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) diff --git a/src/solvers/h48/coordinate_types_macros.h b/src/solvers/h48/coordinate_types_macros.h new file mode 100644 index 0000000..04462d6 --- /dev/null +++ b/src/solvers/h48/coordinate_types_macros.h @@ -0,0 +1,7 @@ +#define H48_ESIZE(h) ((COMB_12_4 * COMB_8_4) << (int64_t)(h)) + +#define COCLASS_MASK (UINT32_C(0xFFFF) << UINT32_C(16)) +#define COCLASS(x) (((x) & COCLASS_MASK) >> UINT32_C(16)) +#define ECLASS(x) COCLASS(x) +#define TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) +#define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index bf67962..cda1608 100644 --- 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 index d887209..4bf5a84 100644 --- 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 index 2d9a9f7..959264d 100644 --- 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 index ec6576a..11940d8 100644 --- 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 index d5a67ef..0cfa773 100644 --- 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 index e6903ce..7718794 100644 --- 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 index dbd15bb..dcec5a4 100644 --- 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 index 65e7606..db888b5 100644 --- 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", -- cgit v1.3