From f2a94031c77de48559827492a8d1bd03c2ece1ed Mon Sep 17 00:00:00 2001 From: Dominique Belhachemi Date: Tue, 10 Nov 2026 21:25:41 +0000 Subject: [PATCH] Add LSX and LASX popcount kernels LoongArch has a per-element population count. vpcnt.{b,h,w,d} on LSX xvpcnt.{b,h,w,d} on LASX --- include/xsimd/arch/xsimd_lasx.hpp | 14 ++++++++++++++ include/xsimd/arch/xsimd_lsx.hpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/xsimd/arch/xsimd_lasx.hpp b/include/xsimd/arch/xsimd_lasx.hpp index 0b10360fd..429e9c3fb 100644 --- a/include/xsimd/arch/xsimd_lasx.hpp +++ b/include/xsimd/arch/xsimd_lasx.hpp @@ -883,6 +883,20 @@ namespace xsimd return __lasx_xvfcmp_cun_d(self.data, self.data); } + // popcount + template >> + XSIMD_INLINE batch popcount(batch const& self, requires_arch) noexcept + { + if constexpr (sizeof(T) == 1) + return __lasx_xvpcnt_b(self.data); + else if constexpr (sizeof(T) == 2) + return __lasx_xvpcnt_h(self.data); + else if constexpr (sizeof(T) == 4) + return __lasx_xvpcnt_w(self.data); + else + return __lasx_xvpcnt_d(self.data); + } + // select template XSIMD_INLINE batch select(batch_bool const& cond, batch const& true_br, batch const& false_br, requires_arch) noexcept diff --git a/include/xsimd/arch/xsimd_lsx.hpp b/include/xsimd/arch/xsimd_lsx.hpp index 7f1ca30fe..7ec0177a6 100644 --- a/include/xsimd/arch/xsimd_lsx.hpp +++ b/include/xsimd/arch/xsimd_lsx.hpp @@ -852,6 +852,20 @@ namespace xsimd return __lsx_vfcmp_cun_d(self.data, self.data); } + // popcount + template >> + XSIMD_INLINE batch popcount(batch const& self, requires_arch) noexcept + { + if constexpr (sizeof(T) == 1) + return __lsx_vpcnt_b(self.data); + else if constexpr (sizeof(T) == 2) + return __lsx_vpcnt_h(self.data); + else if constexpr (sizeof(T) == 4) + return __lsx_vpcnt_w(self.data); + else + return __lsx_vpcnt_d(self.data); + } + // select template XSIMD_INLINE batch select(batch_bool const& cond, batch const& true_br, batch const& false_br, requires_arch) noexcept