diff options
| author | enricotenuti <tenutz_27@outlook.it> | 2024-09-29 12:42:31 +0200 |
|---|---|---|
| committer | enricotenuti <tenutz_27@outlook.it> | 2024-09-29 12:42:31 +0200 |
| commit | 7a52b4cd50a40e4bce919b6bd51203d0e9867141 (patch) | |
| tree | 95ab133f9771c4791d5c784f1b3d4822b1dd7d3c | |
| parent | 8fcfb3a33fe053ed2032d58ecc0b5d640c155931 (diff) | |
| parent | 774a824a6c80b5af495f4fb99d98758e3b9f6b81 (diff) | |
| download | nissy-core-7a52b4cd50a40e4bce919b6bd51203d0e9867141.tar.gz nissy-core-7a52b4cd50a40e4bce919b6bd51203d0e9867141.zip | |
Merge remote-tracking branch 'upstream/master'
Merge upstream
Diffstat (limited to '')
33 files changed, 538 insertions, 347 deletions
| @@ -14,6 +14,7 @@ test/run | |||
| 14 | test/run.DSYM | 14 | test/run.DSYM |
| 15 | tools/.DS_Store | 15 | tools/.DS_Store |
| 16 | run.DSYM | 16 | run.DSYM |
| 17 | run.core | ||
| 17 | test/last.* | 18 | test/last.* |
| 18 | tools/results | 19 | tools/results |
| 19 | .vscode | 20 | .vscode |
| @@ -61,7 +61,7 @@ The results of the last test case run is saved in test/last.out (standard | |||
| 61 | output, the results compared with the .out files) and test/last.err | 61 | output, the results compared with the .out files) and test/last.err |
| 62 | (standard error). | 62 | (standard error). |
| 63 | 63 | ||
| 64 | Tests are always run in "debug mode": this means that optimizations are | 64 | Tests are always run in debug mode: this means that optimizations are |
| 65 | disabled and some extra logging is enabled. | 65 | disabled and some extra logging is enabled. |
| 66 | 66 | ||
| 67 | See the test folder and test/test.sh for details. | 67 | See the test folder and test/test.sh for details. |
| @@ -70,7 +70,7 @@ See the test folder and test/test.sh for details. | |||
| 70 | 70 | ||
| 71 | In the tools folder there are some small programs that test various | 71 | In the tools folder there are some small programs that test various |
| 72 | functionality of the H48 library. They work similarly to test, but they | 72 | functionality of the H48 library. They work similarly to test, but they |
| 73 | are not run in debug mode. | 73 | are not run in debug mode by default. |
| 74 | 74 | ||
| 75 | To run a tool you must select it with the environment variable `TOOL`. | 75 | To run a tool you must select it with the environment variable `TOOL`. |
| 76 | For example the command: | 76 | For example the command: |
| @@ -79,14 +79,26 @@ For example the command: | |||
| 79 | TOOL=stats make tool | 79 | TOOL=stats make tool |
| 80 | ``` | 80 | ``` |
| 81 | 81 | ||
| 82 | Will run the stats_tables_h48 tool. Like for tests, the value of the | 82 | Will run the stats_tables_h48 tool. |
| 83 | `TOOL` variable can be any regular expression matching the name of the | 83 | |
| 84 | tool. Unlike tests, one and only one tool will be selected for each run. | 84 | To pass some arguments to a tool, use the `TOOLARGS` variable: |
| 85 | |||
| 86 | ``` | ||
| 87 | TOOL=gendata TOOLARGS="h48 0;2;20" make tool | ||
| 88 | ``` | ||
| 89 | |||
| 90 | Like for tests, the value of the `TOOL` variable can be any regular | ||
| 91 | expression matching the name of the tool. Unlike tests, one and | ||
| 92 | only one tool will be selected for each run. The content of the | ||
| 93 | `TOOLARGS` variable is used directly as command line arguments for | ||
| 94 | the chosen tool. | ||
| 85 | 95 | ||
| 86 | Each tool run is automatically timed, so these tools can be used as | 96 | Each tool run is automatically timed, so these tools can be used as |
| 87 | benchmark. The output as well as the time of the run are saved to a | 97 | benchmark. The output as well as the time of the run are saved to a |
| 88 | file in the tools/results folder. | 98 | file in the tools/results folder. |
| 89 | 99 | ||
| 100 | To build and run a tool in debug mode, use `make debugtool`. | ||
| 101 | |||
| 90 | ## Running commands manually | 102 | ## Running commands manually |
| 91 | 103 | ||
| 92 | This project also includes a rudimentary shell that can be used to run | 104 | This project also includes a rudimentary shell that can be used to run |
diff --git a/configure.sh b/configure.sh index e61a163..2b2f40b 100755 --- a/configure.sh +++ b/configure.sh | |||
| @@ -22,10 +22,10 @@ | |||
| 22 | # SANITIZE="option1,option2,..." | 22 | # SANITIZE="option1,option2,..." |
| 23 | # Add the options "-fsanitize=option1", "-fsanitize=option2", ... to the | 23 | # Add the options "-fsanitize=option1", "-fsanitize=option2", ... to the |
| 24 | # compilation command when compiling in debug mode. | 24 | # compilation command when compiling in debug mode. |
| 25 | # By default, "-fsanitize=address" and "-fsanitize=undefined" will be used, | 25 | # By default, "-fsanitize=address" and "-fsanitize=undefined" will be used. |
| 26 | # if available. If this variable is set, the default is overridden. | 26 | # If this variable is set, the default is overridden. No check is performed |
| 27 | # No check is performed on the given sanitizers, make sure that the ones you | 27 | # on the availability of any sanitizer used, make sure the ones you use are |
| 28 | # choose are available on your system and compatible with each other. | 28 | # available on your system. |
| 29 | # | 29 | # |
| 30 | # Examples | 30 | # Examples |
| 31 | # | 31 | # |
| @@ -39,10 +39,6 @@ greparch() { | |||
| 39 | $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1" | 39 | $CC -march=native -dM -E - </dev/null 2>/dev/null | grep "$1" |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | grepsan() { | ||
| 43 | $CC -fsanitize="$1" -dM -E -x c - </dev/null 2>/dev/null | grep "SANITIZE" | ||
| 44 | } | ||
| 45 | |||
| 46 | detectthreads() { | 42 | detectthreads() { |
| 47 | echo 16 # TODO: choose based on system | 43 | echo 16 # TODO: choose based on system |
| 48 | } | 44 | } |
| @@ -100,10 +96,7 @@ if [ -n "$SANITIZE" ]; then | |||
| 100 | SAN="$SAN -fsanitize=$san" | 96 | SAN="$SAN -fsanitize=$san" |
| 101 | done | 97 | done |
| 102 | else | 98 | else |
| 103 | # No sanitizer specified, use "address" and "undefined" if present | 99 | SAN="-fsanitize=address -fsanitize=undefined" |
| 104 | [ -n "$(grepsan address)" ] && ADDR="-fsanitize=address" | ||
| 105 | [ -n "$(grepsan undefined)" ] && UNDEF="-fsanitize=undefined" | ||
| 106 | SAN="$ADDR $UNDEF" | ||
| 107 | fi | 100 | fi |
| 108 | LIBS="-lpthread" | 101 | LIBS="-lpthread" |
| 109 | 102 | ||
diff --git a/src/nissy.c b/src/nissy.c index a2da73d..44efb83 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -12,8 +12,11 @@ | |||
| 12 | 12 | ||
| 13 | #include "nissy.h" | 13 | #include "nissy.h" |
| 14 | 14 | ||
| 15 | STATIC int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 15 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); |
| 16 | STATIC int64_t write_result(cube_t, char [static 22]); | 16 | STATIC int64_t write_result(cube_t, char [static 22]); |
| 17 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | ||
| 18 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); | ||
| 19 | STATIC bool checkdata(const void *, const tableinfo_t *); | ||
| 17 | 20 | ||
| 18 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ | 21 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ |
| 19 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } | 22 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } |
| @@ -25,7 +28,7 @@ struct { | |||
| 25 | GETCUBE_OPTIONS(NULL, NULL) | 28 | GETCUBE_OPTIONS(NULL, NULL) |
| 26 | }; | 29 | }; |
| 27 | 30 | ||
| 28 | STATIC int | 31 | int |
| 29 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) | 32 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) |
| 30 | { | 33 | { |
| 31 | bool h_valid, k_valid, maxdepth_valid; | 34 | bool h_valid, k_valid, maxdepth_valid; |
| @@ -63,6 +66,52 @@ parse_h48_options_error: | |||
| 63 | return -1; | 66 | return -1; |
| 64 | } | 67 | } |
| 65 | 68 | ||
| 69 | STATIC bool | ||
| 70 | checkdata(const void *buf, const tableinfo_t *info) | ||
| 71 | { | ||
| 72 | uint64_t distr[INFO_DISTRIBUTION_LEN]; | ||
| 73 | |||
| 74 | if (!strncmp(info->solver, "cocsep", 6)) { | ||
| 75 | getdistribution_cocsep( | ||
| 76 | (uint32_t *)((char *)buf + INFOSIZE), distr); | ||
| 77 | } else if (!strncmp(info->solver, "h48", 3)) { | ||
| 78 | getdistribution_h48((uint8_t *)buf + INFOSIZE, distr, | ||
| 79 | info->h48h, info->bits); | ||
| 80 | } else { | ||
| 81 | LOG("checkdata: unknown solver %s\n", info->solver); | ||
| 82 | return false; | ||
| 83 | } | ||
| 84 | |||
| 85 | return distribution_equal(info->distribution, distr, info->maxvalue); | ||
| 86 | } | ||
| 87 | |||
| 88 | STATIC bool | ||
| 89 | distribution_equal( | ||
| 90 | const uint64_t expected[static INFO_DISTRIBUTION_LEN], | ||
| 91 | const uint64_t actual[static INFO_DISTRIBUTION_LEN], | ||
| 92 | uint8_t maxvalue | ||
| 93 | ) | ||
| 94 | { | ||
| 95 | int wrong; | ||
| 96 | uint8_t i; | ||
| 97 | |||
| 98 | for (i = 0, wrong = 0; i <= MAX(maxvalue, 20); i++) { | ||
| 99 | if (expected[i] != actual[i]) { | ||
| 100 | wrong++; | ||
| 101 | LOG("Value %" PRIu8 ": expected %" PRIu64 ", found %" | ||
| 102 | PRIu64 "\n", i, expected[i], actual[i]); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | if (wrong > 0) { | ||
| 107 | LOG("checkdata: %d wrong values\n", wrong); | ||
| 108 | } else { | ||
| 109 | LOG("checkdata: table is consistent with info\n"); | ||
| 110 | } | ||
| 111 | |||
| 112 | return wrong > 0; | ||
| 113 | } | ||
| 114 | |||
| 66 | STATIC int64_t | 115 | STATIC int64_t |
| 67 | write_result(cube_t cube, char result[static 22]) | 116 | write_result(cube_t cube, char result[static 22]) |
| 68 | { | 117 | { |
| @@ -276,6 +325,26 @@ nissy_gendata( | |||
| 276 | } | 325 | } |
| 277 | 326 | ||
| 278 | int64_t | 327 | int64_t |
| 328 | nissy_checkdata( | ||
| 329 | const char *solver, | ||
| 330 | const char *options, | ||
| 331 | const void *data | ||
| 332 | ) | ||
| 333 | { | ||
| 334 | char *buf; | ||
| 335 | tableinfo_t info; | ||
| 336 | |||
| 337 | for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) { | ||
| 338 | if (!checkdata(buf, &info)) | ||
| 339 | return 1; | ||
| 340 | if (info.next == 0) | ||
| 341 | break; | ||
| 342 | } | ||
| 343 | |||
| 344 | return 0; | ||
| 345 | } | ||
| 346 | |||
| 347 | int64_t | ||
| 279 | nissy_solve( | 348 | nissy_solve( |
| 280 | const char cube[static 22], | 349 | const char cube[static 22], |
| 281 | const char *solver, | 350 | const char *solver, |
diff --git a/src/nissy.h b/src/nissy.h index 336130c..0545556 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -86,6 +86,19 @@ int64_t nissy_gendata( | |||
| 86 | void *generated_data | 86 | void *generated_data |
| 87 | ); | 87 | ); |
| 88 | 88 | ||
| 89 | /* Temporarily added to test h48 intermediate tables */ | ||
| 90 | int64_t nissy_derivedata( | ||
| 91 | const char *options, | ||
| 92 | const void *fulltable, | ||
| 93 | void *generated_data | ||
| 94 | ); | ||
| 95 | |||
| 96 | int64_t nissy_checkdata( | ||
| 97 | const char *solver, | ||
| 98 | const char *options, | ||
| 99 | const void *data | ||
| 100 | ); | ||
| 101 | |||
| 89 | /* Print information on a data table via the provided callback writer */ | 102 | /* Print information on a data table via the provided callback writer */ |
| 90 | int64_t nissy_datainfo( | 103 | int64_t nissy_datainfo( |
| 91 | const void *table, | 104 | const void *table, |
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index 2189145..262793b 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h | |||
| @@ -25,6 +25,7 @@ STATIC_INLINE void set_visited(uint8_t *, int64_t); | |||
| 25 | 25 | ||
| 26 | STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *); | 26 | STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *); |
| 27 | STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); | 27 | STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); |
| 28 | STATIC void getdistribution_cocsep(const uint32_t *, uint64_t [static 21]); | ||
| 28 | 29 | ||
| 29 | STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); | 30 | STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); |
| 30 | 31 | ||
| @@ -157,6 +158,17 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) | |||
| 157 | return cc; | 158 | return cc; |
| 158 | } | 159 | } |
| 159 | 160 | ||
| 161 | STATIC void | ||
| 162 | getdistribution_cocsep(const uint32_t *table, uint64_t distr[static 21]) | ||
| 163 | { | ||
| 164 | size_t i; | ||
| 165 | |||
| 166 | memset(distr, 0, 21 * sizeof(uint64_t)); | ||
| 167 | |||
| 168 | for (i = 0; i < COCSEP_TABLESIZE; i++) | ||
| 169 | distr[CBOUND(table[i])]++; | ||
| 170 | } | ||
| 171 | |||
| 160 | STATIC_INLINE bool | 172 | STATIC_INLINE bool |
| 161 | get_visited(const uint8_t *a, int64_t i) | 173 | get_visited(const uint8_t *a, int64_t i) |
| 162 | { | 174 | { |
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 3445570..75b7abf 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -103,14 +103,19 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); | |||
| 103 | STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); | 103 | STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); |
| 104 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); | 104 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); |
| 105 | STATIC void * gendata_h48k2_runthread(void *); | 105 | STATIC void * gendata_h48k2_runthread(void *); |
| 106 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t); | 106 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); |
| 107 | STATIC void getdistribution_h48(const uint8_t *, | ||
| 108 | uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); | ||
| 107 | 109 | ||
| 108 | STATIC uint32_t *get_cocsepdata_ptr(const void *); | 110 | STATIC uint32_t *get_cocsepdata_ptr(const void *); |
| 109 | STATIC uint8_t *get_h48data_ptr(const void *); | 111 | STATIC uint8_t *get_h48data_ptr(const void *); |
| 110 | 112 | ||
| 111 | STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); | 113 | STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); |
| 112 | STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); | 114 | STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); |
| 113 | STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); | 115 | STATIC_INLINE uint8_t get_h48_bound( |
| 116 | cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); | ||
| 117 | |||
| 118 | size_t gendata_h48_derive(uint8_t, const void *, void *); | ||
| 114 | 119 | ||
| 115 | STATIC uint64_t | 120 | STATIC uint64_t |
| 116 | gendata_h48short(gendata_h48short_arg_t *arg) | 121 | gendata_h48short(gendata_h48short_arg_t *arg) |
| @@ -387,7 +392,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 387 | [11] = 10 | 392 | [11] = 10 |
| 388 | }; | 393 | }; |
| 389 | 394 | ||
| 390 | uint8_t t, selectedbase, *table; | 395 | uint8_t t, *table; |
| 391 | int64_t j; | 396 | int64_t j; |
| 392 | uint64_t i, ii, inext, count; | 397 | uint64_t i, ii, inext, count; |
| 393 | h48map_t shortcubes; | 398 | h48map_t shortcubes; |
| @@ -414,8 +419,9 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 414 | }; | 419 | }; |
| 415 | gendata_h48short(&shortarg); | 420 | gendata_h48short(&shortarg); |
| 416 | 421 | ||
| 417 | selectedbase = arg->base < 20 ? arg->base : base[arg->h]; | 422 | if (arg->base >= 20) |
| 418 | arg->info = makeinfo_h48k2(arg, selectedbase); | 423 | arg->base = base[arg->h]; |
| 424 | arg->info = makeinfo_h48k2(arg); | ||
| 419 | 425 | ||
| 420 | inext = count = 0; | 426 | inext = count = 0; |
| 421 | pthread_mutex_init(&shortcubes_mutex, NULL); | 427 | pthread_mutex_init(&shortcubes_mutex, NULL); |
| @@ -425,7 +431,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 425 | dfsarg[i] = (h48k2_dfs_arg_t){ | 431 | dfsarg[i] = (h48k2_dfs_arg_t){ |
| 426 | .h = arg->h, | 432 | .h = arg->h, |
| 427 | .k = arg->k, | 433 | .k = arg->k, |
| 428 | .base = selectedbase, | 434 | .base = arg->base, |
| 429 | .shortdepth = shortdepth, | 435 | .shortdepth = shortdepth, |
| 430 | .cocsepdata = arg->cocsepdata, | 436 | .cocsepdata = arg->cocsepdata, |
| 431 | .table = table, | 437 | .table = table, |
| @@ -603,14 +609,17 @@ STATIC_INLINE bool | |||
| 603 | gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) | 609 | gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) |
| 604 | { | 610 | { |
| 605 | uint64_t val; | 611 | uint64_t val; |
| 606 | int64_t coord; | 612 | int64_t coord, mutex; |
| 607 | int8_t oldval; | 613 | int8_t oldval; |
| 608 | 614 | ||
| 609 | if (arg->h == 0 || arg->h == 11) { | 615 | if (arg->h == 0 || arg->h == 11) { |
| 610 | /* We are in the "real coordinate" case, we can stop | 616 | /* We are in the "real coordinate" case, we can stop |
| 611 | if this coordinate has already been visited */ | 617 | if this coordinate has already been visited */ |
| 612 | coord = coord_h48(cube, arg->cocsepdata, arg->h); | 618 | coord = coord_h48(cube, arg->cocsepdata, arg->h); |
| 619 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | ||
| 620 | pthread_mutex_lock(arg->table_mutex[mutex]); | ||
| 613 | oldval = get_h48_pval(arg->table, coord, arg->k); | 621 | oldval = get_h48_pval(arg->table, coord, arg->k); |
| 622 | pthread_mutex_unlock(arg->table_mutex[mutex]); | ||
| 614 | return oldval <= depth; | 623 | return oldval <= depth; |
| 615 | } else { | 624 | } else { |
| 616 | /* With 0 < k < 11 we do not have a "real coordinate". | 625 | /* With 0 < k < 11 we do not have a "real coordinate". |
| @@ -637,7 +646,7 @@ gendata_h48k2_realcoord_runthread(void *arg) | |||
| 637 | } | 646 | } |
| 638 | 647 | ||
| 639 | STATIC tableinfo_t | 648 | STATIC tableinfo_t |
| 640 | makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | 649 | makeinfo_h48k2(gendata_h48_arg_t *arg) |
| 641 | { | 650 | { |
| 642 | tableinfo_t info; | 651 | tableinfo_t info; |
| 643 | 652 | ||
| @@ -651,7 +660,7 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | |||
| 651 | .classes = 0, | 660 | .classes = 0, |
| 652 | .h48h = arg->h, | 661 | .h48h = arg->h, |
| 653 | .bits = 2, | 662 | .bits = 2, |
| 654 | .base = base, | 663 | .base = arg->base, |
| 655 | .maxvalue = 3, | 664 | .maxvalue = 3, |
| 656 | .next = 0, | 665 | .next = 0, |
| 657 | }; | 666 | }; |
| @@ -662,6 +671,25 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | |||
| 662 | return info; | 671 | return info; |
| 663 | } | 672 | } |
| 664 | 673 | ||
| 674 | STATIC void | ||
| 675 | getdistribution_h48( | ||
| 676 | const uint8_t *table, | ||
| 677 | uint64_t distr[static INFO_DISTRIBUTION_LEN], | ||
| 678 | uint8_t h, | ||
| 679 | uint8_t k | ||
| 680 | ) { | ||
| 681 | uint8_t val; | ||
| 682 | int64_t i, h48max; | ||
| 683 | |||
| 684 | memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 685 | |||
| 686 | h48max = H48_COORDMAX(h); | ||
| 687 | for (i = 0; i < h48max; i++) { | ||
| 688 | val = get_h48_pval(table, i, k); | ||
| 689 | distr[val]++; | ||
| 690 | } | ||
| 691 | } | ||
| 692 | |||
| 665 | STATIC uint32_t * | 693 | STATIC uint32_t * |
| 666 | get_cocsepdata_ptr(const void *data) | 694 | get_cocsepdata_ptr(const void *data) |
| 667 | { | 695 | { |
| @@ -695,3 +723,77 @@ get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table) | |||
| 695 | coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); | 723 | coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); |
| 696 | return get_h48_pval(table, coord, k); | 724 | return get_h48_pval(table, coord, k); |
| 697 | } | 725 | } |
| 726 | |||
| 727 | size_t | ||
| 728 | gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | ||
| 729 | { | ||
| 730 | size_t cocsepsize, h48size; | ||
| 731 | uint8_t val_full, val_derive, *h48full, *h48derive; | ||
| 732 | int64_t i, j, h48max; | ||
| 733 | gendata_h48_arg_t arg; | ||
| 734 | tableinfo_t cocsepinfo, fulltableinfo; | ||
| 735 | |||
| 736 | /* Initializing values in case of error */ | ||
| 737 | /* TODO cleanup this */ | ||
| 738 | fulltableinfo.bits = 2; | ||
| 739 | fulltableinfo.base = 8; | ||
| 740 | |||
| 741 | readtableinfo_n(fulltable, 2, &fulltableinfo); | ||
| 742 | arg.h = h; | ||
| 743 | arg.k = fulltableinfo.bits; | ||
| 744 | arg.maxdepth = 20; | ||
| 745 | arg.buf = buf; | ||
| 746 | arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); | ||
| 747 | arg.base = fulltableinfo.base; | ||
| 748 | arg.info = makeinfo_h48k2(&arg); | ||
| 749 | |||
| 750 | /* Technically this step is redundant, except that we | ||
| 751 | need selfsim and crep */ | ||
| 752 | cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); | ||
| 753 | arg.h48buf = (uint8_t *)buf + cocsepsize; | ||
| 754 | h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; | ||
| 755 | |||
| 756 | if (buf == NULL) | ||
| 757 | goto gendata_h48_derive_return_size; | ||
| 758 | |||
| 759 | if (!readtableinfo(buf, &cocsepinfo)) { | ||
| 760 | LOG("gendata_h48: could not read info for cocsep table\n"); | ||
| 761 | goto gendata_h48_derive_error; | ||
| 762 | } | ||
| 763 | |||
| 764 | cocsepinfo.next = cocsepsize; | ||
| 765 | if (!writetableinfo(&cocsepinfo, buf)) { | ||
| 766 | LOG("gendata_h48_derive: could not write info for cocsep table" | ||
| 767 | " with updated 'next' value\n"); | ||
| 768 | goto gendata_h48_derive_error; | ||
| 769 | } | ||
| 770 | |||
| 771 | h48full = (uint8_t *)fulltable + cocsepsize + INFOSIZE; | ||
| 772 | h48derive = (uint8_t *)arg.h48buf + INFOSIZE; | ||
| 773 | memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); | ||
| 774 | memset(arg.info.distribution, 0, | ||
| 775 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 776 | |||
| 777 | h48max = H48_COORDMAX(fulltableinfo.h48h); | ||
| 778 | for (i = 0; i < h48max; i++) { | ||
| 779 | if (i % INT64_C(1000000000) == 0 && i > 0) | ||
| 780 | LOG("Processing %" PRId64 "th coordinate\n", i); | ||
| 781 | j = i >> (int64_t)(fulltableinfo.h48h - h); | ||
| 782 | val_full = get_h48_pval(h48full, i, arg.k); | ||
| 783 | val_derive = get_h48_pval(h48derive, j, arg.k); | ||
| 784 | set_h48_pval(h48derive, j, arg.k, MIN(val_full, val_derive)); | ||
| 785 | } | ||
| 786 | |||
| 787 | getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); | ||
| 788 | |||
| 789 | if (!writetableinfo(&arg.info, arg.h48buf)) { | ||
| 790 | LOG("gendata_h48_derive: could not write info for table\n"); | ||
| 791 | goto gendata_h48_derive_error; | ||
| 792 | } | ||
| 793 | |||
| 794 | gendata_h48_derive_return_size: | ||
| 795 | return cocsepsize + h48size; | ||
| 796 | |||
| 797 | gendata_h48_derive_error: | ||
| 798 | return 0; | ||
| 799 | } | ||
diff --git a/src/solvers/tables.h b/src/solvers/tables.h index bad3b2c..a668988 100644 --- a/src/solvers/tables.h +++ b/src/solvers/tables.h | |||
| @@ -7,34 +7,34 @@ | |||
| 7 | #define TABLETYPE_PRUNING 0 | 7 | #define TABLETYPE_PRUNING 0 |
| 8 | #define TABLETYPE_SPECIAL 1 | 8 | #define TABLETYPE_SPECIAL 1 |
| 9 | 9 | ||
| 10 | #define INFO_OFFSET_SOLVER 0 | 10 | #define INFO_OFFSET_DISTRIBUTION 0 |
| 11 | #define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN | 11 | #define INFO_OFFSET_TYPE (INFO_DISTRIBUTION_LEN * sizeof(uint64_t)) |
| 12 | #define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) | 12 | #define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) |
| 13 | #define INFO_OFFSET_FULLSIZE (INFO_OFFSET_INFOSIZE + sizeof(uint64_t)) | 13 | #define INFO_OFFSET_FULLSIZE (INFO_OFFSET_INFOSIZE + sizeof(uint64_t)) |
| 14 | #define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) | 14 | #define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) |
| 15 | #define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) | 15 | #define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) |
| 16 | #define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) | 16 | #define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) |
| 17 | #define INFO_OFFSET_H48H (INFO_OFFSET_CLASSES + sizeof(uint64_t)) | 17 | #define INFO_OFFSET_NEXT (INFO_OFFSET_CLASSES + sizeof(uint64_t)) |
| 18 | #define INFO_OFFSET_SOLVER (INFO_OFFSET_NEXT + sizeof(uint64_t)) | ||
| 19 | #define INFO_OFFSET_H48H (INFO_OFFSET_SOLVER + INFO_SOLVER_STRLEN) | ||
| 18 | #define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t)) | 20 | #define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t)) |
| 19 | #define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) | 21 | #define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) |
| 20 | #define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) | 22 | #define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) |
| 21 | #define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) | ||
| 22 | #define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t)) | ||
| 23 | 23 | ||
| 24 | typedef struct { | 24 | typedef struct { |
| 25 | char solver[INFO_SOLVER_STRLEN]; | 25 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; |
| 26 | uint64_t type; | 26 | uint64_t type; |
| 27 | uint64_t infosize; | 27 | uint64_t infosize; |
| 28 | uint64_t fullsize; | 28 | uint64_t fullsize; |
| 29 | uint64_t hash; | 29 | uint64_t hash; |
| 30 | uint64_t entries; | 30 | uint64_t entries; |
| 31 | uint64_t classes; /* Used only by cocsepdata, for now */ | 31 | uint64_t classes; /* Used only by cocsepdata, for now */ |
| 32 | uint64_t next; | ||
| 33 | char solver[INFO_SOLVER_STRLEN]; | ||
| 32 | uint8_t h48h; /* Specific to H48 tables */ | 34 | uint8_t h48h; /* Specific to H48 tables */ |
| 33 | uint8_t bits; | 35 | uint8_t bits; |
| 34 | uint8_t base; | 36 | uint8_t base; |
| 35 | uint8_t maxvalue; | 37 | uint8_t maxvalue; |
| 36 | uint64_t next; | ||
| 37 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; | ||
| 38 | } tableinfo_t; | 38 | } tableinfo_t; |
| 39 | 39 | ||
| 40 | STATIC bool readtableinfo(const void *, tableinfo_t *); | 40 | STATIC bool readtableinfo(const void *, tableinfo_t *); |
| @@ -54,21 +54,24 @@ readtableinfo(const void *buf, tableinfo_t *info) | |||
| 54 | return false; | 54 | return false; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | memcpy(info->solver, OFFSET(buf, INFO_OFFSET_SOLVER), | 57 | memcpy(info->distribution, OFFSET(buf, INFO_OFFSET_DISTRIBUTION), |
| 58 | INFO_SOLVER_STRLEN); | 58 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); |
| 59 | |||
| 59 | info->type = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_TYPE); | 60 | info->type = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_TYPE); |
| 60 | info->infosize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE); | 61 | info->infosize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE); |
| 61 | info->fullsize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE); | 62 | info->fullsize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE); |
| 62 | info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH); | 63 | info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH); |
| 63 | info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES); | 64 | info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES); |
| 64 | info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES); | 65 | info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES); |
| 66 | info->next = *(const uint64_t* )OFFSET(buf, INFO_OFFSET_NEXT); | ||
| 67 | |||
| 68 | memcpy(info->solver, OFFSET(buf, INFO_OFFSET_SOLVER), | ||
| 69 | INFO_SOLVER_STRLEN); | ||
| 70 | |||
| 65 | info->h48h = *OFFSET(buf, INFO_OFFSET_H48H); | 71 | info->h48h = *OFFSET(buf, INFO_OFFSET_H48H); |
| 66 | info->bits = *OFFSET(buf, INFO_OFFSET_BITS); | 72 | info->bits = *OFFSET(buf, INFO_OFFSET_BITS); |
| 67 | info->base = *OFFSET(buf, INFO_OFFSET_BASE); | 73 | info->base = *OFFSET(buf, INFO_OFFSET_BASE); |
| 68 | info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE); | 74 | info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE); |
| 69 | info->next = *(const uint64_t* )OFFSET(buf, INFO_OFFSET_NEXT); | ||
| 70 | memcpy(info->distribution, OFFSET(buf, INFO_OFFSET_DISTRIBUTION), | ||
| 71 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 72 | 75 | ||
| 73 | return true; | 76 | return true; |
| 74 | } | 77 | } |
| @@ -98,6 +101,17 @@ writetableinfo(const tableinfo_t *info, void *buf) | |||
| 98 | return false; | 101 | return false; |
| 99 | } | 102 | } |
| 100 | 103 | ||
| 104 | memcpy(OFFSET(buf, INFO_OFFSET_DISTRIBUTION), info->distribution, | ||
| 105 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 106 | |||
| 107 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_TYPE) = info->type; | ||
| 108 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE) = info->infosize; | ||
| 109 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE) = info->fullsize; | ||
| 110 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash; | ||
| 111 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries; | ||
| 112 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes; | ||
| 113 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_NEXT) = info->next; | ||
| 114 | |||
| 101 | memcpy(OFFSET(buf, INFO_OFFSET_SOLVER), info->solver, | 115 | memcpy(OFFSET(buf, INFO_OFFSET_SOLVER), info->solver, |
| 102 | INFO_SOLVER_STRLEN); | 116 | INFO_SOLVER_STRLEN); |
| 103 | 117 | ||
| @@ -106,20 +120,10 @@ writetableinfo(const tableinfo_t *info, void *buf) | |||
| 106 | if (*OFFSET(buf, i) == 0) | 120 | if (*OFFSET(buf, i) == 0) |
| 107 | *OFFSET(buf, i) = 0; | 121 | *OFFSET(buf, i) = 0; |
| 108 | 122 | ||
| 109 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_TYPE) = info->type; | ||
| 110 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE) = info->infosize; | ||
| 111 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE) = info->fullsize; | ||
| 112 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash; | ||
| 113 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries; | ||
| 114 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes; | ||
| 115 | *OFFSET(buf, INFO_OFFSET_H48H) = info->h48h; | 123 | *OFFSET(buf, INFO_OFFSET_H48H) = info->h48h; |
| 116 | *OFFSET(buf, INFO_OFFSET_BITS) = info->bits; | 124 | *OFFSET(buf, INFO_OFFSET_BITS) = info->bits; |
| 117 | *OFFSET(buf, INFO_OFFSET_BASE) = info->base; | 125 | *OFFSET(buf, INFO_OFFSET_BASE) = info->base; |
| 118 | *OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue; | 126 | *OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue; |
| 119 | *(uint64_t *)OFFSET(buf, INFO_OFFSET_NEXT) = info->next; | ||
| 120 | |||
| 121 | memcpy(OFFSET(buf, INFO_OFFSET_DISTRIBUTION), info->distribution, | ||
| 122 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 123 | 127 | ||
| 124 | return true; | 128 | return true; |
| 125 | } | 129 | } |
diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c index e1c2015..73c4e21 100644 --- a/test/090_tables_readwrite/tables_readwrite_tests.c +++ b/test/090_tables_readwrite/tables_readwrite_tests.c | |||
| @@ -5,19 +5,19 @@ | |||
| 5 | #define INFO_DISTRIBUTION_LEN 21 | 5 | #define INFO_DISTRIBUTION_LEN 21 |
| 6 | 6 | ||
| 7 | typedef struct { | 7 | typedef struct { |
| 8 | char solver[INFO_SOLVER_STRLEN]; | 8 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; |
| 9 | uint64_t type; | 9 | uint64_t type; |
| 10 | uint64_t infosize; | 10 | uint64_t infosize; |
| 11 | uint64_t fullsize; | 11 | uint64_t fullsize; |
| 12 | uint64_t hash; | 12 | uint64_t hash; |
| 13 | uint64_t entries; | 13 | uint64_t entries; |
| 14 | uint64_t classes; | 14 | uint64_t classes; |
| 15 | uint64_t next; | ||
| 16 | char solver[INFO_SOLVER_STRLEN]; | ||
| 15 | uint8_t h48h; | 17 | uint8_t h48h; |
| 16 | uint8_t bits; | 18 | uint8_t bits; |
| 17 | uint8_t base; | 19 | uint8_t base; |
| 18 | uint8_t maxvalue; | 20 | uint8_t maxvalue; |
| 19 | uint64_t next; | ||
| 20 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; | ||
| 21 | } tableinfo_t; | 21 | } tableinfo_t; |
| 22 | 22 | ||
| 23 | bool readtableinfo(const void *, tableinfo_t *); | 23 | bool readtableinfo(const void *, tableinfo_t *); |
diff --git a/test/100_gendata_cocsep/gendata_cocsep_tests.c b/test/100_gendata_cocsep/gendata_cocsep_tests.c index 7630a71..62f52fb 100644 --- a/test/100_gendata_cocsep/gendata_cocsep_tests.c +++ b/test/100_gendata_cocsep/gendata_cocsep_tests.c | |||
| @@ -6,19 +6,19 @@ | |||
| 6 | #define COCSEP_CLASSES 3393 | 6 | #define COCSEP_CLASSES 3393 |
| 7 | 7 | ||
| 8 | typedef struct { | 8 | typedef struct { |
| 9 | char solver[INFO_SOLVER_STRLEN]; | 9 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; |
| 10 | uint64_t type; | 10 | uint64_t type; |
| 11 | uint64_t infosize; | 11 | uint64_t infosize; |
| 12 | uint64_t fullsize; | 12 | uint64_t fullsize; |
| 13 | uint64_t hash; | 13 | uint64_t hash; |
| 14 | uint64_t entries; | 14 | uint64_t entries; |
| 15 | uint64_t classes; /* Used only by cocsepdata, for now */ | 15 | uint64_t classes; /* Used only by cocsepdata, for now */ |
| 16 | uint64_t next; | ||
| 17 | char solver[INFO_SOLVER_STRLEN]; | ||
| 16 | uint8_t h48h; | 18 | uint8_t h48h; |
| 17 | uint8_t bits; | 19 | uint8_t bits; |
| 18 | uint8_t base; | 20 | uint8_t base; |
| 19 | uint8_t maxvalue; | 21 | uint8_t maxvalue; |
| 20 | uint64_t next; | ||
| 21 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; | ||
| 22 | } tableinfo_t; | 22 | } tableinfo_t; |
| 23 | 23 | ||
| 24 | size_t gendata_cocsep(void *, uint64_t *, cube_t *); | 24 | size_t gendata_cocsep(void *, uint64_t *, cube_t *); |
diff --git a/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c index 41ab10a..7c5b441 100644 --- a/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c +++ b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c | |||
| @@ -6,24 +6,25 @@ | |||
| 6 | #define INFO_DISTRIBUTION_LEN 21 | 6 | #define INFO_DISTRIBUTION_LEN 21 |
| 7 | 7 | ||
| 8 | typedef struct { | 8 | typedef struct { |
| 9 | char solver[INFO_SOLVER_STRLEN]; | 9 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; |
| 10 | uint64_t type; | 10 | uint64_t type; |
| 11 | uint64_t infosize; | 11 | uint64_t infosize; |
| 12 | uint64_t fullsize; | 12 | uint64_t fullsize; |
| 13 | uint64_t hash; | 13 | uint64_t hash; |
| 14 | uint64_t entries; | 14 | uint64_t entries; |
| 15 | uint64_t classes; /* Used only by cocsepdata, for now */ | 15 | uint64_t classes; /* Used only by cocsepdata, for now */ |
| 16 | uint64_t next; | ||
| 17 | char solver[INFO_SOLVER_STRLEN]; | ||
| 16 | uint8_t h48h; | 18 | uint8_t h48h; |
| 17 | uint8_t bits; | 19 | uint8_t bits; |
| 18 | uint8_t base; | 20 | uint8_t base; |
| 19 | uint8_t maxvalue; | 21 | uint8_t maxvalue; |
| 20 | uint64_t next; | ||
| 21 | uint64_t distribution[INFO_DISTRIBUTION_LEN]; | ||
| 22 | } tableinfo_t; | 22 | } tableinfo_t; |
| 23 | 23 | ||
| 24 | typedef struct { | 24 | typedef struct { |
| 25 | uint8_t h; | 25 | uint8_t h; |
| 26 | uint8_t k; | 26 | uint8_t k; |
| 27 | uint8_t base; | ||
| 27 | uint8_t maxdepth; | 28 | uint8_t maxdepth; |
| 28 | tableinfo_t info; | 29 | tableinfo_t info; |
| 29 | void *buf; | 30 | void *buf; |
diff --git a/tools/0002_gendata_h48h0k2/gendata_h48h0k2.c b/tools/0002_gendata_h48h0k2/gendata_h48h0k2.c deleted file mode 100644 index 14f99ee..0000000 --- a/tools/0002_gendata_h48h0k2/gendata_h48h0k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 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 | gendata_run("h48", "0;2;20", "tables/h48h0k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 0, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0004_gendata_h48h0k4/gendata_h48h0k4.c b/tools/0004_gendata_h48h0k4/gendata_h48h0k4.c deleted file mode 100644 index ff34bb9..0000000 --- a/tools/0004_gendata_h48h0k4/gendata_h48h0k4.c +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | [0] = 1, | ||
| 5 | [1] = 1, | ||
| 6 | [2] = 4, | ||
| 7 | [3] = 34, | ||
| 8 | [4] = 331, | ||
| 9 | [5] = 3612, | ||
| 10 | [6] = 41605, | ||
| 11 | [7] = 474128, | ||
| 12 | [8] = 4953846, | ||
| 13 | [9] = 34776317, | ||
| 14 | [10] = 68566704, | ||
| 15 | [11] = 8749194, | ||
| 16 | [12] = 1673, | ||
| 17 | }; | ||
| 18 | |||
| 19 | void run(void) { | ||
| 20 | gendata_run("h48", "0;4;20", "tables/h48h0k4", expected); | ||
| 21 | } | ||
| 22 | |||
| 23 | int main(void) { | ||
| 24 | nissy_setlogger(log_stderr); | ||
| 25 | |||
| 26 | timerun(run, "benchmark gendata_h48 h = 0, k = 4"); | ||
| 27 | |||
| 28 | return 0; | ||
| 29 | } | ||
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c new file mode 100644 index 0000000..90166dd --- /dev/null +++ b/tools/000_gendata/gendata.c | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | #include "../expected_distributions.h" | ||
| 3 | |||
| 4 | char *solver, *options; | ||
| 5 | uint64_t *expected; | ||
| 6 | |||
| 7 | static void | ||
| 8 | run(void) { | ||
| 9 | int64_t size; | ||
| 10 | char *buf, filename[1024]; | ||
| 11 | |||
| 12 | getfilename(solver, options, filename); | ||
| 13 | size = generatetable(solver, options, &buf); | ||
| 14 | switch (size) { | ||
| 15 | case -1: | ||
| 16 | return; | ||
| 17 | case -2: | ||
| 18 | goto gendata_run_finish; | ||
| 19 | default: | ||
| 20 | nissy_datainfo(buf, write_stdout); | ||
| 21 | printf("\n"); | ||
| 22 | printf("Succesfully generated %" PRId64 " bytes. " | ||
| 23 | "See above for details on the tables.\n", size); | ||
| 24 | |||
| 25 | writetable(buf, size, filename); | ||
| 26 | break; | ||
| 27 | } | ||
| 28 | |||
| 29 | gendata_run_finish: | ||
| 30 | free(buf); | ||
| 31 | } | ||
| 32 | |||
| 33 | int main(int argc, char **argv) { | ||
| 34 | uint8_t h, k; | ||
| 35 | char description[256]; | ||
| 36 | |||
| 37 | if (argc < 3) { | ||
| 38 | fprintf(stderr, "Error: not enough arguments. " | ||
| 39 | "A solver and its options must be given.\n"); | ||
| 40 | return 1; | ||
| 41 | } | ||
| 42 | |||
| 43 | solver = argv[1]; | ||
| 44 | options = argv[2]; | ||
| 45 | parse_h48_options(options, &h, &k, NULL); | ||
| 46 | expected = expected_h48[h][k]; | ||
| 47 | sprintf(description, "benchmark gendata_h48 h = %" PRIu8 | ||
| 48 | ", k = %" PRIu8 "", h, k); | ||
| 49 | |||
| 50 | nissy_setlogger(log_stderr); | ||
| 51 | |||
| 52 | timerun(run, description); | ||
| 53 | |||
| 54 | return 0; | ||
| 55 | } | ||
diff --git a/tools/0012_gendata_h48h1k2/gendata_h48h1k2.c b/tools/0012_gendata_h48h1k2/gendata_h48h1k2.c deleted file mode 100644 index 0ebdcaa..0000000 --- a/tools/0012_gendata_h48h1k2/gendata_h48h1k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "1;2;20", "tables/h48h1k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 1, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
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 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | char *opts_large, *opts_small, *filename_large, *filename_small; | ||
| 4 | |||
| 5 | void run(void) { | ||
| 6 | derivedata_run(opts_large, opts_small, filename_large, filename_small); | ||
| 7 | } | ||
| 8 | |||
| 9 | int main(int argc, char **argv) { | ||
| 10 | char description[256]; | ||
| 11 | |||
| 12 | if (argc < 5) { | ||
| 13 | fprintf(stderr, | ||
| 14 | "Error: not enough arguments. Required:\n" | ||
| 15 | "1. Options for large table\n" | ||
| 16 | "2. Options for derived table\n" | ||
| 17 | "3. Filename containing large table\n" | ||
| 18 | "4. Filename for saving derived table\n"); | ||
| 19 | return 1; | ||
| 20 | } | ||
| 21 | |||
| 22 | opts_large = argv[1]; | ||
| 23 | opts_small = argv[2]; | ||
| 24 | filename_large = argv[3]; | ||
| 25 | filename_small = argv[4]; | ||
| 26 | sprintf(description, "deriving %s from %s\n", opts_small, opts_large); | ||
| 27 | |||
| 28 | nissy_setlogger(log_stderr); | ||
| 29 | |||
| 30 | timerun(run, description); | ||
| 31 | |||
| 32 | return 0; | ||
| 33 | } | ||
diff --git a/tools/0022_gendata_h48h2k2/gendata_h48h2k2.c b/tools/0022_gendata_h48h2k2/gendata_h48h2k2.c deleted file mode 100644 index f437e98..0000000 --- a/tools/0022_gendata_h48h2k2/gendata_h48h2k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "2;2;20", "tables/h48h2k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 2, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0032_gendata_h48h3k2/gendata_h48h3k2.c b/tools/0032_gendata_h48h3k2/gendata_h48h3k2.c deleted file mode 100644 index 2e0eab5..0000000 --- a/tools/0032_gendata_h48h3k2/gendata_h48h3k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "3;2;20", "tables/h48h3k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 3, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0042_gendata_h48h4k2/gendata_h48h4k2.c b/tools/0042_gendata_h48h4k2/gendata_h48h4k2.c deleted file mode 100644 index 868c360..0000000 --- a/tools/0042_gendata_h48h4k2/gendata_h48h4k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "4;2;20", "tables/h48h4k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 4, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0052_gendata_h48h5k2/gendata_h48h5k2.c b/tools/0052_gendata_h48h5k2/gendata_h48h5k2.c deleted file mode 100644 index d292d49..0000000 --- a/tools/0052_gendata_h48h5k2/gendata_h48h5k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "5;2;20", "tables/h48h5k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 5, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0062_gendata_h48h6k2/gendata_h48h6k2.c b/tools/0062_gendata_h48h6k2/gendata_h48h6k2.c deleted file mode 100644 index 910d514..0000000 --- a/tools/0062_gendata_h48h6k2/gendata_h48h6k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "6;2;20", "tables/h48h6k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 6, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0072_gendata_h48h7k2/gendata_h48h7k2.c b/tools/0072_gendata_h48h7k2/gendata_h48h7k2.c deleted file mode 100644 index b803328..0000000 --- a/tools/0072_gendata_h48h7k2/gendata_h48h7k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "7;2;20", "tables/h48h7k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 7, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0082_gendata_h48h8k2/gendata_h48h8k2.c b/tools/0082_gendata_h48h8k2/gendata_h48h8k2.c deleted file mode 100644 index 52c377a..0000000 --- a/tools/0082_gendata_h48h8k2/gendata_h48h8k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "8;2;20", "tables/h48h8k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 8, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0092_gendata_h48h9k2/gendata_h48h9k2.c b/tools/0092_gendata_h48h9k2/gendata_h48h9k2.c deleted file mode 100644 index 5d3e34a..0000000 --- a/tools/0092_gendata_h48h9k2/gendata_h48h9k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "9;2;20", "tables/h48h9k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 9, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0102_gendata_h48h10k2/gendata_h48h10k2.c b/tools/0102_gendata_h48h10k2/gendata_h48h10k2.c deleted file mode 100644 index 5e8fbb0..0000000 --- a/tools/0102_gendata_h48h10k2/gendata_h48h10k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "10;2;20", "tables/h48h10k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 10, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0112_gendata_h48h11k2/gendata_h48h11k2.c b/tools/0112_gendata_h48h11k2/gendata_h48h11k2.c deleted file mode 100644 index 00c0747..0000000 --- a/tools/0112_gendata_h48h11k2/gendata_h48h11k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "11;2;20", "tables/h48h11k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 11, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c new file mode 100644 index 0000000..05961c1 --- /dev/null +++ b/tools/100_checkdata/checkdata.c | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | #include "../expected_distributions.h" | ||
| 3 | |||
| 4 | char *solver, *options, *filename; | ||
| 5 | |||
| 6 | static void | ||
| 7 | run(void) { | ||
| 8 | int64_t size; | ||
| 9 | char *buf; | ||
| 10 | FILE *f; | ||
| 11 | |||
| 12 | size = nissy_datasize(solver, options); | ||
| 13 | |||
| 14 | if (size <= 0) { | ||
| 15 | fprintf(stderr, "Error in datasize\n"); | ||
| 16 | return; | ||
| 17 | } | ||
| 18 | |||
| 19 | if ((f = fopen(filename, "rb")) == NULL) { | ||
| 20 | fprintf(stderr, "Error reading file %s\n", filename); | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | buf = malloc(size); | ||
| 25 | fread(buf, size, 1, f); | ||
| 26 | fclose(f); | ||
| 27 | nissy_checkdata(solver, options, buf); | ||
| 28 | free(buf); | ||
| 29 | |||
| 30 | /* TODO: cross-check with expected distributions? */ | ||
| 31 | } | ||
| 32 | |||
| 33 | int main(int argc, char **argv) { | ||
| 34 | char description[256]; | ||
| 35 | |||
| 36 | if (argc < 4) { | ||
| 37 | fprintf(stderr, "Error: not enough arguments. " | ||
| 38 | "A solver, its options and a file name must be given.\n"); | ||
| 39 | return 1; | ||
| 40 | } | ||
| 41 | |||
| 42 | solver = argv[1]; | ||
| 43 | options = argv[2]; | ||
| 44 | filename = argv[3]; | ||
| 45 | sprintf(description, "checking data for solver %s" | ||
| 46 | "with options %s from file %s", solver, options, filename); | ||
| 47 | nissy_setlogger(log_stderr); | ||
| 48 | |||
| 49 | timerun(run, description); | ||
| 50 | |||
| 51 | return 0; | ||
| 52 | } | ||
diff --git a/tools/100_stats_tables_h48/stats_tables_h48.c b/tools/200_stats_tables_h48/stats_tables_h48.c index adac8fa..adac8fa 100644 --- a/tools/100_stats_tables_h48/stats_tables_h48.c +++ b/tools/200_stats_tables_h48/stats_tables_h48.c | |||
diff --git a/tools/200_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c index d476bce..d476bce 100644 --- a/tools/200_solve_small/solve_small.c +++ b/tools/300_solve_small/solve_small.c | |||
diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h new file mode 100644 index 0000000..535cab2 --- /dev/null +++ b/tools/expected_distributions.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | uint64_t expected_h48[12][9][21] = { | ||
| 2 | [0] = { | ||
| 3 | [2] = { | ||
| 4 | [0] = 5473562, | ||
| 5 | [1] = 34776317, | ||
| 6 | [2] = 68566704, | ||
| 7 | [3] = 8750867, | ||
| 8 | }, | ||
| 9 | [4] = { | ||
| 10 | [0] = 1, | ||
| 11 | [1] = 1, | ||
| 12 | [2] = 4, | ||
| 13 | [3] = 34, | ||
| 14 | [4] = 331, | ||
| 15 | [5] = 3612, | ||
| 16 | [6] = 41605, | ||
| 17 | [7] = 474128, | ||
| 18 | [8] = 4953846, | ||
| 19 | [9] = 34776317, | ||
| 20 | [10] = 68566704, | ||
| 21 | [11] = 8749194, | ||
| 22 | [12] = 1673, | ||
| 23 | }, | ||
| 24 | }, | ||
| 25 | [1] = { | ||
| 26 | [2] = { | ||
| 27 | [0] = 6012079, | ||
| 28 | [1] = 45822302, | ||
| 29 | [2] = 142018732, | ||
| 30 | [3] = 41281787, | ||
| 31 | }, | ||
| 32 | }, | ||
| 33 | }; | ||
diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h new file mode 100644 index 0000000..1e714a7 --- /dev/null +++ b/tools/nissy_extra.h | |||
| @@ -0,0 +1,7 @@ | |||
| 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 *); | ||
| 7 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | ||
diff --git a/tools/run_tool.sh b/tools/run_tool.sh index 7e09684..2216a66 100755 --- a/tools/run_tool.sh +++ b/tools/run_tool.sh | |||
| @@ -5,7 +5,7 @@ if [ -z "$TOOL" ]; then | |||
| 5 | exit 1 | 5 | exit 1 |
| 6 | fi | 6 | fi |
| 7 | 7 | ||
| 8 | CC="$CC -D_POSIX_C_SOURCE=199309L" | 8 | CC="$CC -D_POSIX_C_SOURCE=199309L" # For timer |
| 9 | 9 | ||
| 10 | BIN="tools/run" | 10 | BIN="tools/run" |
| 11 | d="$(date +'%Y-%m-%d-%H-%M-%S')" | 11 | d="$(date +'%Y-%m-%d-%H-%M-%S')" |
| @@ -16,7 +16,8 @@ for t in tools/*; do | |||
| 16 | fi | 16 | fi |
| 17 | toolname="$(basename "$t" .c)" | 17 | toolname="$(basename "$t" .c)" |
| 18 | $CC -o $BIN "$t"/*.c "$CUBEOBJ" || exit 1; | 18 | $CC -o $BIN "$t"/*.c "$CUBEOBJ" || exit 1; |
| 19 | $BIN | tee "tools/results/$toolname-$d.txt" "tools/results/last.out" | 19 | $BIN $TOOLARGS \ |
| 20 | | tee "tools/results/$toolname-$d.txt" "tools/results/last.out" | ||
| 20 | break | 21 | break |
| 21 | done | 22 | done |
| 22 | 23 | ||
diff --git a/tools/tool.h b/tools/tool.h index 757657b..c44828d 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -6,14 +6,19 @@ | |||
| 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 *); |
| 14 | static void getfilename(const char *, const char *, char *); | ||
| 13 | static void writetable(const char *, int64_t, const char *); | 15 | static void writetable(const char *, int64_t, const char *); |
| 14 | static int64_t generatetable(const char *, const char *, char **); | 16 | static int64_t generatetable(const char *, const char *, char **); |
| 17 | static int64_t derivetable(const char *, const char *, const char *, char **); | ||
| 15 | static int getdata(const char *, const char *, char **, const char *); | 18 | 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]); | 19 | static void gendata_run(const char *, const char *, uint64_t[static 21]); |
| 20 | static void derivedata_run( | ||
| 21 | const char *, const char *, const char *, const char *); | ||
| 17 | 22 | ||
| 18 | static void | 23 | static void |
| 19 | log_stderr(const char *str, ...) | 24 | log_stderr(const char *str, ...) |
| @@ -70,6 +75,17 @@ timerun(void (*run)(void), const char *name) | |||
| 70 | } | 75 | } |
| 71 | 76 | ||
| 72 | static void | 77 | static void |
| 78 | getfilename(const char *solver, const char *options, char *filename) | ||
| 79 | { | ||
| 80 | uint8_t h, k; | ||
| 81 | |||
| 82 | /* Only h48 supported for now */ | ||
| 83 | parse_h48_options(options, &h, &k, NULL); | ||
| 84 | |||
| 85 | sprintf(filename, "tables/%sh%dk%d", solver, h, k); | ||
| 86 | } | ||
| 87 | |||
| 88 | static void | ||
| 73 | writetable(const char *buf, int64_t size, const char *filename) | 89 | writetable(const char *buf, int64_t size, const char *filename) |
| 74 | { | 90 | { |
| 75 | FILE *f; | 91 | FILE *f; |
| @@ -109,6 +125,44 @@ generatetable(const char *solver, const char *options, char **buf) | |||
| 109 | return gensize; | 125 | return gensize; |
| 110 | } | 126 | } |
| 111 | 127 | ||
| 128 | static int64_t | ||
| 129 | derivetable( | ||
| 130 | const char *opts_large, | ||
| 131 | const char *opts_small, | ||
| 132 | const char *filename_large, | ||
| 133 | char **buf | ||
| 134 | ) | ||
| 135 | { | ||
| 136 | uint8_t h; | ||
| 137 | int64_t size, gensize; | ||
| 138 | char *fulltable; | ||
| 139 | |||
| 140 | if (getdata("h48", opts_large, &fulltable, filename_large) != 0) { | ||
| 141 | printf("Error reading full table.\n"); | ||
| 142 | return -1; | ||
| 143 | } | ||
| 144 | |||
| 145 | size = nissy_datasize("h48", opts_small); | ||
| 146 | if (size == -1) { | ||
| 147 | printf("Error getting table size.\n"); | ||
| 148 | free(fulltable); | ||
| 149 | return -1; | ||
| 150 | } | ||
| 151 | |||
| 152 | h = atoi(opts_small); /* TODO: use option parser */ | ||
| 153 | *buf = malloc(size); | ||
| 154 | gensize = gendata_h48_derive(h, fulltable, *buf); | ||
| 155 | |||
| 156 | if (gensize != size) { | ||
| 157 | fprintf(stderr, "Error deriving table\n"); | ||
| 158 | free(fulltable); | ||
| 159 | return -2; | ||
| 160 | } | ||
| 161 | |||
| 162 | free(fulltable); | ||
| 163 | return gensize; | ||
| 164 | } | ||
| 165 | |||
| 112 | static int | 166 | static int |
| 113 | getdata( | 167 | getdata( |
| 114 | const char *solver, | 168 | const char *solver, |
| @@ -155,13 +209,12 @@ static void | |||
| 155 | gendata_run( | 209 | gendata_run( |
| 156 | const char *solver, | 210 | const char *solver, |
| 157 | const char *options, | 211 | const char *options, |
| 158 | const char *filename, /* TODO: remove filename, use solver name */ | ||
| 159 | uint64_t expected[static 21] | 212 | uint64_t expected[static 21] |
| 160 | ) { | 213 | ) { |
| 161 | int64_t size; | 214 | int64_t size; |
| 162 | char *buf; | 215 | char *buf, filename[1024]; |
| 163 | 216 | ||
| 164 | 217 | getfilename(solver, options, filename); | |
| 165 | size = generatetable(solver, options, &buf); | 218 | size = generatetable(solver, options, &buf); |
| 166 | switch (size) { | 219 | switch (size) { |
| 167 | case -1: | 220 | case -1: |
| @@ -182,3 +235,34 @@ gendata_run( | |||
| 182 | gendata_run_finish: | 235 | gendata_run_finish: |
| 183 | free(buf); | 236 | free(buf); |
| 184 | } | 237 | } |
| 238 | |||
| 239 | static void | ||
| 240 | derivedata_run( | ||
| 241 | const char *opts_large, | ||
| 242 | const char *opts_small, | ||
| 243 | const char *filename_large, | ||
| 244 | const char *filename_small | ||
| 245 | ) | ||
| 246 | { | ||
| 247 | int64_t size; | ||
| 248 | char *buf; | ||
| 249 | |||
| 250 | size = derivetable(opts_large, opts_small, filename_large, &buf); | ||
| 251 | switch (size) { | ||
| 252 | case -1: | ||
| 253 | return; | ||
| 254 | case -2: | ||
| 255 | goto derivedata_run_finish; | ||
| 256 | default: | ||
| 257 | nissy_datainfo(buf, write_stdout); | ||
| 258 | printf("\n"); | ||
| 259 | printf("Succesfully generated %" PRId64 " bytes. " | ||
| 260 | "See above for details on the tables.\n", size); | ||
| 261 | |||
| 262 | writetable(buf, size, filename_small); | ||
| 263 | break; | ||
| 264 | } | ||
| 265 | |||
| 266 | derivedata_run_finish: | ||
| 267 | free(buf); | ||
| 268 | } | ||
