diff options
Diffstat (limited to 'cube.c')
| -rw-r--r-- | cube.c | 43 |
1 files changed, 19 insertions, 24 deletions
| @@ -501,7 +501,7 @@ typedef __m256i cube_fast_t; | |||
| 501 | #define _cocw_avx2 _mm256_set_epi64x(0, 0, 0, 0x2020202020202020) | 501 | #define _cocw_avx2 _mm256_set_epi64x(0, 0, 0, 0x2020202020202020) |
| 502 | #define _eo_avx2 _mm256_set_epi64x(0x10101010, 0x1010101010101010, 0, 0) | 502 | #define _eo_avx2 _mm256_set_epi64x(0x10101010, 0x1010101010101010, 0, 0) |
| 503 | 503 | ||
| 504 | _static inline cube_fast_t fastcube( | 504 | _static_inline cube_fast_t fastcube( |
| 505 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 505 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| 506 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 506 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| 507 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 507 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| @@ -512,11 +512,10 @@ _static cube_t fasttocube(cube_fast_t); | |||
| 512 | _static_inline bool equal_fast(cube_fast_t, cube_fast_t); | 512 | _static_inline bool equal_fast(cube_fast_t, cube_fast_t); |
| 513 | _static_inline bool issolved_fast(cube_fast_t); | 513 | _static_inline bool issolved_fast(cube_fast_t); |
| 514 | _static_inline cube_fast_t invertco_fast(cube_fast_t); | 514 | _static_inline cube_fast_t invertco_fast(cube_fast_t); |
| 515 | _static_inline cube_fast_t cleanaftershuffle(cube_fast_t); | ||
| 516 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); | 515 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); |
| 517 | _static_inline int64_t coord_fast_eo(cube_fast_t); | 516 | _static_inline int64_t coord_fast_eo(cube_fast_t); |
| 518 | 517 | ||
| 519 | _static inline cube_fast_t | 518 | _static_inline cube_fast_t |
| 520 | fastcube( | 519 | fastcube( |
| 521 | uint8_t c_ufr, | 520 | uint8_t c_ufr, |
| 522 | uint8_t c_ubl, | 521 | uint8_t c_ubl, |
| @@ -609,29 +608,23 @@ invertco_fast(cube_fast_t c) | |||
| 609 | } | 608 | } |
| 610 | 609 | ||
| 611 | _static_inline cube_fast_t | 610 | _static_inline cube_fast_t |
| 612 | cleanaftershuffle(cube_fast_t c) | 611 | compose_fast(cube_fast_t c1, cube_fast_t c2) |
| 613 | { | 612 | { |
| 614 | __m256i b; | 613 | cube_fast_t s, b, eo2, co1, co2, aux, auy1, auy2, auz1, auz2; |
| 615 | 614 | ||
| 615 | /* Permute and clean unused bits */ | ||
| 616 | s = _mm256_shuffle_epi8(c1, c2); | ||
| 616 | b = _mm256_set_epi8( | 617 | b = _mm256_set_epi8( |
| 617 | ~0, ~0, ~0, ~0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 618 | ~0, ~0, ~0, ~0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 618 | ~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0, 0, 0, 0, 0, 0, 0, 0, 0 | 619 | ~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 619 | ); | 620 | ); |
| 621 | s = _mm256_andnot_si256(b, s); | ||
| 620 | 622 | ||
| 621 | return _mm256_andnot_si256(b, c); | 623 | /* Change EO */ |
| 622 | } | ||
| 623 | |||
| 624 | _static_inline cube_fast_t | ||
| 625 | compose_fast(cube_fast_t c1, cube_fast_t c2) | ||
| 626 | { | ||
| 627 | cube_fast_t ret; | ||
| 628 | |||
| 629 | cube_fast_t s, eo2, ed, co1, co2, aux, auy1, auy2, auz1, auz2, coclean; | ||
| 630 | |||
| 631 | eo2 = _mm256_and_si256(c2, _eo_avx2); | 624 | eo2 = _mm256_and_si256(c2, _eo_avx2); |
| 632 | s = _mm256_shuffle_epi8(c1, c2); | 625 | s = _mm256_xor_si256(s, eo2); |
| 633 | s = cleanaftershuffle(s); | 626 | |
| 634 | ed = _mm256_xor_si256(s, eo2); | 627 | /* Change CO */ |
| 635 | co1 = _mm256_and_si256(s, _co2_avx2); | 628 | co1 = _mm256_and_si256(s, _co2_avx2); |
| 636 | co2 = _mm256_and_si256(c2, _co2_avx2); | 629 | co2 = _mm256_and_si256(c2, _co2_avx2); |
| 637 | aux = _mm256_add_epi8(co1, co2); | 630 | aux = _mm256_add_epi8(co1, co2); |
| @@ -639,10 +632,12 @@ compose_fast(cube_fast_t c1, cube_fast_t c2) | |||
| 639 | auy2 = _mm256_srli_epi32(auy1, 2); | 632 | auy2 = _mm256_srli_epi32(auy1, 2); |
| 640 | auz1 = _mm256_add_epi8(aux, auy2); | 633 | auz1 = _mm256_add_epi8(aux, auy2); |
| 641 | auz2 = _mm256_and_si256(auz1, _co2_avx2); | 634 | auz2 = _mm256_and_si256(auz1, _co2_avx2); |
| 642 | coclean = _mm256_andnot_si256(_co2_avx2, ed); | ||
| 643 | ret = _mm256_or_si256(coclean, auz2); | ||
| 644 | 635 | ||
| 645 | return ret; | 636 | /* Put together */ |
| 637 | s = _mm256_andnot_si256(_co2_avx2, s); | ||
| 638 | s = _mm256_or_si256(s, auz2); | ||
| 639 | |||
| 640 | return s; | ||
| 646 | } | 641 | } |
| 647 | 642 | ||
| 648 | _static_inline int64_t | 643 | _static_inline int64_t |
| @@ -671,7 +666,7 @@ in the previous section(s) for unsupported architectures. | |||
| 671 | 666 | ||
| 672 | typedef cube_t cube_fast_t; | 667 | typedef cube_t cube_fast_t; |
| 673 | 668 | ||
| 674 | _static cube_fast_t fastcube( | 669 | _static_inline cube_fast_t fastcube( |
| 675 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 670 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| 676 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 671 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| 677 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 672 | uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| @@ -685,7 +680,7 @@ _static_inline cube_fast_t invertco_fast(cube_fast_t); | |||
| 685 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); | 680 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); |
| 686 | _static_inline int64_t coord_fast_eo(cube_fast_t); | 681 | _static_inline int64_t coord_fast_eo(cube_fast_t); |
| 687 | 682 | ||
| 688 | _static inline cube_fast_t | 683 | _static_inline cube_fast_t |
| 689 | fastcube( | 684 | fastcube( |
| 690 | uint8_t c_ufr, | 685 | uint8_t c_ufr, |
| 691 | uint8_t c_ubl, | 686 | uint8_t c_ubl, |
| @@ -1018,7 +1013,7 @@ inverse(cube_t cube) | |||
| 1018 | DBG_ASSERT(isconsistent(cube), zero, | 1013 | DBG_ASSERT(isconsistent(cube), zero, |
| 1019 | "inverse error: inconsistent cube\n"); | 1014 | "inverse error: inconsistent cube\n"); |
| 1020 | 1015 | ||
| 1021 | ret = zero_fast; | 1016 | ret = zero; |
| 1022 | 1017 | ||
| 1023 | for (i = 0; i < 12; i++) { | 1018 | for (i = 0; i < 12; i++) { |
| 1024 | piece = cube.edge[i]; | 1019 | piece = cube.edge[i]; |
