From 7ff76870242b6906b6f3caf22da3c094822ed140 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 1 Aug 2025 23:32:19 +0200 Subject: Move is_eo_even to more appropriate module --- src/arch/avx2.h | 14 ++++++++++++++ src/arch/common.h | 2 ++ src/arch/neon.h | 18 ++++++++++++++++-- src/arch/portable.h | 11 +++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) (limited to 'src/arch') diff --git a/src/arch/avx2.h b/src/arch/avx2.h index 3fb46c9..cb9c0cd 100644 --- a/src/arch/avx2.h +++ b/src/arch/avx2.h @@ -426,3 +426,17 @@ invcoord_epe(uint64_t i) return _mm256_set_epi64x(a, SOLVED_L, 0, SOLVED_L); } + +STATIC_INLINE bool +is_eo_even(cube_t cube) +{ + uint8_t count; + __m256i e; + + e = _mm256_and_si256(cube, EO_AVX2); + e = _mm256_srli_si256(e, EOSHIFT); + + count = _mm256_reduce_add_epi8(e); + + return count % 2 == 0; +} diff --git a/src/arch/common.h b/src/arch/common.h index 1c8c0b0..d76b65f 100644 --- a/src/arch/common.h +++ b/src/arch/common.h @@ -30,6 +30,8 @@ STATIC_INLINE uint64_t coord_eo(cube_t); STATIC_INLINE uint64_t coord_esep(cube_t); STATIC_INLINE cube_t invcoord_esep(uint64_t); +STATIC_INLINE bool is_eo_even(cube_t); + STATIC_INLINE void copy_corners(cube_t [static 1], cube_t); STATIC_INLINE void copy_edges(cube_t [static 1], cube_t); STATIC_INLINE void set_eo(cube_t [static 1], uint64_t); diff --git a/src/arch/neon.h b/src/arch/neon.h index 5723b60..2c35c58 100644 --- a/src/arch/neon.h +++ b/src/arch/neon.h @@ -1,5 +1,6 @@ -#define CO2_NEON vdup_n_u8(0x60) -#define COCW_NEON vdup_n_u8(0x20) +#define CO2_NEON vdup_n_u8(0x60) +#define COCW_NEON vdup_n_u8(0x20) +#define EO_NEON vdupq_n_u8(0x10) #define PBITS8_NEON vdup_n_u8(PBITS) STATIC_INLINE uint8x16_t compose_edges_slim(uint8x16_t, uint8x16_t); @@ -501,3 +502,16 @@ invcoord_epe(uint64_t i) .edge = vcombine_u8(vld1_u8(SOLVED_L), a) }; } + +STATIC_INLINE bool +is_eo_even(cube_t cube) +{ + int8_t count; + uint8x16_t e; + + e = vandq_u8(cube.edge, EO_NEON); + e = vshrq_n_u8(e, EOSHIFT); + count = vaddvq_u8(e); + + return count % 2 == 0; +} diff --git a/src/arch/portable.h b/src/arch/portable.h index 26001ee..d673f15 100644 --- a/src/arch/portable.h +++ b/src/arch/portable.h @@ -356,3 +356,14 @@ invcoord_epe(uint64_t i) return STATIC_CUBE(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, e[0]+8, e[1]+8, e[2]+8, e[3]+8); } + +STATIC_INLINE bool +is_eo_even(cube_t cube) +{ + uint8_t i, count; + + for (i = 0, count = 0; i < 12; i++) + count += (cube.edge[i] & EOBIT) >> EOSHIFT; + + return count % 2 == 0; +} -- cgit v1.3