Skip to content

Commit c982bae

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

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

include/xsimd/arch/xsimd_rvv.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,16 @@ 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+
auto ones = detail::broadcast<as_unsigned_integer_t<T>, A::width>(1);
1516+
auto iota = detail::vindex<A, T>();
1517+
auto powers = detail::rvvsll(ones, iota);
1518+
return __riscv_vredor(self.data.as_mask(), powers, as_unsigned_integer_t<T>(0), batch_bool<T, A>::size);
1519+
}
15101520
} // namespace kernel
15111521
} // namespace xsimd
15121522

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)