diff options
author | David Robillard <d@drobilla.net> | 2018-08-26 21:00:06 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:50:32 +0200 |
commit | 7a7f6f69369a858f9022e44e7f1a8a30bff56c3e (patch) | |
tree | 8c4c1e79e31020915bfc182990d96b91c46167e3 | |
parent | c1360b06e558323af4e9ac3654a828316a5ac07c (diff) | |
download | chilbert-7a7f6f69369a858f9022e44e7f1a8a30bff56c3e.tar.gz chilbert-7a7f6f69369a858f9022e44e7f1a8a30bff56c3e.tar.bz2 chilbert-7a7f6f69369a858f9022e44e7f1a8a30bff56c3e.zip |
Remove branch from gray_code_inv
-rw-r--r-- | chilbert/detail/MultiBitVec.hpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/chilbert/detail/MultiBitVec.hpp b/chilbert/detail/MultiBitVec.hpp index 283601f..a184287 100644 --- a/chilbert/detail/MultiBitVec.hpp +++ b/chilbert/detail/MultiBitVec.hpp @@ -24,6 +24,7 @@ #include "chilbert/detail/BitVecMask.hpp" #include "chilbert/detail/operations.hpp" +#include <array> #include <cassert> #include <climits> #include <cstdint> @@ -366,15 +367,16 @@ template <class Derived> void gray_code_inv(MultiBitVec<Derived>& value) { - typename MultiBitVec<Derived>::Rack s = 0; + using Rack = typename MultiBitVec<Derived>::Rack; + + constexpr std::array<Rack, 2> masks{Rack{0}, ~Rack{0}}; + bool s = 0; for (size_t ri = 0; ri < value.num_racks(); ++ri) { const size_t i = value.num_racks() - ri - 1; auto& rack = value.rack(i); gray_code_inv(rack); - if (s) { - rack = ~rack; - } + rack ^= masks[s]; s = rack & 1; } } |