aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/gendata_h48.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-21 14:33:01 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-21 14:44:07 +0200
commit510a7471348788fccba6b7c4b9f7b7cc9aee6ba9 (patch)
tree58df7791242d9a4f52e80da93ad3af20ed5e3528 /src/solvers/h48/gendata_h48.h
parent1d9b8acfeece68c4f55d2499d8aed127f98a383c (diff)
downloadnissy-core-510a7471348788fccba6b7c4b9f7b7cc9aee6ba9.tar.gz
nissy-core-510a7471348788fccba6b7c4b9f7b7cc9aee6ba9.zip
Always use unsigned char * for data buffers
Before this commit I was inconsistently using one of void *, char * and uint8_t *.
Diffstat (limited to 'src/solvers/h48/gendata_h48.h')
-rw-r--r--src/solvers/h48/gendata_h48.h90
1 files changed, 48 insertions, 42 deletions
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(
13STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]); 13STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]);
14STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]); 14STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]);
15STATIC void *getdistribution_h48_runthread(void *); 15STATIC void *getdistribution_h48_runthread(void *);
16STATIC void getdistribution_h48(const uint8_t *, 16STATIC void getdistribution_h48(const unsigned char *,
17 uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); 17 uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t);
18 18
19STATIC const uint32_t *get_cocsepdata_constptr(const void *); 19STATIC const uint32_t *get_cocsepdata_constptr(const unsigned char *);
20STATIC const uint8_t *get_h48data_constptr(const void *); 20STATIC const unsigned char *get_h48data_constptr(const unsigned char *);
21 21
22STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); 22STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, int64_t, uint8_t);
23STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); 23STATIC_INLINE void set_h48_pval(unsigned char *, int64_t, uint8_t, uint8_t);
24STATIC_INLINE uint8_t get_h48_pval_atomic( 24STATIC_INLINE uint8_t get_h48_pval_atomic(
25 _Atomic const uint8_t *, int64_t, uint8_t); 25 _Atomic const unsigned char *, int64_t, uint8_t);
26STATIC_INLINE void set_h48_pval_atomic( 26STATIC_INLINE void set_h48_pval_atomic(
27 _Atomic uint8_t *, int64_t, uint8_t, uint8_t); 27 _Atomic unsigned char *, int64_t, uint8_t, uint8_t);
28 28
29size_t gendata_h48_derive(uint8_t, const void *, void *); 29size_t gendata_h48_derive(uint8_t, const unsigned char *, unsigned char *);
30 30
31STATIC uint64_t 31STATIC uint64_t
32gendata_h48short(gendata_h48short_arg_t arg[static 1]) 32gendata_h48short(gendata_h48short_arg_t arg[static 1])
@@ -67,7 +67,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1])
67{ 67{
68 uint64_t size, cocsepsize, h48size, fallbacksize, fallback2size, of; 68 uint64_t size, cocsepsize, h48size, fallbacksize, fallback2size, of;
69 long long r; 69 long long r;
70 void *cocsepdata_offset; 70 unsigned char *cocsepdata_offset;
71 tableinfo_t cocsepinfo, h48info, fallbackinfo; 71 tableinfo_t cocsepinfo, h48info, fallbackinfo;
72 gendata_h48_arg_t arg_h0k4; 72 gendata_h48_arg_t arg_h0k4;
73 73
@@ -95,9 +95,9 @@ gendata_h48(gendata_h48_arg_t arg[static 1])
95 95
96 gendata_cocsep(arg->buf, arg->selfsim, arg->crep); 96 gendata_cocsep(arg->buf, arg->selfsim, arg->crep);
97 97
98 cocsepdata_offset = (char *)arg->buf + INFOSIZE; 98 cocsepdata_offset = arg->buf + INFOSIZE;
99 arg->cocsepdata = (uint32_t *)cocsepdata_offset; 99 arg->cocsepdata = (uint32_t *)cocsepdata_offset;
100 arg->h48buf = (char *)arg->buf + cocsepsize; 100 arg->h48buf = (_Atomic unsigned char*)arg->buf + cocsepsize;
101 101
102 arg->base = 99; /* TODO: set this somewhere else */ 102 arg->base = 99; /* TODO: set this somewhere else */
103 103
@@ -136,8 +136,8 @@ gendata_h48(gendata_h48_arg_t arg[static 1])
136 arg_h0k4.base = 0; 136 arg_h0k4.base = 0;
137 arg_h0k4.maxdepth = 20; 137 arg_h0k4.maxdepth = 20;
138 arg_h0k4.buf_size = arg->buf_size - h48size; 138 arg_h0k4.buf_size = arg->buf_size - h48size;
139 arg_h0k4.buf = (char *)arg->buf + cocsepsize + h48size; 139 arg_h0k4.buf = arg->buf + cocsepsize + h48size;
140 arg_h0k4.h48buf = (char *)arg->h48buf + h48size; 140 arg_h0k4.h48buf = arg->h48buf + h48size;
141 141
142 gendata_h48h0k4(&arg_h0k4); 142 gendata_h48h0k4(&arg_h0k4);
143 143
@@ -145,7 +145,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1])
145 145
146 /* Add eoesep fallback table */ 146 /* Add eoesep fallback table */
147 147
148 gendata_eoesep((char *)arg->buf + (size - fallback2size), 20); 148 gendata_eoesep(arg->buf + (size - fallback2size), 20);
149 149
150 /* Update tableinfo with correct next values */ 150 /* Update tableinfo with correct next values */
151 151
@@ -157,7 +157,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1])
157 } 157 }
158 h48info.next = h48size; 158 h48info.next = h48size;
159 r = writetableinfo(&h48info, 159 r = writetableinfo(&h48info,
160 arg->buf_size - cocsepsize, (char *)arg->buf + cocsepsize); 160 arg->buf_size - cocsepsize, arg->buf + cocsepsize);
161 if (r != NISSY_OK) { 161 if (r != NISSY_OK) {
162 LOG("[H48 gendata] Error: could not write info " 162 LOG("[H48 gendata] Error: could not write info "
163 "for h48 table\n"); 163 "for h48 table\n");
@@ -174,8 +174,8 @@ gendata_h48(gendata_h48_arg_t arg[static 1])
174 174
175 of = cocsepsize + h48size; 175 of = cocsepsize + h48size;
176 fallbackinfo.next = fallbacksize; 176 fallbackinfo.next = fallbacksize;
177 r = writetableinfo(&fallbackinfo, 177 r = writetableinfo(
178 arg->buf_size - of, (char *)arg->buf + of); 178 &fallbackinfo, arg->buf_size - of, arg->buf + of);
179 if (r != NISSY_OK) { 179 if (r != NISSY_OK) {
180 LOG("[H48 gendata] Error: could not write info for " 180 LOG("[H48 gendata] Error: could not write info for "
181 "h48 fallback table\n"); 181 "h48 fallback table\n");
@@ -189,7 +189,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1])
189STATIC void 189STATIC void
190gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) 190gendata_h48h0k4(gendata_h48_arg_t arg[static 1])
191{ 191{
192 _Atomic uint8_t *table; 192 _Atomic unsigned char *table;
193 uint8_t val; 193 uint8_t val;
194 int64_t i, sc, done, d, h48max; 194 int64_t i, sc, done, d, h48max;
195 uint64_t t, tt, isize, cc, bufsize; 195 uint64_t t, tt, isize, cc, bufsize;
@@ -212,7 +212,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1])
212 .next = 0, 212 .next = 0,
213 }; 213 };
214 214
215 table = (_Atomic uint8_t *)arg->h48buf + INFOSIZE; 215 table = arg->h48buf + INFOSIZE;
216 memset(table, 0xFF, H48_TABLESIZE(0, 4)); 216 memset(table, 0xFF, H48_TABLESIZE(0, 4));
217 217
218 h48max = (int64_t)H48_COORDMAX(0); 218 h48max = (int64_t)H48_COORDMAX(0);
@@ -261,7 +261,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1])
261 261
262 arg->info.maxvalue = d - 1; 262 arg->info.maxvalue = d - 1;
263 bufsize = arg->buf_size - COCSEP_FULLSIZE; 263 bufsize = arg->buf_size - COCSEP_FULLSIZE;
264 writetableinfo(&arg->info, bufsize, arg->h48buf); 264 writetableinfo(&arg->info, bufsize, (unsigned char *)arg->h48buf);
265} 265}
266 266
267STATIC void * 267STATIC void *
@@ -374,7 +374,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1])
374 }; 374 };
375 375
376 uint8_t t; 376 uint8_t t;
377 uint8_t *table; 377 unsigned char *table;
378 int64_t j; 378 int64_t j;
379 uint64_t i, ii, inext, count, bufsize; 379 uint64_t i, ii, inext, count, bufsize;
380 h48map_t shortcubes; 380 h48map_t shortcubes;
@@ -383,7 +383,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1])
383 pthread_t thread[THREADS]; 383 pthread_t thread[THREADS];
384 pthread_mutex_t shortcubes_mutex, table_mutex[CHUNKS]; 384 pthread_mutex_t shortcubes_mutex, table_mutex[CHUNKS];
385 385
386 table = (uint8_t *)arg->h48buf + INFOSIZE; 386 table = (unsigned char *)arg->h48buf + INFOSIZE;
387 memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); 387 memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k));
388 388
389 LOG("[H48 gendata] Computing depth <=%" PRIu8 "\n", shortdepth) 389 LOG("[H48 gendata] Computing depth <=%" PRIu8 "\n", shortdepth)
@@ -439,7 +439,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1])
439 } 439 }
440 440
441 bufsize = arg->buf_size - COCSEP_FULLSIZE; 441 bufsize = arg->buf_size - COCSEP_FULLSIZE;
442 writetableinfo(&arg->info, bufsize, arg->h48buf); 442 writetableinfo(&arg->info, bufsize, (unsigned char *)arg->h48buf);
443} 443}
444 444
445STATIC void * 445STATIC void *
@@ -653,7 +653,7 @@ STATIC void *
653getdistribution_h48_runthread(void *arg) 653getdistribution_h48_runthread(void *arg)
654{ 654{
655 getdistribution_h48_data_t *data = (getdistribution_h48_data_t *)arg; 655 getdistribution_h48_data_t *data = (getdistribution_h48_data_t *)arg;
656 const uint8_t *table; 656 const unsigned char *table;
657 uint8_t j, k, m; 657 uint8_t j, k, m;
658 int64_t i; 658 int64_t i;
659 659
@@ -671,7 +671,7 @@ getdistribution_h48_runthread(void *arg)
671 671
672STATIC void 672STATIC void
673getdistribution_h48( 673getdistribution_h48(
674 const uint8_t *table, 674 const unsigned char *table,
675 uint64_t distr[static INFO_DISTRIBUTION_LEN], 675 uint64_t distr[static INFO_DISTRIBUTION_LEN],
676 uint8_t h, 676 uint8_t h,
677 uint8_t k 677 uint8_t k
@@ -708,50 +708,55 @@ getdistribution_h48(
708} 708}
709 709
710STATIC const uint32_t * 710STATIC const uint32_t *
711get_cocsepdata_constptr(const void *data) 711get_cocsepdata_constptr(const unsigned char *data)
712{ 712{
713 return (uint32_t *)((char *)data + INFOSIZE); 713 return (uint32_t *)(data + INFOSIZE);
714} 714}
715 715
716STATIC const uint8_t * 716STATIC const unsigned char *
717get_h48data_constptr(const void *data) 717get_h48data_constptr(const unsigned char *data)
718{ 718{
719 return (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE; 719 return data + COCSEP_FULLSIZE + INFOSIZE;
720} 720}
721 721
722STATIC_INLINE uint8_t 722STATIC_INLINE uint8_t
723get_h48_pval(const uint8_t *table, int64_t i, uint8_t k) 723get_h48_pval(const unsigned char *table, int64_t i, uint8_t k)
724{ 724{
725 return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); 725 return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k);
726} 726}
727 727
728STATIC_INLINE uint8_t 728STATIC_INLINE uint8_t
729get_h48_pval_atomic(_Atomic const uint8_t *table, int64_t i, uint8_t k) 729get_h48_pval_atomic(_Atomic const unsigned char *table, int64_t i, uint8_t k)
730{ 730{
731 return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); 731 return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k);
732} 732}
733 733
734STATIC_INLINE void 734STATIC_INLINE void
735set_h48_pval(uint8_t *table, int64_t i, uint8_t k, uint8_t val) 735set_h48_pval(unsigned char *table, int64_t i, uint8_t k, uint8_t val)
736{ 736{
737 table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) 737 table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k)))
738 | (val << H48_SHIFT(i, k)); 738 | (val << H48_SHIFT(i, k));
739} 739}
740 740
741STATIC_INLINE void 741STATIC_INLINE void
742set_h48_pval_atomic(_Atomic uint8_t *table, int64_t i, uint8_t k, uint8_t val) 742set_h48_pval_atomic(
743 _Atomic unsigned char *table,
744 int64_t i,
745 uint8_t k,
746 uint8_t val
747)
743{ 748{
744 table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) 749 table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k)))
745 | (val << H48_SHIFT(i, k)); 750 | (val << H48_SHIFT(i, k));
746} 751}
747 752
748size_t 753size_t
749gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) 754gendata_h48_derive(uint8_t h, const unsigned char *fulltable, unsigned char *buf)
750{ 755{
751 size_t cocsepsize, h48size; 756 size_t cocsepsize, h48size;
752 uint8_t val_full, val_derive; 757 uint8_t val_full, val_derive;
753 const uint8_t *h48full; 758 const unsigned char *h48full;
754 uint8_t *h48derive; 759 unsigned char *h48derive;
755 int64_t i, j, h48max; 760 int64_t i, j, h48max;
756 uint64_t bufsize; 761 uint64_t bufsize;
757 gendata_h48_arg_t arg; 762 gendata_h48_arg_t arg;
@@ -770,14 +775,14 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf)
770 arg.k = fulltableinfo.bits; 775 arg.k = fulltableinfo.bits;
771 arg.maxdepth = 20; 776 arg.maxdepth = 20;
772 arg.buf = buf; 777 arg.buf = buf;
773 arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); 778 arg.cocsepdata = (uint32_t *)(buf + INFOSIZE);
774 arg.base = fulltableinfo.base; 779 arg.base = fulltableinfo.base;
775 arg.info = makeinfo_h48k2(&arg); 780 arg.info = makeinfo_h48k2(&arg);
776 781
777 /* Technically this step is redundant, except that we 782 /* Technically this step is redundant, except that we
778 need selfsim and crep */ 783 need selfsim and crep */
779 cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); 784 cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep);
780 arg.h48buf = (_Atomic uint8_t *)buf + cocsepsize; 785 arg.h48buf = (_Atomic unsigned char *)buf + cocsepsize;
781 h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; 786 h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE;
782 787
783 if (buf == NULL) 788 if (buf == NULL)
@@ -798,8 +803,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf)
798 goto gendata_h48_derive_error; 803 goto gendata_h48_derive_error;
799 } 804 }
800 805
801 h48full = (const uint8_t *)fulltable + cocsepsize + INFOSIZE; 806 h48full = fulltable + cocsepsize + INFOSIZE;
802 h48derive = (uint8_t *)arg.h48buf + INFOSIZE; 807 h48derive = (unsigned char *)arg.h48buf + INFOSIZE;
803 memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); 808 memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k));
804 memset(arg.info.distribution, 0, 809 memset(arg.info.distribution, 0,
805 INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); 810 INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
@@ -819,7 +824,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf)
819 getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); 824 getdistribution_h48(h48derive, arg.info.distribution, h, arg.k);
820 825
821 bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; 826 bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE;
822 if (writetableinfo(&arg.info, bufsize, arg.h48buf) != NISSY_OK) { 827 if (writetableinfo(&arg.info, bufsize, (unsigned char *)arg.h48buf)
828 != NISSY_OK) {
823 LOG("H48 derive gendata] Error: could not write info " 829 LOG("H48 derive gendata] Error: could not write info "
824 "for table\n"); 830 "for table\n");
825 goto gendata_h48_derive_error; 831 goto gendata_h48_derive_error;

Generated with cgit - Back to sebastiano.tronto.net