diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-01 16:52:44 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-01 16:52:44 +0200 |
| commit | 1bd4691d9cc46ec75adbe899b289a1ebc5460721 (patch) | |
| tree | ea71166e05d399e57a13d6e3d7d96d4737f8f7bd /src/arch/avx2.h | |
| parent | 0844b0ecd00bd6d68a7bafaeae0ee3d420db8ff6 (diff) | |
| download | nissy-core-1bd4691d9cc46ec75adbe899b289a1ebc5460721.tar.gz nissy-core-1bd4691d9cc46ec75adbe899b289a1ebc5460721.zip | |
Added CPEPE coordinate in preparation of full DRFIN solver
Diffstat (limited to 'src/arch/avx2.h')
| -rw-r--r-- | src/arch/avx2.h | 73 |
1 files changed, 66 insertions, 7 deletions
diff --git a/src/arch/avx2.h b/src/arch/avx2.h index 24c8280..3fb46c9 100644 --- a/src/arch/avx2.h +++ b/src/arch/avx2.h | |||
| @@ -24,9 +24,9 @@ | |||
| 24 | #define ZERO_CUBE _mm256_set_epi64x(0, 0, 0, 0) | 24 | #define ZERO_CUBE _mm256_set_epi64x(0, 0, 0, 0) |
| 25 | #define SOLVED_CUBE _mm256_set_epi64x(SOLVED_H, SOLVED_L, 0, SOLVED_L) | 25 | #define SOLVED_CUBE _mm256_set_epi64x(SOLVED_H, SOLVED_L, 0, SOLVED_L) |
| 26 | 26 | ||
| 27 | 27 | STATIC_INLINE uint64_t permtoindex_Nx8(uint64_t, int64_t); | |
| 28 | STATIC_INLINE uint64_t permtoindex_8x8(int64_t); | ||
| 29 | STATIC_INLINE int64_t indextoperm_8x8(uint64_t); | 28 | STATIC_INLINE int64_t indextoperm_8x8(uint64_t); |
| 29 | STATIC_INLINE int64_t indextoperm_4x8(uint64_t); | ||
| 30 | 30 | ||
| 31 | STATIC_INLINE int | 31 | STATIC_INLINE int |
| 32 | popcount_u32(uint32_t x) | 32 | popcount_u32(uint32_t x) |
| @@ -295,17 +295,17 @@ set_eo(cube_t cube[static 1], uint64_t eo) | |||
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | STATIC_INLINE uint64_t | 297 | STATIC_INLINE uint64_t |
| 298 | permtoindex_8x8(int64_t a) | 298 | permtoindex_Nx8(uint64_t n, int64_t a) |
| 299 | { | 299 | { |
| 300 | uint64_t i, c, ret; | 300 | uint64_t i, c, ret; |
| 301 | __m64 cmp; | 301 | __m64 cmp; |
| 302 | 302 | ||
| 303 | for (i = 0, ret = 0; i < 8; i++) { | 303 | for (i = 0, ret = 0; i < n; i++) { |
| 304 | cmp = _mm_set1_pi8(a & INT64_C(0xFF)); | 304 | cmp = _mm_set1_pi8(a & INT64_C(0xFF)); |
| 305 | a = (a >> INT64_C(8)) | INT64_C(0x0F00000000000000); | 305 | a = (a >> INT64_C(8)) | INT64_C(0x0F00000000000000); |
| 306 | cmp = _mm_cmpgt_pi8(cmp, _mm_cvtsi64_m64(a)); | 306 | cmp = _mm_cmpgt_pi8(cmp, _mm_cvtsi64_m64(a)); |
| 307 | c = _mm_popcnt_u64(_mm_cvtm64_si64(cmp)) >> UINT64_C(3); | 307 | c = _mm_popcnt_u64(_mm_cvtm64_si64(cmp)) >> UINT64_C(3); |
| 308 | ret += c * factorial[7-i]; | 308 | ret += c * factorial[n-1-i]; |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | return ret; | 311 | return ret; |
| @@ -332,6 +332,39 @@ indextoperm_8x8(uint64_t p) | |||
| 332 | return ret; | 332 | return ret; |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | STATIC_INLINE int64_t | ||
| 336 | indextoperm_4x8(uint64_t p) | ||
| 337 | { | ||
| 338 | static const int64_t A[FACT_4] = { | ||
| 339 | [0] = INT64_C(0x03020100), | ||
| 340 | [1] = INT64_C(0x02030100), | ||
| 341 | [2] = INT64_C(0x03010200), | ||
| 342 | [3] = INT64_C(0x01030200), | ||
| 343 | [4] = INT64_C(0x02010300), | ||
| 344 | [5] = INT64_C(0x01020300), | ||
| 345 | [6] = INT64_C(0x03020001), | ||
| 346 | [7] = INT64_C(0x02030001), | ||
| 347 | [8] = INT64_C(0x03000201), | ||
| 348 | [9] = INT64_C(0x00030201), | ||
| 349 | [10] = INT64_C(0x02000301), | ||
| 350 | [11] = INT64_C(0x00020301), | ||
| 351 | [12] = INT64_C(0x03010002), | ||
| 352 | [13] = INT64_C(0x01030002), | ||
| 353 | [14] = INT64_C(0x03000102), | ||
| 354 | [15] = INT64_C(0x00030102), | ||
| 355 | [16] = INT64_C(0x01000302), | ||
| 356 | [17] = INT64_C(0x00010302), | ||
| 357 | [18] = INT64_C(0x02010003), | ||
| 358 | [19] = INT64_C(0x01020003), | ||
| 359 | [20] = INT64_C(0x02000103), | ||
| 360 | [21] = INT64_C(0x00020103), | ||
| 361 | [22] = INT64_C(0x01000203), | ||
| 362 | [23] = INT64_C(0x00010203), | ||
| 363 | }; | ||
| 364 | |||
| 365 | return A[p]; | ||
| 366 | } | ||
| 367 | |||
| 335 | STATIC_INLINE uint64_t | 368 | STATIC_INLINE uint64_t |
| 336 | coord_cp(cube_t cube) | 369 | coord_cp(cube_t cube) |
| 337 | { | 370 | { |
| @@ -341,7 +374,7 @@ coord_cp(cube_t cube) | |||
| 341 | cp = _mm256_and_si256(cube, CP_AVX2); | 374 | cp = _mm256_and_si256(cube, CP_AVX2); |
| 342 | _mm256_storeu_si256((__m256i_u *)aux, cp); | 375 | _mm256_storeu_si256((__m256i_u *)aux, cp); |
| 343 | 376 | ||
| 344 | return permtoindex_8x8(aux[0]); | 377 | return permtoindex_Nx8(8, aux[0]); |
| 345 | } | 378 | } |
| 346 | 379 | ||
| 347 | STATIC_INLINE cube_t | 380 | STATIC_INLINE cube_t |
| @@ -359,7 +392,7 @@ coord_epud(cube_t cube) | |||
| 359 | ep = _mm256_and_si256(cube, EP_AVX2); | 392 | ep = _mm256_and_si256(cube, EP_AVX2); |
| 360 | _mm256_storeu_si256((__m256i_u *)aux, ep); | 393 | _mm256_storeu_si256((__m256i_u *)aux, ep); |
| 361 | 394 | ||
| 362 | return permtoindex_8x8(aux[2]); | 395 | return permtoindex_Nx8(8, aux[2]); |
| 363 | } | 396 | } |
| 364 | 397 | ||
| 365 | STATIC_INLINE cube_t | 398 | STATIC_INLINE cube_t |
| @@ -367,3 +400,29 @@ invcoord_epud(uint64_t i) | |||
| 367 | { | 400 | { |
| 368 | return _mm256_set_epi64x(SOLVED_H, indextoperm_8x8(i), 0, SOLVED_L); | 401 | return _mm256_set_epi64x(SOLVED_H, indextoperm_8x8(i), 0, SOLVED_L); |
| 369 | } | 402 | } |
| 403 | |||
| 404 | STATIC_INLINE uint64_t | ||
| 405 | coord_epe(cube_t cube) | ||
| 406 | { | ||
| 407 | cube_t ep; | ||
| 408 | int64_t aux[4]; | ||
| 409 | |||
| 410 | ep = _mm256_and_si256(cube, EP_AVX2); | ||
| 411 | ep = _mm256_xor_si256(ep, _mm256_set1_epi8(8)); | ||
| 412 | _mm256_storeu_si256((__m256i_u *)aux, ep); | ||
| 413 | |||
| 414 | return permtoindex_Nx8(4, aux[3]); | ||
| 415 | } | ||
| 416 | |||
| 417 | STATIC_INLINE cube_t | ||
| 418 | invcoord_epe(uint64_t i) | ||
| 419 | { | ||
| 420 | int64_t a; | ||
| 421 | __m64 a64; | ||
| 422 | |||
| 423 | a = indextoperm_4x8(i); | ||
| 424 | a64 = _mm_add_pi8(_mm_cvtsi64_m64(a), _mm_set_pi32(0, 0x08080808)); | ||
| 425 | a = _mm_cvtm64_si64(a64); | ||
| 426 | |||
| 427 | return _mm256_set_epi64x(a, SOLVED_L, 0, SOLVED_L); | ||
| 428 | } | ||
