From fb93b9d81f04f47e868ca1b05e225e2f790b3861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 13 Dec 2021 17:05:01 +0200 Subject: [PATCH] Use fold expressions to enable potential simd optimizations --- src/openrct2/core/BitSet.hpp | 38 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/openrct2/core/BitSet.hpp b/src/openrct2/core/BitSet.hpp index 9256010a96..988af874db 100644 --- a/src/openrct2/core/BitSet.hpp +++ b/src/openrct2/core/BitSet.hpp @@ -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>(res, other, std::make_index_sequence{}); 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>(res, other, std::make_index_sequence{}); 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>(res, other, std::make_index_sequence{}); return res; } @@ -500,6 +479,17 @@ namespace OpenRCT2 } private: + template + void ApplyOp(BitSet& dst, const BitSet& src, std::index_sequence) 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)