Corrected signed/unsigned inconsistencies in LogicDataSnapshot
authorJoel Holdsworth <joel@airwebreathe.org.uk>
Sat, 13 Oct 2012 21:14:06 +0000 (22:14 +0100)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Sat, 20 Oct 2012 17:29:24 +0000 (18:29 +0100)
pv/logicdatasnapshot.cpp
pv/logicdatasnapshot.h
test/logicdatasnapshot.cpp

index 2b3e8cae7c06b4e8c3e125a941d2d2cb865c5f4c..b78047d761ca29c351c1300230aa94553cf5434b 100644 (file)
@@ -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<EdgePair> &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
index 21541202d81cfb6afa8114183f141bbb60dee259..8e494bedccc916d64f883363a59f7e2c1f0ccaf0 100644 (file)
@@ -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<EdgePair> &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];
index 02d719566e34a54295f3c34aeb1868204e055c33..8891ba9f22a09fda10386951453ecf0cf37abc46 100644 (file)
@@ -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);