aboutsummaryrefslogtreecommitdiff
path: root/src/arch/neon.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-07-24 09:00:49 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-07-24 10:18:07 +0200
commit7c3701364542355c29b2e4ebc6d719ddd123c0f2 (patch)
tree78a7aed4aea3a8f438a61ff2af4dff481767becd /src/arch/neon.h
parent836d626e7caba9578c3440ec0484e7ff1b4cc48e (diff)
downloadnissy-core-7c3701364542355c29b2e4ebc6d719ddd123c0f2.tar.gz
nissy-core-7c3701364542355c29b2e4ebc6d719ddd123c0f2.zip
Use bit trick for portable and arm popcount
Diffstat (limited to 'src/arch/neon.h')
-rw-r--r--src/arch/neon.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/arch/neon.h b/src/arch/neon.h
index 6261c9a..1fb1c82 100644
--- a/src/arch/neon.h
+++ b/src/arch/neon.h
@@ -30,16 +30,17 @@ STATIC_INLINE uint8x8_t compose_corners_slim(uint8x8_t, uint8x8_t);
30#define SOLVED_CUBE STATIC_CUBE( \ 30#define SOLVED_CUBE STATIC_CUBE( \
31 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) 31 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
32 32
33/* TODO: optimize this (use intrinsics?) */
34STATIC_INLINE int 33STATIC_INLINE int
35popcount_u32(uint32_t x) 34popcount_u32(uint32_t x)
36{ 35{
37 int ret; 36 /* Same as the portable version */
37 x -= (x >> UINT32_C(1)) & UINT32_C(0x55555555);
38 x = (x & UINT32_C(0x33333333)) +
39 ((x >> UINT32_C(2)) & UINT32_C(0x33333333));
40 x = (x + (x >> UINT32_C(4))) & UINT32_C(0x0F0F0F0F);
41 x = (x * UINT32_C(0x01010101)) >> UINT32_C(24);
38 42
39 for (ret = 0; x != 0; x >>= 1) 43 return (int)x;
40 ret += x & 1;
41
42 return ret;
43} 44}
44 45
45STATIC void 46STATIC void

Generated with cgit - Back to sebastiano.tronto.net