From 283effb16646112ee9c6bba57e021e80f322b29f Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 4 Oct 2024 14:29:00 +0200 Subject: Avoid repeating typedefs in tests --- src/solvers/h48/coordinate.h | 8 +-- src/solvers/h48/coordinate_macros.h | 6 +++ src/solvers/h48/gendata_cocsep.h | 22 -------- src/solvers/h48/gendata_h48.h | 73 -------------------------- src/solvers/h48/gendata_types_macros.h | 94 ++++++++++++++++++++++++++++++++++ src/solvers/h48/h48.h | 1 + src/solvers/h48/map.h | 18 +------ src/solvers/h48/map_types_macros.h | 16 ++++++ 8 files changed, 121 insertions(+), 117 deletions(-) create mode 100644 src/solvers/h48/coordinate_macros.h create mode 100644 src/solvers/h48/gendata_types_macros.h create mode 100644 src/solvers/h48/map_types_macros.h (limited to 'src/solvers/h48') diff --git a/src/solvers/h48/coordinate.h b/src/solvers/h48/coordinate.h index 25e13f9..6caac2a 100644 --- 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 new file mode 100644 index 0000000..5b67177 --- /dev/null +++ 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 index 5f0fae9..3daaf2a 100644 --- 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 index 6db3998..5da9dc3 100644 --- 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 new file mode 100644 index 0000000..4b503ab --- /dev/null +++ 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 index 176ce22..3cf02b7 100644 --- 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 index e74a5dd..e6903ce 100644 --- 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 new file mode 100644 index 0000000..b77c68a --- /dev/null +++ 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; -- cgit v1.3