Skip to content

Commit 4ab58de

Browse files
Implement batch_bool::mask() for riscv
As a followup to #1236
1 parent 58bdc0a commit 4ab58de

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/xsimd/arch/xsimd_rvv.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,18 @@ namespace xsimd
15071507
const auto mask = abs(arg) < constants::maxflint<batch<T, A>>();
15081508
return select(mask, to_float(detail::rvvfcvt_default(arg)), arg, rvv {});
15091509
}
1510+
1511+
// mask
1512+
template <class A, class T>
1513+
XSIMD_INLINE uint64_t mask(batch_bool<T, A> const& self, requires_arch<rvv>) noexcept
1514+
{
1515+
const auto zero = detail::broadcast<as_unsigned_integer_t<T>, types::detail::rvv_width_m1>(T(0));
1516+
auto ones = detail::broadcast<as_unsigned_integer_t<T>, A::width>(1);
1517+
auto iota = detail::vindex<A, T>();
1518+
auto powers = detail::rvvsll(ones, iota);
1519+
auto r = __riscv_vredor(self.data.as_mask(), (typename decltype(powers)::register_type)powers, zero, batch_bool<T, A>::size);
1520+
return detail::reduce_scalar<A, T>(r);
1521+
}
15101522
} // namespace kernel
15111523
} // namespace xsimd
15121524

include/xsimd/types/xsimd_rvv_register.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ namespace xsimd
391391
{
392392
}
393393
operator type() const noexcept { return bool_info::bitcast(value); }
394+
type as_mask() const noexcept { return (type) * this; }
394395
};
395396

396397
template <class T, size_t Width = XSIMD_RVV_BITS>

0 commit comments

Comments
 (0)