Closed VVD closed 5 months ago
That fix is broken - it's truncating the value to 32-bits before taking the popcount.
Any reason you don't use the __builtin_popcountll()
fallback, the same as __MINGW32__
? I suspect that fallback could just be
#if !defined(__x86_64__)
return static_cast<int>(__builtin_popcountll(v));
#else
I'm new to this, so I did it this way. Your patch fixed the build issue too and look better. Thanks!
Thanks for confirming - I'll get that in for 4.9.
If, before writing the patch, I had read what the popcnt instructions do, I would have suggested the following patch:
return static_cast<int>(_mm_popcnt_u32(static_cast<uint32_t>(v)) + _mm_popcnt_u32(static_cast<uint32_t>(v >> 32)));
:-)
Patch against main branch:
--- Source/astcenc_vecmathlib_sse_4.h.orig 2024-05-07 09:59:55 UTC
+++ Source/astcenc_vecmathlib_sse_4.h
@@ -1307,7 +1307,11 @@ ASTCENC_SIMD_INLINE vfloat4 dot3(vfloat4 a, vfloat4 b)
*/
ASTCENC_SIMD_INLINE int popcount(uint64_t v)
{
+#if defined(__x86_64__)
return static_cast<int>(_mm_popcnt_u64(v));
+#else
+ return static_cast<int>(__builtin_popcountll(v));
+#endif
}
#endif // ASTCENC_POPCNT >= 1
Fixed on main.
I got this build error related to
popcnt
andi386
:FreeBSD 13.2 i386, llvm 14.0.5,
-march=nehalem
or newer, as a workaround I can use-march=penryn
to prevent usage ofpopcnt
.This patch work for me: