diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nissy.c | 10 | ||||
| -rw-r--r-- | src/nissy.h | 7 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 99 |
3 files changed, 100 insertions, 16 deletions
diff --git a/src/nissy.c b/src/nissy.c index 08cacf0..e610199 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -13,8 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | 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( | 16 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], |
| 17 | const uint64_t [static 21], const uint64_t [static 21], uint8_t); | 17 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); |
| 18 | STATIC bool checkdata(const void *, const tableinfo_t *); | 18 | STATIC bool checkdata(const void *, const tableinfo_t *); |
| 19 | 19 | ||
| 20 | /* 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... */ |
| @@ -68,7 +68,7 @@ parse_h48_options_error: | |||
| 68 | STATIC bool | 68 | STATIC bool |
| 69 | checkdata(const void *buf, const tableinfo_t *info) | 69 | checkdata(const void *buf, const tableinfo_t *info) |
| 70 | { | 70 | { |
| 71 | uint64_t distr[21]; | 71 | uint64_t distr[INFO_DISTRIBUTION_LEN]; |
| 72 | 72 | ||
| 73 | if (!strncmp(info->solver, "cocsep", 6)) { | 73 | if (!strncmp(info->solver, "cocsep", 6)) { |
| 74 | getdistribution_cocsep( | 74 | getdistribution_cocsep( |
| @@ -86,8 +86,8 @@ checkdata(const void *buf, const tableinfo_t *info) | |||
| 86 | 86 | ||
| 87 | STATIC bool | 87 | STATIC bool |
| 88 | distribution_equal( | 88 | distribution_equal( |
| 89 | const uint64_t expected[static 21], | 89 | const uint64_t expected[static INFO_DISTRIBUTION_LEN], |
| 90 | const uint64_t actual[static 21], | 90 | const uint64_t actual[static INFO_DISTRIBUTION_LEN], |
| 91 | uint8_t maxvalue | 91 | uint8_t maxvalue |
| 92 | ) | 92 | ) |
| 93 | { | 93 | { |
diff --git a/src/nissy.h b/src/nissy.h index e8c35c3..0545556 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -86,6 +86,13 @@ 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 | |||
| 89 | int64_t nissy_checkdata( | 96 | int64_t nissy_checkdata( |
| 90 | const char *solver, | 97 | const char *solver, |
| 91 | const char *options, | 98 | const char *options, |
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 6e7b0ca..b1ae38c 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -103,9 +103,9 @@ 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( | 107 | STATIC void getdistribution_h48(const uint8_t *, |
| 108 | const uint8_t *, uint64_t [static 21], uint8_t, uint8_t); | 108 | uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); |
| 109 | 109 | ||
| 110 | STATIC uint32_t *get_cocsepdata_ptr(const void *); | 110 | STATIC uint32_t *get_cocsepdata_ptr(const void *); |
| 111 | STATIC uint8_t *get_h48data_ptr(const void *); | 111 | STATIC uint8_t *get_h48data_ptr(const void *); |
| @@ -115,6 +115,8 @@ STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); | |||
| 115 | STATIC_INLINE uint8_t get_h48_bound( | 115 | STATIC_INLINE uint8_t get_h48_bound( |
| 116 | cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); | 116 | cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); |
| 117 | 117 | ||
| 118 | size_t gendata_h48_derive(uint8_t, const void *, void *); | ||
| 119 | |||
| 118 | STATIC uint64_t | 120 | STATIC uint64_t |
| 119 | gendata_h48short(gendata_h48short_arg_t *arg) | 121 | gendata_h48short(gendata_h48short_arg_t *arg) |
| 120 | { | 122 | { |
| @@ -390,7 +392,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 390 | [11] = 10 | 392 | [11] = 10 |
| 391 | }; | 393 | }; |
| 392 | 394 | ||
| 393 | uint8_t t, selectedbase, *table; | 395 | uint8_t t, *table; |
| 394 | int64_t j; | 396 | int64_t j; |
| 395 | uint64_t i, ii, inext, count; | 397 | uint64_t i, ii, inext, count; |
| 396 | h48map_t shortcubes; | 398 | h48map_t shortcubes; |
| @@ -417,8 +419,9 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 417 | }; | 419 | }; |
| 418 | gendata_h48short(&shortarg); | 420 | gendata_h48short(&shortarg); |
| 419 | 421 | ||
| 420 | selectedbase = arg->base < 20 ? arg->base : base[arg->h]; | 422 | if (arg->base >= 20) |
| 421 | arg->info = makeinfo_h48k2(arg, selectedbase); | 423 | arg->base = base[arg->h]; |
| 424 | arg->info = makeinfo_h48k2(arg); | ||
| 422 | 425 | ||
| 423 | inext = count = 0; | 426 | inext = count = 0; |
| 424 | pthread_mutex_init(&shortcubes_mutex, NULL); | 427 | pthread_mutex_init(&shortcubes_mutex, NULL); |
| @@ -428,7 +431,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 428 | dfsarg[i] = (h48k2_dfs_arg_t){ | 431 | dfsarg[i] = (h48k2_dfs_arg_t){ |
| 429 | .h = arg->h, | 432 | .h = arg->h, |
| 430 | .k = arg->k, | 433 | .k = arg->k, |
| 431 | .base = selectedbase, | 434 | .base = arg->base, |
| 432 | .shortdepth = shortdepth, | 435 | .shortdepth = shortdepth, |
| 433 | .cocsepdata = arg->cocsepdata, | 436 | .cocsepdata = arg->cocsepdata, |
| 434 | .table = table, | 437 | .table = table, |
| @@ -640,7 +643,7 @@ gendata_h48k2_realcoord_runthread(void *arg) | |||
| 640 | } | 643 | } |
| 641 | 644 | ||
| 642 | STATIC tableinfo_t | 645 | STATIC tableinfo_t |
| 643 | makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | 646 | makeinfo_h48k2(gendata_h48_arg_t *arg) |
| 644 | { | 647 | { |
| 645 | tableinfo_t info; | 648 | tableinfo_t info; |
| 646 | 649 | ||
| @@ -654,7 +657,7 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | |||
| 654 | .classes = 0, | 657 | .classes = 0, |
| 655 | .h48h = arg->h, | 658 | .h48h = arg->h, |
| 656 | .bits = 2, | 659 | .bits = 2, |
| 657 | .base = base, | 660 | .base = arg->base, |
| 658 | .maxvalue = 3, | 661 | .maxvalue = 3, |
| 659 | .next = 0, | 662 | .next = 0, |
| 660 | }; | 663 | }; |
| @@ -668,14 +671,14 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | |||
| 668 | STATIC void | 671 | STATIC void |
| 669 | getdistribution_h48( | 672 | getdistribution_h48( |
| 670 | const uint8_t *table, | 673 | const uint8_t *table, |
| 671 | uint64_t distr[static 21], | 674 | uint64_t distr[static INFO_DISTRIBUTION_LEN], |
| 672 | uint8_t h, | 675 | uint8_t h, |
| 673 | uint8_t k | 676 | uint8_t k |
| 674 | ) { | 677 | ) { |
| 675 | uint8_t val; | 678 | uint8_t val; |
| 676 | int64_t i, h48max; | 679 | int64_t i, h48max; |
| 677 | 680 | ||
| 678 | memset(distr, 0, 21 * sizeof(uint64_t)); | 681 | memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); |
| 679 | 682 | ||
| 680 | h48max = H48_COORDMAX(h); | 683 | h48max = H48_COORDMAX(h); |
| 681 | for (i = 0; i < h48max; i++) { | 684 | for (i = 0; i < h48max; i++) { |
| @@ -717,3 +720,77 @@ get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table) | |||
| 717 | coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); | 720 | coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); |
| 718 | return get_h48_pval(table, coord, k); | 721 | return get_h48_pval(table, coord, k); |
| 719 | } | 722 | } |
| 723 | |||
| 724 | size_t | ||
| 725 | gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | ||
| 726 | { | ||
| 727 | size_t cocsepsize, h48size; | ||
| 728 | uint8_t val_full, val_derive, *h48full, *h48derive; | ||
| 729 | int64_t i, j, h48max; | ||
| 730 | gendata_h48_arg_t arg; | ||
| 731 | tableinfo_t cocsepinfo, fulltableinfo; | ||
| 732 | |||
| 733 | /* Initializing values in case of error */ | ||
| 734 | /* TODO cleanup this */ | ||
| 735 | fulltableinfo.bits = 2; | ||
| 736 | fulltableinfo.base = 8; | ||
| 737 | |||
| 738 | readtableinfo_n(fulltable, 2, &fulltableinfo); | ||
| 739 | arg.h = h; | ||
| 740 | arg.k = fulltableinfo.bits; | ||
| 741 | arg.maxdepth = 20; | ||
| 742 | arg.buf = buf; | ||
| 743 | arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); | ||
| 744 | arg.base = fulltableinfo.base; | ||
| 745 | arg.info = makeinfo_h48k2(&arg); | ||
| 746 | |||
| 747 | /* Technically this step is redundant, except that we | ||
| 748 | need selfsim and crep */ | ||
| 749 | cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); | ||
| 750 | arg.h48buf = (char *)buf + cocsepsize; | ||
| 751 | h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; | ||
| 752 | |||
| 753 | if (buf == NULL) | ||
| 754 | goto gendata_h48_derive_return_size; | ||
| 755 | |||
| 756 | if (!readtableinfo(buf, &cocsepinfo)) { | ||
| 757 | LOG("gendata_h48: could not read info for cocsep table\n"); | ||
| 758 | goto gendata_h48_derive_error; | ||
| 759 | } | ||
| 760 | |||
| 761 | cocsepinfo.next = cocsepsize; | ||
| 762 | if (!writetableinfo(&cocsepinfo, buf)) { | ||
| 763 | LOG("gendata_h48_derive: could not write info for cocsep table" | ||
| 764 | " with updated 'next' value\n"); | ||
| 765 | goto gendata_h48_derive_error; | ||
| 766 | } | ||
| 767 | |||
| 768 | h48full = (uint8_t *)fulltable + INFOSIZE; | ||
| 769 | h48derive = (uint8_t *)arg.h48buf + INFOSIZE; | ||
| 770 | memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); | ||
| 771 | memset(arg.info.distribution, 0, | ||
| 772 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 773 | |||
| 774 | h48max = H48_COORDMAX(11); | ||
| 775 | for (i = 0; i < h48max; i++) { | ||
| 776 | if (i % INT64_C(1000000000) == 0) | ||
| 777 | LOG("Processing %" PRId64 "th coordinate\n", i); | ||
| 778 | j = i >> (int64_t)(11-h); | ||
| 779 | val_full = get_h48_pval(h48full, i, arg.k); | ||
| 780 | val_derive = get_h48_pval(h48derive, j, arg.k); | ||
| 781 | set_h48_pval(h48derive, j, arg.k, MIN(val_full, val_derive)); | ||
| 782 | } | ||
| 783 | |||
| 784 | getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); | ||
| 785 | |||
| 786 | if (!writetableinfo(&arg.info, buf)) { | ||
| 787 | LOG("gendata_h48_derive: could not write info for table\n"); | ||
| 788 | goto gendata_h48_derive_error; | ||
| 789 | } | ||
| 790 | |||
| 791 | gendata_h48_derive_return_size: | ||
| 792 | return cocsepsize + h48size; | ||
| 793 | |||
| 794 | gendata_h48_derive_error: | ||
| 795 | return 0; | ||
| 796 | } | ||
