diff options
Diffstat (limited to 'tools')
| -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 | 65 |
3 files changed, 90 insertions, 2 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 index 17906d4..1e714a7 100644 --- a/tools/nissy_extra.h +++ b/tools/nissy_extra.h | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | /* Intended only for tools */ | 1 | /* |
| 2 | This header file exposes certain functions that are meant to be used | ||
| 3 | for testing purposes only. | ||
| 4 | */ | ||
| 2 | 5 | ||
| 6 | size_t gendata_h48_derive(uint8_t, const void *, void *); | ||
| 3 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 7 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); |
diff --git a/tools/tool.h b/tools/tool.h index 18b8ce9..5eec318 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -14,8 +14,10 @@ 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 int getdata(const char *, const char *, char **, const char *); | 18 | static int getdata(const char *, const char *, char **, const char *); |
| 18 | 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]); | ||
| 19 | 21 | ||
| 20 | static void | 22 | static void |
| 21 | log_stderr(const char *str, ...) | 23 | log_stderr(const char *str, ...) |
| @@ -122,6 +124,41 @@ generatetable(const char *solver, const char *options, char **buf) | |||
| 122 | return gensize; | 124 | return gensize; |
| 123 | } | 125 | } |
| 124 | 126 | ||
| 127 | static int64_t | ||
| 128 | derivetable(uint8_t h, char **buf) | ||
| 129 | { | ||
| 130 | int64_t size, gensize; | ||
| 131 | char *fulltable; | ||
| 132 | |||
| 133 | char options[20] = " ;2;20"; /* Fixed for k = 2 for now */ | ||
| 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"); | ||
| 139 | return -1; | ||
| 140 | } | ||
| 141 | |||
| 142 | size = nissy_datasize("h48", options); | ||
| 143 | if (size == -1) { | ||
| 144 | printf("Error getting table size.\n"); | ||
| 145 | free(fulltable); | ||
| 146 | return -1; | ||
| 147 | } | ||
| 148 | |||
| 149 | *buf = malloc(size); | ||
| 150 | gensize = gendata_h48_derive(h, fulltable, *buf); | ||
| 151 | |||
| 152 | if (gensize != size) { | ||
| 153 | fprintf(stderr, "Error deriving table\n"); | ||
| 154 | free(fulltable); | ||
| 155 | return -2; | ||
| 156 | } | ||
| 157 | |||
| 158 | free(fulltable); | ||
| 159 | return gensize; | ||
| 160 | } | ||
| 161 | |||
| 125 | static int | 162 | static int |
| 126 | getdata( | 163 | getdata( |
| 127 | const char *solver, | 164 | const char *solver, |
| @@ -194,3 +231,29 @@ gendata_run( | |||
| 194 | gendata_run_finish: | 231 | gendata_run_finish: |
| 195 | free(buf); | 232 | free(buf); |
| 196 | } | 233 | } |
| 234 | |||
| 235 | static void | ||
| 236 | derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) | ||
| 237 | { | ||
| 238 | int64_t size; | ||
| 239 | char *buf; | ||
| 240 | |||
| 241 | size = derivetable(h, &buf); | ||
| 242 | switch (size) { | ||
| 243 | case -1: | ||
| 244 | return; | ||
| 245 | case -2: | ||
| 246 | goto derivedata_run_finish; | ||
| 247 | default: | ||
| 248 | nissy_datainfo(buf, write_stdout); | ||
| 249 | printf("\n"); | ||
| 250 | printf("Succesfully generated %" PRId64 " bytes. " | ||
| 251 | "See above for details on the tables.\n", size); | ||
| 252 | |||
| 253 | writetable(buf, size, filename); | ||
| 254 | break; | ||
| 255 | } | ||
| 256 | |||
| 257 | derivedata_run_finish: | ||
| 258 | free(buf); | ||
| 259 | } | ||
