aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nissy.h7
-rw-r--r--src/solvers/h48/gendata_h48.h95
-rw-r--r--tools/1002_derive_h48h0k2/derive_h48h0k2.c21
-rw-r--r--tools/nissy_extra.h6
-rw-r--r--tools/tool.h65
5 files changed, 185 insertions, 9 deletions
diff --git a/src/nissy.h b/src/nissy.h
index e8c35c3..0545556 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -86,6 +86,13 @@ int64_t nissy_gendata(
86 void *generated_data 86 void *generated_data
87); 87);
88 88
89/* Temporarily added to test h48 intermediate tables */
90int64_t nissy_derivedata(
91 const char *options,
92 const void *fulltable,
93 void *generated_data
94);
95
89int64_t nissy_checkdata( 96int64_t nissy_checkdata(
90 const char *solver, 97 const char *solver,
91 const char *options, 98 const char *options,
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index 6e7b0ca..48d5582 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -103,7 +103,7 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *);
103STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); 103STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *);
104STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); 104STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg);
105STATIC void * gendata_h48k2_runthread(void *); 105STATIC void * gendata_h48k2_runthread(void *);
106STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t); 106STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *);
107STATIC void getdistribution_h48( 107STATIC void getdistribution_h48(
108 const uint8_t *, uint64_t [static 21], uint8_t, uint8_t); 108 const uint8_t *, uint64_t [static 21], uint8_t, uint8_t);
109 109
@@ -115,6 +115,8 @@ STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t);
115STATIC_INLINE uint8_t get_h48_bound( 115STATIC_INLINE uint8_t get_h48_bound(
116 cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); 116 cube_t, uint32_t, uint8_t, uint8_t, uint8_t *);
117 117
118size_t gendata_h48_derive(uint8_t, const void *, void *);
119
118STATIC uint64_t 120STATIC uint64_t
119gendata_h48short(gendata_h48short_arg_t *arg) 121gendata_h48short(gendata_h48short_arg_t *arg)
120{ 122{
@@ -390,7 +392,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
390 [11] = 10 392 [11] = 10
391 }; 393 };
392 394
393 uint8_t t, selectedbase, *table; 395 uint8_t t, *table;
394 int64_t j; 396 int64_t j;
395 uint64_t i, ii, inext, count; 397 uint64_t i, ii, inext, count;
396 h48map_t shortcubes; 398 h48map_t shortcubes;
@@ -417,8 +419,9 @@ gendata_h48k2(gendata_h48_arg_t *arg)
417 }; 419 };
418 gendata_h48short(&shortarg); 420 gendata_h48short(&shortarg);
419 421
420 selectedbase = arg->base < 20 ? arg->base : base[arg->h]; 422 if (arg->base >= 20)
421 arg->info = makeinfo_h48k2(arg, selectedbase); 423 arg->base = base[arg->h];
424 arg->info = makeinfo_h48k2(arg);
422 425
423 inext = count = 0; 426 inext = count = 0;
424 pthread_mutex_init(&shortcubes_mutex, NULL); 427 pthread_mutex_init(&shortcubes_mutex, NULL);
@@ -428,7 +431,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
428 dfsarg[i] = (h48k2_dfs_arg_t){ 431 dfsarg[i] = (h48k2_dfs_arg_t){
429 .h = arg->h, 432 .h = arg->h,
430 .k = arg->k, 433 .k = arg->k,
431 .base = selectedbase, 434 .base = arg->base,
432 .shortdepth = shortdepth, 435 .shortdepth = shortdepth,
433 .cocsepdata = arg->cocsepdata, 436 .cocsepdata = arg->cocsepdata,
434 .table = table, 437 .table = table,
@@ -640,7 +643,7 @@ gendata_h48k2_realcoord_runthread(void *arg)
640} 643}
641 644
642STATIC tableinfo_t 645STATIC tableinfo_t
643makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) 646makeinfo_h48k2(gendata_h48_arg_t *arg)
644{ 647{
645 tableinfo_t info; 648 tableinfo_t info;
646 649
@@ -654,7 +657,7 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base)
654 .classes = 0, 657 .classes = 0,
655 .h48h = arg->h, 658 .h48h = arg->h,
656 .bits = 2, 659 .bits = 2,
657 .base = base, 660 .base = arg->base,
658 .maxvalue = 3, 661 .maxvalue = 3,
659 .next = 0, 662 .next = 0,
660 }; 663 };
@@ -717,3 +720,81 @@ get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table)
717 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); 720 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h);
718 return get_h48_pval(table, coord, k); 721 return get_h48_pval(table, coord, k);
719} 722}
723
724size_t
725gendata_h48_derive(uint8_t h, const void *fulltable, void *buf)
726{
727 size_t cocsepsize, h48size;
728 uint8_t val_full, val_derive, val_new, *h48full, *h48derive;
729 int64_t i, j, h48max;
730 gendata_h48_arg_t arg;
731 tableinfo_t cocsepinfo, fulltableinfo;
732
733 /* Initializing values in case of error */
734 fulltableinfo.bits = 2;
735 fulltableinfo.base = 8;
736
737 readtableinfo_n(fulltable, 2, &fulltableinfo);
738 arg.h = h;
739 arg.k = fulltableinfo.bits;
740 arg.maxdepth = 20;
741 arg.buf = buf;
742 arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE);
743 arg.base = fulltableinfo.base;
744 arg.info = makeinfo_h48k2(&arg);
745
746 /* Technically this step is redundant, except that we
747 need selfsim and crep */
748 cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep);
749 arg.h48buf = (char *)buf + cocsepsize;
750 h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE;
751
752 if (buf == NULL)
753 goto gendata_h48_derive_return_size;
754
755 if (!readtableinfo(buf, &cocsepinfo)) {
756 LOG("gendata_h48: could not read info for cocsep table\n");
757 goto gendata_h48_derive_error;
758 }
759
760 cocsepinfo.next = cocsepsize;
761 if (!writetableinfo(&cocsepinfo, buf)) {
762 LOG("gendata_h48_derive: could not write info for cocsep table"
763 " with updated 'next' value\n");
764 goto gendata_h48_derive_error;
765 }
766
767 h48full = (uint8_t *)fulltable + INFOSIZE;
768 h48derive = (uint8_t *)arg.h48buf + INFOSIZE;
769 memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k));
770 memset(arg.info.distribution, 0,
771 INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
772
773 h48max = H48_COORDMAX(11);
774 for (i = 0; i < h48max; i++) {
775 if (i % INT64_C(1000000000) == 0)
776 LOG("Processing %" PRId64 "th coordinate\n", i);
777 j = i >> (int64_t)(11-h);
778 val_full = get_h48_pval(h48full, i, arg.k);
779 val_derive = get_h48_pval(h48derive, j, arg.k);
780 val_new = MIN(val_full, val_derive);
781 set_h48_pval(h48derive, j, arg.k, val_new);
782 }
783
784 h48max = H48_COORDMAX(h);
785 for (i = 0; i < h48max; i++) {
786 val_derive = get_h48_pval(h48derive, i, arg.k);
787 arg.info.distribution[val_derive]++;
788 }
789
790 if (!writetableinfo(&arg.info, buf)) {
791 LOG("gendata_h48_derive: could not write info for table\n");
792 goto gendata_h48_derive_error;
793 }
794
795gendata_h48_derive_return_size:
796 return cocsepsize + h48size;
797
798gendata_h48_derive_error:
799 return 0;
800}
diff --git a/tools/1002_derive_h48h0k2/derive_h48h0k2.c b/tools/1002_derive_h48h0k2/derive_h48h0k2.c
new file mode 100644
index 0000000..73fab2e
--- /dev/null
+++ b/tools/1002_derive_h48h0k2/derive_h48h0k2.c
@@ -0,0 +1,21 @@
1#include "../tool.h"
2
3uint64_t expected[21] = {
4 /* Base value is 8 */
5 [0] = 5473562,
6 [1] = 34776317,
7 [2] = 68566704,
8 [3] = 8750867,
9};
10
11void run(void) {
12 derivedata_run(0, "tables/h48h0k2_derived", expected);
13}
14
15int main(void) {
16 nissy_setlogger(log_stderr);
17
18 timerun(run, "benchmark derivedata_h48 h = 0, k = 2");
19
20 return 0;
21}
diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h
index 17906d4..1e714a7 100644
--- a/tools/nissy_extra.h
+++ b/tools/nissy_extra.h
@@ -1,3 +1,7 @@
1/* Intended only for tools */ 1/*
2This header file exposes certain functions that are meant to be used
3for testing purposes only.
4*/
2 5
6size_t gendata_h48_derive(uint8_t, const void *, void *);
3int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); 7int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *);
diff --git a/tools/tool.h b/tools/tool.h
index 18b8ce9..5eec318 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -14,8 +14,10 @@ static double timerun(void (*)(void), const char *);
14static void getfilename(const char *, const char *, char *); 14static void getfilename(const char *, const char *, char *);
15static void writetable(const char *, int64_t, const char *); 15static void writetable(const char *, int64_t, const char *);
16static int64_t generatetable(const char *, const char *, char **); 16static int64_t generatetable(const char *, const char *, char **);
17static int64_t derivetable(uint8_t, char **);
17static int getdata(const char *, const char *, char **, const char *); 18static int getdata(const char *, const char *, char **, const char *);
18static void gendata_run(const char *, const char *, uint64_t [static 21]); 19static void gendata_run(const char *, const char *, uint64_t[static 21]);
20static void derivedata_run(uint8_t, const char *, uint64_t[static 21]);
19 21
20static void 22static void
21log_stderr(const char *str, ...) 23log_stderr(const char *str, ...)
@@ -122,6 +124,41 @@ generatetable(const char *solver, const char *options, char **buf)
122 return gensize; 124 return gensize;
123} 125}
124 126
127static int64_t
128derivetable(uint8_t h, char **buf)
129{
130 int64_t size, gensize;
131 char *fulltable;
132
133 char options[20] = " ;2;20"; /* Fixed for k = 2 for now */
134 options[0] = (char)(h + '0'); /* h = 10 not supported for now */
135
136 /* Support only b8 for now */
137 if (getdata("h48", "11;2;20", &fulltable, "tables/h48h11k2_b8") != 0) {
138 printf("Error reading full table.\n");
139 return -1;
140 }
141
142 size = nissy_datasize("h48", options);
143 if (size == -1) {
144 printf("Error getting table size.\n");
145 free(fulltable);
146 return -1;
147 }
148
149 *buf = malloc(size);
150 gensize = gendata_h48_derive(h, fulltable, *buf);
151
152 if (gensize != size) {
153 fprintf(stderr, "Error deriving table\n");
154 free(fulltable);
155 return -2;
156 }
157
158 free(fulltable);
159 return gensize;
160}
161
125static int 162static int
126getdata( 163getdata(
127 const char *solver, 164 const char *solver,
@@ -194,3 +231,29 @@ gendata_run(
194gendata_run_finish: 231gendata_run_finish:
195 free(buf); 232 free(buf);
196} 233}
234
235static void
236derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21])
237{
238 int64_t size;
239 char *buf;
240
241 size = derivetable(h, &buf);
242 switch (size) {
243 case -1:
244 return;
245 case -2:
246 goto derivedata_run_finish;
247 default:
248 nissy_datainfo(buf, write_stdout);
249 printf("\n");
250 printf("Succesfully generated %" PRId64 " bytes. "
251 "See above for details on the tables.\n", size);
252
253 writetable(buf, size, filename);
254 break;
255 }
256
257derivedata_run_finish:
258 free(buf);
259}

Generated with cgit - Back to sebastiano.tronto.net