get_sample(end) & sig_mask));
}
-int64_t LogicDataSnapshot::pow2_ceil(int64_t x, int power)
+int64_t LogicDataSnapshot::pow2_ceil(int64_t x, unsigned int power)
{
- return ((x >> power) + 1) << power;
+ const int64_t p = 1 << power;
+ return ((x < 0) ? x : (x + p - 1)) / p * p;
}
#include <vector>
namespace LogicDataSnapshotTest {
+ class Pow2;
class Basic;
class LargeData;
}
private:
- static inline int64_t pow2_ceil(int64_t x, int power);
+ static int64_t pow2_ceil(int64_t x, unsigned int power);
private:
struct MipMapLevel _mip_map[ScaleStepCount];
uint64_t _last_append_sample;
+ friend class LogicDataSnapshotTest::Pow2;
friend class LogicDataSnapshotTest::Basic;
friend class LogicDataSnapshotTest::LargeData;
};
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define __STDC_LIMIT_MACROS
+#include <stdint.h>
+
#include <boost/test/unit_test.hpp>
#include "../logicdatasnapshot.h"
delete[] (uint8_t*)logic.data;
}
+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);
+
+ BOOST_CHECK_EQUAL(
+ LogicDataSnapshot::pow2_ceil(INT64_MIN, 0), INT64_MIN);
+ 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);
+ BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(3, 1), 4);
+}
+
BOOST_AUTO_TEST_CASE(Basic)
{
// Create an empty LogicDataSnapshot object