commit 283effb16646112ee9c6bba57e021e80f322b29f parent fc150adaf3bff133da0e59d842f13b7b21297fc0 Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Fri, 4 Oct 2024 14:29:00 +0200 Avoid repeating typedefs in tests Diffstat:
20 files changed, 170 insertions(+), 261 deletions(-)
diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h @@ -1,9 +1,5 @@ -#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 TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) -#define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) +/* 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_edges(cube_t, int64_t, uint8_t, uint8_t); diff --git a/src/solvers/h48/coordinate_macros.h b/src/solvers/h48/coordinate_macros.h @@ -0,0 +1,6 @@ +#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 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 @@ -1,25 +1,3 @@ -#define COCSEP_CLASSES ((size_t)3393) -#define COCSEP_TABLESIZE ((size_t)POW_3_7 << (size_t)7) -#define COCSEP_VISITEDSIZE DIV_ROUND_UP(COCSEP_TABLESIZE, (size_t)8) -#define COCSEP_FULLSIZE (INFOSIZE + (size_t)4 * COCSEP_TABLESIZE) - -#define VISITED_IND(i) ((uint32_t)(i) / UINT32_C(8)) -#define VISITED_MASK(i) (UINT32_C(1) << ((uint32_t)(i) % UINT32_C(8))) - -#define CBOUND_MASK UINT32_C(0xFF) -#define CBOUND(x) ((x) & CBOUND_MASK) - -typedef struct { - cube_t cube; - uint8_t depth; - uint8_t maxdepth; - uint16_t *n; - uint32_t *buf32; - uint8_t *visited; - uint64_t *selfsim; - cube_t *rep; -} cocsep_dfs_arg_t; - STATIC_INLINE bool get_visited(const uint8_t *, int64_t); STATIC_INLINE void set_visited(uint8_t *, int64_t); diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -1,16 +1,3 @@ -#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * COMB_12_4 * COMB_8_4)) -#define H48_COORDMAX(h) (H48_COORDMAX_NOEO << (int64_t)(h)) -#define H48_DIV(k) ((size_t)8 / (size_t)(k)) -#define H48_TABLESIZE(h, k) DIV_ROUND_UP((size_t)H48_COORDMAX((h)), H48_DIV(k)) - -#define H48_COEFF(k) (INT64_C(8) / (int64_t)(k)) -#define H48_INDEX(i, k) ((i) / H48_COEFF(k)) -#define H48_SHIFT(i, k) ((uint8_t)(k) * (uint8_t)((i) % H48_COEFF(k))) -#define H48_MASK(i, k) ((UINT8_BIT(k) - UINT8_C(1)) << H48_SHIFT(i, k)) - -#define MAXLEN 20 -#define CHUNKS COCSEP_CLASSES - /* TODO: This loop over similar h48 coordinates can be improved by only transforming edges, but we need to compose transformations (i.e. conjugate @@ -30,66 +17,6 @@ _t by _ttrep). ARG_ACTION \ } -typedef struct { - uint8_t h; - uint8_t k; - uint8_t base; - uint8_t maxdepth; - tableinfo_t info; - void *buf; - void *h48buf; - uint32_t *cocsepdata; - uint64_t selfsim[COCSEP_CLASSES]; - cube_t crep[COCSEP_CLASSES]; -} gendata_h48_arg_t; - -typedef struct { - uint8_t maxdepth; - const uint32_t *cocsepdata; - const cube_t *crep; - const uint64_t *selfsim; - h48map_t *map; -} gendata_h48short_arg_t; - -typedef struct { - uint8_t depth; - uint32_t *cocsepdata; - _Atomic uint8_t *table; - uint64_t *selfsim; - cube_t *crep; - uint64_t start; - uint64_t end; - pthread_mutex_t *table_mutex[CHUNKS]; -} h48h0k4_bfs_arg_t; - -typedef struct { - cube_t cube; - uint8_t h; - uint8_t k; - uint8_t base; - uint8_t shortdepth; - uint32_t *cocsepdata; - _Atomic uint8_t *table; - uint64_t *selfsim; - cube_t *crep; - h48map_t *shortcubes; - pthread_mutex_t *shortcubes_mutex; - pthread_mutex_t *table_mutex[CHUNKS]; - uint64_t *next; - uint64_t *count; -} h48k2_dfs_arg_t; - -typedef struct { - cube_t cube; - int8_t depth; - uint8_t h; - uint8_t k; - uint32_t *cocsepdata; - uint64_t *selfsim; - _Atomic uint8_t *table; - pthread_mutex_t **table_mutex; -} gendata_h48_mark_t; - STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *); STATIC size_t gendata_h48(gendata_h48_arg_t *); STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); diff --git a/src/solvers/h48/gendata_types_macros.h b/src/solvers/h48/gendata_types_macros.h @@ -0,0 +1,94 @@ +#define COCSEP_CLASSES ((size_t)3393) +#define COCSEP_TABLESIZE ((size_t)POW_3_7 << (size_t)7) +#define COCSEP_VISITEDSIZE DIV_ROUND_UP(COCSEP_TABLESIZE, (size_t)8) +#define COCSEP_FULLSIZE (INFOSIZE + (size_t)4 * COCSEP_TABLESIZE) + +#define VISITED_IND(i) ((uint32_t)(i) / UINT32_C(8)) +#define VISITED_MASK(i) (UINT32_C(1) << ((uint32_t)(i) % UINT32_C(8))) + +#define CBOUND_MASK UINT32_C(0xFF) +#define CBOUND(x) ((x) & CBOUND_MASK) + +#define H48_COORDMAX_NOEO ((int64_t)(COCSEP_CLASSES * COMB_12_4 * COMB_8_4)) +#define H48_COORDMAX(h) (H48_COORDMAX_NOEO << (int64_t)(h)) +#define H48_DIV(k) ((size_t)8 / (size_t)(k)) +#define H48_TABLESIZE(h, k) DIV_ROUND_UP((size_t)H48_COORDMAX((h)), H48_DIV(k)) + +#define H48_COEFF(k) (INT64_C(8) / (int64_t)(k)) +#define H48_INDEX(i, k) ((i) / H48_COEFF(k)) +#define H48_SHIFT(i, k) ((uint8_t)(k) * (uint8_t)((i) % H48_COEFF(k))) +#define H48_MASK(i, k) ((UINT8_BIT(k) - UINT8_C(1)) << H48_SHIFT(i, k)) + +#define MAXLEN 20 +#define CHUNKS COCSEP_CLASSES + +typedef struct { + cube_t cube; + uint8_t depth; + uint8_t maxdepth; + uint16_t *n; + uint32_t *buf32; + uint8_t *visited; + uint64_t *selfsim; + cube_t *rep; +} cocsep_dfs_arg_t; + +typedef struct { + uint8_t h; + uint8_t k; + uint8_t base; + uint8_t maxdepth; + tableinfo_t info; + void *buf; + void *h48buf; + uint32_t *cocsepdata; + uint64_t selfsim[COCSEP_CLASSES]; + cube_t crep[COCSEP_CLASSES]; +} gendata_h48_arg_t; + +typedef struct { + uint8_t maxdepth; + const uint32_t *cocsepdata; + const cube_t *crep; + const uint64_t *selfsim; + h48map_t *map; +} gendata_h48short_arg_t; + +typedef struct { + uint8_t depth; + uint32_t *cocsepdata; + _Atomic uint8_t *table; + uint64_t *selfsim; + cube_t *crep; + uint64_t start; + uint64_t end; + pthread_mutex_t *table_mutex[CHUNKS]; +} h48h0k4_bfs_arg_t; + +typedef struct { + cube_t cube; + uint8_t h; + uint8_t k; + uint8_t base; + uint8_t shortdepth; + uint32_t *cocsepdata; + _Atomic uint8_t *table; + uint64_t *selfsim; + cube_t *crep; + h48map_t *shortcubes; + pthread_mutex_t *shortcubes_mutex; + pthread_mutex_t *table_mutex[CHUNKS]; + uint64_t *next; + uint64_t *count; +} h48k2_dfs_arg_t; + +typedef struct { + cube_t cube; + int8_t depth; + uint8_t h; + uint8_t k; + uint32_t *cocsepdata; + uint64_t *selfsim; + _Atomic uint8_t *table; + pthread_mutex_t **table_mutex; +} gendata_h48_mark_t; diff --git a/src/solvers/h48/h48.h b/src/solvers/h48/h48.h @@ -1,5 +1,6 @@ #include "coordinate.h" #include "map.h" +#include "gendata_types_macros.h" #include "gendata_cocsep.h" #include "gendata_h48.h" #include "stats.h" diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h @@ -1,19 +1,5 @@ -#define MAP_UNSET UINT64_C(0xFFFFFFFFFFFFFFFF) -#define MAP_KEYMASK UINT64_C(0xFFFFFFFFFF) -#define MAP_KEYSHIFT UINT64_C(40) -#define MAP_UNSET_VAL (MAP_UNSET >> MAP_KEYSHIFT) - -typedef struct { - uint64_t n; - uint64_t capacity; - uint64_t randomizer; - uint64_t *table; -} h48map_t; - -typedef struct { - uint64_t key; - uint64_t val; -} kvpair_t; +/* 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 *); diff --git a/src/solvers/h48/map_types_macros.h b/src/solvers/h48/map_types_macros.h @@ -0,0 +1,16 @@ +#define MAP_UNSET UINT64_C(0xFFFFFFFFFFFFFFFF) +#define MAP_KEYMASK UINT64_C(0xFFFFFFFFFF) +#define MAP_KEYSHIFT UINT64_C(40) +#define MAP_UNSET_VAL (MAP_UNSET >> MAP_KEYSHIFT) + +typedef struct { + uint64_t n; + uint64_t capacity; + uint64_t randomizer; + uint64_t *table; +} h48map_t; + +typedef struct { + uint64_t key; + uint64_t val; +} kvpair_t; diff --git a/src/solvers/tables.h b/src/solvers/tables.h @@ -1,41 +1,5 @@ -#define OFFSET(B, K) (((uint8_t *)B) + K) - -#define INFOSIZE 512 -#define INFO_SOLVER_STRLEN 100 -#define INFO_DISTRIBUTION_LEN 21 - -#define TABLETYPE_PRUNING 0 -#define TABLETYPE_SPECIAL 1 - -#define INFO_OFFSET_DISTRIBUTION 0 -#define INFO_OFFSET_TYPE (INFO_DISTRIBUTION_LEN * sizeof(uint64_t)) -#define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) -#define INFO_OFFSET_FULLSIZE (INFO_OFFSET_INFOSIZE + sizeof(uint64_t)) -#define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) -#define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) -#define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) -#define INFO_OFFSET_NEXT (INFO_OFFSET_CLASSES + sizeof(uint64_t)) -#define INFO_OFFSET_SOLVER (INFO_OFFSET_NEXT + sizeof(uint64_t)) -#define INFO_OFFSET_H48H (INFO_OFFSET_SOLVER + INFO_SOLVER_STRLEN) -#define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t)) -#define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) -#define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) - -typedef struct { - uint64_t distribution[INFO_DISTRIBUTION_LEN]; - uint64_t type; - uint64_t infosize; - uint64_t fullsize; - uint64_t hash; - uint64_t entries; - uint64_t classes; /* Used only by cocsepdata, for now */ - uint64_t next; - char solver[INFO_SOLVER_STRLEN]; - uint8_t h48h; /* Specific to H48 tables */ - uint8_t bits; - uint8_t base; - uint8_t maxvalue; -} tableinfo_t; +/* Type definitions and macros are in a separate file for easier testing */ +#include "tables_types_macros.h" STATIC bool readtableinfo(const void *, tableinfo_t *); STATIC bool readtableinfo_n(const void *, uint8_t, tableinfo_t *); diff --git a/src/solvers/tables_types_macros.h b/src/solvers/tables_types_macros.h @@ -0,0 +1,38 @@ +#define OFFSET(B, K) (((uint8_t *)B) + K) + +#define INFOSIZE 512 +#define INFO_SOLVER_STRLEN 100 +#define INFO_DISTRIBUTION_LEN 21 + +#define TABLETYPE_PRUNING 0 +#define TABLETYPE_SPECIAL 1 + +#define INFO_OFFSET_DISTRIBUTION 0 +#define INFO_OFFSET_TYPE (INFO_DISTRIBUTION_LEN * sizeof(uint64_t)) +#define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) +#define INFO_OFFSET_FULLSIZE (INFO_OFFSET_INFOSIZE + sizeof(uint64_t)) +#define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) +#define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) +#define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) +#define INFO_OFFSET_NEXT (INFO_OFFSET_CLASSES + sizeof(uint64_t)) +#define INFO_OFFSET_SOLVER (INFO_OFFSET_NEXT + sizeof(uint64_t)) +#define INFO_OFFSET_H48H (INFO_OFFSET_SOLVER + INFO_SOLVER_STRLEN) +#define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t)) +#define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) +#define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) + +typedef struct { + uint64_t distribution[INFO_DISTRIBUTION_LEN]; + uint64_t type; + uint64_t infosize; + uint64_t fullsize; + uint64_t hash; + uint64_t entries; + uint64_t classes; /* Used only by cocsepdata, for now */ + uint64_t next; + char solver[INFO_SOLVER_STRLEN]; + uint8_t h48h; /* Specific to H48 tables */ + uint8_t bits; + uint8_t base; + uint8_t maxvalue; +} tableinfo_t; diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c @@ -1,25 +1,5 @@ #include "../test.h" -#define INFOSIZE 512 -#define INFO_SOLVER_STRLEN 100 -#define INFO_DISTRIBUTION_LEN 21 - -typedef struct { - uint64_t distribution[INFO_DISTRIBUTION_LEN]; - uint64_t type; - uint64_t infosize; - uint64_t fullsize; - uint64_t hash; - uint64_t entries; - uint64_t classes; - uint64_t next; - char solver[INFO_SOLVER_STRLEN]; - uint8_t h48h; - uint8_t bits; - uint8_t base; - uint8_t maxvalue; -} tableinfo_t; - bool readtableinfo(const void *, tableinfo_t *); bool writetableinfo(const tableinfo_t *, void *); diff --git a/test/100_gendata_cocsep/gendata_cocsep_tests.c b/test/100_gendata_cocsep/gendata_cocsep_tests.c @@ -1,26 +1,5 @@ #include "../test.h" -#define INFOSIZE 512 -#define INFO_SOLVER_STRLEN 100 -#define INFO_DISTRIBUTION_LEN 21 -#define COCSEP_CLASSES 3393 - -typedef struct { - uint64_t distribution[INFO_DISTRIBUTION_LEN]; - uint64_t type; - uint64_t infosize; - uint64_t fullsize; - uint64_t hash; - uint64_t entries; - uint64_t classes; /* Used only by cocsepdata, for now */ - uint64_t next; - char solver[INFO_SOLVER_STRLEN]; - uint8_t h48h; - uint8_t bits; - uint8_t base; - uint8_t maxvalue; -} tableinfo_t; - size_t gendata_cocsep(void *, uint64_t *, cube_t *); bool readtableinfo(const void *, tableinfo_t *); diff --git a/test/101_cocsep_transform_invariant/cocsep_transform_invariant.c b/test/101_cocsep_transform_invariant/cocsep_transform_invariant.c @@ -1,11 +1,5 @@ #include "../test.h" -#define COCLASS_MASK (UINT32_C(0xFFFF) << UINT32_C(16)) -#define COCLASS(x) (((x) & COCLASS_MASK) >> UINT32_C(16)) - -#define INFOSIZE 512 -#define COCSEP_CLASSES 3393 - size_t gendata_cocsep(void *, uint64_t *, cube_t *); cube_t transform(cube_t, uint8_t); int64_t coord_cocsep(cube_t); diff --git a/test/102_cocsep_selfsim/cocsep_selfsim_tests.c b/test/102_cocsep_selfsim/cocsep_selfsim_tests.c @@ -7,9 +7,6 @@ */ #include "../test.h" -#define COCSEP_CLASSES 3393 -#define INFOSIZE 512 - size_t gendata_cocsep(void *, uint64_t *, cube_t *); int64_t coord_cocsep(cube_t); diff --git a/test/103_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c b/test/103_cocsep_selfsim_distribution/cocsep_selfsim_distribution_tests.c @@ -1,7 +1,5 @@ #include "../test.h" -#define COCSEP_CLASSES 3393 - size_t gendata_cocsep(void *, uint64_t *, cube_t *); int64_t coord_cocsep(cube_t); @@ -19,8 +17,7 @@ int bcount(uint64_t x) { void run(void) { char buf[2000000]; int size[65], tot, j; - int64_t i; - uint64_t selfsim[COCSEP_CLASSES], sim; + uint64_t i, selfsim[COCSEP_CLASSES], sim; cube_t rep[COCSEP_CLASSES]; memset(size, 0, 65 * sizeof(int)); diff --git a/test/104_cocsep_ttrep/cocsep_ttrep_tests.c b/test/104_cocsep_ttrep/cocsep_ttrep_tests.c @@ -1,11 +1,5 @@ #include "../test.h" -#define TTREP_MASK (UINT32_C(0xFF) << UINT32_C(8)) -#define TTREP(x) (((x) & TTREP_MASK) >> UINT32_C(8)) - -#define COCSEP_CLASSES 3393 -#define INFOSIZE 512 - uint8_t inverse_trans(uint8_t); cube_t transform_corners(cube_t, uint8_t); int64_t coord_cocsep(cube_t); @@ -15,8 +9,8 @@ void run(void) { uint8_t t; char buf[2000000]; uint32_t *cocsepdata, tt; - uint64_t selfsim[COCSEP_CLASSES]; - int64_t i, j, k, l; + uint64_t i, selfsim[COCSEP_CLASSES]; + int64_t j, k, l; cube_t rep[COCSEP_CLASSES], c, d; gendata_cocsep(buf, selfsim, rep); diff --git a/test/110_coord_invcoord_h48/coord_invcoord_h48_tests.c b/test/110_coord_invcoord_h48/coord_invcoord_h48_tests.c @@ -1,8 +1,5 @@ #include "../test.h" -#define COCSEP_CLASSES 3393 -#define INFOSIZE 512 - size_t gendata_cocsep(void *, uint64_t *, cube_t *); int64_t coord_h48(cube_t, const uint32_t *, uint8_t); cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); diff --git a/test/111_h48map/h48map_tests.c b/test/111_h48map/h48map_tests.c @@ -1,20 +1,7 @@ #include "../test.h" -#define MAP_KEYSHIFT UINT64_C(40) #define MAXPOS 1000 -typedef struct { - uint64_t n; - uint64_t capacity; - uint64_t randomizer; - uint64_t *table; -} h48map_t; - -typedef struct { - uint64_t key; - uint64_t val; -} kvpair_t; - void h48map_create(h48map_t *, uint64_t, uint64_t); void h48map_destroy(h48map_t *); void h48map_insertmin(h48map_t *, uint64_t, uint64_t); diff --git a/test/112_gendata_h48short/gendata_h48short_tests.c b/test/112_gendata_h48short/gendata_h48short_tests.c @@ -1,33 +1,6 @@ #include "../test.h" -#define COCSEP_CLASSES 3393 -#define INFOSIZE 512 -#define MAXPOS 200 - -typedef struct { - uint64_t n; - uint64_t capacity; - uint64_t randomizer; - uint64_t *table; - uint32_t *info; - uint32_t *cocsepdata; - uint32_t *h48data; - uint64_t selfsim[COCSEP_CLASSES]; - cube_t crep[COCSEP_CLASSES]; -} h48map_t; - -typedef struct { - uint64_t key; - uint64_t val; -} kvpair_t; - -typedef struct { - uint8_t maxdepth; - const uint32_t *cocsepdata; - const cube_t *crep; - const uint64_t *selfsim; - h48map_t *map; -} gendata_h48short_arg_t; +#define MAXPOS 200 void h48map_create(h48map_t *, uint64_t, uint64_t); void h48map_destroy(h48map_t *); diff --git a/test/test.h b/test/test.h @@ -1,6 +1,7 @@ #define TEST_H #include <inttypes.h> +#include <pthread.h> #include <stdarg.h> #include <stdbool.h> #include <stdio.h> @@ -8,6 +9,10 @@ #include <string.h> #include "../src/arch/arch.h" +#include "../src/solvers/tables_types_macros.h" +#include "../src/solvers/h48/coordinate_macros.h" +#include "../src/solvers/h48/map_types_macros.h" +#include "../src/solvers/h48/gendata_types_macros.h" #define STRLENMAX 10000