diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-13 19:16:32 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-14 10:26:34 +0100 |
| commit | b25989e47adfadabcf0dabfd58d615622887cee0 (patch) | |
| tree | bf0037801f22e4bff1d29ce1724725cab098d4a5 /src/solvers/h48/gendata_h48.h | |
| parent | 6c42463b800bbab4583e90aeb748a79037c65a9e (diff) | |
| download | nissy-core-b25989e47adfadabcf0dabfd58d615622887cee0.tar.gz nissy-core-b25989e47adfadabcf0dabfd58d615622887cee0.zip | |
Intertwined table seems to work
Diffstat (limited to 'src/solvers/h48/gendata_h48.h')
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 7ccadd6..8470b2f 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -20,6 +20,10 @@ STATIC const unsigned char *get_h48data_constptr(const unsigned char *); | |||
| 20 | 20 | ||
| 21 | STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, uint64_t, uint8_t); | 21 | STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, uint64_t, uint8_t); |
| 22 | STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t, uint8_t); | 22 | STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t, uint8_t); |
| 23 | STATIC_INLINE uint8_t get_h48_pvalmin( | ||
| 24 | const unsigned char *, uint64_t, uint8_t); | ||
| 25 | STATIC_INLINE void set_h48_pvalmin( | ||
| 26 | unsigned char *, uint64_t, uint8_t, uint8_t); | ||
| 23 | STATIC_INLINE uint8_t get_h48_pval_atomic( | 27 | STATIC_INLINE uint8_t get_h48_pval_atomic( |
| 24 | wrapthread_atomic const unsigned char *, uint64_t, uint8_t); | 28 | wrapthread_atomic const unsigned char *, uint64_t, uint8_t); |
| 25 | STATIC_INLINE void set_h48_pval_atomic( | 29 | STATIC_INLINE void set_h48_pval_atomic( |
| @@ -300,6 +304,7 @@ gendata_h48h0k4_runthread(void *arg) | |||
| 300 | .depth = bfsarg->depth, | 304 | .depth = bfsarg->depth, |
| 301 | .h = 0, | 305 | .h = 0, |
| 302 | .k = 4, | 306 | .k = 4, |
| 307 | .base = 0, /* Unused */ | ||
| 303 | .cocsepdata = bfsarg->cocsepdata, | 308 | .cocsepdata = bfsarg->cocsepdata, |
| 304 | .selfsim = bfsarg->selfsim, | 309 | .selfsim = bfsarg->selfsim, |
| 305 | .table_atomic = bfsarg->table, | 310 | .table_atomic = bfsarg->table, |
| @@ -343,10 +348,6 @@ gendata_h48h0k4_runthread(void *arg) | |||
| 343 | STATIC void | 348 | STATIC void |
| 344 | gendata_h48k2(gendata_h48_arg_t arg[static 1]) | 349 | gendata_h48k2(gendata_h48_arg_t arg[static 1]) |
| 345 | { | 350 | { |
| 346 | static const uint8_t shortdepth = 8; | ||
| 347 | static const uint64_t capacity = 10000019; | ||
| 348 | static const uint64_t randomizer = 10000079; | ||
| 349 | |||
| 350 | /* | 351 | /* |
| 351 | * A good base value for the k=2 tables have few positions with value | 352 | * A good base value for the k=2 tables have few positions with value |
| 352 | * 0, because those are treated as lower bound 0 and require a second | 353 | * 0, because those are treated as lower bound 0 and require a second |
| @@ -391,6 +392,10 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 391 | [11] = 10 | 392 | [11] = 10 |
| 392 | }; | 393 | }; |
| 393 | 394 | ||
| 395 | static const uint8_t shortdepth = 8; | ||
| 396 | static const uint64_t capacity = 10000019; | ||
| 397 | static const uint64_t randomizer = 10000079; | ||
| 398 | |||
| 394 | uint8_t t; | 399 | uint8_t t; |
| 395 | int sleeptime; | 400 | int sleeptime; |
| 396 | unsigned char *table; | 401 | unsigned char *table; |
| @@ -481,10 +486,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 481 | 486 | ||
| 482 | h48map_destroy(&shortcubes); | 487 | h48map_destroy(&shortcubes); |
| 483 | 488 | ||
| 484 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { | 489 | getdistribution_h48(table, arg->info.distribution, &arg->info); |
| 485 | t = get_h48_pval(table, j, 2); | ||
| 486 | arg->info.distribution[t]++; | ||
| 487 | } | ||
| 488 | 490 | ||
| 489 | bufsize = arg->buf_size - COCSEP_FULLSIZE; | 491 | bufsize = arg->buf_size - COCSEP_FULLSIZE; |
| 490 | writetableinfo(&arg->info, bufsize, (unsigned char *)arg->h48buf); | 492 | writetableinfo(&arg->info, bufsize, (unsigned char *)arg->h48buf); |
| @@ -493,7 +495,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 493 | STATIC void * | 495 | STATIC void * |
| 494 | gendata_h48k2_runthread(void *arg) | 496 | gendata_h48k2_runthread(void *arg) |
| 495 | { | 497 | { |
| 496 | uint64_t coord; | 498 | uint64_t coord, coordext, coordmin; |
| 497 | kvpair_t kv; | 499 | kvpair_t kv; |
| 498 | h48k2_dfs_arg_t *dfsarg; | 500 | h48k2_dfs_arg_t *dfsarg; |
| 499 | wrapthread_define_if_threads(uint64_t, mutex); | 501 | wrapthread_define_if_threads(uint64_t, mutex); |
| @@ -513,9 +515,13 @@ gendata_h48k2_runthread(void *arg) | |||
| 513 | 515 | ||
| 514 | if (kv.val < dfsarg->shortdepth) { | 516 | if (kv.val < dfsarg->shortdepth) { |
| 515 | coord = kv.key >> (uint64_t)(11 - dfsarg->h); | 517 | coord = kv.key >> (uint64_t)(11 - dfsarg->h); |
| 516 | mutex = H48_INDEX(coord, dfsarg->k) % CHUNKS; | 518 | coordext = H48_LINE_EXT(coord); |
| 519 | coordmin = H48_LINE_MIN(coord); | ||
| 520 | |||
| 521 | mutex = H48_LINE(coord) % CHUNKS; | ||
| 517 | wrapthread_mutex_lock(dfsarg->table_mutex[mutex]); | 522 | wrapthread_mutex_lock(dfsarg->table_mutex[mutex]); |
| 518 | set_h48_pval(dfsarg->table, coord, dfsarg->k, 0); | 523 | set_h48_pval(dfsarg->table, coordext, dfsarg->k, 0); |
| 524 | set_h48_pvalmin(dfsarg->table, coordmin, dfsarg->k, kv.val); | ||
| 519 | wrapthread_mutex_unlock(dfsarg->table_mutex[mutex]); | 525 | wrapthread_mutex_unlock(dfsarg->table_mutex[mutex]); |
| 520 | } else { | 526 | } else { |
| 521 | dfsarg->cube = invcoord_h48(kv.key, dfsarg->crep, 11); | 527 | dfsarg->cube = invcoord_h48(kv.key, dfsarg->crep, 11); |
| @@ -537,6 +543,7 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t arg[static 1]) | |||
| 537 | markarg = (gendata_h48_mark_t) { | 543 | markarg = (gendata_h48_mark_t) { |
| 538 | .h = arg->h, | 544 | .h = arg->h, |
| 539 | .k = arg->k, | 545 | .k = arg->k, |
| 546 | .base = arg->base, | ||
| 540 | .cocsepdata = arg->cocsepdata, | 547 | .cocsepdata = arg->cocsepdata, |
| 541 | .selfsim = arg->selfsim, | 548 | .selfsim = arg->selfsim, |
| 542 | .table = arg->table, | 549 | .table = arg->table, |
| @@ -629,17 +636,23 @@ gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) | |||
| 629 | STATIC_INLINE void | 636 | STATIC_INLINE void |
| 630 | gendata_h48_mark(gendata_h48_mark_t arg[static 1]) | 637 | gendata_h48_mark(gendata_h48_mark_t arg[static 1]) |
| 631 | { | 638 | { |
| 632 | uint8_t oldval, newval; | 639 | uint8_t oldval, newval, v; |
| 633 | uint64_t coord; | 640 | uint64_t coord, coordext, coordmin; |
| 634 | wrapthread_define_if_threads(uint64_t, mutex); | 641 | wrapthread_define_if_threads(uint64_t, mutex); |
| 635 | 642 | ||
| 636 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, | 643 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, |
| 637 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); | 644 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); |
| 638 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | 645 | coordext = H48_LINE_EXT(coord); |
| 646 | coordmin = H48_LINE_MIN(coord); | ||
| 647 | |||
| 648 | mutex = H48_LINE(coord) % CHUNKS; | ||
| 639 | wrapthread_mutex_lock(arg->table_mutex[mutex]); | 649 | wrapthread_mutex_lock(arg->table_mutex[mutex]); |
| 640 | oldval = get_h48_pval(arg->table, coord, arg->k); | 650 | oldval = get_h48_pval(arg->table, coordext, arg->k); |
| 641 | newval = (uint8_t)MAX(arg->depth, 0); | 651 | newval = (uint8_t)MAX(arg->depth, 0); |
| 642 | set_h48_pval(arg->table, coord, arg->k, MIN(newval, oldval)); | 652 | v = MIN(newval, oldval); |
| 653 | set_h48_pval(arg->table, coordext, arg->k, v); | ||
| 654 | v = arg->depth + arg->base; | ||
| 655 | set_h48_pvalmin(arg->table, coordmin, arg->k, v); | ||
| 643 | wrapthread_mutex_unlock(arg->table_mutex[mutex]); | 656 | wrapthread_mutex_unlock(arg->table_mutex[mutex]); |
| 644 | ) | 657 | ) |
| 645 | } | 658 | } |
| @@ -648,7 +661,7 @@ STATIC_INLINE bool | |||
| 648 | gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) | 661 | gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) |
| 649 | { | 662 | { |
| 650 | uint64_t val; | 663 | uint64_t val; |
| 651 | uint64_t coord; | 664 | uint64_t coord, coordext; |
| 652 | wrapthread_define_if_threads(uint64_t, mutex); | 665 | wrapthread_define_if_threads(uint64_t, mutex); |
| 653 | int8_t oldval; | 666 | int8_t oldval; |
| 654 | 667 | ||
| @@ -656,9 +669,10 @@ gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) | |||
| 656 | /* We are in the "real coordinate" case, we can stop | 669 | /* We are in the "real coordinate" case, we can stop |
| 657 | if this coordinate has already been visited */ | 670 | if this coordinate has already been visited */ |
| 658 | coord = coord_h48(cube, arg->cocsepdata, arg->h); | 671 | coord = coord_h48(cube, arg->cocsepdata, arg->h); |
| 659 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | 672 | coordext = H48_LINE_EXT(coord); |
| 673 | mutex = H48_LINE(coord) % CHUNKS; | ||
| 660 | wrapthread_mutex_lock(arg->table_mutex[mutex]); | 674 | wrapthread_mutex_lock(arg->table_mutex[mutex]); |
| 661 | oldval = get_h48_pval(arg->table, coord, arg->k); | 675 | oldval = get_h48_pval(arg->table, coordext, arg->k); |
| 662 | wrapthread_mutex_unlock(arg->table_mutex[mutex]); | 676 | wrapthread_mutex_unlock(arg->table_mutex[mutex]); |
| 663 | return oldval <= d; | 677 | return oldval <= d; |
| 664 | } else { | 678 | } else { |
| @@ -682,7 +696,7 @@ makeinfo_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 682 | .infosize = INFOSIZE, | 696 | .infosize = INFOSIZE, |
| 683 | .fullsize = H48_TABLESIZE(arg->h, 2) + INFOSIZE, | 697 | .fullsize = H48_TABLESIZE(arg->h, 2) + INFOSIZE, |
| 684 | .hash = 0, | 698 | .hash = 0, |
| 685 | .entries = H48_COORDMAX(arg->h), | 699 | .entries = H48_COORDMAX(arg->h) + 2 * H48_LINES(arg->h), |
| 686 | .classes = 0, | 700 | .classes = 0, |
| 687 | .h48h = arg->h, | 701 | .h48h = arg->h, |
| 688 | .bits = 2, | 702 | .bits = 2, |
| @@ -716,6 +730,13 @@ get_h48_pval(const unsigned char *table, uint64_t i, uint8_t k) | |||
| 716 | } | 730 | } |
| 717 | 731 | ||
| 718 | STATIC_INLINE uint8_t | 732 | STATIC_INLINE uint8_t |
| 733 | get_h48_pvalmin(const unsigned char *table, uint64_t i, uint8_t k) | ||
| 734 | { | ||
| 735 | return (get_h48_pval(table, i, k) << UINT8_C(2)) + | ||
| 736 | get_h48_pval(table, i+UINT64_C(1), k); | ||
| 737 | } | ||
| 738 | |||
| 739 | STATIC_INLINE uint8_t | ||
| 719 | get_h48_pval_atomic( | 740 | get_h48_pval_atomic( |
| 720 | wrapthread_atomic const unsigned char *table, | 741 | wrapthread_atomic const unsigned char *table, |
| 721 | uint64_t i, | 742 | uint64_t i, |
| @@ -733,6 +754,16 @@ set_h48_pval(unsigned char *table, uint64_t i, uint8_t k, uint8_t val) | |||
| 733 | } | 754 | } |
| 734 | 755 | ||
| 735 | STATIC_INLINE void | 756 | STATIC_INLINE void |
| 757 | set_h48_pvalmin(unsigned char *table, uint64_t i, uint8_t k, uint8_t val) | ||
| 758 | { | ||
| 759 | uint8_t v; | ||
| 760 | |||
| 761 | v = MIN(val, get_h48_pvalmin(table, i, k)); | ||
| 762 | set_h48_pval(table, i, k, v >> UINT8_C(2)); | ||
| 763 | set_h48_pval(table, i+UINT64_C(1), k, v % UINT8_C(4)); | ||
| 764 | } | ||
| 765 | |||
| 766 | STATIC_INLINE void | ||
| 736 | set_h48_pval_atomic( | 767 | set_h48_pval_atomic( |
| 737 | wrapthread_atomic unsigned char *table, | 768 | wrapthread_atomic unsigned char *table, |
| 738 | uint64_t i, | 769 | uint64_t i, |
