diff options
| -rw-r--r-- | TODO.txt | 6 | ||||
| -rw-r--r-- | cube.c | 34 | ||||
| -rw-r--r-- | test/073_coord_csep/00_solved.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/00_solved.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/01_U.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/01_U.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/02_U2.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/02_U2.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/03_U3.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/03_U3.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/04_D.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/04_D.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/07_R.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/07_R.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/08_R2.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/08_R2.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/13_F.in | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/13_F.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/20_scrambled.in | 3 | ||||
| -rw-r--r-- | test/073_coord_csep/20_scrambled.out | 1 | ||||
| -rw-r--r-- | test/073_coord_csep/coord_csep_tests.c | 21 |
21 files changed, 77 insertions, 4 deletions
| @@ -1,9 +1,9 @@ | |||
| 1 | ## (find better name) H48 solver, ideas | 1 | ## (find better name) H48 solver, ideas |
| 2 | 2 | ||
| 3 | TODO next: implement cosep coordinate | 3 | TODO next: epsep, precise coordinate unlike cpsep which is redundant |
| 4 | 4 | ||
| 5 | First compute co + csep. Use csep as a binary number (2^8 instead of 70, | 5 | First compute co + csep. Use csep as a binary number (2^7 instead of 70, |
| 6 | loose a factor of 3.66 but still fits in a few megabytes or less). Use | 6 | loose a factor of 1.8 but still fits in a few megabytes or less). Use |
| 7 | co + csep as an index in a table whose entries have: 6 bits for ttrep, | 7 | co + csep as an index in a table whose entries have: 6 bits for ttrep, |
| 8 | 12 bits for rep, 4 bits for pruning. Optionally, 4 more bits could be | 8 | 12 bits for rep, 4 bits for pruning. Optionally, 4 more bits could be |
| 9 | used for the base of the pruning table, if we want to have a different | 9 | used for the base of the pruning table, if we want to have a different |
| @@ -5,6 +5,7 @@ | |||
| 5 | #include "cube.h" | 5 | #include "cube.h" |
| 6 | 6 | ||
| 7 | #ifdef DEBUG | 7 | #ifdef DEBUG |
| 8 | |||
| 8 | #include <stdio.h> | 9 | #include <stdio.h> |
| 9 | #define _static | 10 | #define _static |
| 10 | #define _static_inline | 11 | #define _static_inline |
| @@ -15,12 +16,15 @@ | |||
| 15 | DBG_LOG(__VA_ARGS__); \ | 16 | DBG_LOG(__VA_ARGS__); \ |
| 16 | return retval; \ | 17 | return retval; \ |
| 17 | } | 18 | } |
| 19 | |||
| 18 | #else | 20 | #else |
| 21 | |||
| 19 | #define _static static | 22 | #define _static static |
| 20 | #define _static_inline static inline | 23 | #define _static_inline static inline |
| 21 | #define DBG_LOG(...) | 24 | #define DBG_LOG(...) |
| 22 | #define DBG_WARN(condition, ...) | 25 | #define DBG_WARN(condition, ...) |
| 23 | #define DBG_ASSERT(condition, retval, ...) | 26 | #define DBG_ASSERT(condition, retval, ...) |
| 27 | |||
| 24 | #endif | 28 | #endif |
| 25 | 29 | ||
| 26 | /****************************************************************************** | 30 | /****************************************************************************** |
| @@ -495,6 +499,7 @@ typedef __m256i cube_fast_t; | |||
| 495 | 499 | ||
| 496 | #define _co2_avx2 _mm256_set_epi64x(0, 0, 0, 0x6060606060606060) | 500 | #define _co2_avx2 _mm256_set_epi64x(0, 0, 0, 0x6060606060606060) |
| 497 | #define _cocw_avx2 _mm256_set_epi64x(0, 0, 0, 0x2020202020202020) | 501 | #define _cocw_avx2 _mm256_set_epi64x(0, 0, 0, 0x2020202020202020) |
| 502 | #define _cp_avx2 _mm256_set_epi64x(0, 0, 0, 0x0707070707070707) | ||
| 498 | #define _eo_avx2 _mm256_set_epi64x(0x10101010, 0x1010101010101010, 0, 0) | 503 | #define _eo_avx2 _mm256_set_epi64x(0x10101010, 0x1010101010101010, 0, 0) |
| 499 | 504 | ||
| 500 | _static_inline cube_fast_t fastcube( | 505 | _static_inline cube_fast_t fastcube( |
| @@ -511,6 +516,7 @@ _static_inline cube_fast_t invertco_fast(cube_fast_t); | |||
| 511 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); | 516 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); |
| 512 | 517 | ||
| 513 | _static_inline int64_t coord_fast_co(cube_fast_t); | 518 | _static_inline int64_t coord_fast_co(cube_fast_t); |
| 519 | _static_inline int64_t coord_fast_csep(cube_fast_t); | ||
| 514 | _static_inline int64_t coord_fast_eo(cube_fast_t); | 520 | _static_inline int64_t coord_fast_eo(cube_fast_t); |
| 515 | 521 | ||
| 516 | _static_inline cube_fast_t | 522 | _static_inline cube_fast_t |
| @@ -641,7 +647,7 @@ compose_fast(cube_fast_t c1, cube_fast_t c2) | |||
| 641 | _static_inline int64_t | 647 | _static_inline int64_t |
| 642 | coord_fast_co(cube_fast_t c) | 648 | coord_fast_co(cube_fast_t c) |
| 643 | { | 649 | { |
| 644 | cube_fast_t co, shifted; | 650 | cube_fast_t co; |
| 645 | int64_t mem[4], ret, i, p; | 651 | int64_t mem[4], ret, i, p; |
| 646 | 652 | ||
| 647 | co = _mm256_and_si256(c, _co2_avx2); | 653 | co = _mm256_and_si256(c, _co2_avx2); |
| @@ -655,6 +661,19 @@ coord_fast_co(cube_fast_t c) | |||
| 655 | } | 661 | } |
| 656 | 662 | ||
| 657 | _static_inline int64_t | 663 | _static_inline int64_t |
| 664 | coord_fast_csep(cube_fast_t c) | ||
| 665 | { | ||
| 666 | cube_fast_t cp, shifted; | ||
| 667 | int64_t mask; | ||
| 668 | |||
| 669 | cp = _mm256_and_si256(c, _cp_avx2); | ||
| 670 | shifted = _mm256_slli_epi32(cp, 5); | ||
| 671 | mask = _mm256_movemask_epi8(shifted); | ||
| 672 | |||
| 673 | return mask & 0x7F; | ||
| 674 | } | ||
| 675 | |||
| 676 | _static_inline int64_t | ||
| 658 | coord_fast_eo(cube_fast_t c) | 677 | coord_fast_eo(cube_fast_t c) |
| 659 | { | 678 | { |
| 660 | cube_fast_t eo, shifted; | 679 | cube_fast_t eo, shifted; |
| @@ -709,6 +728,7 @@ _static_inline cube_fast_t invertco_fast(cube_fast_t); | |||
| 709 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); | 728 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); |
| 710 | 729 | ||
| 711 | _static_inline int64_t coord_fast_co(cube_fast_t); | 730 | _static_inline int64_t coord_fast_co(cube_fast_t); |
| 731 | _static_inline int64_t coord_fast_csep(cube_fast_t); | ||
| 712 | _static_inline int64_t coord_fast_eo(cube_fast_t); | 732 | _static_inline int64_t coord_fast_eo(cube_fast_t); |
| 713 | 733 | ||
| 714 | _static_inline cube_fast_t | 734 | _static_inline cube_fast_t |
| @@ -844,6 +864,18 @@ coord_fast_co(cube_fast_t c) | |||
| 844 | } | 864 | } |
| 845 | 865 | ||
| 846 | _static_inline int64_t | 866 | _static_inline int64_t |
| 867 | coord_fast_csep(cube_fast_t c) | ||
| 868 | { | ||
| 869 | int i, p; | ||
| 870 | int64_t ret; | ||
| 871 | |||
| 872 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 2) | ||
| 873 | ret += p * ((c.corner[i] & _pbits) >> 2U); | ||
| 874 | |||
| 875 | return ret; | ||
| 876 | } | ||
| 877 | |||
| 878 | _static_inline int64_t | ||
| 847 | coord_fast_eo(cube_fast_t c) | 879 | coord_fast_eo(cube_fast_t c) |
| 848 | { | 880 | { |
| 849 | int i, p; | 881 | int i, p; |
diff --git a/test/073_coord_csep/00_solved.in b/test/073_coord_csep/00_solved.in new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/073_coord_csep/00_solved.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | |||
diff --git a/test/073_coord_csep/00_solved.out b/test/073_coord_csep/00_solved.out new file mode 100644 index 0000000..194b81c --- /dev/null +++ b/test/073_coord_csep/00_solved.out | |||
| @@ -0,0 +1 @@ | |||
| 112 | |||
diff --git a/test/073_coord_csep/01_U.in b/test/073_coord_csep/01_U.in new file mode 100644 index 0000000..b5b36ad --- /dev/null +++ b/test/073_coord_csep/01_U.in | |||
| @@ -0,0 +1 @@ | |||
| UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0 | |||
diff --git a/test/073_coord_csep/01_U.out b/test/073_coord_csep/01_U.out new file mode 100644 index 0000000..3fdcd7c --- /dev/null +++ b/test/073_coord_csep/01_U.out | |||
| @@ -0,0 +1 @@ | |||
| 67 | |||
diff --git a/test/073_coord_csep/02_U2.in b/test/073_coord_csep/02_U2.in new file mode 100644 index 0000000..316ad57 --- /dev/null +++ b/test/073_coord_csep/02_U2.in | |||
| @@ -0,0 +1 @@ | |||
| UB0 UF0 DB0 DF0 UL0 UR0 DL0 DR0 FR0 FL0 BL0 BR0 UBL0 UFR0 DFL0 DBR0 UBR0 UFL0 DFR0 DBL0 | |||
diff --git a/test/073_coord_csep/02_U2.out b/test/073_coord_csep/02_U2.out new file mode 100644 index 0000000..194b81c --- /dev/null +++ b/test/073_coord_csep/02_U2.out | |||
| @@ -0,0 +1 @@ | |||
| 112 | |||
diff --git a/test/073_coord_csep/03_U3.in b/test/073_coord_csep/03_U3.in new file mode 100644 index 0000000..7721ab5 --- /dev/null +++ b/test/073_coord_csep/03_U3.in | |||
| @@ -0,0 +1 @@ | |||
| UL0 UR0 DB0 DF0 UF0 UB0 DL0 DR0 FR0 FL0 BL0 BR0 UFL0 UBR0 DFL0 DBR0 UBL0 UFR0 DFR0 DBL0 | |||
diff --git a/test/073_coord_csep/03_U3.out b/test/073_coord_csep/03_U3.out new file mode 100644 index 0000000..3fdcd7c --- /dev/null +++ b/test/073_coord_csep/03_U3.out | |||
| @@ -0,0 +1 @@ | |||
| 67 | |||
diff --git a/test/073_coord_csep/04_D.in b/test/073_coord_csep/04_D.in new file mode 100644 index 0000000..cf4f816 --- /dev/null +++ b/test/073_coord_csep/04_D.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DR0 DL0 UR0 UL0 DB0 DF0 FR0 FL0 BL0 BR0 UFR0 UBL0 DBL0 DFR0 UFL0 UBR0 DFL0 DBR0 | |||
diff --git a/test/073_coord_csep/04_D.out b/test/073_coord_csep/04_D.out new file mode 100644 index 0000000..abdfb05 --- /dev/null +++ b/test/073_coord_csep/04_D.out | |||
| @@ -0,0 +1 @@ | |||
| 60 | |||
diff --git a/test/073_coord_csep/07_R.in b/test/073_coord_csep/07_R.in new file mode 100644 index 0000000..8c8fcb3 --- /dev/null +++ b/test/073_coord_csep/07_R.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 FR0 UL0 DL0 BR0 DR0 FL0 BL0 UR0 DFR2 UBL0 DFL0 UBR2 UFL0 UFR1 DBR1 DBL0 | |||
diff --git a/test/073_coord_csep/07_R.out b/test/073_coord_csep/07_R.out new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/test/073_coord_csep/07_R.out | |||
| @@ -0,0 +1 @@ | |||
| 25 | |||
diff --git a/test/073_coord_csep/08_R2.in b/test/073_coord_csep/08_R2.in new file mode 100644 index 0000000..90765e2 --- /dev/null +++ b/test/073_coord_csep/08_R2.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 DR0 UL0 DL0 UR0 BR0 FL0 BL0 FR0 DBR0 UBL0 DFL0 UFR0 UFL0 DFR0 UBR0 DBL0 | |||
diff --git a/test/073_coord_csep/08_R2.out b/test/073_coord_csep/08_R2.out new file mode 100644 index 0000000..194b81c --- /dev/null +++ b/test/073_coord_csep/08_R2.out | |||
| @@ -0,0 +1 @@ | |||
| 112 | |||
diff --git a/test/073_coord_csep/13_F.in b/test/073_coord_csep/13_F.in new file mode 100644 index 0000000..e805af8 --- /dev/null +++ b/test/073_coord_csep/13_F.in | |||
| @@ -0,0 +1 @@ | |||
| FL1 UB0 DB0 FR1 UR0 UL0 DL0 DR0 UF1 DF1 BL0 BR0 UFL1 UBL0 DFR1 DBR0 DFL2 UBR0 UFR2 DBL0 | |||
diff --git a/test/073_coord_csep/13_F.out b/test/073_coord_csep/13_F.out new file mode 100644 index 0000000..81b5c5d --- /dev/null +++ b/test/073_coord_csep/13_F.out | |||
| @@ -0,0 +1 @@ | |||
| 37 | |||
diff --git a/test/073_coord_csep/20_scrambled.in b/test/073_coord_csep/20_scrambled.in new file mode 100644 index 0000000..274d30b --- /dev/null +++ b/test/073_coord_csep/20_scrambled.in | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | ||
| 2 | |||
| 3 | // Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B' | ||
diff --git a/test/073_coord_csep/20_scrambled.out b/test/073_coord_csep/20_scrambled.out new file mode 100644 index 0000000..52bd8e4 --- /dev/null +++ b/test/073_coord_csep/20_scrambled.out | |||
| @@ -0,0 +1 @@ | |||
| 120 | |||
diff --git a/test/073_coord_csep/coord_csep_tests.c b/test/073_coord_csep/coord_csep_tests.c new file mode 100644 index 0000000..b36bf1a --- /dev/null +++ b/test/073_coord_csep/coord_csep_tests.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | int64_t coord_fast_csep(cube_fast_t); | ||
| 4 | cube_fast_t cubetofast(cube_t); | ||
| 5 | |||
| 6 | int main(void) { | ||
| 7 | char str[STRLENMAX]; | ||
| 8 | cube_t cube; | ||
| 9 | cube_fast_t fast; | ||
| 10 | int64_t result; | ||
| 11 | |||
| 12 | fgets(str, STRLENMAX, stdin); | ||
| 13 | cube = readcube("H48", str); | ||
| 14 | fast = cubetofast(cube); | ||
| 15 | |||
| 16 | result = coord_fast_csep(fast); | ||
| 17 | |||
| 18 | printf("%" PRId64 "\n", result); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
