aboutsummaryrefslogtreecommitdiffstats
path: root/chilbert/FixBitVec.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-19 01:42:30 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:47:26 +0200
commit09f8d4a4b20f234dafcdf2ce667f220801b9210f (patch)
tree76e02b8e23d33c86e803193eeb2d4d906c8e4728 /chilbert/FixBitVec.hpp
parent967d2ac6c2034d1374fc603e64212fc06b5f6133 (diff)
downloadchilbert-09f8d4a4b20f234dafcdf2ce667f220801b9210f.tar.gz
chilbert-09f8d4a4b20f234dafcdf2ce667f220801b9210f.tar.bz2
chilbert-09f8d4a4b20f234dafcdf2ce667f220801b9210f.zip
Make size of bit vectors precise
Diffstat (limited to 'chilbert/FixBitVec.hpp')
-rw-r--r--chilbert/FixBitVec.hpp41
1 files changed, 19 insertions, 22 deletions
diff --git a/chilbert/FixBitVec.hpp b/chilbert/FixBitVec.hpp
index 0dab483..f9ce94a 100644
--- a/chilbert/FixBitVec.hpp
+++ b/chilbert/FixBitVec.hpp
@@ -79,25 +79,27 @@ public:
Rack m_mask;
};
- CFixBitVec(const size_t bits = bits_per_rack)
+ explicit CFixBitVec(const size_t bits)
: m_rack{0}
+ , m_size{bits}
{
assert(bits <= bits_per_rack);
}
CFixBitVec(const size_t bits, const Rack value)
: m_rack{value}
+ , m_size{bits}
{
assert(bits <= bits_per_rack);
}
/// Return the size in bits
- size_t size() const { return bits_per_rack; }
+ size_t size() const { return m_size; }
/// Set all bits to one
CFixBitVec& set()
{
- m_rack = FBV1S;
+ m_rack = FBV1S & FBVN1S(size());
return *this;
}
@@ -255,32 +257,26 @@ public:
return t;
}
- /// Right-rotate the least significant `width` bits by `bits` positions
- CFixBitVec& rotr(const size_t bits, const size_t width)
+ /// Right-rotate by `bits` positions
+ CFixBitVec& rotr(const size_t bits)
{
if (bits) {
- assert(width > 0);
- assert(bits < width);
- assert(bits < bits_per_rack);
- assert((width - bits) < bits_per_rack);
- m_rack &= FBVN1S(width);
- m_rack = (m_rack >> bits) | (m_rack << (width - bits));
- m_rack &= FBVN1S(width);
+ assert(bits <= bits_per_rack);
+ m_rack &= FBVN1S(size());
+ m_rack = (m_rack >> bits) | (m_rack << (size() - bits));
+ m_rack &= FBVN1S(size());
}
return *this;
}
- /// Left-rotate the least significant `width` bits by `bits` positions
- CFixBitVec& rotl(const size_t bits, const size_t width)
+ /// Left-rotate by `bits` positions
+ CFixBitVec& rotl(const size_t bits)
{
if (bits > 0) {
- assert(width > 0);
- assert(bits < width);
- assert(bits < bits_per_rack);
- assert((width - bits) < bits_per_rack);
- m_rack &= FBVN1S(width);
- m_rack = (m_rack << bits) | (m_rack >> (width - bits));
- m_rack &= FBVN1S(width);
+ assert(bits <= bits_per_rack);
+ m_rack &= FBVN1S(size());
+ m_rack = (m_rack << bits) | (m_rack >> (size() - bits));
+ m_rack &= FBVN1S(size());
}
return *this;
}
@@ -401,7 +397,8 @@ private:
static_assert(8 * sizeof(Rack) == bits_per_rack, "");
static_assert((sizeof(Rack) == 4) || (sizeof(Rack) == 8), "");
- Rack m_rack{};
+ Rack m_rack{};
+ size_t m_size{};
};
template <>