From 0b32395de2500ad87e15fbb0ff4a852e313037e9 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 27 Sep 2024 08:19:53 +0200 Subject: First try for derive tables --- tools/1002_derive_h48h0k2/derive_h48h0k2.c | 21 ++++++++++ tools/nissy_extra.h | 6 +++ tools/tool.h | 64 ++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 tools/1002_derive_h48h0k2/derive_h48h0k2.c create mode 100644 tools/nissy_extra.h (limited to 'tools') 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 @@ +#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/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 @@ +/* +This header file exposes certain functions that are meant to be used +for testing purposes only. +*/ + +size_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 @@ #include #include "../src/nissy.h" +#include "nissy_extra.h" static void log_stderr(const char *, ...); static void log_stdout(const char *, ...); static double timerun(void (*)(void), const 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 int getdata(const char *, const char *, char **, const char *); static void gendata_run(const char *, const char *, const char *, uint64_t[static 21]); +static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); static void log_stderr(const char *str, ...) @@ -109,6 +112,41 @@ generatetable(const char *solver, const char *options, char **buf) return gensize; } +static int64_t +derivetable(uint8_t h, char **buf) +{ + int64_t size, gensize; + char *fulltable; + + char options[20] = " ;2;20"; /* Fixed 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) { + printf("Error reading full table.\n"); + return -1; + } + + size = nissy_datasize("h48", options); + if (size == -1) { + printf("Error getting table size.\n"); + free(fulltable); + return -1; + } + + *buf = malloc(size); + gensize = gendata_h48_derive(h, fulltable, *buf); + + if (gensize != size) { + fprintf(stderr, "Error deriving table\n"); + free(fulltable); + return -2; + } + + free(fulltable); + return gensize; +} + static int getdata( const char *solver, @@ -182,3 +220,29 @@ gendata_run( gendata_run_finish: free(buf); } + +static void +derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) +{ + int64_t size; + char *buf; + + size = derivetable(h, &buf); + switch (size) { + case -1: + return; + case -2: + goto derivedata_run_finish; + default: + nissy_datainfo(buf, write_stdout); + printf("\n"); + printf("Succesfully generated %" PRId64 " bytes. " + "See above for details on the tables.\n", size); + + writetable(buf, size, filename); + break; + } + +derivedata_run_finish: + free(buf); +} -- cgit v1.3