diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-02 20:05:29 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-02 20:05:29 +0100 |
| commit | a61382e9dec22ea1ff3fea2d59d3c605c0aa2aac (patch) | |
| tree | b7b7a120439d45c780a3f664462bf29f56af5df2 /src/cube.c | |
| parent | a2b8556e3cdc59bbb4a89c2779d2094db975eaa5 (diff) | |
| download | nissy-core-a61382e9dec22ea1ff3fea2d59d3c605c0aa2aac.tar.gz nissy-core-a61382e9dec22ea1ff3fea2d59d3c605c0aa2aac.zip | |
Optimized compose for avx2
Diffstat (limited to 'src/cube.c')
| -rw-r--r-- | src/cube.c | 26 |
1 files changed, 22 insertions, 4 deletions
| @@ -939,19 +939,36 @@ inverse(cube_t c) | |||
| 939 | cube_t | 939 | cube_t |
| 940 | compose(cube_t c1, cube_t c2) | 940 | compose(cube_t c1, cube_t c2) |
| 941 | { | 941 | { |
| 942 | /* TODO: optimize for avx2 */ | ||
| 943 | uint8_t i, piece1, piece2, p, orien, aux, auy; | ||
| 944 | cube_t ret; | 942 | cube_t ret; |
| 945 | 943 | ||
| 946 | setzero(ret); | ||
| 947 | |||
| 948 | #ifdef DEBUG | 944 | #ifdef DEBUG |
| 949 | if (!isconsistent(c1) || !isconsistent(c2)) { | 945 | if (!isconsistent(c1) || !isconsistent(c2)) { |
| 950 | fprintf(stderr, "compose error, inconsistent cube\n"); | 946 | fprintf(stderr, "compose error, inconsistent cube\n"); |
| 947 | setzero(ret); | ||
| 951 | return ret; | 948 | return ret; |
| 952 | } | 949 | } |
| 953 | #endif | 950 | #endif |
| 954 | 951 | ||
| 952 | #ifdef CUBE_AVX2 | ||
| 953 | cube_t shuf, eo, eodone, co2, aux, auy1, auy2, cw, auz1, auz2, coclean; | ||
| 954 | |||
| 955 | co2 = _mm256_and_si256(c2, _co_avx2); | ||
| 956 | eo = _mm256_and_si256(c2, _eo_avx2); | ||
| 957 | shufd = _mm256_shuffle_epi8(c1, c2); | ||
| 958 | eodone = _mm256_(shufd, eo); | ||
| 959 | aux = _mm256_add_epi8(c1, co2); | ||
| 960 | cw = _mm256_set_epi64x(0, 0x2020202020202020, 0, 0); | ||
| 961 | auy1 = _mm256_add_epi8(aux, cw); | ||
| 962 | auy2 = _mm256_srli_si256(auy1, 2); | ||
| 963 | auz1 = _mm256_add_epi8(aux, auy2); | ||
| 964 | auz2 = _mm256_and_si256(auz1, _co_avx2); | ||
| 965 | coclean = _mm256_andnot_si256(eodone, _co_avx2); | ||
| 966 | ret = _mm256_or_si256(coclean, auz2); | ||
| 967 | #else | ||
| 968 | uint8_t i, piece1, piece2, p, orien, aux, auy; | ||
| 969 | |||
| 970 | setzero(ret); | ||
| 971 | |||
| 955 | for (i = 0; i < 12; i++) { | 972 | for (i = 0; i < 12; i++) { |
| 956 | piece2 = get_edge(c2, i); | 973 | piece2 = get_edge(c2, i); |
| 957 | p = piece2 & _pbits; | 974 | p = piece2 & _pbits; |
| @@ -969,6 +986,7 @@ compose(cube_t c1, cube_t c2) | |||
| 969 | orien = (aux + auy) & _cobits2; | 986 | orien = (aux + auy) & _cobits2; |
| 970 | set_corner(ret, i, (piece1 & _pbits) | orien); | 987 | set_corner(ret, i, (piece1 & _pbits) | orien); |
| 971 | } | 988 | } |
| 989 | #endif | ||
| 972 | 990 | ||
| 973 | return ret; | 991 | return ret; |
| 974 | } | 992 | } |
