PR5207: change APInt::doubleToBits() and APInt::floatToBits() to be

static methods that return a new APInt.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120261 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jay Foad 2010-11-28 21:04:48 +00:00
parent d8f717911d
commit e4d19c9eb2
4 changed files with 12 additions and 26 deletions

View File

@ -1293,37 +1293,27 @@ public:
} }
/// The conversion does not do a translation from double to integer, it just /// The conversion does not do a translation from double to integer, it just
/// re-interprets the bits of the double. Note that it is valid to do this on /// re-interprets the bits of the double.
/// any bit width but bits from V may get truncated.
/// @brief Converts a double to APInt bits. /// @brief Converts a double to APInt bits.
APInt& doubleToBits(double V) { static APInt doubleToBits(double V) {
union { union {
uint64_t I; uint64_t I;
double D; double D;
} T; } T;
T.D = V; T.D = V;
if (isSingleWord()) return APInt(sizeof T * CHAR_BIT, T.I);
VAL = T.I;
else
pVal[0] = T.I;
return clearUnusedBits();
} }
/// The conversion does not do a translation from float to integer, it just /// The conversion does not do a translation from float to integer, it just
/// re-interprets the bits of the float. Note that it is valid to do this on /// re-interprets the bits of the float.
/// any bit width but bits from V may get truncated.
/// @brief Converts a float to APInt bits. /// @brief Converts a float to APInt bits.
APInt& floatToBits(float V) { static APInt floatToBits(float V) {
union { union {
unsigned I; unsigned I;
float F; float F;
} T; } T;
T.F = V; T.F = V;
if (isSingleWord()) return APInt(sizeof T * CHAR_BIT, T.I);
VAL = T.I;
else
pVal[0] = T.I;
return clearUnusedBits();
} }
/// @} /// @}

View File

@ -637,11 +637,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
break; break;
case Type::FloatTyID: case Type::FloatTyID:
assert(DestTy->isIntegerTy(32) && "Invalid bitcast"); assert(DestTy->isIntegerTy(32) && "Invalid bitcast");
GV.IntVal.floatToBits(GV.FloatVal); GV.IntVal = APInt::floatToBits(GV.FloatVal);
break; break;
case Type::DoubleTyID: case Type::DoubleTyID:
assert(DestTy->isIntegerTy(64) && "Invalid bitcast"); assert(DestTy->isIntegerTy(64) && "Invalid bitcast");
GV.IntVal.doubleToBits(GV.DoubleVal); GV.IntVal = APInt::doubleToBits(GV.DoubleVal);
break; break;
case Type::PointerTyID: case Type::PointerTyID:
assert(DestTy->isPointerTy() && "Invalid bitcast"); assert(DestTy->isPointerTy() && "Invalid bitcast");

View File

@ -1060,11 +1060,9 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy,
Dest.PointerVal = Src.PointerVal; Dest.PointerVal = Src.PointerVal;
} else if (DstTy->isIntegerTy()) { } else if (DstTy->isIntegerTy()) {
if (SrcTy->isFloatTy()) { if (SrcTy->isFloatTy()) {
Dest.IntVal.zext(sizeof(Src.FloatVal) * CHAR_BIT); Dest.IntVal = APInt::floatToBits(Src.FloatVal);
Dest.IntVal.floatToBits(Src.FloatVal);
} else if (SrcTy->isDoubleTy()) { } else if (SrcTy->isDoubleTy()) {
Dest.IntVal.zext(sizeof(Src.DoubleVal) * CHAR_BIT); Dest.IntVal = APInt::doubleToBits(Src.DoubleVal);
Dest.IntVal.doubleToBits(Src.DoubleVal);
} else if (SrcTy->isIntegerTy()) { } else if (SrcTy->isIntegerTy()) {
Dest.IntVal = Src.IntVal; Dest.IntVal = Src.IntVal;
} else } else

View File

@ -3258,14 +3258,12 @@ APFloat::APFloat(const APInt& api, bool isIEEE)
APFloat::APFloat(float f) APFloat::APFloat(float f)
{ {
APInt api = APInt(32, 0); initFromAPInt(APInt::floatToBits(f));
initFromAPInt(api.floatToBits(f));
} }
APFloat::APFloat(double d) APFloat::APFloat(double d)
{ {
APInt api = APInt(64, 0); initFromAPInt(APInt::doubleToBits(d));
initFromAPInt(api.doubleToBits(d));
} }
namespace { namespace {