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 /src | |
| parent | bb09e52a7481718ae1fe324d16b99970450908f8 (diff) | |
| download | nissy-core-0b32395de2500ad87e15fbb0ff4a852e313037e9.tar.gz nissy-core-0b32395de2500ad87e15fbb0ff4a852e313037e9.zip | |
First try for derive tables
Diffstat (limited to '')
| -rw-r--r-- | src/nissy.h | 7 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 95 |
2 files changed, 95 insertions, 7 deletions
diff --git a/src/nissy.h b/src/nissy.h index 336130c..63e7a90 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 | /* Print information on a data table via the provided callback writer */ | 96 | /* Print information on a data table via the provided callback writer */ |
| 90 | int64_t nissy_datainfo( | 97 | int64_t nissy_datainfo( |
| 91 | const void *table, | 98 | const void *table, |
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 3445570..a88eb4f 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -103,7 +103,7 @@ 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 | 107 | ||
| 108 | STATIC uint32_t *get_cocsepdata_ptr(const void *); | 108 | STATIC uint32_t *get_cocsepdata_ptr(const void *); |
| 109 | STATIC uint8_t *get_h48data_ptr(const void *); | 109 | STATIC uint8_t *get_h48data_ptr(const void *); |
| @@ -112,6 +112,8 @@ 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); | 112 | 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 *); | 113 | STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); |
| 114 | 114 | ||
| 115 | size_t gendata_h48_derive(uint8_t, const void *, void *); | ||
| 116 | |||
| 115 | STATIC uint64_t | 117 | STATIC uint64_t |
| 116 | gendata_h48short(gendata_h48short_arg_t *arg) | 118 | gendata_h48short(gendata_h48short_arg_t *arg) |
| 117 | { | 119 | { |
| @@ -387,7 +389,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 387 | [11] = 10 | 389 | [11] = 10 |
| 388 | }; | 390 | }; |
| 389 | 391 | ||
| 390 | uint8_t t, selectedbase, *table; | 392 | uint8_t t, *table; |
| 391 | int64_t j; | 393 | int64_t j; |
| 392 | uint64_t i, ii, inext, count; | 394 | uint64_t i, ii, inext, count; |
| 393 | h48map_t shortcubes; | 395 | h48map_t shortcubes; |
| @@ -414,8 +416,9 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 414 | }; | 416 | }; |
| 415 | gendata_h48short(&shortarg); | 417 | gendata_h48short(&shortarg); |
| 416 | 418 | ||
| 417 | selectedbase = arg->base < 20 ? arg->base : base[arg->h]; | 419 | if (arg->base >= 20) |
| 418 | arg->info = makeinfo_h48k2(arg, selectedbase); | 420 | arg->base = base[arg->h]; |
| 421 | arg->info = makeinfo_h48k2(arg); | ||
| 419 | 422 | ||
| 420 | inext = count = 0; | 423 | inext = count = 0; |
| 421 | pthread_mutex_init(&shortcubes_mutex, NULL); | 424 | pthread_mutex_init(&shortcubes_mutex, NULL); |
| @@ -425,7 +428,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 425 | dfsarg[i] = (h48k2_dfs_arg_t){ | 428 | dfsarg[i] = (h48k2_dfs_arg_t){ |
| 426 | .h = arg->h, | 429 | .h = arg->h, |
| 427 | .k = arg->k, | 430 | .k = arg->k, |
| 428 | .base = selectedbase, | 431 | .base = arg->base, |
| 429 | .shortdepth = shortdepth, | 432 | .shortdepth = shortdepth, |
| 430 | .cocsepdata = arg->cocsepdata, | 433 | .cocsepdata = arg->cocsepdata, |
| 431 | .table = table, | 434 | .table = table, |
| @@ -637,7 +640,7 @@ gendata_h48k2_realcoord_runthread(void *arg) | |||
| 637 | } | 640 | } |
| 638 | 641 | ||
| 639 | STATIC tableinfo_t | 642 | STATIC tableinfo_t |
| 640 | makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | 643 | makeinfo_h48k2(gendata_h48_arg_t *arg) |
| 641 | { | 644 | { |
| 642 | tableinfo_t info; | 645 | tableinfo_t info; |
| 643 | 646 | ||
| @@ -651,7 +654,7 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) | |||
| 651 | .classes = 0, | 654 | .classes = 0, |
| 652 | .h48h = arg->h, | 655 | .h48h = arg->h, |
| 653 | .bits = 2, | 656 | .bits = 2, |
| 654 | .base = base, | 657 | .base = arg->base, |
| 655 | .maxvalue = 3, | 658 | .maxvalue = 3, |
| 656 | .next = 0, | 659 | .next = 0, |
| 657 | }; | 660 | }; |
| @@ -695,3 +698,81 @@ 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); | 698 | coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); |
| 696 | return get_h48_pval(table, coord, k); | 699 | return get_h48_pval(table, coord, k); |
| 697 | } | 700 | } |
| 701 | |||
| 702 | size_t | ||
| 703 | gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | ||
| 704 | { | ||
| 705 | size_t cocsepsize, h48size; | ||
| 706 | uint8_t val_full, val_derive, val_new, *h48full, *h48derive; | ||
| 707 | int64_t i, j, h48max; | ||
| 708 | gendata_h48_arg_t arg; | ||
| 709 | tableinfo_t cocsepinfo, fulltableinfo; | ||
| 710 | |||
| 711 | /* Initializing values in case of error */ | ||
| 712 | fulltableinfo.bits = 2; | ||
| 713 | fulltableinfo.base = 8; | ||
| 714 | |||
| 715 | readtableinfo_n(fulltable, 2, &fulltableinfo); | ||
| 716 | arg.h = h; | ||
| 717 | arg.k = fulltableinfo.bits; | ||
| 718 | arg.maxdepth = 20; | ||
| 719 | arg.buf = buf; | ||
| 720 | arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); | ||
| 721 | arg.base = fulltableinfo.base; | ||
| 722 | arg.info = makeinfo_h48k2(&arg); | ||
| 723 | |||
| 724 | /* Technically this step is redundant, except that we | ||
| 725 | need selfsim and crep */ | ||
| 726 | cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); | ||
| 727 | arg.h48buf = (char *)buf + cocsepsize; | ||
| 728 | h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; | ||
| 729 | |||
| 730 | if (buf == NULL) | ||
| 731 | goto gendata_h48_derive_return_size; | ||
| 732 | |||
| 733 | if (!readtableinfo(buf, &cocsepinfo)) { | ||
| 734 | LOG("gendata_h48: could not read info for cocsep table\n"); | ||
| 735 | goto gendata_h48_derive_error; | ||
| 736 | } | ||
| 737 | |||
| 738 | cocsepinfo.next = cocsepsize; | ||
| 739 | if (!writetableinfo(&cocsepinfo, buf)) { | ||
| 740 | LOG("gendata_h48_derive: could not write info for cocsep table" | ||
| 741 | " with updated 'next' value\n"); | ||
| 742 | goto gendata_h48_derive_error; | ||
| 743 | } | ||
| 744 | |||
| 745 | h48full = (uint8_t *)fulltable + INFOSIZE; | ||
| 746 | h48derive = (uint8_t *)arg.h48buf + INFOSIZE; | ||
| 747 | memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); | ||
| 748 | memset(arg.info.distribution, 0, | ||
| 749 | INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 750 | |||
| 751 | h48max = H48_COORDMAX(11); | ||
| 752 | for (i = 0; i < h48max; i++) { | ||
| 753 | if (i % INT64_C(1000000000) == 0) | ||
| 754 | LOG("Processing %" PRId64 "th coordinate\n", i); | ||
| 755 | j = i >> (int64_t)(11-h); | ||
| 756 | val_full = get_h48_pval(h48full, i, arg.k); | ||
| 757 | val_derive = get_h48_pval(h48derive, j, arg.k); | ||
| 758 | val_new = MIN(val_full, val_derive); | ||
| 759 | set_h48_pval(h48derive, j, arg.k, val_new); | ||
| 760 | } | ||
| 761 | |||
| 762 | h48max = H48_COORDMAX(h); | ||
| 763 | for (i = 0; i < h48max; i++) { | ||
| 764 | val_derive = get_h48_pval(h48derive, i, arg.k); | ||
| 765 | arg.info.distribution[val_derive]++; | ||
| 766 | } | ||
| 767 | |||
| 768 | if (!writetableinfo(&arg.info, buf)) { | ||
| 769 | LOG("gendata_h48_derive: could not write info for table\n"); | ||
| 770 | goto gendata_h48_derive_error; | ||
| 771 | } | ||
| 772 | |||
| 773 | gendata_h48_derive_return_size: | ||
| 774 | return cocsepsize + h48size; | ||
| 775 | |||
| 776 | gendata_h48_derive_error: | ||
| 777 | return 0; | ||
| 778 | } | ||
