From af08b8b820acc71b02e7e8e4d0de3679c7971773 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 20 Jun 2014 02:31:07 +0000 Subject: [PATCH] Support: Clean up getRounded() tests git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211337 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ScaledNumber.h | 12 ++++++++++++ unittests/Support/ScaledNumberTest.cpp | 26 ++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/llvm/Support/ScaledNumber.h b/include/llvm/Support/ScaledNumber.h index 54b5386c5ac..f6594ec6aa5 100644 --- a/include/llvm/Support/ScaledNumber.h +++ b/include/llvm/Support/ScaledNumber.h @@ -53,6 +53,18 @@ inline std::pair getRounded(DigitsT Digits, int16_t Scale, return std::make_pair(Digits, Scale); } +/// \brief Convenience helper for 32-bit rounding. +inline std::pair getRounded32(uint32_t Digits, int16_t Scale, + bool ShouldRound) { + return getRounded(Digits, Scale, ShouldRound); +} + +/// \brief Convenience helper for 64-bit rounding. +inline std::pair getRounded64(uint64_t Digits, int16_t Scale, + bool ShouldRound) { + return getRounded(Digits, Scale, ShouldRound); +} + /// \brief Adjust a 64-bit scaled number down to the appropriate width. /// /// Adjust a soft float with 64-bits of digits down, keeping as much diff --git a/unittests/Support/ScaledNumberTest.cpp b/unittests/Support/ScaledNumberTest.cpp index dac24051a62..d1277d0479a 100644 --- a/unittests/Support/ScaledNumberTest.cpp +++ b/unittests/Support/ScaledNumberTest.cpp @@ -41,21 +41,19 @@ typedef ScaledPair SP32; typedef ScaledPair SP64; TEST(ScaledNumberHelpersTest, getRounded) { - EXPECT_EQ(getRounded(0, 0, false), SP32(0, 0)); - EXPECT_EQ(getRounded(0, 0, true), SP32(1, 0)); - EXPECT_EQ(getRounded(20, 21, true), SP32(21, 21)); - EXPECT_EQ(getRounded(UINT32_MAX, 0, false), SP32(UINT32_MAX, 0)); - EXPECT_EQ(getRounded(UINT32_MAX, 0, true), SP32(1 << 31, 1)); + EXPECT_EQ(getRounded32(0, 0, false), SP32(0, 0)); + EXPECT_EQ(getRounded32(0, 0, true), SP32(1, 0)); + EXPECT_EQ(getRounded32(20, 21, true), SP32(21, 21)); + EXPECT_EQ(getRounded32(UINT32_MAX, 0, false), SP32(UINT32_MAX, 0)); + EXPECT_EQ(getRounded32(UINT32_MAX, 0, true), SP32(1 << 31, 1)); - EXPECT_EQ(getRounded(0, 0, false), SP64(0, 0)); - EXPECT_EQ(getRounded(0, 0, true), SP64(1, 0)); - EXPECT_EQ(getRounded(20, 21, true), SP64(21, 21)); - EXPECT_EQ(getRounded(UINT32_MAX, 0, false), SP64(UINT32_MAX, 0)); - EXPECT_EQ(getRounded(UINT32_MAX, 0, true), - SP64(UINT64_C(1) << 32, 0)); - EXPECT_EQ(getRounded(UINT64_MAX, 0, false), SP64(UINT64_MAX, 0)); - EXPECT_EQ(getRounded(UINT64_MAX, 0, true), - SP64(UINT64_C(1) << 63, 1)); + EXPECT_EQ(getRounded64(0, 0, false), SP64(0, 0)); + EXPECT_EQ(getRounded64(0, 0, true), SP64(1, 0)); + EXPECT_EQ(getRounded64(20, 21, true), SP64(21, 21)); + EXPECT_EQ(getRounded64(UINT32_MAX, 0, false), SP64(UINT32_MAX, 0)); + EXPECT_EQ(getRounded64(UINT32_MAX, 0, true), SP64(UINT64_C(1) << 32, 0)); + EXPECT_EQ(getRounded64(UINT64_MAX, 0, false), SP64(UINT64_MAX, 0)); + EXPECT_EQ(getRounded64(UINT64_MAX, 0, true), SP64(UINT64_C(1) << 63, 1)); } TEST(FloatsTest, getAdjusted) {