diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-27 08:19:53 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-27 08:19:53 +0200 |
| commit | 0b32395de2500ad87e15fbb0ff4a852e313037e9 (patch) | |
| tree | 2607145be078cfac3b8f6b982c1b63352ebaf79e /tools | |
| parent | bb09e52a7481718ae1fe324d16b99970450908f8 (diff) | |
| download | nissy-core-0b32395de2500ad87e15fbb0ff4a852e313037e9.tar.gz nissy-core-0b32395de2500ad87e15fbb0ff4a852e313037e9.zip | |
First try for derive tables
Diffstat (limited to '')
| -rw-r--r-- | tools/1002_derive_h48h0k2/derive_h48h0k2.c | 21 | ||||
| -rw-r--r-- | tools/nissy_extra.h | 6 | ||||
| -rw-r--r-- | tools/tool.h | 64 |
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 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 5473562, | ||
| 6 | [1] = 34776317, | ||
| 7 | [2] = 68566704, | ||
| 8 | [3] = 8750867, | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | derivedata_run(0, "tables/h48h0k2_derived", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int 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 | /* | ||
| 2 | This header file exposes certain functions that are meant to be used | ||
| 3 | for testing purposes only. | ||
| 4 | */ | ||
| 5 | |||
| 6 | 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 @@ | |||
| 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 | ||
| 10 | static void log_stderr(const char *, ...); | 11 | static void log_stderr(const char *, ...); |
| 11 | static void log_stdout(const char *, ...); | 12 | static void log_stdout(const char *, ...); |
| 12 | static double timerun(void (*)(void), const char *); | 13 | static double timerun(void (*)(void), const char *); |
| 13 | static void writetable(const char *, int64_t, const char *); | 14 | static void writetable(const char *, int64_t, const char *); |
| 14 | static int64_t generatetable(const char *, const char *, char **); | 15 | static int64_t generatetable(const char *, const char *, char **); |
| 16 | static int64_t derivetable(uint8_t, char **); | ||
| 15 | static int getdata(const char *, const char *, char **, const char *); | 17 | static int getdata(const char *, const char *, char **, const char *); |
| 16 | static void gendata_run(const char *, const char *, const char *, uint64_t[static 21]); | 18 | static void gendata_run(const char *, const char *, const char *, uint64_t[static 21]); |
| 19 | static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); | ||
| 17 | 20 | ||
| 18 | static void | 21 | static void |
| 19 | log_stderr(const char *str, ...) | 22 | log_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 | ||
| 115 | static int64_t | ||
| 116 | derivetable(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 | |||
| 112 | static int | 150 | static int |
| 113 | getdata( | 151 | getdata( |
| 114 | const char *solver, | 152 | const char *solver, |
| @@ -182,3 +220,29 @@ gendata_run( | |||
| 182 | gendata_run_finish: | 220 | gendata_run_finish: |
| 183 | free(buf); | 221 | free(buf); |
| 184 | } | 222 | } |
| 223 | |||
| 224 | static void | ||
| 225 | derivedata_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 | |||
| 246 | derivedata_run_finish: | ||
| 247 | free(buf); | ||
| 248 | } | ||
