From 60b0c2daf2291a8358e3905515c1dfa47956590f Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 13 Oct 2012 22:14:06 +0100 Subject: [PATCH] Corrected signed/unsigned inconsistencies in LogicDataSnapshot --- pv/logicdatasnapshot.cpp | 18 +++++++++--------- pv/logicdatasnapshot.h | 6 +++--- test/logicdatasnapshot.cpp | 5 ----- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/pv/logicdatasnapshot.cpp b/pv/logicdatasnapshot.cpp index 2b3e8cae..b78047d7 100644 --- a/pv/logicdatasnapshot.cpp +++ b/pv/logicdatasnapshot.cpp @@ -121,7 +121,7 @@ void LogicDataSnapshot::append_payload_to_mipmap() } // Compute higher level mipmaps - for(int level = 1; level < ScaleStepCount; level++) + for(unsigned int level = 1; level < ScaleStepCount; level++) { MipMapLevel &m = _mip_map[level]; const MipMapLevel &ml = _mip_map[level-1]; @@ -169,11 +169,11 @@ uint64_t LogicDataSnapshot::get_sample(uint64_t index) const void LogicDataSnapshot::get_subsampled_edges( std::vector &edges, - int64_t start, int64_t end, + uint64_t start, uint64_t end, float min_length, int sig_index) { - int64_t index = start; - int level; + uint64_t index = start; + unsigned int level; bool last_sample; bool fast_forward; @@ -184,8 +184,8 @@ void LogicDataSnapshot::get_subsampled_edges( assert(sig_index >= 0); assert(sig_index < SR_MAX_NUM_PROBES); - const int64_t block_length = (int64_t)max(min_length, 1.0f); - const int min_level = max((int)floorf(logf(min_length) / + const uint64_t block_length = (uint64_t)max(min_length, 1.0f); + const unsigned int min_level = max((int)floorf(logf(min_length) / LogMipMapScaleFactor) - 1, 0); const uint64_t sig_mask = 1ULL << sig_index; @@ -350,10 +350,10 @@ uint64_t LogicDataSnapshot::get_subsample(int level, uint64_t offset) const _unit_size * offset); } -int64_t LogicDataSnapshot::pow2_ceil(int64_t x, unsigned int power) +uint64_t LogicDataSnapshot::pow2_ceil(uint64_t x, unsigned int power) { - const int64_t p = 1 << power; - return ((x < 0) ? x : (x + p - 1)) / p * p; + const uint64_t p = 1 << power; + return (x + p - 1) / p * p; } } // namespace pv diff --git a/pv/logicdatasnapshot.h b/pv/logicdatasnapshot.h index 21541202..8e494bed 100644 --- a/pv/logicdatasnapshot.h +++ b/pv/logicdatasnapshot.h @@ -44,7 +44,7 @@ private: }; private: - static const int ScaleStepCount = 10; + static const unsigned int ScaleStepCount = 10; static const int MipMapScalePower; static const int MipMapScaleFactor; static const float LogMipMapScaleFactor; @@ -79,13 +79,13 @@ public: * @param[in] sig_index The index of the signal. **/ void get_subsampled_edges(std::vector &edges, - int64_t start, int64_t end, + uint64_t start, uint64_t end, float min_length, int sig_index); private: uint64_t get_subsample(int level, uint64_t offset) const; - static int64_t pow2_ceil(int64_t x, unsigned int power); + static uint64_t pow2_ceil(uint64_t x, unsigned int power); private: struct MipMapLevel _mip_map[ScaleStepCount]; diff --git a/test/logicdatasnapshot.cpp b/test/logicdatasnapshot.cpp index 02d71956..8891ba9f 100644 --- a/test/logicdatasnapshot.cpp +++ b/test/logicdatasnapshot.cpp @@ -46,8 +46,6 @@ void push_logic(LogicDataSnapshot &s, unsigned int length, uint8_t value) BOOST_AUTO_TEST_CASE(Pow2) { - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-2, 0), -2); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-1, 0), -1); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(0, 0), 0); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(1, 0), 1); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(2, 0), 2); @@ -57,9 +55,6 @@ BOOST_AUTO_TEST_CASE(Pow2) BOOST_CHECK_EQUAL( LogicDataSnapshot::pow2_ceil(INT64_MAX, 0), INT64_MAX); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-3, 1), -2); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-2, 1), -2); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-1, 1), 0); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(0, 1), 0); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(1, 1), 2); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(2, 1), 2); -- 2.30.2