aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/000_gendata/gendata.c21
-rw-r--r--tools/001_derive_h48/derive_h48.c40
-rw-r--r--tools/100_checkdata/checkdata.c10
-rw-r--r--tools/expected_distributions.h267
-rw-r--r--tools/nissy_extra.h14
-rw-r--r--tools/tool.h86
6 files changed, 9 insertions, 429 deletions
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c
index 66c4864..f2da890 100644
--- a/tools/000_gendata/gendata.c
+++ b/tools/000_gendata/gendata.c
@@ -1,13 +1,10 @@
1#include "../tool.h" 1#include "../tool.h"
2#include "../expected_distributions.h"
3 2
4char *solver; 3char *solver;
5uint64_t *expected;
6 4
7static void 5static void
8run(void) { 6run(void) {
9 int64_t size; 7 int64_t size;
10 bool consistent, expected;
11 char filename[1024], dataid[NISSY_SIZE_DATAID]; 8 char filename[1024], dataid[NISSY_SIZE_DATAID];
12 unsigned char *buf; 9 unsigned char *buf;
13 10
@@ -18,20 +15,14 @@ run(void) {
18 case -2: 15 case -2:
19 goto gendata_run_finish; 16 goto gendata_run_finish;
20 default: 17 default:
21 nissy_datainfo(size, buf); 18 if (nissy_checkdata(solver, size, buf) == NISSY_OK) {
22 consistent = nissy_checkdata(size, buf) == 0;
23 expected = check_distribution(solver, size, buf);
24 if (consistent && expected) {
25 printf("\n"); 19 printf("\n");
26 printf("Generated %" PRId64 " bytes.\n", size); 20 printf("Generated %" PRId64 " bytes.\n", size);
27 sprintf(filename, "tables/%s", dataid); 21 sprintf(filename, "tables/%s", dataid);
28 writetable(buf, size, filename); 22 writetable(buf, size, filename);
23 } else {
24 printf("Error: table generated incorrectly!\n");
29 } 25 }
30 if (!consistent)
31 printf("Error: table is not consistent with info"
32 " (nissy_checkdata() failed)\n");
33 if (!expected)
34 printf("Error: distribution is not as expected\n");
35 break; 26 break;
36 } 27 }
37 28
@@ -40,8 +31,6 @@ gendata_run_finish:
40} 31}
41 32
42int main(int argc, char **argv) { 33int main(int argc, char **argv) {
43 uint8_t h, k;
44
45 if (argc < 2) { 34 if (argc < 2) {
46 printf("Error: not enough arguments. " 35 printf("Error: not enough arguments. "
47 "A solver must be given.\n"); 36 "A solver must be given.\n");
@@ -49,11 +38,7 @@ int main(int argc, char **argv) {
49 } 38 }
50 39
51 solver = argv[1]; 40 solver = argv[1];
52 parse_h48_hk(solver, &h, &k);
53 expected = expected_h48[h][k];
54
55 nissy_setlogger(log_stderr, NULL); 41 nissy_setlogger(log_stderr, NULL);
56
57 timerun(run); 42 timerun(run);
58 43
59 return 0; 44 return 0;
diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c
deleted file mode 100644
index e8db207..0000000
--- a/tools/001_derive_h48/derive_h48.c
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2This tool is specific to the H48 solver. It can be used to derive small
3intermediate tables from larger tables, including the full h11 table.
4
5When using k=2, the base values for the tables may differ. If you want
6to change this value, for example for generating a table with base = 9
7from the h11 table with base = 10, you must re-generate the large table
8with the correct base value. The easiest way to do so is to manually
9edit the base value in the source code and recompile.
10*/
11
12#include "../tool.h"
13
14char *solver_large, *solver_small, *filename_large, *filename_small;
15
16void run(void) {
17 derivedata_run(solver_large, solver_small, filename_large, filename_small);
18}
19
20int main(int argc, char **argv) {
21 if (argc < 5) {
22 printf("Error: not enough arguments. Required:\n"
23 "1. Solver name for large table\n"
24 "2. Solver name for derived table\n"
25 "3. Filename containing large table\n"
26 "4. Filename for saving derived table\n");
27 return 1;
28 }
29
30 solver_large = argv[1];
31 solver_small = argv[2];
32 filename_large = argv[3];
33 filename_small = argv[4];
34
35 nissy_setlogger(log_stderr, NULL);
36
37 timerun(run);
38
39 return 0;
40}
diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c
index c284aa4..3a3c098 100644
--- a/tools/100_checkdata/checkdata.c
+++ b/tools/100_checkdata/checkdata.c
@@ -1,11 +1,11 @@
1#include "../tool.h" 1#include "../tool.h"
2#include "../expected_distributions.h"
3 2
4char *solver, *filename; 3char *solver, *filename;
5 4
6static void 5static void
7run(void) { 6run(void) {
8 long long int size, sizeread, result; 7 bool result;
8 long long int size, sizeread;
9 char dataid[NISSY_SIZE_DATAID]; 9 char dataid[NISSY_SIZE_DATAID];
10 unsigned char *buf; 10 unsigned char *buf;
11 FILE *f; 11 FILE *f;
@@ -25,10 +25,12 @@ run(void) {
25 buf = malloc(size); 25 buf = malloc(size);
26 sizeread = fread(buf, size, 1, f); 26 sizeread = fread(buf, size, 1, f);
27 fclose(f); 27 fclose(f);
28 result = sizeread == 1 && nissy_checkdata(size, buf); 28 if (sizeread != 1)
29 printf("File has unexpected size\n");
30 result = sizeread == 1 && nissy_checkdata(solver, size, buf) == NISSY_OK;
29 free(buf); 31 free(buf);
30 32
31 printf("checkdata %s\n", result == 0 ? "succeeded" : "failed"); 33 printf("checkdata %s\n", result ? "succeeded" : "failed");
32 34
33 /* TODO: cross-check with expected distributions? */ 35 /* TODO: cross-check with expected distributions? */
34} 36}
diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h
deleted file mode 100644
index 1193fb3..0000000
--- a/tools/expected_distributions.h
+++ /dev/null
@@ -1,267 +0,0 @@
1uint64_t expected_cocsep[21] = {
2 [0] = 1,
3 [1] = 6,
4 [2] = 63,
5 [3] = 468,
6 [4] = 3068,
7 [5] = 15438,
8 [6] = 53814,
9 [7] = 71352,
10 [8] = 8784,
11 [9] = 96
12};
13
14uint64_t expected_h48[12][9][21] = {
15 [0] = {
16 [2] = {
17 [0] = 5473562,
18 [1] = 34776317,
19 [2] = 68566704,
20 [3] = 8750867,
21 },
22 [4] = {
23 [0] = 1,
24 [1] = 1,
25 [2] = 4,
26 [3] = 34,
27 [4] = 331,
28 [5] = 3612,
29 [6] = 41605,
30 [7] = 474128,
31 [8] = 4953846,
32 [9] = 34776317,
33 [10] = 68566704,
34 [11] = 8749194,
35 [12] = 1673,
36 },
37 },
38 [1] = {
39 [2] = {
40 [0] = 6012079,
41 [1] = 45822302,
42 [2] = 142018732,
43 [3] = 41281787,
44 },
45 },
46 [2] = {
47 [2] = {
48 [0] = 6391286,
49 [1] = 55494785,
50 [2] = 252389935,
51 [3] = 155993794,
52 },
53 },
54 [3] = {
55 [2] = {
56 [0] = 6686828,
57 [1] = 63867852,
58 [2] = 392789689,
59 [3] = 477195231,
60 },
61 },
62 [4] = {
63 [2] = {
64 [0] = 77147213,
65 [1] = 543379415,
66 [2] = 1139570251,
67 [3] = 120982321,
68 },
69 },
70 [5] = {
71 [2] = {
72 [0] = 82471284,
73 [1] = 687850732,
74 [2] = 2345840746,
75 [3] = 645995638,
76 },
77 },
78 [6] = {
79 [2] = {
80 [0] = 85941099,
81 [1] = 804752968,
82 [2] = 4077248182,
83 [3] = 2556374551,
84 },
85 },
86 [7] = {
87 [2] = {
88 [0] = 88529761,
89 [1] = 897323475,
90 [2] = 6126260791,
91 [3] = 7936519573,
92 },
93 },
94 [8] = {
95 [2] = {
96 [0] = 1051579940,
97 [1] = 8136021316,
98 [2] = 19024479822,
99 [3] = 18851861220,
100 },
101 },
102 [9] = {
103 [2] = {
104 [0] = 1102038189,
105 [1] = 9888265242,
106 [2] = 38299375805,
107 [3] = 10904855164,
108 },
109 },
110 [10] = {
111 [2] = {
112 [0] = 1133240039,
113 [1] = 11196285614,
114 [2] = 64164702961,
115 [3] = 43894840186,
116 },
117 },
118 [11] = {
119 [2] = {
120 [0] = 1150763161,
121 [1] = 12045845660,
122 [2] = 91163433330,
123 [3] = 136418095449,
124 },
125 },
126};
127
128uint64_t expected_eo[21] = {
129 [0] = 1,
130 [1] = 2,
131 [2] = 25,
132 [3] = 202,
133 [4] = 620,
134 [5] = 900,
135 [6] = 285,
136 [7] = 13,
137};
138
139uint64_t expected_dr[21] = {
140 [0] = 1,
141 [1] = 1,
142 [2] = 5,
143 [3] = 44,
144 [4] = 487,
145 [5] = 5841,
146 [6] = 68364,
147 [7] = 776568,
148 [8] = 7950748,
149 [9] = 52098876,
150 [10] = 76236234,
151 [11] = 3771112,
152 [12] = 129,
153};
154
155uint64_t expected_dreo[21] = {
156 [0] = 1,
157 [1] = 1,
158 [2] = 4,
159 [3] = 22,
160 [4] = 160,
161 [5] = 1286,
162 [6] = 8550,
163 [7] = 42152,
164 [8] = 90748,
165 [9] = 33466,
166 [10] = 757,
167};
168
169static bool
170distribution_equal(const uint64_t *expected, const uint64_t *actual, int n)
171{
172 bool equal;
173 int i;
174
175 for (i = 0, equal = true; i <= n; i++) {
176 if (expected[i] != actual[i]) {
177 equal = false;
178 printf("Wrong value for %d: expected %" PRIu64
179 ", actual %" PRIu64 "\n",
180 i, expected[i], actual[i]);
181 }
182 }
183
184 return equal;
185}
186
187STATIC bool
188check_table(uint64_t *exp, tableinfo_t *info)
189{
190 if (!distribution_equal(exp, info->distribution, info->maxvalue)) {
191 printf("ERROR! Distribution is incorrect\n");
192 return false;
193 }
194
195 printf("Distribution is correct\n");
196 return true;
197}
198
199static bool
200check_cocsep(size_t data_size, const unsigned char *data)
201{
202 tableinfo_t info;
203
204 readtableinfo(data_size, data, &info);
205 return distribution_equal(
206 expected_cocsep, info.distribution, info.maxvalue);
207}
208
209static bool
210unknown_h48(uint8_t h, uint8_t k)
211{
212 if (k != 2 && k != 4)
213 return true;
214
215 if (k == 4 && h != 0)
216 return true;
217
218 return k == 2 && h > 7;
219}
220
221STATIC bool
222check_distribution(
223 const char *solver,
224 size_t data_size,
225 const unsigned char *data
226)
227{
228 const char *str;
229 tableinfo_t info = {0};
230
231 if (!strncmp(solver, "h48", 3)) {
232 readtableinfo(data_size, data, &info);
233 if (!distribution_equal(
234 expected_cocsep, info.distribution, info.maxvalue)) {
235 printf("ERROR! cocsep distribution is incorrect\n");
236 return false;
237 }
238 printf("cocsep distribution is correct\n");
239
240 readtableinfo_n(data_size, data, 2, &info);
241 if (unknown_h48(info.h48h, info.bits))
242 goto check_distribution_unknown;
243
244 return check_table(expected_h48[info.h48h][info.bits], &info);
245 }
246
247 if (!strncmp(solver, "coord_", 6)) {
248 readtableinfo(data_size, data, &info);
249 if (!strncmp(info.solver, "coord helper table for ", 23))
250 readtableinfo_n(data_size, data, 2, &info);
251
252 str = info.solver + 22; /* "coordinate solver for COORD" */
253 if (!strcmp(str, "EO")) {
254 return check_table(expected_eo, &info);
255 } else if (!strcmp(str, "DR")) {
256 return check_table(expected_dr, &info);
257 } else if (!strcmp(str, "DREO")) {
258 return check_table(expected_dreo, &info);
259 } else {
260 goto check_distribution_unknown;
261 }
262 }
263
264check_distribution_unknown:
265 printf("Distribution unknown, not checked\n");
266 return true;
267}
diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h
deleted file mode 100644
index 9a7df50..0000000
--- a/tools/nissy_extra.h
+++ /dev/null
@@ -1,14 +0,0 @@
1/*
2This header file exposes certain functions that are meant to be used
3for testing purposes only.
4*/
5
6#define STATIC static
7#define LOG printf
8
9#include "../src/solvers/tables_types_macros.h"
10#include "../src/solvers/tables.h"
11
12size_t gendata_h48_derive(uint8_t, const unsigned char *, unsigned char *);
13long long parse_h48_hk(const char *, uint8_t [static 1], uint8_t [static 1]);
14long long int nissy_datainfo(uint64_t, const unsigned char *);
diff --git a/tools/tool.h b/tools/tool.h
index 225f789..9c55d2b 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -7,19 +7,14 @@
7#include <string.h> 7#include <string.h>
8 8
9#include "../src/nissy.h" 9#include "../src/nissy.h"
10#include "nissy_extra.h"
11 10
12static void log_stderr(const char *, void *); 11static void log_stderr(const char *, void *);
13static double timerun(void (*)(void)); 12static double timerun(void (*)(void));
14static void writetable(const unsigned char *, int64_t, const char *); 13static void writetable(const unsigned char *, int64_t, const char *);
15static long long int generatetable(const char *, unsigned char **, 14static long long int generatetable(const char *, unsigned char **,
16 char [static NISSY_SIZE_DATAID]); 15 char [static NISSY_SIZE_DATAID]);
17static long long int derivetable(
18 const char *, const char *, const char *, unsigned char **);
19static int getdata(const char *, unsigned char **, const char *); 16static int getdata(const char *, unsigned char **, const char *);
20static void gendata_run(const char *, uint64_t[static 21]); 17static void gendata_run(const char *, uint64_t[static 21]);
21static void derivedata_run(
22 const char *, const char *, const char *, const char *);
23 18
24static void 19static void
25log_stderr(const char *str, void *unused) 20log_stderr(const char *str, void *unused)
@@ -100,53 +95,6 @@ generatetable(
100 return gensize; 95 return gensize;
101} 96}
102 97
103static long long int
104derivetable(
105 const char *solver_large,
106 const char *solver_small,
107 const char *filename_large,
108 unsigned char **buf
109)
110{
111 uint8_t h, k;
112 long long int size, gensize;
113 char dataid[NISSY_SIZE_DATAID];
114 unsigned char *fulltable;
115
116 if (getdata(solver_large, &fulltable, filename_large) != 0) {
117 printf("Error reading full table.\n");
118 gensize = -1;
119 goto derivetable_error_nofree;
120 }
121
122 size = nissy_solverinfo(solver_small, dataid);
123 if (size == -1) {
124 printf("Error getting table size.\n");
125 gensize = -2;
126 goto derivetable_error;
127 }
128
129 if (parse_h48_hk(solver_small, &h, &k) != NISSY_OK) {
130 gensize = -3;
131 goto derivetable_error;
132 }
133
134 *buf = malloc(size);
135 gensize = gendata_h48_derive(h, fulltable, *buf);
136
137 if (gensize != size) {
138 printf("Error deriving table\n");
139 gensize = -4;
140 goto derivetable_error;
141 }
142
143derivetable_error:
144 free(fulltable);
145
146derivetable_error_nofree:
147 return gensize;
148}
149
150static int 98static int
151getdata( 99getdata(
152 const char *solver, 100 const char *solver,
@@ -206,8 +154,6 @@ gendata_run(
206 case -2: 154 case -2:
207 goto gendata_run_finish; 155 goto gendata_run_finish;
208 default: 156 default:
209 nissy_datainfo(size, buf);
210 printf("\n");
211 printf("Succesfully generated %lld bytes. " 157 printf("Succesfully generated %lld bytes. "
212 "See above for details on the tables.\n", size); 158 "See above for details on the tables.\n", size);
213 159
@@ -219,35 +165,3 @@ gendata_run(
219gendata_run_finish: 165gendata_run_finish:
220 free(buf); 166 free(buf);
221} 167}
222
223static void
224derivedata_run(
225 const char *solver_large,
226 const char *solver_small,
227 const char *filename_large,
228 const char *filename_small
229)
230{
231 long long int size;
232 unsigned char *buf;
233
234 buf = NULL;
235 size = derivetable(solver_large, solver_small, filename_large, &buf);
236 switch (size) {
237 case -1:
238 return;
239 case -2:
240 goto derivedata_run_finish;
241 default:
242 nissy_datainfo(size, buf);
243 printf("\n");
244 printf("Succesfully generated %lld bytes. "
245 "See above for details on the tables.\n", size);
246
247 writetable(buf, size, filename_small);
248 break;
249 }
250
251derivedata_run_finish:
252 free(buf);
253}

Generated with cgit - Back to sebastiano.tronto.net