Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fea7cd2c authored by Ryan Prichard's avatar Ryan Prichard Committed by Gerrit Code Review
Browse files

Merge "Rename ExtendedAccumulator::Wrap enumerators" into main

parents 7a299118 770f3621
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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;
@@ -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);
+3 −3
Original line number Diff line number Diff line
@@ -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