summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuxin Yang <shuxin.llvm@gmail.com>2013-01-07 18:59:35 +0000
committerShuxin Yang <shuxin.llvm@gmail.com>2013-01-07 18:59:35 +0000
commit4fb504fec1a97be27e1130ab53aa169120339464 (patch)
tree803191d2180b6e15822a218a4c1640eb42530ccd
parenta9cc2491dde81261044a4ac21798fcfeb6c83d8a (diff)
downloadbcm5719-llvm-4fb504fec1a97be27e1130ab53aa169120339464.tar.gz
bcm5719-llvm-4fb504fec1a97be27e1130ab53aa169120339464.zip
Implement APFloat::isDenormal()
llvm-svn: 171764
-rw-r--r--llvm/include/llvm/ADT/APFloat.h1
-rw-r--r--llvm/lib/Support/APFloat.cpp7
-rw-r--r--llvm/unittests/ADT/APFloatTest.cpp52
3 files changed, 60 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 31c6e6adbfc..93d343a5124 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -327,6 +327,7 @@ namespace llvm {
bool isNegative() const { return sign; }
bool isPosZero() const { return isZero() && !isNegative(); }
bool isNegZero() const { return isZero() && isNegative(); }
+ bool isDenormal() const;
APFloat& operator=(const APFloat &);
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 17f38918b32..0e3c619170d 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -697,6 +697,13 @@ APFloat::operator=(const APFloat &rhs)
}
bool
+APFloat::isDenormal() const {
+ return isNormal() && (exponent == semantics->minExponent) &&
+ (APInt::tcExtractBit(significandParts(),
+ semantics->precision - 1) == 0);
+}
+
+bool
APFloat::bitwiseIsEqual(const APFloat &rhs) const {
if (this == &rhs)
return true;
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp
index ff350a78728..7345e124cd7 100644
--- a/llvm/unittests/ADT/APFloatTest.cpp
+++ b/llvm/unittests/ADT/APFloatTest.cpp
@@ -33,6 +33,58 @@ static std::string convertToString(double d, unsigned Prec, unsigned Pad) {
namespace {
+TEST(APFloatTest, Denormal) {
+ APFloat::roundingMode rdmd = APFloat::rmNearestTiesToEven;
+
+ // Test single precision
+ {
+ const char *MinNormalStr = "1.17549435082228750797e-38";
+ EXPECT_FALSE(APFloat(APFloat::IEEEsingle, MinNormalStr).isDenormal());
+ EXPECT_FALSE(APFloat(APFloat::IEEEsingle, 0.0).isDenormal());
+
+ APFloat Val2(APFloat::IEEEsingle, 2.0e0);
+ APFloat T(APFloat::IEEEsingle, MinNormalStr);
+ T.divide(Val2, rdmd);
+ EXPECT_TRUE(T.isDenormal());
+ }
+
+ // Test double precision
+ {
+ const char *MinNormalStr = "2.22507385850720138309e-308";
+ EXPECT_FALSE(APFloat(APFloat::IEEEdouble, MinNormalStr).isDenormal());
+ EXPECT_FALSE(APFloat(APFloat::IEEEdouble, 0.0).isDenormal());
+
+ APFloat Val2(APFloat::IEEEdouble, 2.0e0);
+ APFloat T(APFloat::IEEEdouble, MinNormalStr);
+ T.divide(Val2, rdmd);
+ EXPECT_TRUE(T.isDenormal());
+ }
+
+ // Test Intel double-ext
+ {
+ const char *MinNormalStr = "3.36210314311209350626e-4932";
+ EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended, MinNormalStr).isDenormal());
+ EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended, 0.0).isDenormal());
+
+ APFloat Val2(APFloat::x87DoubleExtended, 2.0e0);
+ APFloat T(APFloat::x87DoubleExtended, MinNormalStr);
+ T.divide(Val2, rdmd);
+ EXPECT_TRUE(T.isDenormal());
+ }
+
+ // Test quadruple precision
+ {
+ const char *MinNormalStr = "3.36210314311209350626267781732175260e-4932";
+ EXPECT_FALSE(APFloat(APFloat::IEEEquad, MinNormalStr).isDenormal());
+ EXPECT_FALSE(APFloat(APFloat::IEEEquad, 0.0).isDenormal());
+
+ APFloat Val2(APFloat::IEEEquad, 2.0e0);
+ APFloat T(APFloat::IEEEquad, MinNormalStr);
+ T.divide(Val2, rdmd);
+ EXPECT_TRUE(T.isDenormal());
+ }
+}
+
TEST(APFloatTest, Zero) {
EXPECT_EQ(0.0f, APFloat(0.0f).convertToFloat());
EXPECT_EQ(-0.0f, APFloat(-0.0f).convertToFloat());
OpenPOWER on IntegriCloud