diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-27 08:22:55 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-27 08:25:41 +0200 |
| commit | cee9856b2cb151f705acf6d27454ec08ef2b9a4e (patch) | |
| tree | 4616e5c59e01be16e96103f9e9897ef004434eb7 /src/nissy.c | |
| parent | 0b32395de2500ad87e15fbb0ff4a852e313037e9 (diff) | |
| parent | 79500f46632ba50b1640d16983942b940dd7955f (diff) | |
| download | nissy-core-cee9856b2cb151f705acf6d27454ec08ef2b9a4e.tar.gz nissy-core-cee9856b2cb151f705acf6d27454ec08ef2b9a4e.zip | |
Merge branch 'master' of tronto.net:h48
Diffstat (limited to 'src/nissy.c')
| -rw-r--r-- | src/nissy.c | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/src/nissy.c b/src/nissy.c index 6bc4aea..953471f 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -11,8 +11,11 @@ | |||
| 11 | 11 | ||
| 12 | #include "nissy.h" | 12 | #include "nissy.h" |
| 13 | 13 | ||
| 14 | STATIC int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 14 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); |
| 15 | STATIC int64_t write_result(cube_t, char [static 22]); | 15 | STATIC int64_t write_result(cube_t, char [static 22]); |
| 16 | STATIC bool distribution_equal( | ||
| 17 | const uint64_t [static 21], const uint64_t [static 21], uint8_t); | ||
| 18 | STATIC bool checkdata(const void *, const tableinfo_t *); | ||
| 16 | 19 | ||
| 17 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ | 20 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ |
| 18 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } | 21 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } |
| @@ -24,7 +27,7 @@ struct { | |||
| 24 | GETCUBE_OPTIONS(NULL, NULL) | 27 | GETCUBE_OPTIONS(NULL, NULL) |
| 25 | }; | 28 | }; |
| 26 | 29 | ||
| 27 | STATIC int | 30 | int |
| 28 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) | 31 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) |
| 29 | { | 32 | { |
| 30 | bool h_valid, k_valid, maxdepth_valid; | 33 | bool h_valid, k_valid, maxdepth_valid; |
| @@ -62,6 +65,52 @@ parse_h48_options_error: | |||
| 62 | return -1; | 65 | return -1; |
| 63 | } | 66 | } |
| 64 | 67 | ||
| 68 | STATIC bool | ||
| 69 | checkdata(const void *buf, const tableinfo_t *info) | ||
| 70 | { | ||
| 71 | uint64_t distr[21]; | ||
| 72 | |||
| 73 | if (!strncmp(info->solver, "cocsep", 6)) { | ||
| 74 | getdistribution_cocsep( | ||
| 75 | (uint32_t *)((char *)buf + INFOSIZE), distr); | ||
| 76 | } else if (!strncmp(info->solver, "h48", 3)) { | ||
| 77 | getdistribution_h48((uint8_t *)buf + INFOSIZE, distr, | ||
| 78 | info->h48h, info->bits); | ||
| 79 | } else { | ||
| 80 | LOG("checkdata: unknown solver %s\n", info->solver); | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | |||
| 84 | return distribution_equal(info->distribution, distr, info->maxvalue); | ||
| 85 | } | ||
| 86 | |||
| 87 | STATIC bool | ||
| 88 | distribution_equal( | ||
| 89 | const uint64_t expected[static 21], | ||
| 90 | const uint64_t actual[static 21], | ||
| 91 | uint8_t maxvalue | ||
| 92 | ) | ||
| 93 | { | ||
| 94 | int wrong; | ||
| 95 | uint8_t i; | ||
| 96 | |||
| 97 | for (i = 0, wrong = 0; i <= MAX(maxvalue, 20); i++) { | ||
| 98 | if (expected[i] != actual[i]) { | ||
| 99 | wrong++; | ||
| 100 | LOG("Value %" PRIu8 ": expected %" PRIu64 ", found %" | ||
| 101 | PRIu64 "\n", i, expected[i], actual[i]); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | if (wrong > 0) { | ||
| 106 | LOG("checkdata: %d wrong values\n", wrong); | ||
| 107 | } else { | ||
| 108 | LOG("checkdata: table is consistent with info\n"); | ||
| 109 | } | ||
| 110 | |||
| 111 | return wrong > 0; | ||
| 112 | } | ||
| 113 | |||
| 65 | STATIC int64_t | 114 | STATIC int64_t |
| 66 | write_result(cube_t cube, char result[static 22]) | 115 | write_result(cube_t cube, char result[static 22]) |
| 67 | { | 116 | { |
| @@ -275,6 +324,23 @@ nissy_gendata( | |||
| 275 | } | 324 | } |
| 276 | 325 | ||
| 277 | int64_t | 326 | int64_t |
| 327 | nissy_checkdata( | ||
| 328 | const char *solver, | ||
| 329 | const char *options, | ||
| 330 | const void *data | ||
| 331 | ) | ||
| 332 | { | ||
| 333 | char *buf; | ||
| 334 | tableinfo_t info; | ||
| 335 | |||
| 336 | for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) | ||
| 337 | if (!checkdata(buf, &info)) | ||
| 338 | return 1; | ||
| 339 | |||
| 340 | return 0; | ||
| 341 | } | ||
| 342 | |||
| 343 | int64_t | ||
| 278 | nissy_solve( | 344 | nissy_solve( |
| 279 | const char cube[static 22], | 345 | const char cube[static 22], |
| 280 | const char *solver, | 346 | const char *solver, |
