aboutsummaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-08-06 16:34:21 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-08-06 16:52:12 +0200
commit57a7520545134ab95f7bb0397dcbe991c906a3e9 (patch)
tree689e20a92ec3830533d2fb868e5dc141dec45877 /src/arch
parenta5c9b857a346343443baf49679eebf12c18b4008 (diff)
downloadnissy-core-57a7520545134ab95f7bb0397dcbe991c906a3e9.tar.gz
nissy-core-57a7520545134ab95f7bb0397dcbe991c906a3e9.zip
Added HTR solver
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/avx2.h24
-rw-r--r--src/arch/common.h39
-rw-r--r--src/arch/neon.h23
-rw-r--r--src/arch/portable.h16
4 files changed, 100 insertions, 2 deletions
diff --git a/src/arch/avx2.h b/src/arch/avx2.h
index 74aad53..1c7248b 100644
--- a/src/arch/avx2.h
+++ b/src/arch/avx2.h
@@ -437,5 +437,27 @@ is_eo_even(cube_t cube)
437 e = _mm256_slli_epi16(e, 7-EOSHIFT); 437 e = _mm256_slli_epi16(e, 7-EOSHIFT);
438 mask = _mm256_movemask_epi8(e); 438 mask = _mm256_movemask_epi8(e);
439 439
440 return popcount_u32(mask) % 2; 440 return popcount_u32(mask) % 2 == 0;
441}
442
443STATIC_INLINE uint64_t
444coord_epudsep(cube_t cube)
445{
446 uint8_t aux[32];
447
448 _mm256_storeu_si256((__m256i_u *)aux, cube);
449 return coord_epudsep_array(aux + 16);
450}
451
452STATIC_INLINE cube_t
453invcoord_epudsep(uint64_t i)
454{
455 cube_t cube, elow;
456 uint8_t e[32];
457
458 invcoord_epudsep_array(i, e+16);
459 elow = _mm256_load_si256((__m256i *)e);
460 cube = _mm256_set_epi64x(SOLVED_H, 0, 0, SOLVED_L);
461
462 return _mm256_or_si256(elow, cube);
441} 463}
diff --git a/src/arch/common.h b/src/arch/common.h
index d76b65f..f06f8d7 100644
--- a/src/arch/common.h
+++ b/src/arch/common.h
@@ -29,6 +29,8 @@ STATIC_INLINE uint64_t coord_cocsep(cube_t);
29STATIC_INLINE uint64_t coord_eo(cube_t); 29STATIC_INLINE uint64_t coord_eo(cube_t);
30STATIC_INLINE uint64_t coord_esep(cube_t); 30STATIC_INLINE uint64_t coord_esep(cube_t);
31STATIC_INLINE cube_t invcoord_esep(uint64_t); 31STATIC_INLINE cube_t invcoord_esep(uint64_t);
32STATIC_INLINE uint64_t coord_epudsep(cube_t);
33STATIC_INLINE cube_t invcoord_epudsep(uint64_t);
32 34
33STATIC_INLINE bool is_eo_even(cube_t); 35STATIC_INLINE bool is_eo_even(cube_t);
34 36
@@ -38,6 +40,8 @@ STATIC_INLINE void set_eo(cube_t [static 1], uint64_t);
38 40
39STATIC_INLINE void invcoord_esep_array(uint64_t, uint64_t, uint8_t[static 12]); 41STATIC_INLINE void invcoord_esep_array(uint64_t, uint64_t, uint8_t[static 12]);
40STATIC_INLINE cube_t invcoord_eoesep(uint64_t); 42STATIC_INLINE cube_t invcoord_eoesep(uint64_t);
43STATIC_INLINE uint64_t coord_epudsep_array(const uint8_t [8]);
44STATIC_INLINE void invcoord_epudsep_array(uint64_t, uint8_t [8]);
41 45
42STATIC_INLINE uint64_t coord_cp(cube_t); 46STATIC_INLINE uint64_t coord_cp(cube_t);
43STATIC_INLINE cube_t invcoord_cp(uint64_t); 47STATIC_INLINE cube_t invcoord_cp(uint64_t);
@@ -85,3 +89,38 @@ invcoord_eoesep(uint64_t i)
85 89
86 return c; 90 return c;
87} 91}
92
93STATIC_INLINE uint64_t
94coord_epudsep_array(const uint8_t e[8])
95{
96 uint8_t i, k, is;
97 uint64_t ret;
98
99 ret = 0;
100 k = 4;
101 for (i = 0; i < 8; i++) {
102 is = (e[i] & UINT8_C(4)) >> UINT8_C(2);
103 ret += is * binomial[7-i][k];
104 k -= is;
105 }
106
107 return ret;
108}
109
110STATIC_INLINE void
111invcoord_epudsep_array(uint64_t c, uint8_t ret[8])
112{
113 uint8_t i, k, is, x, y;
114
115 k = 4;
116 x = 0;
117 y = 4;
118 for (i = 0; i < 8; i++) {
119 is = c >= binomial[7-i][k];
120 ret[i] = is*y + (1-is)*x;
121 y += is;
122 x += 1-is;
123 c -= is * binomial[7-i][k];
124 k -= is;
125 }
126}
diff --git a/src/arch/neon.h b/src/arch/neon.h
index 2c35c58..9871125 100644
--- a/src/arch/neon.h
+++ b/src/arch/neon.h
@@ -453,7 +453,7 @@ invcoord_cp(uint64_t i)
453{ 453{
454 return (cube_t) { 454 return (cube_t) {
455 .corner = indextoperm_8x8(i), 455 .corner = indextoperm_8x8(i),
456 .edge = vcombine_u8(vld1_u8(SOLVED_L), vld1_u8(SOLVED_H)) 456 .edge = vcombine_u8(vld1_u8(SOLVED_L), vld1_u8(SOLVED_H))
457 }; 457 };
458} 458}
459 459
@@ -515,3 +515,24 @@ is_eo_even(cube_t cube)
515 515
516 return count % 2 == 0; 516 return count % 2 == 0;
517} 517}
518
519STATIC_INLINE uint64_t
520coord_epudsep(cube_t cube)
521{
522 uint8_t e[8];
523
524 vst1_u8(e, vget_low_u8(cube.edge));
525 return coord_epudsep_array(e);
526}
527
528STATIC_INLINE cube_t
529invcoord_epudsep(uint64_t i)
530{
531 uint8_t e[8];
532
533 invcoord_epudsep_array(i, e);
534 return (cube_t) {
535 .corner = vld1_u8(SOLVED_L),
536 .edge = vcombine_u8(vld1_u8(e), vld1_u8(SOLVED_H))
537 };
538}
diff --git a/src/arch/portable.h b/src/arch/portable.h
index d673f15..c7f2de0 100644
--- a/src/arch/portable.h
+++ b/src/arch/portable.h
@@ -367,3 +367,19 @@ is_eo_even(cube_t cube)
367 367
368 return count % 2 == 0; 368 return count % 2 == 0;
369} 369}
370
371STATIC_INLINE uint64_t
372coord_epudsep(cube_t cube)
373{
374 return coord_epudsep_array(cube.edge);
375}
376
377STATIC_INLINE cube_t
378invcoord_epudsep(uint64_t c)
379{
380 cube_t ret;
381
382 ret = SOLVED_CUBE;
383 invcoord_epudsep_array(c, ret.edge);
384 return ret;
385}

Generated with cgit - Back to sebastiano.tronto.net