aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-19 17:59:20 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:49:56 +0200
commit7567f77828ff9661f85eabe3b4cfb1876b307d42 (patch)
tree82c44086cd8a8ed7025b342d5e3edd1add6ea1e0
parentc48d56bcc0c919007d712d8716c86714e387554b (diff)
downloadchilbert-7567f77828ff9661f85eabe3b4cfb1876b307d42.tar.gz
chilbert-7567f77828ff9661f85eabe3b4cfb1876b307d42.tar.bz2
chilbert-7567f77828ff9661f85eabe3b4cfb1876b307d42.zip
Remove old macros
-rw-r--r--chilbert/Hilbert.ipp10
-rw-r--r--chilbert/SmallBitVec.hpp19
-rw-r--r--test/test_hilbert.cpp19
3 files changed, 16 insertions, 32 deletions
diff --git a/chilbert/Hilbert.ipp b/chilbert/Hilbert.ipp
index 571166d..837375e 100644
--- a/chilbert/Hilbert.ipp
+++ b/chilbert/Hilbert.ipp
@@ -323,7 +323,7 @@ coords_to_compact_index(const P* const p,
// speed by a bit (4% when n=4, m=20)
size_t* const ds = new size_t[m];
- if (mn > FBV_BITS) {
+ if (mn > SmallBitVec::bits_per_rack) {
DynamicBitVec h(mn);
detail::coords_to_index<P, DynamicBitVec, I>(
p, m, n, h, std::move(scratch), ds);
@@ -421,7 +421,7 @@ coords_to_index(const P* const p, const size_t m, const size_t n, H& h)
assert(detail::num_bits(h) >= n * m);
assert(detail::num_bits(p[0]) >= m);
- if (n <= FBV_BITS) {
+ if (n <= SmallBitVec::bits_per_rack) {
// Intermediate variables will fit in fixed width
detail::coords_to_index<P, H, SmallBitVec>(p, m, n, h, SmallBitVec(n));
} else {
@@ -440,7 +440,7 @@ index_to_coords(P* const p, const size_t m, const size_t n, const H& h)
assert(detail::num_bits(h) >= n * m);
assert(detail::num_bits(p[0]) >= m);
- if (n <= FBV_BITS) {
+ if (n <= SmallBitVec::bits_per_rack) {
// Intermediate variables will fit in fixed width
detail::index_to_coords<P, H, SmallBitVec>(p, m, n, h, SmallBitVec(n));
} else {
@@ -461,7 +461,7 @@ coords_to_compact_index(const P* const p,
{
assert(hc.size() >= std::accumulate(ms, ms + n, size_t(0)));
- if (n <= FBV_BITS) {
+ if (n <= SmallBitVec::bits_per_rack) {
// Intermediate variables will fit in fixed width
detail::coords_to_compact_index<P, HC, SmallBitVec>(
p, ms, n, hc, SmallBitVec(n), M, m);
@@ -483,7 +483,7 @@ compact_index_to_coords(P* const p,
{
assert(hc.size() >= std::accumulate(ms, ms + n, size_t(0)));
- if (n <= FBV_BITS) {
+ if (n <= SmallBitVec::bits_per_rack) {
// Intermediate variables will fit in fixed width
SmallBitVec scratch(n);
detail::compact_index_to_coords<P, HC, SmallBitVec>(
diff --git a/chilbert/SmallBitVec.hpp b/chilbert/SmallBitVec.hpp
index 96652e9..308d943 100644
--- a/chilbert/SmallBitVec.hpp
+++ b/chilbert/SmallBitVec.hpp
@@ -29,17 +29,6 @@
namespace chilbert {
-/* This must be an unsigned integer that is either 32 or 64 bits. Otherwise,
- there are places in the code that simply will not work. For speed, this
- should be the native word size. */
-typedef uint64_t FBV_UINT;
-
-#define FBV_BITS 64
-
-#define FBV1 (FBV_UINT{1})
-#define FBV1S (~FBV_UINT{0})
-#define FBVN1S(n) (n == FBV_BITS ? FBV1S : (FBV1 << n) - 1)
-
/** A bit vector small enough to fit in a single word. */
class SmallBitVec
{
@@ -100,7 +89,7 @@ public:
/// Set all bits to one
SmallBitVec& set()
{
- m_rack = FBV1S & FBVN1S(size());
+ m_rack = ~Rack{0} >> (bits_per_rack - m_size);
return *this;
}
@@ -221,9 +210,8 @@ public:
{
if (bits > 0 && bits < size()) {
assert(bits <= bits_per_rack);
- m_rack &= FBVN1S(size());
m_rack = (m_rack >> bits) | (m_rack << (size() - bits));
- m_rack &= FBVN1S(size());
+ m_rack &= (~Rack{0} >> (bits_per_rack - size()));
}
return *this;
}
@@ -233,9 +221,8 @@ public:
{
if (bits > 0 && bits < size()) {
assert(bits <= bits_per_rack);
- m_rack &= FBVN1S(size());
m_rack = (m_rack << bits) | (m_rack >> (size() - bits));
- m_rack &= FBVN1S(size());
+ m_rack &= (~Rack{0} >> (bits_per_rack - size()));
}
return *this;
}
diff --git a/test/test_hilbert.cpp b/test/test_hilbert.cpp
index ad99454..a217dc2 100644
--- a/test/test_hilbert.cpp
+++ b/test/test_hilbert.cpp
@@ -69,10 +69,11 @@ template <class T>
mpz_class
to_big_int(const T& vec)
{
+ using Rack = typename T::Rack;
+
mpz_t ia;
mpz_init(ia);
- mpz_import(
- ia, vec.num_racks(), -1, sizeof(chilbert::FBV_UINT), 0, 0, vec.data());
+ mpz_import(ia, vec.num_racks(), -1, sizeof(Rack), 0, 0, vec.data());
const mpz_class num(ia);
mpz_clear(ia);
return num;
@@ -83,15 +84,11 @@ template <class T, size_t M>
T
from_big_int(const mpz_class& num)
{
+ using Rack = typename T::Rack;
+
T vec = make_zero_bitvec<T, M>();
size_t count = 0;
- mpz_export(vec.data(),
- &count,
- -1,
- sizeof(chilbert::FBV_UINT),
- 0,
- 0,
- num.get_mpz_t());
+ mpz_export(vec.data(), &count, -1, sizeof(Rack), 0, 0, num.get_mpz_t());
assert(count <= static_cast<size_t>(vec.num_racks()));
return vec;
}
@@ -100,7 +97,7 @@ template <class H, size_t M, size_t D>
void
test_standard(Context& ctx)
{
- static_assert(M < sizeof(chilbert::FBV_UINT) * CHAR_BIT, "");
+ static_assert(M < sizeof(typename H::Rack) * CHAR_BIT, "");
// Generate random point and its hilbert index
const auto pa = make_random_point<M, D>(ctx);
@@ -135,7 +132,7 @@ template <class T, size_t M, size_t D>
void
test_compact(Context& ctx)
{
- static_assert(M < sizeof(chilbert::FBV_UINT) * CHAR_BIT, "");
+ static_assert(M < sizeof(typename T::Rack) * CHAR_BIT, "");
// Generate random point and its hilbert index
const auto ms = make_random_precisions<D * M, D>(ctx);