mirror of
https://github.com/matrix-construct/construct
synced 2024-09-30 12:48:54 +02:00
ircd::simd: Add population mask convenience template.
This commit is contained in:
parent
e3e6bb8dbf
commit
aec21af0e4
1 changed files with 29 additions and 0 deletions
|
@ -18,6 +18,9 @@
|
|||
|
||||
namespace ircd::simd
|
||||
{
|
||||
template<class T> T popmask(const T) noexcept;
|
||||
template<class T> size_t popcount(const T) noexcept;
|
||||
|
||||
// xmmx shifter workarounds
|
||||
template<int bits, class T> T shl(const T &a) noexcept;
|
||||
template<int bits, class T> T shr(const T &a) noexcept;
|
||||
|
@ -34,6 +37,32 @@ namespace ircd
|
|||
using simd::lane_cast;
|
||||
}
|
||||
|
||||
/// Convenience template. Vector compare instructions yield 0xff on equal;
|
||||
/// sometimes one might need an actual value of 1 for accumulators or maybe
|
||||
/// some bool-type reason...
|
||||
template<class T>
|
||||
inline size_t
|
||||
ircd::simd::popcount(const T a)
|
||||
noexcept
|
||||
{
|
||||
size_t i(0), ret(0);
|
||||
while(i < lanes(a))
|
||||
ret += __builtin_popcountll(a[i++]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Convenience template. Vector compare instructions yield 0xff on equal;
|
||||
/// sometimes one might need an actual value of 1 for accumulators or maybe
|
||||
/// some bool-type reason...
|
||||
template<class T>
|
||||
inline T
|
||||
ircd::simd::popmask(const T a)
|
||||
noexcept
|
||||
{
|
||||
return a & 1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_X86INTRIN_H
|
||||
template<int b>
|
||||
[[using gnu: always_inline, gnu_inline, artificial]]
|
||||
|
|
Loading…
Reference in a new issue