diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-27 16:37:55 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-27 16:37:55 +0200 |
| commit | 41be2d294e5b6f55d485d635065096f274bc89c1 (patch) | |
| tree | d1906840307eedc503e66f6aebf746717f57d1ed /tools/tool.h | |
| parent | 15fe089b3e625cb6d3a19dee661f4fc9c6224699 (diff) | |
| download | nissy-core-41be2d294e5b6f55d485d635065096f274bc89c1.tar.gz nissy-core-41be2d294e5b6f55d485d635065096f274bc89c1.zip | |
Made table derivation tool more flexible
So apparently my RAM is broken. That took me a while to figure out.
While I get a replacement, I have to restrict myself to a weaker
test for the intermediate tables: instead of deriving them from
the huge table and checking that they are the same, I have to derive
a small h0k2 table from the intermediate ones and check that it is
correct. This is not a 100% proof of correctness, but it is good
enough (and much faster).
Diffstat (limited to '')
| -rw-r--r-- | tools/tool.h | 33 |
1 files changed, 21 insertions, 12 deletions
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 *); | |||
| 14 | static void getfilename(const char *, const char *, char *); | 14 | static void getfilename(const char *, const char *, char *); |
| 15 | static void writetable(const char *, int64_t, const char *); | 15 | static void writetable(const char *, int64_t, const char *); |
| 16 | static int64_t generatetable(const char *, const char *, char **); | 16 | static int64_t generatetable(const char *, const char *, char **); |
| 17 | static int64_t derivetable(uint8_t, char **); | 17 | static int64_t derivetable(const char *, const char *, const char *, char **); |
| 18 | static int getdata(const char *, const char *, char **, const char *); | 18 | static int getdata(const char *, const char *, char **, const char *); |
| 19 | static void gendata_run(const char *, const char *, uint64_t[static 21]); | 19 | static void gendata_run(const char *, const char *, uint64_t[static 21]); |
| 20 | static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); | 20 | static void derivedata_run( |
| 21 | const char *, const char *, const char *, const char *); | ||
| 21 | 22 | ||
| 22 | static void | 23 | static void |
| 23 | log_stderr(const char *str, ...) | 24 | log_stderr(const char *str, ...) |
| @@ -125,27 +126,30 @@ generatetable(const char *solver, const char *options, char **buf) | |||
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | static int64_t | 128 | static int64_t |
| 128 | derivetable(uint8_t h, char **buf) | 129 | derivetable( |
| 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 | ||
| 235 | static void | 239 | static void |
| 236 | derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) | 240 | derivedata_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 | ||
