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.h64
5 files changed, 186 insertions, 7 deletions
diff --git a/src/nissy.h b/src/nissy.h
index 336130c..63e7a90 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
89/* Print information on a data table via the provided callback writer */ 96/* Print information on a data table via the provided callback writer */
90int64_t nissy_datainfo( 97int64_t nissy_datainfo(
91 const void *table, 98 const void *table,
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index 3445570..a88eb4f 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 *);
107 107
108STATIC uint32_t *get_cocsepdata_ptr(const void *); 108STATIC uint32_t *get_cocsepdata_ptr(const void *);
109STATIC uint8_t *get_h48data_ptr(const void *); 109STATIC uint8_t *get_h48data_ptr(const void *);
@@ -112,6 +112,8 @@ STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t);
112STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); 112STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t);
113STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); 113STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *);
114 114
115size_t gendata_h48_derive(uint8_t, const void *, void *);
116
115STATIC uint64_t 117STATIC uint64_t
116gendata_h48short(gendata_h48short_arg_t *arg) 118gendata_h48short(gendata_h48short_arg_t *arg)
117{ 119{
@@ -387,7 +389,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
387 [11] = 10 389 [11] = 10
388 }; 390 };
389 391
390 uint8_t t, selectedbase, *table; 392 uint8_t t, *table;
391 int64_t j; 393 int64_t j;
392 uint64_t i, ii, inext, count; 394 uint64_t i, ii, inext, count;
393 h48map_t shortcubes; 395 h48map_t shortcubes;
@@ -414,8 +416,9 @@ gendata_h48k2(gendata_h48_arg_t *arg)
414 }; 416 };
415 gendata_h48short(&shortarg); 417 gendata_h48short(&shortarg);
416 418
417 selectedbase = arg->base < 20 ? arg->base : base[arg->h]; 419 if (arg->base >= 20)
418 arg->info = makeinfo_h48k2(arg, selectedbase); 420 arg->base = base[arg->h];
421 arg->info = makeinfo_h48k2(arg);
419 422
420 inext = count = 0; 423 inext = count = 0;
421 pthread_mutex_init(&shortcubes_mutex, NULL); 424 pthread_mutex_init(&shortcubes_mutex, NULL);
@@ -425,7 +428,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
425 dfsarg[i] = (h48k2_dfs_arg_t){ 428 dfsarg[i] = (h48k2_dfs_arg_t){
426 .h = arg->h, 429 .h = arg->h,
427 .k = arg->k, 430 .k = arg->k,
428 .base = selectedbase, 431 .base = arg->base,
429 .shortdepth = shortdepth, 432 .shortdepth = shortdepth,
430 .cocsepdata = arg->cocsepdata, 433 .cocsepdata = arg->cocsepdata,
431 .table = table, 434 .table = table,
@@ -637,7 +640,7 @@ gendata_h48k2_realcoord_runthread(void *arg)
637} 640}
638 641
639STATIC tableinfo_t 642STATIC tableinfo_t
640makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) 643makeinfo_h48k2(gendata_h48_arg_t *arg)
641{ 644{
642 tableinfo_t info; 645 tableinfo_t info;
643 646
@@ -651,7 +654,7 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base)
651 .classes = 0, 654 .classes = 0,
652 .h48h = arg->h, 655 .h48h = arg->h,
653 .bits = 2, 656 .bits = 2,
654 .base = base, 657 .base = arg->base,
655 .maxvalue = 3, 658 .maxvalue = 3,
656 .next = 0, 659 .next = 0,
657 }; 660 };
@@ -695,3 +698,81 @@ get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table)
695 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); 698 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h);
696 return get_h48_pval(table, coord, k); 699 return get_h48_pval(table, coord, k);
697} 700}
701
702size_t
703gendata_h48_derive(uint8_t h, const void *fulltable, void *buf)
704{
705 size_t cocsepsize, h48size;
706 uint8_t val_full, val_derive, val_new, *h48full, *h48derive;
707 int64_t i, j, h48max;
708 gendata_h48_arg_t arg;
709 tableinfo_t cocsepinfo, fulltableinfo;
710
711 /* Initializing values in case of error */
712 fulltableinfo.bits = 2;
713 fulltableinfo.base = 8;
714
715 readtableinfo_n(fulltable, 2, &fulltableinfo);
716 arg.h = h;
717 arg.k = fulltableinfo.bits;
718 arg.maxdepth = 20;
719 arg.buf = buf;
720 arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE);
721 arg.base = fulltableinfo.base;
722 arg.info = makeinfo_h48k2(&arg);
723
724 /* Technically this step is redundant, except that we
725 need selfsim and crep */
726 cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep);
727 arg.h48buf = (char *)buf + cocsepsize;
728 h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE;
729
730 if (buf == NULL)
731 goto gendata_h48_derive_return_size;
732
733 if (!readtableinfo(buf, &cocsepinfo)) {
734 LOG("gendata_h48: could not read info for cocsep table\n");
735 goto gendata_h48_derive_error;
736 }
737
738 cocsepinfo.next = cocsepsize;
739 if (!writetableinfo(&cocsepinfo, buf)) {
740 LOG("gendata_h48_derive: could not write info for cocsep table"
741 " with updated 'next' value\n");
742 goto gendata_h48_derive_error;
743 }
744
745 h48full = (uint8_t *)fulltable + INFOSIZE;
746 h48derive = (uint8_t *)arg.h48buf + INFOSIZE;
747 memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k));
748 memset(arg.info.distribution, 0,
749 INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
750
751 h48max = H48_COORDMAX(11);
752 for (i = 0; i < h48max; i++) {
753 if (i % INT64_C(1000000000) == 0)
754 LOG("Processing %" PRId64 "th coordinate\n", i);
755 j = i >> (int64_t)(11-h);
756 val_full = get_h48_pval(h48full, i, arg.k);
757 val_derive = get_h48_pval(h48derive, j, arg.k);
758 val_new = MIN(val_full, val_derive);
759 set_h48_pval(h48derive, j, arg.k, val_new);
760 }
761
762 h48max = H48_COORDMAX(h);
763 for (i = 0; i < h48max; i++) {
764 val_derive = get_h48_pval(h48derive, i, arg.k);
765 arg.info.distribution[val_derive]++;
766 }
767
768 if (!writetableinfo(&arg.info, buf)) {
769 LOG("gendata_h48_derive: could not write info for table\n");
770 goto gendata_h48_derive_error;
771 }
772
773gendata_h48_derive_return_size:
774 return cocsepsize + h48size;
775
776gendata_h48_derive_error:
777 return 0;
778}
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
new file mode 100644
index 0000000..4294c24
--- /dev/null
+++ b/tools/nissy_extra.h
@@ -0,0 +1,6 @@
1/*
2This header file exposes certain functions that are meant to be used
3for testing purposes only.
4*/
5
6size_t gendata_h48_derive(uint8_t, const void *, void *);
diff --git a/tools/tool.h b/tools/tool.h
index 757657b..59407b6 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -6,14 +6,17 @@
6#include <stdlib.h> 6#include <stdlib.h>
7 7
8#include "../src/nissy.h" 8#include "../src/nissy.h"
9#include "nissy_extra.h"
9 10
10static void log_stderr(const char *, ...); 11static void log_stderr(const char *, ...);
11static void log_stdout(const char *, ...); 12static void log_stdout(const char *, ...);
12static double timerun(void (*)(void), const char *); 13static double timerun(void (*)(void), const char *);
13static void writetable(const char *, int64_t, const char *); 14static void writetable(const char *, int64_t, const char *);
14static int64_t generatetable(const char *, const char *, char **); 15static int64_t generatetable(const char *, const char *, char **);
16static int64_t derivetable(uint8_t, char **);
15static int getdata(const char *, const char *, char **, const char *); 17static int getdata(const char *, const char *, char **, const char *);
16static void gendata_run(const char *, const char *, const char *, uint64_t[static 21]); 18static void gendata_run(const char *, const char *, const char *, uint64_t[static 21]);
19static void derivedata_run(uint8_t, const char *, uint64_t[static 21]);
17 20
18static void 21static void
19log_stderr(const char *str, ...) 22log_stderr(const char *str, ...)
@@ -109,6 +112,41 @@ generatetable(const char *solver, const char *options, char **buf)
109 return gensize; 112 return gensize;
110} 113}
111 114
115static int64_t
116derivetable(uint8_t h, char **buf)
117{
118 int64_t size, gensize;
119 char *fulltable;
120
121 char options[20] = " ;2;20"; /* Fixed for k = 2 for now */
122 options[0] = (char)(h + '0'); /* h = 10 not supported for now */
123
124 /* Support only b8 for now */
125 if (getdata("h48", "11;2;20", &fulltable, "tables/h48h11k2_b8") != 0) {
126 printf("Error reading full table.\n");
127 return -1;
128 }
129
130 size = nissy_datasize("h48", options);
131 if (size == -1) {
132 printf("Error getting table size.\n");
133 free(fulltable);
134 return -1;
135 }
136
137 *buf = malloc(size);
138 gensize = gendata_h48_derive(h, fulltable, *buf);
139
140 if (gensize != size) {
141 fprintf(stderr, "Error deriving table\n");
142 free(fulltable);
143 return -2;
144 }
145
146 free(fulltable);
147 return gensize;
148}
149
112static int 150static int
113getdata( 151getdata(
114 const char *solver, 152 const char *solver,
@@ -182,3 +220,29 @@ gendata_run(
182gendata_run_finish: 220gendata_run_finish:
183 free(buf); 221 free(buf);
184} 222}
223
224static void
225derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21])
226{
227 int64_t size;
228 char *buf;
229
230 size = derivetable(h, &buf);
231 switch (size) {
232 case -1:
233 return;
234 case -2:
235 goto derivedata_run_finish;
236 default:
237 nissy_datainfo(buf, write_stdout);
238 printf("\n");
239 printf("Succesfully generated %" PRId64 " bytes. "
240 "See above for details on the tables.\n", size);
241
242 writetable(buf, size, filename);
243 break;
244 }
245
246derivedata_run_finish:
247 free(buf);
248}

Generated with cgit - Back to sebastiano.tronto.net