aboutsummaryrefslogtreecommitdiff
path: root/src/cube_avx2.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-06-09 12:43:49 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-06-09 12:43:49 +0200
commitc5c5017a335208881e27fc8f72c1d0145a04622a (patch)
tree7a1518e5b05f3fbde810fa3080c41099ba7d5ae8 /src/cube_avx2.h
parent28ad019d62583b7e89b4e76922aa73857d5876eb (diff)
downloadnissy-core-c5c5017a335208881e27fc8f72c1d0145a04622a.tar.gz
nissy-core-c5c5017a335208881e27fc8f72c1d0145a04622a.zip
Remvoed cube_fast_t and more. More cleaning up to do.
Diffstat (limited to 'src/cube_avx2.h')
-rw-r--r--src/cube_avx2.h204
1 files changed, 64 insertions, 140 deletions
diff --git a/src/cube_avx2.h b/src/cube_avx2.h
index f3fe731..42ca9b5 100644
--- a/src/cube_avx2.h
+++ b/src/cube_avx2.h
@@ -1,4 +1,4 @@
1typedef __m256i cube_fast_t; 1typedef __m256i cube_t;
2 2
3#define _co2_avx2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x6060606060606060)) 3#define _co2_avx2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x6060606060606060))
4#define _cocw_avx2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x2020202020202020)) 4#define _cocw_avx2 _mm256_set_epi64x(0, 0, 0, INT64_C(0x2020202020202020))
@@ -8,117 +8,47 @@ typedef __m256i cube_fast_t;
8#define _eo_avx2 \ 8#define _eo_avx2 \
9 _mm256_set_epi64x(INT64_C(0x10101010), INT64_C(0x1010101010101010), 0, 0) 9 _mm256_set_epi64x(INT64_C(0x10101010), INT64_C(0x1010101010101010), 0, 0)
10 10
11_static_inline cube_fast_t fastcube( 11#define static_cube(c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl, \
12 uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, 12 e_uf, e_ub, e_db, e_df, e_ur, e_ul, e_dl, e_dr, e_fr, e_fl, e_bl, e_br) \
13 uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, 13 _mm256_set_epi8(0, 0, 0, 0, e_br, e_bl, e_fl, e_fr, \
14 uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, 14 e_dr, e_dl, e_ul, e_ur, e_df, e_db, e_ub, e_uf, \
15 uint8_t, uint8_t, uint8_t, uint8_t, uint8_t 15 0, 0, 0, 0, 0, 0, 0, 0, \
16); 16 c_dbl, c_dfr, c_ubr, c_ufl, c_dbr, c_dfl, c_ubl, c_ufr)
17_static uint8_t corner(cube_fast_t, int); 17#define zero _mm256_set_epi64x(0, 0, 0, 0)
18_static uint8_t edge(cube_fast_t, int); 18#define solved static_cube( \
19_static cube_fast_t cubetofast(cube_t); 19 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
20_static cube_t fasttocube(cube_fast_t);
21_static_inline bool equal_fast(cube_fast_t, cube_fast_t);
22_static_inline bool issolved_fast(cube_fast_t);
23_static_inline cube_fast_t invertco_fast(cube_fast_t);
24_static_inline cube_fast_t compose_epcpeo(cube_fast_t, cube_fast_t);
25_static_inline cube_fast_t compose_fast_edges(cube_fast_t, cube_fast_t);
26_static_inline cube_fast_t compose_fast_corners(cube_fast_t, cube_fast_t);
27_static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t);
28 20
29_static_inline int64_t coord_fast_co(cube_fast_t); 21_static void pieces(cube_t *, uint8_t [static 8], uint8_t [static 12]);
30_static_inline int64_t coord_fast_csep(cube_fast_t); 22_static_inline bool equal(cube_t, cube_t);
31_static_inline int64_t coord_fast_cocsep(cube_fast_t); 23_static_inline cube_t invertco(cube_t);
32_static_inline int64_t coord_fast_eo(cube_fast_t); 24_static_inline cube_t compose_epcpeo(cube_t, cube_t);
33_static_inline int64_t coord_fast_esep(cube_fast_t); 25_static_inline cube_t compose_edges(cube_t, cube_t);
26_static_inline cube_t compose_corners(cube_t, cube_t);
27_static_inline cube_t compose(cube_t, cube_t);
34 28
35_static_inline void copy_corners_fast(cube_fast_t *, cube_fast_t); 29_static_inline int64_t coord_co(cube_t);
36_static_inline void copy_edges_fast(cube_fast_t *, cube_fast_t); 30_static_inline int64_t coord_csep(cube_t);
37_static_inline void set_eo_fast(cube_fast_t *, int64_t); 31_static_inline int64_t coord_cocsep(cube_t);
38_static_inline cube_fast_t invcoord_fast_esep(int64_t); 32_static_inline int64_t coord_eo(cube_t);
33_static_inline int64_t coord_esep(cube_t);
39 34
40_static_inline cube_fast_t 35_static_inline void copy_corners(cube_t *, cube_t);
41fastcube( 36_static_inline void copy_edges(cube_t *, cube_t);
42 uint8_t c_ufr, 37_static_inline void set_eo(cube_t *, int64_t);
43 uint8_t c_ubl, 38_static_inline cube_t invcoord_esep(int64_t);
44 uint8_t c_dfl,
45 uint8_t c_dbr,
46 uint8_t c_ufl,
47 uint8_t c_ubr,
48 uint8_t c_dfr,
49 uint8_t c_dbl,
50 39
51 uint8_t e_uf, 40_static void
52 uint8_t e_ub, 41pieces(cube_t *cube, uint8_t c[static 8], uint8_t e[static 12])
53 uint8_t e_db,
54 uint8_t e_df,
55 uint8_t e_ur,
56 uint8_t e_ul,
57 uint8_t e_dl,
58 uint8_t e_dr,
59 uint8_t e_fr,
60 uint8_t e_fl,
61 uint8_t e_bl,
62 uint8_t e_br
63)
64{
65 return _mm256_set_epi8(
66 0, 0, 0, 0, e_br, e_bl, e_fl, e_fr,
67 e_dr, e_dl, e_ul, e_ur, e_df, e_db, e_ub, e_uf,
68 0, 0, 0, 0, 0, 0, 0, 0,
69 c_dbl, c_dfr, c_ubr, c_ufl, c_dbr, c_dfl, c_ubl, c_ufr
70 );
71}
72
73_static uint8_t
74corner(cube_fast_t c, int i)
75{
76 uint8_t aux[32];
77
78 DBG_ASSERT(i >= 0 && i < 8, 255, "Corner must be between 0 and 7\n");
79 _mm256_storeu_si256((__m256i_u *)aux, c);
80
81 return aux[i];
82}
83
84_static uint8_t
85edge(cube_fast_t c, int i)
86{ 42{
87 uint8_t aux[32]; 43 uint8_t aux[32];
88 44
89 DBG_ASSERT(i >= 0 && i < 12, 255, "Edge must be between 0 and 11\n"); 45 _mm256_storeu_si256((__m256i_u *)aux, *cube);
90 _mm256_storeu_si256((__m256i_u *)aux, c); 46 memcpy(c, aux, 8);
91 47 memcpy(e, aux+16, 12);
92 return aux[i+16];
93}
94
95_static cube_fast_t
96cubetofast(cube_t a)
97{
98 uint8_t aux[32];
99
100 memset(aux, 0, 32);
101 memcpy(aux, &a.corner, 8);
102 memcpy(aux + 16, &a.edge, 12);
103
104 return _mm256_loadu_si256((__m256i_u *)&aux);
105}
106
107_static cube_t
108fasttocube(cube_fast_t c)
109{
110 cube_t a;
111 uint8_t aux[32];
112
113 _mm256_storeu_si256((__m256i_u *)aux, c);
114 memcpy(&a.corner, aux, 8);
115 memcpy(&a.edge, aux + 16, 12);
116
117 return a;
118} 48}
119 49
120_static_inline bool 50_static_inline bool
121equal_fast(cube_fast_t c1, cube_fast_t c2) 51equal(cube_t c1, cube_t c2)
122{ 52{
123 int32_t mask; 53 int32_t mask;
124 __m256i cmp; 54 __m256i cmp;
@@ -129,16 +59,10 @@ equal_fast(cube_fast_t c1, cube_fast_t c2)
129 return mask == ~0; 59 return mask == ~0;
130} 60}
131 61
132_static_inline bool 62_static_inline cube_t
133issolved_fast(cube_fast_t cube) 63invertco(cube_t c)
134{
135 return equal_fast(cube, solved_fast);
136}
137
138_static_inline cube_fast_t
139invertco_fast(cube_fast_t c)
140{ 64{
141 cube_fast_t co, shleft, shright, summed, newco, cleanco, ret; 65 cube_t co, shleft, shright, summed, newco, cleanco, ret;
142 66
143 co = _mm256_and_si256(c, _co2_avx2); 67 co = _mm256_and_si256(c, _co2_avx2);
144 shleft = _mm256_slli_epi32(co, 1); 68 shleft = _mm256_slli_epi32(co, 1);
@@ -151,10 +75,10 @@ invertco_fast(cube_fast_t c)
151 return ret; 75 return ret;
152} 76}
153 77
154_static_inline cube_fast_t 78_static_inline cube_t
155compose_epcpeo(cube_fast_t c1, cube_fast_t c2) 79compose_epcpeo(cube_t c1, cube_t c2)
156{ 80{
157 cube_fast_t b, s, eo2; 81 cube_t b, s, eo2;
158 82
159 /* Permute and clean unused bits */ 83 /* Permute and clean unused bits */
160 s = _mm256_shuffle_epi8(c1, c2); 84 s = _mm256_shuffle_epi8(c1, c2);
@@ -171,27 +95,27 @@ compose_epcpeo(cube_fast_t c1, cube_fast_t c2)
171 return s; 95 return s;
172} 96}
173 97
174_static_inline cube_fast_t 98_static_inline cube_t
175compose_fast_edges(cube_fast_t c1, cube_fast_t c2) 99compose_edges(cube_t c1, cube_t c2)
176{ 100{
177 return compose_epcpeo(c1, c2); 101 return compose_epcpeo(c1, c2);
178} 102}
179 103
180_static_inline cube_fast_t 104_static_inline cube_t
181compose_fast_corners(cube_fast_t c1, cube_fast_t c2) 105compose_corners(cube_t c1, cube_t c2)
182{ 106{
183 /* 107 /*
184 * We do a full compose. Minor optimizations are possible, like 108 * We do a full compose. Minor optimizations are possible, like
185 * saving one instruction by not doing EO, but it should not 109 * saving one instruction by not doing EO, but it should not
186 * be significant. 110 * be significant.
187 */ 111 */
188 return compose_fast(c1, c2); 112 return compose(c1, c2);
189} 113}
190 114
191_static_inline cube_fast_t 115_static_inline cube_t
192compose_fast(cube_fast_t c1, cube_fast_t c2) 116compose(cube_t c1, cube_t c2)
193{ 117{
194 cube_fast_t s, co1, co2, aux, auy1, auy2, auz1, auz2; 118 cube_t s, co1, co2, aux, auy1, auy2, auz1, auz2;
195 119
196 s = compose_epcpeo(c1, c2); 120 s = compose_epcpeo(c1, c2);
197 121
@@ -212,9 +136,9 @@ compose_fast(cube_fast_t c1, cube_fast_t c2)
212} 136}
213 137
214_static_inline int64_t 138_static_inline int64_t
215coord_fast_co(cube_fast_t c) 139coord_co(cube_t c)
216{ 140{
217 cube_fast_t co; 141 cube_t co;
218 int64_t mem[4], ret, i, p; 142 int64_t mem[4], ret, i, p;
219 143
220 co = _mm256_and_si256(c, _co2_avx2); 144 co = _mm256_and_si256(c, _co2_avx2);
@@ -228,9 +152,9 @@ coord_fast_co(cube_fast_t c)
228} 152}
229 153
230_static_inline int64_t 154_static_inline int64_t
231coord_fast_csep(cube_fast_t c) 155coord_csep(cube_t c)
232{ 156{
233 cube_fast_t cp, shifted; 157 cube_t cp, shifted;
234 int64_t mask; 158 int64_t mask;
235 159
236 cp = _mm256_and_si256(c, _cp_avx2); 160 cp = _mm256_and_si256(c, _cp_avx2);
@@ -241,15 +165,15 @@ coord_fast_csep(cube_fast_t c)
241} 165}
242 166
243_static_inline int64_t 167_static_inline int64_t
244coord_fast_cocsep(cube_fast_t c) 168coord_cocsep(cube_t c)
245{ 169{
246 return (coord_fast_co(c) << 7) + coord_fast_csep(c); 170 return (coord_co(c) << 7) + coord_csep(c);
247} 171}
248 172
249_static_inline int64_t 173_static_inline int64_t
250coord_fast_eo(cube_fast_t c) 174coord_eo(cube_t c)
251{ 175{
252 cube_fast_t eo, shifted; 176 cube_t eo, shifted;
253 int64_t mask; 177 int64_t mask;
254 178
255 eo = _mm256_and_si256(c, _eo_avx2); 179 eo = _mm256_and_si256(c, _eo_avx2);
@@ -260,9 +184,9 @@ coord_fast_eo(cube_fast_t c)
260} 184}
261 185
262_static_inline int64_t 186_static_inline int64_t
263coord_fast_esep(cube_fast_t c) 187coord_esep(cube_t c)
264{ 188{
265 cube_fast_t ep; 189 cube_t ep;
266 int64_t e, mem[4], i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; 190 int64_t e, mem[4], i, j, jj, k, l, ret1, ret2, bit1, bit2, is1;
267 191
268 ep = _mm256_and_si256(c, _ep_avx2); 192 ep = _mm256_and_si256(c, _ep_avx2);
@@ -291,19 +215,19 @@ coord_fast_esep(cube_fast_t c)
291} 215}
292 216
293_static_inline void 217_static_inline void
294copy_corners_fast(cube_fast_t *dest, cube_fast_t src) 218copy_corners(cube_t *dest, cube_t src)
295{ 219{
296 *dest = _mm256_blend_epi32(*dest, src, 0x0F); 220 *dest = _mm256_blend_epi32(*dest, src, 0x0F);
297} 221}
298 222
299_static_inline void 223_static_inline void
300copy_edges_fast(cube_fast_t *dest, cube_fast_t src) 224copy_edges(cube_t *dest, cube_t src)
301{ 225{
302 *dest = _mm256_blend_epi32(*dest, src, 0xF0); 226 *dest = _mm256_blend_epi32(*dest, src, 0xF0);
303} 227}
304 228
305_static_inline void 229_static_inline void
306set_eo_fast(cube_fast_t *cube, int64_t eo) 230set_eo(cube_t *cube, int64_t eo)
307{ 231{
308 int64_t eo12, eotop, eobot; 232 int64_t eo12, eotop, eobot;
309 __m256i veo; 233 __m256i veo;
@@ -327,10 +251,10 @@ set_eo_fast(cube_fast_t *cube, int64_t eo)
327 *cube = _mm256_or_si256(*cube, veo); 251 *cube = _mm256_or_si256(*cube, veo);
328} 252}
329 253
330_static_inline cube_fast_t 254_static_inline cube_t
331invcoord_fast_esep(int64_t esep) 255invcoord_esep(int64_t esep)
332{ 256{
333 cube_fast_t eee, ret; 257 cube_t eee, ret;
334 int64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1, set1, set2; 258 int64_t bit1, bit2, i, j, jj, k, l, s, v, w, is1, set1, set2;
335 uint8_t mem[32]; 259 uint8_t mem[32];
336 uint8_t slice[3] = {0}; 260 uint8_t slice[3] = {0};
@@ -356,9 +280,9 @@ invcoord_fast_esep(int64_t esep)
356 mem[i+16] = (slice[s]++) | (uint8_t)(s << 2); 280 mem[i+16] = (slice[s]++) | (uint8_t)(s << 2);
357 } 281 }
358 282
359 ret = cubetofast(solved); 283 ret = solved;
360 eee = _mm256_loadu_si256((__m256i_u *)&mem); 284 eee = _mm256_loadu_si256((__m256i_u *)&mem);
361 copy_edges_fast(&ret, eee); 285 copy_edges(&ret, eee);
362 286
363 return ret; 287 return ret;
364} 288}

Generated with cgit - Back to sebastiano.tronto.net