Loading media/utils/include/mediautils/ExtendedAccumulator.h +5 −5 Original line number Diff line number Diff line Loading @@ -48,9 +48,9 @@ class ExtendedAccumulator { public: enum class Wrap { NORMAL = 0, UNDERFLOW = 1, OVERFLOW = 2, Normal = 0, Underflow = 1, Overflow = 2, }; using UnsignedInt = Integral; Loading @@ -63,11 +63,11 @@ class ExtendedAccumulator { std::pair<SignedInt, Wrap> poll(UnsignedInt value) { auto acc = mAccumulated.load(std::memory_order_relaxed); const auto bottom_bits = static_cast<UnsignedInt>(acc); std::pair<SignedInt, Wrap> res = {0, Wrap::NORMAL}; std::pair<SignedInt, Wrap> res = {0, Wrap::Normal}; const bool overflow = __builtin_sub_overflow(value, bottom_bits, &res.first); if (overflow) { res.second = (res.first > 0) ? Wrap::OVERFLOW : Wrap::UNDERFLOW; res.second = (res.first > 0) ? Wrap::Overflow : Wrap::Underflow; } const bool acc_overflow = __builtin_add_overflow(acc, res.first, &acc); Loading media/utils/tests/extended_accumulator_tests.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -68,10 +68,10 @@ void testPair(TestUInt prevVal, std::make_signed_t<TestUInt> delta) { EXPECT_EQ(result, delta); // Test overflow/underflow event reporting. if (next < base) EXPECT_EQ(TestDetect::Wrap::UNDERFLOW, status); if (next < base) EXPECT_EQ(TestDetect::Wrap::Underflow, status); else if (next > base + std::numeric_limits<TestUInt>::max()) EXPECT_EQ(TestDetect::Wrap::OVERFLOW, status); else EXPECT_EQ(TestDetect::Wrap::NORMAL, status); EXPECT_EQ(TestDetect::Wrap::Overflow, status); else EXPECT_EQ(TestDetect::Wrap::Normal, status); } // Test this utility on every combination of prior and update value for the Loading Loading
media/utils/include/mediautils/ExtendedAccumulator.h +5 −5 Original line number Diff line number Diff line Loading @@ -48,9 +48,9 @@ class ExtendedAccumulator { public: enum class Wrap { NORMAL = 0, UNDERFLOW = 1, OVERFLOW = 2, Normal = 0, Underflow = 1, Overflow = 2, }; using UnsignedInt = Integral; Loading @@ -63,11 +63,11 @@ class ExtendedAccumulator { std::pair<SignedInt, Wrap> poll(UnsignedInt value) { auto acc = mAccumulated.load(std::memory_order_relaxed); const auto bottom_bits = static_cast<UnsignedInt>(acc); std::pair<SignedInt, Wrap> res = {0, Wrap::NORMAL}; std::pair<SignedInt, Wrap> res = {0, Wrap::Normal}; const bool overflow = __builtin_sub_overflow(value, bottom_bits, &res.first); if (overflow) { res.second = (res.first > 0) ? Wrap::OVERFLOW : Wrap::UNDERFLOW; res.second = (res.first > 0) ? Wrap::Overflow : Wrap::Underflow; } const bool acc_overflow = __builtin_add_overflow(acc, res.first, &acc); Loading
media/utils/tests/extended_accumulator_tests.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -68,10 +68,10 @@ void testPair(TestUInt prevVal, std::make_signed_t<TestUInt> delta) { EXPECT_EQ(result, delta); // Test overflow/underflow event reporting. if (next < base) EXPECT_EQ(TestDetect::Wrap::UNDERFLOW, status); if (next < base) EXPECT_EQ(TestDetect::Wrap::Underflow, status); else if (next > base + std::numeric_limits<TestUInt>::max()) EXPECT_EQ(TestDetect::Wrap::OVERFLOW, status); else EXPECT_EQ(TestDetect::Wrap::NORMAL, status); EXPECT_EQ(TestDetect::Wrap::Overflow, status); else EXPECT_EQ(TestDetect::Wrap::Normal, status); } // Test this utility on every combination of prior and update value for the Loading