Use fold expressions to enable potential simd optimizations

This commit is contained in:
ζeh Matt 2021-12-13 17:05:01 +02:00
parent e405658f6a
commit fb93b9d81f
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
1 changed files with 14 additions and 24 deletions

View File

@ -404,14 +404,7 @@ namespace OpenRCT2
constexpr BitSet operator^(const BitSet& other) const noexcept
{
BitSet res = *this;
for (size_t i = 0; i < _data.size(); i++)
{
res._data[i] ^= other._data[i];
}
if constexpr (RequiresTrim)
{
res.Trim();
}
ApplyOp<std::bit_xor<BlockType>>(res, other, std::make_index_sequence<BlockCount>{});
return res;
}
@ -424,14 +417,7 @@ namespace OpenRCT2
constexpr BitSet operator|(const BitSet& other) const noexcept
{
BitSet res = *this;
for (size_t i = 0; i < _data.size(); i++)
{
res._data[i] |= other._data[i];
}
if constexpr (RequiresTrim)
{
res.Trim();
}
ApplyOp<std::bit_or<BlockType>>(res, other, std::make_index_sequence<BlockCount>{});
return res;
}
@ -444,14 +430,7 @@ namespace OpenRCT2
constexpr BitSet operator&(const BitSet& other) const noexcept
{
BitSet res = *this;
for (size_t i = 0; i < _data.size(); i++)
{
res._data[i] &= other._data[i];
}
if constexpr (RequiresTrim)
{
res.Trim();
}
ApplyOp<std::bit_and<BlockType>>(res, other, std::make_index_sequence<BlockCount>{});
return res;
}
@ -500,6 +479,17 @@ namespace OpenRCT2
}
private:
template<typename TOperator, size_t... TIndex>
void ApplyOp(BitSet& dst, const BitSet& src, std::index_sequence<TIndex...>) const
{
TOperator op{};
((dst._data[TIndex] = op(dst._data[TIndex], src._data[TIndex])), ...);
if constexpr (RequiresTrim)
{
dst.Trim();
}
}
static constexpr size_t ComputeBlockIndex(size_t idx) noexcept
{
if constexpr (BlockCount == 1)