Index: llvm/trunk/include/llvm/Support/ScaledNumber.h =================================================================== --- llvm/trunk/include/llvm/Support/ScaledNumber.h +++ llvm/trunk/include/llvm/Support/ScaledNumber.h @@ -514,7 +514,7 @@ : Digits(Digits), Scale(Scale) {} private: - ScaledNumber(const std::pair &X) + ScaledNumber(const std::pair &X) : Digits(X.first), Scale(X.second) {} public: @@ -732,11 +732,21 @@ SCALED_NUMBER_BOP(-, -= ) SCALED_NUMBER_BOP(*, *= ) SCALED_NUMBER_BOP(/, /= ) -SCALED_NUMBER_BOP(<<, <<= ) -SCALED_NUMBER_BOP(>>, >>= ) #undef SCALED_NUMBER_BOP template +ScaledNumber operator<<(const ScaledNumber &L, + int16_t Shift) { + return ScaledNumber(L) <<= Shift; +} + +template +ScaledNumber operator>>(const ScaledNumber &L, + int16_t Shift) { + return ScaledNumber(L) >>= Shift; +} + +template raw_ostream &operator<<(raw_ostream &OS, const ScaledNumber &X) { return X.print(OS, 10); } Index: llvm/trunk/unittests/Support/ScaledNumberTest.cpp =================================================================== --- llvm/trunk/unittests/Support/ScaledNumberTest.cpp +++ llvm/trunk/unittests/Support/ScaledNumberTest.cpp @@ -532,4 +532,28 @@ EXPECT_EQ(SP64(0, 0), getDifference64(1, -64, 1, -1)); } +TEST(ScaledNumberHelpersTest, arithmeticOperators) { + EXPECT_EQ(ScaledNumber(10, 0), + ScaledNumber(1, 3) + ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(6, 0), + ScaledNumber(1, 3) - ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(2, 3), + ScaledNumber(1, 3) * ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(1, 2), + ScaledNumber(1, 3) / ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(1, 2), ScaledNumber(1, 3) >> 1); + EXPECT_EQ(ScaledNumber(1, 4), ScaledNumber(1, 3) << 1); + + EXPECT_EQ(ScaledNumber(10, 0), + ScaledNumber(1, 3) + ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(6, 0), + ScaledNumber(1, 3) - ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(2, 3), + ScaledNumber(1, 3) * ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(1, 2), + ScaledNumber(1, 3) / ScaledNumber(1, 1)); + EXPECT_EQ(ScaledNumber(1, 2), ScaledNumber(1, 3) >> 1); + EXPECT_EQ(ScaledNumber(1, 4), ScaledNumber(1, 3) << 1); +} + } // end namespace