summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APFloat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r--llvm/lib/Support/APFloat.cpp56
1 files changed, 37 insertions, 19 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3a33d742683..fa56edad02b 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -3238,23 +3238,6 @@ void IEEEFloat::initFromAPInt(const fltSemantics *Sem, const APInt &api) {
llvm_unreachable(nullptr);
}
-IEEEFloat IEEEFloat::getAllOnesValue(unsigned BitWidth) {
- switch (BitWidth) {
- case 16:
- return IEEEFloat(IEEEhalf, APInt::getAllOnesValue(BitWidth));
- case 32:
- return IEEEFloat(IEEEsingle, APInt::getAllOnesValue(BitWidth));
- case 64:
- return IEEEFloat(IEEEdouble, APInt::getAllOnesValue(BitWidth));
- case 80:
- return IEEEFloat(x87DoubleExtended, APInt::getAllOnesValue(BitWidth));
- case 128:
- return IEEEFloat(IEEEquad, APInt::getAllOnesValue(BitWidth));
- default:
- llvm_unreachable("Unknown floating bit width");
- }
-}
-
/// Make this number the largest magnitude normal number in the given
/// semantics.
void IEEEFloat::makeLargest(bool Negative) {
@@ -3902,6 +3885,18 @@ DoubleAPFloat &DoubleAPFloat::operator=(const DoubleAPFloat &RHS) {
} // End detail namespace
+APFloat::Storage::Storage(IEEEFloat F, const fltSemantics &Semantics) {
+ if (usesLayout<IEEEFloat>(Semantics)) {
+ new (&IEEE) IEEEFloat(std::move(F));
+ } else if (usesLayout<DoubleAPFloat>(Semantics)) {
+ new (&Double)
+ DoubleAPFloat(Semantics, APFloat(std::move(F), F.getSemantics()),
+ APFloat(IEEEdouble));
+ } else {
+ llvm_unreachable("Unexpected semantics");
+ }
+}
+
APFloat::opStatus APFloat::convertFromString(StringRef Str, roundingMode RM) {
return getIEEE().convertFromString(Str, RM);
}
@@ -3925,16 +3920,39 @@ APFloat::opStatus APFloat::convert(const fltSemantics &ToSemantics,
assert(&ToSemantics == &PPCDoubleDouble);
auto Ret = U.IEEE.convert(PPCDoubleDoubleImpl, RM, losesInfo);
*this = APFloat(
- DoubleAPFloat(PPCDoubleDouble, std::move(*this), APFloat(IEEEdouble)));
+ DoubleAPFloat(PPCDoubleDouble, std::move(*this), APFloat(IEEEdouble)),
+ ToSemantics);
return Ret;
} else if (usesLayout<DoubleAPFloat>(getSemantics()) &&
usesLayout<IEEEFloat>(ToSemantics)) {
auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
- *this = APFloat(std::move(getIEEE()));
+ *this = APFloat(std::move(getIEEE()), ToSemantics);
return Ret;
} else {
llvm_unreachable("Unexpected semantics");
}
}
+APFloat APFloat::getAllOnesValue(unsigned BitWidth, bool isIEEE) {
+ if (isIEEE) {
+ switch (BitWidth) {
+ case 16:
+ return APFloat(IEEEhalf, APInt::getAllOnesValue(BitWidth));
+ case 32:
+ return APFloat(IEEEsingle, APInt::getAllOnesValue(BitWidth));
+ case 64:
+ return APFloat(IEEEdouble, APInt::getAllOnesValue(BitWidth));
+ case 80:
+ return APFloat(x87DoubleExtended, APInt::getAllOnesValue(BitWidth));
+ case 128:
+ return APFloat(IEEEquad, APInt::getAllOnesValue(BitWidth));
+ default:
+ llvm_unreachable("Unknown floating bit width");
+ }
+ } else {
+ assert(BitWidth == 128);
+ return APFloat(PPCDoubleDouble, APInt::getAllOnesValue(BitWidth));
+ }
+}
+
} // End llvm namespace
OpenPOWER on IntegriCloud