aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tools/1002_derive_h48h0k2/derive_h48h0k2.c21
-rw-r--r--tools/nissy_extra.h6
-rw-r--r--tools/tool.h64
3 files changed, 91 insertions, 0 deletions
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