From 41be2d294e5b6f55d485d635065096f274bc89c1 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 27 Sep 2024 16:37:55 +0200 Subject: 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). --- tools/001_derive_h48/derive_h48.c | 33 +++++++++++++++++++++++++++++++ tools/001_derive_h48h0k2/derive_h48h0k2.c | 21 -------------------- tools/expected_distributions.h | 8 ++++++++ tools/tool.h | 33 ++++++++++++++++++++----------- 4 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 tools/001_derive_h48/derive_h48.c delete mode 100644 tools/001_derive_h48h0k2/derive_h48h0k2.c (limited to 'tools') 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 @@ +#include "../tool.h" + +char *opts_large, *opts_small, *filename_large, *filename_small; + +void run(void) { + derivedata_run(opts_large, opts_small, filename_large, filename_small); +} + +int main(int argc, char **argv) { + char description[256]; + + if (argc < 5) { + fprintf(stderr, + "Error: not enough arguments. Required:\n" + "1. Options for large table\n" + "2. Options for derived table\n" + "3. Filename containing large table\n" + "4. Filename for saving derived table\n"); + return 1; + } + + opts_large = argv[1]; + opts_small = argv[2]; + filename_large = argv[3]; + filename_small = argv[4]; + sprintf(description, "deriving %s from %s\n", opts_small, opts_large); + + nissy_setlogger(log_stderr); + + timerun(run, description); + + return 0; +} 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 @@ -#include "../tool.h" - -uint64_t expected[21] = { - /* Base value is 8 */ - [0] = 5473562, - [1] = 34776317, - [2] = 68566704, - [3] = 8750867, -}; - -void run(void) { - derivedata_run(0, "tables/h48h0k2_derived", expected); -} - -int main(void) { - nissy_setlogger(log_stderr); - - timerun(run, "benchmark derivedata_h48 h = 0, k = 2"); - - return 0; -} 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] = { [12] = 1673, }, }, + [1] = { + [2] = { + [0] = 6012079, + [1] = 45822302, + [2] = 142018732, + [3] = 41281787, + }, + }, }; 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 *); static void getfilename(const char *, const char *, char *); static void writetable(const char *, int64_t, const char *); static int64_t generatetable(const char *, const char *, char **); -static int64_t derivetable(uint8_t, char **); +static int64_t derivetable(const char *, const char *, const char *, char **); static int getdata(const char *, const char *, char **, const char *); static void gendata_run(const char *, const char *, uint64_t[static 21]); -static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); +static void derivedata_run( + const char *, const char *, const char *, const char *); static void log_stderr(const char *str, ...) @@ -125,27 +126,30 @@ generatetable(const char *solver, const char *options, char **buf) } static int64_t -derivetable(uint8_t h, char **buf) +derivetable( + const char *opts_large, + const char *opts_small, + const char *filename_large, + char **buf +) { + uint8_t h; int64_t size, gensize; char *fulltable; - char options[20] = " ;2;20"; /* Only for k = 2 for now */ - options[0] = (char)(h + '0'); /* h = 10 not supported for now */ - - /* Support only b8 for now */ - if (getdata("h48", "11;2;20", &fulltable, "tables/h48h11k2_b8") != 0) { + if (getdata("h48", opts_large, &fulltable, filename_large) != 0) { printf("Error reading full table.\n"); return -1; } - size = nissy_datasize("h48", options); + size = nissy_datasize("h48", opts_small); if (size == -1) { printf("Error getting table size.\n"); free(fulltable); return -1; } + h = atoi(opts_small); /* TODO: use option parser */ *buf = malloc(size); gensize = gendata_h48_derive(h, fulltable, *buf); @@ -233,12 +237,17 @@ gendata_run_finish: } static void -derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) +derivedata_run( + const char *opts_large, + const char *opts_small, + const char *filename_large, + const char *filename_small +) { int64_t size; char *buf; - size = derivetable(h, &buf); + size = derivetable(opts_large, opts_small, filename_large, &buf); switch (size) { case -1: return; @@ -250,7 +259,7 @@ derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) printf("Succesfully generated %" PRId64 " bytes. " "See above for details on the tables.\n", size); - writetable(buf, size, filename); + writetable(buf, size, filename_small); break; } -- cgit v1.3