aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/001_derive_h48/derive_h48.c33
-rw-r--r--tools/001_derive_h48h0k2/derive_h48h0k2.c21
-rw-r--r--tools/expected_distributions.h8
-rw-r--r--tools/tool.h33
4 files changed, 62 insertions, 33 deletions
diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c
new file mode 100644
index 0000000..3c7f8cc
--- /dev/null
+++ b/tools/001_derive_h48/derive_h48.c
@@ -0,0 +1,33 @@
1#include "../tool.h"
2
3char *opts_large, *opts_small, *filename_large, *filename_small;
4
5void run(void) {
6 derivedata_run(opts_large, opts_small, filename_large, filename_small);
7}
8
9int main(int argc, char **argv) {
10 char description[256];
11
12 if (argc < 5) {
13 fprintf(stderr,
14 "Error: not enough arguments. Required:\n"
15 "1. Options for large table\n"
16 "2. Options for derived table\n"
17 "3. Filename containing large table\n"
18 "4. Filename for saving derived table\n");
19 return 1;
20 }
21
22 opts_large = argv[1];
23 opts_small = argv[2];
24 filename_large = argv[3];
25 filename_small = argv[4];
26 sprintf(description, "deriving %s from %s\n", opts_small, opts_large);
27
28 nissy_setlogger(log_stderr);
29
30 timerun(run, description);
31
32 return 0;
33}
diff --git a/tools/001_derive_h48h0k2/derive_h48h0k2.c b/tools/001_derive_h48h0k2/derive_h48h0k2.c
deleted file mode 100644
index 73fab2e..0000000
--- a/tools/001_derive_h48h0k2/derive_h48h0k2.c
+++ /dev/null
@@ -1,21 +0,0 @@
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/expected_distributions.h b/tools/expected_distributions.h
index 27bd64a..535cab2 100644
--- a/tools/expected_distributions.h
+++ b/tools/expected_distributions.h
@@ -22,4 +22,12 @@ uint64_t expected_h48[12][9][21] = {
22 [12] = 1673, 22 [12] = 1673,
23 }, 23 },
24 }, 24 },
25 [1] = {
26 [2] = {
27 [0] = 6012079,
28 [1] = 45822302,
29 [2] = 142018732,
30 [3] = 41281787,
31 },
32 },
25}; 33};
diff --git a/tools/tool.h b/tools/tool.h
index d9071fb..c44828d 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -14,10 +14,11 @@ 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 int64_t derivetable(const char *, const char *, const char *, char **);
18static int getdata(const char *, const char *, char **, const char *); 18static int getdata(const char *, const char *, char **, const char *);
19static 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]); 20static void derivedata_run(
21 const char *, const char *, const char *, const char *);
21 22
22static void 23static void
23log_stderr(const char *str, ...) 24log_stderr(const char *str, ...)
@@ -125,27 +126,30 @@ generatetable(const char *solver, const char *options, char **buf)
125} 126}
126 127
127static int64_t 128static int64_t
128derivetable(uint8_t h, char **buf) 129derivetable(
130 const char *opts_large,
131 const char *opts_small,
132 const char *filename_large,
133 char **buf
134)
129{ 135{
136 uint8_t h;
130 int64_t size, gensize; 137 int64_t size, gensize;
131 char *fulltable; 138 char *fulltable;
132 139
133 char options[20] = " ;2;20"; /* Only for k = 2 for now */ 140 if (getdata("h48", opts_large, &fulltable, filename_large) != 0) {
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"); 141 printf("Error reading full table.\n");
139 return -1; 142 return -1;
140 } 143 }
141 144
142 size = nissy_datasize("h48", options); 145 size = nissy_datasize("h48", opts_small);
143 if (size == -1) { 146 if (size == -1) {
144 printf("Error getting table size.\n"); 147 printf("Error getting table size.\n");
145 free(fulltable); 148 free(fulltable);
146 return -1; 149 return -1;
147 } 150 }
148 151
152 h = atoi(opts_small); /* TODO: use option parser */
149 *buf = malloc(size); 153 *buf = malloc(size);
150 gensize = gendata_h48_derive(h, fulltable, *buf); 154 gensize = gendata_h48_derive(h, fulltable, *buf);
151 155
@@ -233,12 +237,17 @@ gendata_run_finish:
233} 237}
234 238
235static void 239static void
236derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) 240derivedata_run(
241 const char *opts_large,
242 const char *opts_small,
243 const char *filename_large,
244 const char *filename_small
245)
237{ 246{
238 int64_t size; 247 int64_t size;
239 char *buf; 248 char *buf;
240 249
241 size = derivetable(h, &buf); 250 size = derivetable(opts_large, opts_small, filename_large, &buf);
242 switch (size) { 251 switch (size) {
243 case -1: 252 case -1:
244 return; 253 return;
@@ -250,7 +259,7 @@ derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21])
250 printf("Succesfully generated %" PRId64 " bytes. " 259 printf("Succesfully generated %" PRId64 " bytes. "
251 "See above for details on the tables.\n", size); 260 "See above for details on the tables.\n", size);
252 261
253 writetable(buf, size, filename); 262 writetable(buf, size, filename_small);
254 break; 263 break;
255 } 264 }
256 265

Generated with cgit - Back to sebastiano.tronto.net