aboutsummaryrefslogtreecommitdiff
path: root/src/arch/neon.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/neon.h')
-rw-r--r--src/arch/neon.h79
1 files changed, 72 insertions, 7 deletions
diff --git a/src/arch/neon.h b/src/arch/neon.h
index fef6220..5723b60 100644
--- a/src/arch/neon.h
+++ b/src/arch/neon.h
@@ -1,6 +1,6 @@
1#define CO2_NEON vdup_n_u8(0x60) 1#define CO2_NEON vdup_n_u8(0x60)
2#define COCW_NEON vdup_n_u8(0x20) 2#define COCW_NEON vdup_n_u8(0x20)
3#define PBITS8_NEON vdup_n_u8(0x07) 3#define PBITS8_NEON vdup_n_u8(PBITS)
4 4
5STATIC_INLINE uint8x16_t compose_edges_slim(uint8x16_t, uint8x16_t); 5STATIC_INLINE uint8x16_t compose_edges_slim(uint8x16_t, uint8x16_t);
6STATIC_INLINE uint8x8_t compose_corners_slim(uint8x8_t, uint8x8_t); 6STATIC_INLINE uint8x8_t compose_corners_slim(uint8x8_t, uint8x8_t);
@@ -29,8 +29,9 @@ STATIC_INLINE uint8x8_t compose_corners_slim(uint8x8_t, uint8x8_t);
29const uint8_t SOLVED_L[8] = {0, 1, 2, 3, 4, 5, 6, 7}; 29const uint8_t SOLVED_L[8] = {0, 1, 2, 3, 4, 5, 6, 7};
30const uint8_t SOLVED_H[8] = {8, 9, 10, 11, 0, 0, 0}; 30const uint8_t SOLVED_H[8] = {8, 9, 10, 11, 0, 0, 0};
31 31
32STATIC_INLINE uint64_t permtoindex_8x8(uint8x8_t); 32STATIC_INLINE uint64_t permtoindex_Nx8(uint64_t, uint8x8_t);
33STATIC_INLINE uint8x8_t indextoperm_8x8(uint64_t); 33STATIC_INLINE uint8x8_t indextoperm_8x8(uint64_t);
34STATIC_INLINE uint8x8_t indextoperm_4x8(uint64_t);
34 35
35STATIC_INLINE int 36STATIC_INLINE int
36popcount_u32(uint32_t x) 37popcount_u32(uint32_t x)
@@ -364,14 +365,14 @@ invcoord_esep(uint64_t esep)
364} 365}
365 366
366STATIC_INLINE uint64_t 367STATIC_INLINE uint64_t
367permtoindex_8x8(uint8x8_t a) 368permtoindex_Nx8(uint64_t n, uint8x8_t a)
368{ 369{
369 uint64_t i, c, ret; 370 uint64_t i, c, ret;
370 uint8x8_t cmp; 371 uint8x8_t cmp;
371 uint64x1_t anum; 372 uint64x1_t anum;
372 uint8_t or[8] = {0, 0, 0, 0, 0, 0, 0, 0x0F}; 373 uint8_t or[8] = {0, 0, 0, 0, 0, 0, 0, 0x0F};
373 374
374 for (i = 0, ret = 0; i < 8; i++) { 375 for (i = 0, ret = 0; i < n; i++) {
375 cmp = vdup_lane_u8(a, 0); 376 cmp = vdup_lane_u8(a, 0);
376 anum = vreinterpret_u64_u8(a); 377 anum = vreinterpret_u64_u8(a);
377 anum = vshr_n_u64(anum, 8); 378 anum = vshr_n_u64(anum, 8);
@@ -379,7 +380,7 @@ permtoindex_8x8(uint8x8_t a)
379 a = vorr_u8(a, vld1_u8(or)); 380 a = vorr_u8(a, vld1_u8(or));
380 cmp = vcgt_u8(cmp, a); 381 cmp = vcgt_u8(cmp, a);
381 c = vaddv_u8(vshr_n_u8(cmp, 7)); 382 c = vaddv_u8(vshr_n_u8(cmp, 7));
382 ret += c * factorial[7-i]; 383 ret += c * factorial[n-1-i];
383 } 384 }
384 385
385 return ret; 386 return ret;
@@ -407,10 +408,43 @@ indextoperm_8x8(uint64_t p)
407 return vld1_u8(ret); 408 return vld1_u8(ret);
408} 409}
409 410
411STATIC_INLINE uint8x8_t
412indextoperm_4x8(uint64_t p)
413{
414 static const int64_t A[FACT_4] = {
415 [0] = UINT64_C(0x03020100),
416 [1] = UINT64_C(0x02030100),
417 [2] = UINT64_C(0x03010200),
418 [3] = UINT64_C(0x01030200),
419 [4] = UINT64_C(0x02010300),
420 [5] = UINT64_C(0x01020300),
421 [6] = UINT64_C(0x03020001),
422 [7] = UINT64_C(0x02030001),
423 [8] = UINT64_C(0x03000201),
424 [9] = UINT64_C(0x00030201),
425 [10] = UINT64_C(0x02000301),
426 [11] = UINT64_C(0x00020301),
427 [12] = UINT64_C(0x03010002),
428 [13] = UINT64_C(0x01030002),
429 [14] = UINT64_C(0x03000102),
430 [15] = UINT64_C(0x00030102),
431 [16] = UINT64_C(0x01000302),
432 [17] = UINT64_C(0x00010302),
433 [18] = UINT64_C(0x02010003),
434 [19] = UINT64_C(0x01020003),
435 [20] = UINT64_C(0x02000103),
436 [21] = UINT64_C(0x00020103),
437 [22] = UINT64_C(0x01000203),
438 [23] = UINT64_C(0x00010203),
439 };
440
441 return vreinterpret_u8_u64(vdup_n_u64(A[p]));
442}
443
410STATIC_INLINE uint64_t 444STATIC_INLINE uint64_t
411coord_cp(cube_t cube) 445coord_cp(cube_t cube)
412{ 446{
413 return permtoindex_8x8(vand_u8(cube.corner, PBITS8_NEON)); 447 return permtoindex_Nx8(8, vand_u8(cube.corner, PBITS8_NEON));
414} 448}
415 449
416STATIC_INLINE cube_t 450STATIC_INLINE cube_t
@@ -425,7 +459,12 @@ invcoord_cp(uint64_t i)
425STATIC_INLINE uint64_t 459STATIC_INLINE uint64_t
426coord_epud(cube_t cube) 460coord_epud(cube_t cube)
427{ 461{
428 return permtoindex_8x8(vand_u8(vget_low_u8(cube.edge), PBITS8_NEON)); 462 uint8x8_t a;
463
464 a = vget_low_u8(cube.edge);
465 a = vand_u8(a, PBITS8_NEON);
466
467 return permtoindex_Nx8(8, a);
429} 468}
430 469
431STATIC_INLINE cube_t 470STATIC_INLINE cube_t
@@ -436,3 +475,29 @@ invcoord_epud(uint64_t i)
436 .edge = vcombine_u8(indextoperm_8x8(i), vld1_u8(SOLVED_H)) 475 .edge = vcombine_u8(indextoperm_8x8(i), vld1_u8(SOLVED_H))
437 }; 476 };
438} 477}
478
479STATIC_INLINE uint64_t
480coord_epe(cube_t cube)
481{
482 uint8x8_t a;
483
484 a = vget_high_u8(cube.edge);
485 a = vand_u8(a, PBITS8_NEON);
486 a = veor_u8(a, vdup_n_u8(8));
487
488 return permtoindex_Nx8(4, a);
489}
490
491STATIC_INLINE cube_t
492invcoord_epe(uint64_t i)
493{
494 uint8x8_t a;
495
496 a = indextoperm_4x8(i);
497 a = vadd_u8(a, vreinterpret_u8_u64(vdup_n_u64(UINT64_C(0x08080808))));
498
499 return (cube_t) {
500 .corner = vld1_u8(SOLVED_L),
501 .edge = vcombine_u8(vld1_u8(SOLVED_L), a)
502 };
503}

Generated with cgit - Back to sebastiano.tronto.net