aboutsummaryrefslogtreecommitdiff
path: root/src/arch/avx2.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-29 12:12:43 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-29 12:12:43 +0200
commitea0387796a349c91032fbcb10f50c6ad8607b0f6 (patch)
treeaed484690d24c0c28c7695d4b5389f2e3c341b96 /src/arch/avx2.h
parent52c21640508c3fc668107778ae027ff4428ebd89 (diff)
downloadnissy-core-ea0387796a349c91032fbcb10f50c6ad8607b0f6.tar.gz
nissy-core-ea0387796a349c91032fbcb10f50c6ad8607b0f6.zip
All coordinates unsigned
Diffstat (limited to 'src/arch/avx2.h')
-rw-r--r--src/arch/avx2.h60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/arch/avx2.h b/src/arch/avx2.h
index 7764c6b..24c8280 100644
--- a/src/arch/avx2.h
+++ b/src/arch/avx2.h
@@ -25,8 +25,8 @@
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
28STATIC_INLINE int64_t permtoindex_8x8(int64_t); 28STATIC_INLINE uint64_t permtoindex_8x8(int64_t);
29STATIC_INLINE int64_t indextoperm_8x8(int64_t); 29STATIC_INLINE int64_t indextoperm_8x8(uint64_t);
30 30
31STATIC_INLINE int 31STATIC_INLINE int
32popcount_u32(uint32_t x) 32popcount_u32(uint32_t x)
@@ -144,11 +144,11 @@ inverse(cube_t c)
144 return invertco(ret); 144 return invertco(ret);
145} 145}
146 146
147STATIC_INLINE int64_t 147STATIC_INLINE uint64_t
148coord_co(cube_t c) 148coord_co(cube_t c)
149{ 149{
150 cube_t co; 150 cube_t co;
151 int64_t mem[4], ret, i, p; 151 uint64_t mem[4], ret, i, p;
152 152
153 co = _mm256_and_si256(c, CO2_AVX2); 153 co = _mm256_and_si256(c, CO2_AVX2);
154 _mm256_storeu_si256((__m256i *)mem, co); 154 _mm256_storeu_si256((__m256i *)mem, co);
@@ -161,15 +161,15 @@ coord_co(cube_t c)
161} 161}
162 162
163STATIC_INLINE cube_t 163STATIC_INLINE cube_t
164invcoord_co(int64_t coord) 164invcoord_co(uint64_t coord)
165{ 165{
166 int64_t i, c, p, co, mem[4] = {0}; 166 uint64_t i, c, p, co, mem[4] = {0};
167 cube_t cube, cc; 167 cube_t cube, cc;
168 168
169 for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) { 169 for (i = 0, p = 0, c = coord; i < 8; i++, c /= 3) {
170 co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3); 170 co = i == 7 ? ((3 - (p % 3)) % 3) : (c % 3);
171 p += co; 171 p += co;
172 mem[0] |= (int64_t)(i + (co << COSHIFT)) << (int64_t)(8 * i); 172 mem[0] |= (uint64_t)(i + (co << COSHIFT)) << (uint64_t)(8 * i);
173 } 173 }
174 174
175 cc = _mm256_loadu_si256((const __m256i *)mem); 175 cc = _mm256_loadu_si256((const __m256i *)mem);
@@ -179,43 +179,43 @@ invcoord_co(int64_t coord)
179 return cube; 179 return cube;
180} 180}
181 181
182STATIC_INLINE int64_t 182STATIC_INLINE uint64_t
183coord_csep(cube_t c) 183coord_csep(cube_t c)
184{ 184{
185 cube_t cp, shifted; 185 cube_t cp, shifted;
186 int64_t mask; 186 int mask;
187 187
188 cp = _mm256_and_si256(c, CP_AVX2); 188 cp = _mm256_and_si256(c, CP_AVX2);
189 shifted = _mm256_slli_epi32(cp, 5); 189 shifted = _mm256_slli_epi32(cp, 5);
190 mask = _mm256_movemask_epi8(shifted); 190 mask = _mm256_movemask_epi8(shifted);
191 191
192 return mask & 0x7F; 192 return (uint64_t)(mask & 0x7F);
193} 193}
194 194
195STATIC_INLINE int64_t 195STATIC_INLINE uint64_t
196coord_cocsep(cube_t c) 196coord_cocsep(cube_t c)
197{ 197{
198 return (coord_co(c) << 7) + coord_csep(c); 198 return (coord_co(c) << UINT8_C(7)) + coord_csep(c);
199} 199}
200 200
201STATIC_INLINE int64_t 201STATIC_INLINE uint64_t
202coord_eo(cube_t c) 202coord_eo(cube_t c)
203{ 203{
204 cube_t eo, shifted; 204 cube_t eo, shifted;
205 int64_t mask; 205 int mask;
206 206
207 eo = _mm256_and_si256(c, EO_AVX2); 207 eo = _mm256_and_si256(c, EO_AVX2);
208 shifted = _mm256_slli_epi32(eo, 3); 208 shifted = _mm256_slli_epi32(eo, 3);
209 mask = _mm256_movemask_epi8(shifted); 209 mask = _mm256_movemask_epi8(shifted);
210 210
211 return mask >> 17; 211 return (uint64_t)(mask >> 17);
212} 212}
213 213
214STATIC_INLINE int64_t 214STATIC_INLINE uint64_t
215coord_esep(cube_t c) 215coord_esep(cube_t c)
216{ 216{
217 cube_t ep; 217 cube_t ep;
218 int64_t e, mem[4], i, j, jj, k, l, ret1, ret2, bit1, bit2, is1; 218 uint64_t e, mem[4], i, j, jj, k, l, ret1, ret2, bit1, bit2, is1;
219 219
220 ep = _mm256_and_si256(c, EP_AVX2); 220 ep = _mm256_and_si256(c, EP_AVX2);
221 _mm256_storeu_si256((__m256i *)mem, ep); 221 _mm256_storeu_si256((__m256i *)mem, ep);
@@ -243,12 +243,12 @@ coord_esep(cube_t c)
243} 243}
244 244
245STATIC_INLINE cube_t 245STATIC_INLINE cube_t
246invcoord_esep(int64_t esep) 246invcoord_esep(uint64_t esep)
247{ 247{
248 cube_t eee, ret; 248 cube_t eee, ret;
249 uint8_t mem[32] = {0}; 249 uint8_t mem[32] = {0};
250 250
251 invcoord_esep_array(esep % 70, esep / 70, mem+16); 251 invcoord_esep_array(esep % UINT64_C(70), esep / UINT64_C(70), mem+16);
252 252
253 ret = SOLVED_CUBE; 253 ret = SOLVED_CUBE;
254 eee = _mm256_loadu_si256((__m256i_u *)&mem); 254 eee = _mm256_loadu_si256((__m256i_u *)&mem);
@@ -270,9 +270,9 @@ copy_edges(cube_t dest[static 1], cube_t src)
270} 270}
271 271
272STATIC_INLINE void 272STATIC_INLINE void
273set_eo(cube_t cube[static 1], int64_t eo) 273set_eo(cube_t cube[static 1], uint64_t eo)
274{ 274{
275 int64_t eo12, eotop, eobot; 275 uint64_t eo12, eotop, eobot;
276 __m256i veo; 276 __m256i veo;
277 277
278 eo12 = (eo << 1) + (_mm_popcnt_u64(eo) % 2); 278 eo12 = (eo << 1) + (_mm_popcnt_u64(eo) % 2);
@@ -294,17 +294,17 @@ set_eo(cube_t cube[static 1], int64_t eo)
294 *cube = _mm256_or_si256(*cube, veo); 294 *cube = _mm256_or_si256(*cube, veo);
295} 295}
296 296
297STATIC_INLINE int64_t 297STATIC_INLINE uint64_t
298permtoindex_8x8(int64_t a) 298permtoindex_8x8(int64_t a)
299{ 299{
300 int64_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 < 8; 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)) >> INT64_C(3); 307 c = _mm_popcnt_u64(_mm_cvtm64_si64(cmp)) >> UINT64_C(3);
308 ret += c * factorial[7-i]; 308 ret += c * factorial[7-i];
309 } 309 }
310 310
@@ -312,10 +312,10 @@ permtoindex_8x8(int64_t a)
312} 312}
313 313
314STATIC_INLINE int64_t 314STATIC_INLINE int64_t
315indextoperm_8x8(int64_t p) 315indextoperm_8x8(uint64_t p)
316{ 316{
317 int used; 317 int used;
318 int64_t c, k, i, j, ret; 318 uint64_t c, k, i, j, ret;
319 319
320 for (i = 0, ret = 0, used = 0; i < 8; i++) { 320 for (i = 0, ret = 0, used = 0; i < 8; i++) {
321 k = p / factorial[7-i]; 321 k = p / factorial[7-i];
@@ -332,7 +332,7 @@ indextoperm_8x8(int64_t p)
332 return ret; 332 return ret;
333} 333}
334 334
335STATIC_INLINE int64_t 335STATIC_INLINE uint64_t
336coord_cp(cube_t cube) 336coord_cp(cube_t cube)
337{ 337{
338 cube_t cp; 338 cube_t cp;
@@ -345,12 +345,12 @@ coord_cp(cube_t cube)
345} 345}
346 346
347STATIC_INLINE cube_t 347STATIC_INLINE cube_t
348invcoord_cp(int64_t i) 348invcoord_cp(uint64_t i)
349{ 349{
350 return _mm256_set_epi64x(SOLVED_H, SOLVED_L, 0, indextoperm_8x8(i)); 350 return _mm256_set_epi64x(SOLVED_H, SOLVED_L, 0, indextoperm_8x8(i));
351} 351}
352 352
353STATIC_INLINE int64_t 353STATIC_INLINE uint64_t
354coord_epud(cube_t cube) 354coord_epud(cube_t cube)
355{ 355{
356 cube_t ep; 356 cube_t ep;
@@ -363,7 +363,7 @@ coord_epud(cube_t cube)
363} 363}
364 364
365STATIC_INLINE cube_t 365STATIC_INLINE cube_t
366invcoord_epud(int64_t i) 366invcoord_epud(uint64_t i)
367{ 367{
368 return _mm256_set_epi64x(SOLVED_H, indextoperm_8x8(i), 0, SOLVED_L); 368 return _mm256_set_epi64x(SOLVED_H, indextoperm_8x8(i), 0, SOLVED_L);
369} 369}

Generated with cgit - Back to sebastiano.tronto.net