From 510a7471348788fccba6b7c4b9f7b7cc9aee6ba9 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 21 Apr 2025 14:33:01 +0200 Subject: Always use unsigned char * for data buffers Before this commit I was inconsistently using one of void *, char * and uint8_t *. --- src/solvers/h48/gendata_cocsep.h | 4 +- src/solvers/h48/gendata_eoesep.h | 21 ++++---- src/solvers/h48/gendata_h48.h | 90 ++++++++++++++++++---------------- src/solvers/h48/gendata_types_macros.h | 16 +++--- src/solvers/h48/solve.h | 18 +++---- 5 files changed, 76 insertions(+), 73 deletions(-) (limited to 'src/solvers/h48') diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index f07b71a..2eac383 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h @@ -1,4 +1,4 @@ -STATIC size_t gendata_cocsep(char *, uint64_t *, cube_t *); +STATIC size_t gendata_cocsep(unsigned char *, uint64_t *, cube_t *); 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]); @@ -13,7 +13,7 @@ STATIC_INLINE int8_t get_h48_cdata( STATIC size_t gendata_cocsep( - char *buf, + unsigned char *buf, uint64_t *selfsim, cube_t *rep ) diff --git a/src/solvers/h48/gendata_eoesep.h b/src/solvers/h48/gendata_eoesep.h index 4bf5a84..f1e3d4c 100644 --- a/src/solvers/h48/gendata_eoesep.h +++ b/src/solvers/h48/gendata_eoesep.h @@ -1,7 +1,7 @@ STATIC int64_t coord_eoesep_sym(cube_t, const uint32_t [static ESEP_MAX]); STATIC size_t gendata_esep_classes( uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); -STATIC size_t gendata_eoesep(char *, uint8_t); +STATIC size_t gendata_eoesep(unsigned char *, uint8_t); STATIC uint32_t gendata_eoesep_bfs(uint8_t, uint8_t [static EOESEP_BUF], uint32_t [static ESEP_MAX], uint16_t [static ESEP_CLASSES]); STATIC uint32_t gendata_eoesep_fromnew(uint8_t, uint8_t [static EOESEP_BUF], @@ -14,7 +14,7 @@ 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 [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t); -STATIC uint8_t get_eoesep_pval_cube(const void *, cube_t); +STATIC uint8_t get_eoesep_pval_cube(const unsigned char *, cube_t); STATIC void set_eoesep_pval( uint8_t [static DIV_ROUND_UP(EOESEP_TABLESIZE, 2)], int64_t, uint8_t); @@ -67,9 +67,10 @@ gendata_esep_classes( } STATIC size_t -gendata_eoesep(char *buf, uint8_t maxdepth) +gendata_eoesep(unsigned char *buf, uint8_t maxdepth) { - uint8_t *buf8, d; + uint8_t d; + unsigned char *buf8; uint16_t rep[ESEP_CLASSES]; uint32_t *esep_classes, done, level; int64_t coord; @@ -81,7 +82,7 @@ gendata_eoesep(char *buf, uint8_t maxdepth) LOG("Computing eoesep data\n"); memset(buf, 0xFF, EOESEP_FULLSIZE); esep_classes = (uint32_t *)(buf + INFOSIZE); - buf8 = (uint8_t *)(buf + INFOSIZE + 4*ESEP_MAX); + buf8 = buf + INFOSIZE + 4*ESEP_MAX; gendata_esep_classes(esep_classes, rep); info = (tableinfo_t) { @@ -258,17 +259,13 @@ get_eoesep_pval( } STATIC uint8_t -get_eoesep_pval_cube(const void *data, cube_t c) +get_eoesep_pval_cube(const unsigned char *data, cube_t c) { int64_t coord; - const uint8_t *table; - const uint32_t *esep_classes; - esep_classes = (const uint32_t *)data; - table = (const uint8_t *)data + 4*ESEP_MAX; - coord = coord_eoesep_sym(c, esep_classes); + coord = coord_eoesep_sym(c, (const uint32_t *)data); - return get_eoesep_pval(table, coord); + return get_eoesep_pval(data + 4*ESEP_MAX, coord); } STATIC void diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 18157dc..a878978 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -13,20 +13,20 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop( 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_runthread(void *); -STATIC void getdistribution_h48(const uint8_t *, +STATIC void getdistribution_h48(const unsigned char *, uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); -STATIC const uint32_t *get_cocsepdata_constptr(const void *); -STATIC const uint8_t *get_h48data_constptr(const void *); +STATIC const uint32_t *get_cocsepdata_constptr(const unsigned char *); +STATIC const unsigned char *get_h48data_constptr(const unsigned char *); -STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); -STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); +STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, int64_t, uint8_t); +STATIC_INLINE void set_h48_pval(unsigned char *, int64_t, uint8_t, uint8_t); STATIC_INLINE uint8_t get_h48_pval_atomic( - _Atomic const uint8_t *, int64_t, uint8_t); + _Atomic const unsigned char *, int64_t, uint8_t); STATIC_INLINE void set_h48_pval_atomic( - _Atomic uint8_t *, int64_t, uint8_t, uint8_t); + _Atomic unsigned char *, int64_t, uint8_t, uint8_t); -size_t gendata_h48_derive(uint8_t, const void *, void *); +size_t gendata_h48_derive(uint8_t, const unsigned char *, unsigned char *); STATIC uint64_t gendata_h48short(gendata_h48short_arg_t arg[static 1]) @@ -67,7 +67,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) { uint64_t size, cocsepsize, h48size, fallbacksize, fallback2size, of; long long r; - void *cocsepdata_offset; + unsigned char *cocsepdata_offset; tableinfo_t cocsepinfo, h48info, fallbackinfo; gendata_h48_arg_t arg_h0k4; @@ -95,9 +95,9 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) gendata_cocsep(arg->buf, arg->selfsim, arg->crep); - cocsepdata_offset = (char *)arg->buf + INFOSIZE; + cocsepdata_offset = arg->buf + INFOSIZE; arg->cocsepdata = (uint32_t *)cocsepdata_offset; - arg->h48buf = (char *)arg->buf + cocsepsize; + arg->h48buf = (_Atomic unsigned char*)arg->buf + cocsepsize; arg->base = 99; /* TODO: set this somewhere else */ @@ -136,8 +136,8 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) arg_h0k4.base = 0; arg_h0k4.maxdepth = 20; arg_h0k4.buf_size = arg->buf_size - h48size; - arg_h0k4.buf = (char *)arg->buf + cocsepsize + h48size; - arg_h0k4.h48buf = (char *)arg->h48buf + h48size; + arg_h0k4.buf = arg->buf + cocsepsize + h48size; + arg_h0k4.h48buf = arg->h48buf + h48size; gendata_h48h0k4(&arg_h0k4); @@ -145,7 +145,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) /* Add eoesep fallback table */ - gendata_eoesep((char *)arg->buf + (size - fallback2size), 20); + gendata_eoesep(arg->buf + (size - fallback2size), 20); /* Update tableinfo with correct next values */ @@ -157,7 +157,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) } h48info.next = h48size; r = writetableinfo(&h48info, - arg->buf_size - cocsepsize, (char *)arg->buf + cocsepsize); + arg->buf_size - cocsepsize, arg->buf + cocsepsize); if (r != NISSY_OK) { LOG("[H48 gendata] Error: could not write info " "for h48 table\n"); @@ -174,8 +174,8 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) of = cocsepsize + h48size; fallbackinfo.next = fallbacksize; - r = writetableinfo(&fallbackinfo, - arg->buf_size - of, (char *)arg->buf + of); + r = writetableinfo( + &fallbackinfo, arg->buf_size - of, arg->buf + of); if (r != NISSY_OK) { LOG("[H48 gendata] Error: could not write info for " "h48 fallback table\n"); @@ -189,7 +189,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) STATIC void gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) { - _Atomic uint8_t *table; + _Atomic unsigned char *table; uint8_t val; int64_t i, sc, done, d, h48max; uint64_t t, tt, isize, cc, bufsize; @@ -212,7 +212,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) .next = 0, }; - table = (_Atomic uint8_t *)arg->h48buf + INFOSIZE; + table = arg->h48buf + INFOSIZE; memset(table, 0xFF, H48_TABLESIZE(0, 4)); h48max = (int64_t)H48_COORDMAX(0); @@ -261,7 +261,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) arg->info.maxvalue = d - 1; bufsize = arg->buf_size - COCSEP_FULLSIZE; - writetableinfo(&arg->info, bufsize, arg->h48buf); + writetableinfo(&arg->info, bufsize, (unsigned char *)arg->h48buf); } STATIC void * @@ -374,7 +374,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) }; uint8_t t; - uint8_t *table; + unsigned char *table; int64_t j; uint64_t i, ii, inext, count, bufsize; h48map_t shortcubes; @@ -383,7 +383,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) pthread_t thread[THREADS]; pthread_mutex_t shortcubes_mutex, table_mutex[CHUNKS]; - table = (uint8_t *)arg->h48buf + INFOSIZE; + table = (unsigned char *)arg->h48buf + INFOSIZE; memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); LOG("[H48 gendata] Computing depth <=%" PRIu8 "\n", shortdepth) @@ -439,7 +439,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) } bufsize = arg->buf_size - COCSEP_FULLSIZE; - writetableinfo(&arg->info, bufsize, arg->h48buf); + writetableinfo(&arg->info, bufsize, (unsigned char *)arg->h48buf); } STATIC void * @@ -653,7 +653,7 @@ STATIC void * getdistribution_h48_runthread(void *arg) { getdistribution_h48_data_t *data = (getdistribution_h48_data_t *)arg; - const uint8_t *table; + const unsigned char *table; uint8_t j, k, m; int64_t i; @@ -671,7 +671,7 @@ getdistribution_h48_runthread(void *arg) STATIC void getdistribution_h48( - const uint8_t *table, + const unsigned char *table, uint64_t distr[static INFO_DISTRIBUTION_LEN], uint8_t h, uint8_t k @@ -708,50 +708,55 @@ getdistribution_h48( } STATIC const uint32_t * -get_cocsepdata_constptr(const void *data) +get_cocsepdata_constptr(const unsigned char *data) { - return (uint32_t *)((char *)data + INFOSIZE); + return (uint32_t *)(data + INFOSIZE); } -STATIC const uint8_t * -get_h48data_constptr(const void *data) +STATIC const unsigned char * +get_h48data_constptr(const unsigned char *data) { - return (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE; + return data + COCSEP_FULLSIZE + INFOSIZE; } STATIC_INLINE uint8_t -get_h48_pval(const uint8_t *table, int64_t i, uint8_t k) +get_h48_pval(const unsigned char *table, int64_t i, uint8_t k) { return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); } STATIC_INLINE uint8_t -get_h48_pval_atomic(_Atomic const uint8_t *table, int64_t i, uint8_t k) +get_h48_pval_atomic(_Atomic const unsigned char *table, int64_t i, uint8_t k) { return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); } STATIC_INLINE void -set_h48_pval(uint8_t *table, int64_t i, uint8_t k, uint8_t val) +set_h48_pval(unsigned char *table, int64_t i, uint8_t k, uint8_t val) { table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) | (val << H48_SHIFT(i, k)); } STATIC_INLINE void -set_h48_pval_atomic(_Atomic uint8_t *table, int64_t i, uint8_t k, uint8_t val) +set_h48_pval_atomic( + _Atomic unsigned char *table, + int64_t i, + uint8_t k, + uint8_t val +) { table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) | (val << H48_SHIFT(i, k)); } size_t -gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) +gendata_h48_derive(uint8_t h, const unsigned char *fulltable, unsigned char *buf) { size_t cocsepsize, h48size; uint8_t val_full, val_derive; - const uint8_t *h48full; - uint8_t *h48derive; + const unsigned char *h48full; + unsigned char *h48derive; int64_t i, j, h48max; uint64_t bufsize; gendata_h48_arg_t arg; @@ -770,14 +775,14 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) arg.k = fulltableinfo.bits; arg.maxdepth = 20; arg.buf = buf; - arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); + arg.cocsepdata = (uint32_t *)(buf + INFOSIZE); arg.base = fulltableinfo.base; arg.info = makeinfo_h48k2(&arg); /* Technically this step is redundant, except that we need selfsim and crep */ cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); - arg.h48buf = (_Atomic uint8_t *)buf + cocsepsize; + arg.h48buf = (_Atomic unsigned char *)buf + cocsepsize; h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; if (buf == NULL) @@ -798,8 +803,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) goto gendata_h48_derive_error; } - h48full = (const uint8_t *)fulltable + cocsepsize + INFOSIZE; - h48derive = (uint8_t *)arg.h48buf + INFOSIZE; + h48full = fulltable + cocsepsize + INFOSIZE; + h48derive = (unsigned char *)arg.h48buf + INFOSIZE; memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); memset(arg.info.distribution, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); @@ -819,7 +824,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; - if (writetableinfo(&arg.info, bufsize, arg.h48buf) != NISSY_OK) { + if (writetableinfo(&arg.info, bufsize, (unsigned char *)arg.h48buf) + != NISSY_OK) { LOG("H48 derive gendata] Error: could not write info " "for table\n"); goto gendata_h48_derive_error; diff --git a/src/solvers/h48/gendata_types_macros.h b/src/solvers/h48/gendata_types_macros.h index 3f0c666..c4b1b5a 100644 --- a/src/solvers/h48/gendata_types_macros.h +++ b/src/solvers/h48/gendata_types_macros.h @@ -55,7 +55,7 @@ typedef struct { uint8_t maxdepth; uint16_t *n; uint32_t *buf32; - uint8_t *visited; + unsigned char *visited; uint64_t *selfsim; cube_t *rep; } cocsep_dfs_arg_t; @@ -67,8 +67,8 @@ typedef struct { uint8_t maxdepth; tableinfo_t info; uint64_t buf_size; - void *buf; - void *h48buf; + unsigned char *buf; + _Atomic unsigned char *h48buf; uint32_t *cocsepdata; uint64_t selfsim[COCSEP_CLASSES]; cube_t crep[COCSEP_CLASSES]; @@ -85,7 +85,7 @@ typedef struct { typedef struct { uint8_t depth; uint32_t *cocsepdata; - _Atomic uint8_t *table; + _Atomic unsigned char *table; uint64_t *selfsim; cube_t *crep; uint64_t start; @@ -100,7 +100,7 @@ typedef struct { uint8_t base; uint8_t shortdepth; uint32_t *cocsepdata; - uint8_t *table; + unsigned char *table; uint64_t *selfsim; cube_t *crep; h48map_t *shortcubes; @@ -117,8 +117,8 @@ typedef struct { uint8_t k; uint32_t *cocsepdata; uint64_t *selfsim; - uint8_t *table; - _Atomic uint8_t *table_atomic; + unsigned char *table; + _Atomic unsigned char *table_atomic; pthread_mutex_t **table_mutex; } gendata_h48_mark_t; @@ -127,5 +127,5 @@ typedef struct { int64_t max; uint8_t k; uint64_t *distr; - const uint8_t *table; + const unsigned char *table; } getdistribution_h48_data_t; diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 0fd419d..cf7095c 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h @@ -22,9 +22,9 @@ typedef struct { uint8_t k; uint8_t base; const uint32_t *cocsepdata; - const uint8_t *h48data; - const uint8_t *h48data_fallback_h0k4; - const void *h48data_fallback_eoesep; + const unsigned char *h48data; + const unsigned char *h48data_fallback_h0k4; + const unsigned char *h48data_fallback_eoesep; uint32_t movemask_normal; uint32_t movemask_inverse; int64_t nodes_visited; @@ -53,7 +53,7 @@ STATIC int64_t solve_h48_maketasks( STATIC void *solve_h48_runthread(void *); STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); STATIC int64_t solve_h48(cube_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, - uint64_t, const void *, size_t n, char [n], + uint64_t, const unsigned char *, size_t n, char [n], long long [static NISSY_SIZE_SOLVE_STATS]); STATIC_INLINE bool @@ -349,7 +349,7 @@ solve_h48( uint8_t optimal, uint8_t threads, uint64_t data_size, - const void *data, + const unsigned char *data, size_t solutions_size, char solutions[solutions_size], long long stats[static NISSY_SIZE_SOLVE_STATS] @@ -365,8 +365,8 @@ solve_h48( int64_t nodes_visited, table_lookups, table_fallbacks; tableinfo_t info, fbinfo, fbinfo2; const uint32_t *cocsepdata; - const uint8_t *fallback, *h48data; - const void *fallback2; + const unsigned char *fallback, *h48data; + const unsigned char *fallback2; solution_moves_t solution_moves[THREADS]; solution_settings_t settings; solution_list_t sollist; @@ -379,8 +379,8 @@ solve_h48( if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) goto solve_h48_error_data; - cocsepdata = (uint32_t *)((char *)data + INFOSIZE); - h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE; + cocsepdata = (uint32_t *)(data + INFOSIZE); + h48data = data + COCSEP_FULLSIZE + INFOSIZE; /* Read fallback table(s) */ fallback = NULL; -- cgit v1.3