llvm.org GIT mirror llvm / 7111b02
Rename APFloat::convertToAPInt to bitcastToAPInt to make it clearer what the function does. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57325 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 11 years ago
15 changed file(s) with 51 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
128128 static const fltSemantics IEEEquad;
129129 static const fltSemantics PPCDoubleDouble;
130130 static const fltSemantics x87DoubleExtended;
131 /* And this psuedo, used to construct APFloats that cannot
131 /* And this pseudo, used to construct APFloats that cannot
132132 conflict with anything real. */
133133 static const fltSemantics Bogus;
134134
225225 opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int,
226226 bool, roundingMode);
227227 opStatus convertFromString(const char *, roundingMode);
228 APInt convertToAPInt() const;
228 APInt bitcastToAPInt() const;
229229 double convertToDouble() const;
230230 float convertToFloat() const;
231231
237237 /* IEEE comparison with another floating point number (NaNs
238238 compare unordered, 0==-0). */
239239 cmpResult compare(const APFloat &) const;
240
241 /* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
242 bool bitwiseIsEqual(const APFloat &) const;
240243
241244 /* Write out a hexadecimal representation of the floating point
242245 value to DST, which must be of sufficient size, in the C99 form
244247 excluding the terminating NUL. */
245248 unsigned int convertToHexString(char *dst, unsigned int hexDigits,
246249 bool upperCase, roundingMode) const;
247
248 /* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
249 bool bitwiseIsEqual(const APFloat &) const;
250250
251251 /* Simple queries. */
252252 fltCategory getCategory() const { return category; }
541541 Code = bitc::CST_CODE_FLOAT;
542542 const Type *Ty = CFP->getType();
543543 if (Ty == Type::FloatTy || Ty == Type::DoubleTy) {
544 Record.push_back(CFP->getValueAPF().convertToAPInt().getZExtValue());
544 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
545545 } else if (Ty == Type::X86_FP80Ty) {
546546 // api needed to prevent premature destruction
547 APInt api = CFP->getValueAPF().convertToAPInt();
547 APInt api = CFP->getValueAPF().bitcastToAPInt();
548548 const uint64_t *p = api.getRawData();
549549 Record.push_back(p[0]);
550550 Record.push_back((uint16_t)p[1]);
551551 } else if (Ty == Type::FP128Ty || Ty == Type::PPC_FP128Ty) {
552 APInt api = CFP->getValueAPF().convertToAPInt();
552 APInt api = CFP->getValueAPF().bitcastToAPInt();
553553 const uint64_t *p = api.getRawData();
554554 Record.push_back(p[0]);
555555 Record.push_back(p[1]);
1616 using namespace llvm;
1717
1818 void APFloat::Emit(Serializer& S) const {
19 S.Emit(convertToAPInt());
19 S.Emit(bitcastToAPInt());
2020 }
968968 // precision...
969969 if (CFP->getType() == Type::DoubleTy) {
970970 double Val = CFP->getValueAPF().convertToDouble(); // for comment only
971 uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue();
971 uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
972972 if (TAI->getData64bitsDirective())
973973 O << TAI->getData64bitsDirective() << i << '\t'
974974 << TAI->getCommentString() << " double value: " << Val << '\n';
991991 } else if (CFP->getType() == Type::FloatTy) {
992992 float Val = CFP->getValueAPF().convertToFloat(); // for comment only
993993 O << TAI->getData32bitsDirective()
994 << CFP->getValueAPF().convertToAPInt().getZExtValue()
994 << CFP->getValueAPF().bitcastToAPInt().getZExtValue()
995995 << '\t' << TAI->getCommentString() << " float " << Val << '\n';
996996 return;
997997 } else if (CFP->getType() == Type::X86_FP80Ty) {
998998 // all long double variants are printed as hex
999999 // api needed to prevent premature destruction
1000 APInt api = CFP->getValueAPF().convertToAPInt();
1000 APInt api = CFP->getValueAPF().bitcastToAPInt();
10011001 const uint64_t *p = api.getRawData();
10021002 APFloat DoubleVal = CFP->getValueAPF();
10031003 DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
10411041 } else if (CFP->getType() == Type::PPC_FP128Ty) {
10421042 // all long double variants are printed as hex
10431043 // api needed to prevent premature destruction
1044 APInt api = CFP->getValueAPF().convertToAPInt();
1044 APInt api = CFP->getValueAPF().bitcastToAPInt();
10451045 const uint64_t *p = api.getRawData();
10461046 if (TD->isBigEndian()) {
10471047 O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
877877 break;
878878 }
879879 case Type::FloatTyID: {
880 uint32_t val = cast(PC)->getValueAPF().convertToAPInt().
880 uint32_t val = cast(PC)->getValueAPF().bitcastToAPInt().
881881 getZExtValue();
882882 if (TD->isBigEndian())
883883 val = ByteSwap_32(val);
888888 break;
889889 }
890890 case Type::DoubleTyID: {
891 uint64_t val = cast(PC)->getValueAPF().convertToAPInt().
891 uint64_t val = cast(PC)->getValueAPF().bitcastToAPInt().
892892 getZExtValue();
893893 if (TD->isBigEndian())
894894 val = ByteSwap_64(val);
46294629 if ((!AfterLegalize && !ST->isVolatile()) ||
46304630 TLI.isOperationLegal(ISD::STORE, MVT::i32)) {
46314631 Tmp = DAG.getConstant((uint32_t)CFP->getValueAPF().
4632 convertToAPInt().getZExtValue(), MVT::i32);
4632 bitcastToAPInt().getZExtValue(), MVT::i32);
46334633 return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
46344634 ST->getSrcValueOffset(), ST->isVolatile(),
46354635 ST->getAlignment());
46384638 case MVT::f64:
46394639 if ((!AfterLegalize && !ST->isVolatile()) ||
46404640 TLI.isOperationLegal(ISD::STORE, MVT::i64)) {
4641 Tmp = DAG.getConstant(CFP->getValueAPF().convertToAPInt().
4641 Tmp = DAG.getConstant(CFP->getValueAPF().bitcastToAPInt().
46424642 getZExtValue(), MVT::i64);
46434643 return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
46444644 ST->getSrcValueOffset(), ST->isVolatile(),
46484648 // Many FP stores are not made apparent until after legalize, e.g. for
46494649 // argument passing. Since this is so common, custom legalize the
46504650 // 64-bit integer store into two 32-bit stores.
4651 uint64_t Val = CFP->getValueAPF().convertToAPInt().getZExtValue();
4651 uint64_t Val = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
46524652 SDValue Lo = DAG.getConstant(Val & 0xFFFFFFFF, MVT::i32);
46534653 SDValue Hi = DAG.getConstant(Val >> 32, MVT::i32);
46544654 if (TLI.isBigEndian()) std::swap(Lo, Hi);
444444 if (!UseCP) {
445445 if (VT!=MVT::f64 && VT!=MVT::f32)
446446 assert(0 && "Invalid type expansion");
447 return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt(),
447 return DAG.getConstant(LLVMC->getValueAPF().bitcastToAPInt(),
448448 (VT == MVT::f64) ? MVT::i64 : MVT::i32);
449449 }
450450
23562356 if (CFP->getValueType(0) == MVT::f32 &&
23572357 getTypeAction(MVT::i32) == Legal) {
23582358 Tmp3 = DAG.getConstant(CFP->getValueAPF().
2359 convertToAPInt().zextOrTrunc(32),
2359 bitcastToAPInt().zextOrTrunc(32),
23602360 MVT::i32);
23612361 Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
23622362 SVOffset, isVolatile, Alignment);
23642364 } else if (CFP->getValueType(0) == MVT::f64) {
23652365 // If this target supports 64-bit registers, do a single 64-bit store.
23662366 if (getTypeAction(MVT::i64) == Legal) {
2367 Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt().
2367 Tmp3 = DAG.getConstant(CFP->getValueAPF().bitcastToAPInt().
23682368 zextOrTrunc(64), MVT::i64);
23692369 Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
23702370 SVOffset, isVolatile, Alignment);
23732373 // Otherwise, if the target supports 32-bit registers, use 2 32-bit
23742374 // stores. If the target supports neither 32- nor 64-bits, this
23752375 // xform is certainly not worth it.
2376 const APInt &IntVal =CFP->getValueAPF().convertToAPInt();
2376 const APInt &IntVal =CFP->getValueAPF().bitcastToAPInt();
23772377 SDValue Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32);
23782378 SDValue Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32);
23792379 if (TLI.isBigEndian()) std::swap(Lo, Hi);
59115911 case ISD::ConstantFP: {
59125912 ConstantFPSDNode *CFP = cast(Node);
59135913 if (CFP->getValueType(0) == MVT::ppcf128) {
5914 APInt api = CFP->getValueAPF().convertToAPInt();
5914 APInt api = CFP->getValueAPF().bitcastToAPInt();
59155915 Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])),
59165916 MVT::f64);
59175917 Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])),
9292 }
9393
9494 SDValue DAGTypeLegalizer::SoftenFloatRes_ConstantFP(ConstantFPSDNode *N) {
95 return DAG.getConstant(N->getValueAPF().convertToAPInt(),
95 return DAG.getConstant(N->getValueAPF().bitcastToAPInt(),
9696 TLI.getTypeToTransformTo(N->getValueType(0)));
9797 }
9898
585585 MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
586586 assert(NVT.getSizeInBits() == integerPartWidth &&
587587 "Do not know how to expand this float constant!");
588 APInt C = cast(N)->getValueAPF().convertToAPInt();
588 APInt C = cast(N)->getValueAPF().bitcastToAPInt();
589589 Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
590590 &C.getRawData()[1])), NVT);
591591 Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
466466 (void)apf.convertFromAPInt(GV.IntVal,
467467 false,
468468 APFloat::rmNearestTiesToEven);
469 GV.IntVal = apf.convertToAPInt();
469 GV.IntVal = apf.bitcastToAPInt();
470470 }
471471 return GV;
472472 }
482482 (void)apf.convertFromAPInt(GV.IntVal,
483483 true,
484484 APFloat::rmNearestTiesToEven);
485 GV.IntVal = apf.convertToAPInt();
485 GV.IntVal = apf.bitcastToAPInt();
486486 }
487487 return GV;
488488 }
613613 default: assert(0 && "Invalid long double opcode"); abort();
614614 case Instruction::Add:
615615 apfLHS.add(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
616 GV.IntVal = apfLHS.convertToAPInt();
616 GV.IntVal = apfLHS.bitcastToAPInt();
617617 break;
618618 case Instruction::Sub:
619619 apfLHS.subtract(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
620 GV.IntVal = apfLHS.convertToAPInt();
620 GV.IntVal = apfLHS.bitcastToAPInt();
621621 break;
622622 case Instruction::Mul:
623623 apfLHS.multiply(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
624 GV.IntVal = apfLHS.convertToAPInt();
624 GV.IntVal = apfLHS.bitcastToAPInt();
625625 break;
626626 case Instruction::FDiv:
627627 apfLHS.divide(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
628 GV.IntVal = apfLHS.convertToAPInt();
628 GV.IntVal = apfLHS.bitcastToAPInt();
629629 break;
630630 case Instruction::FRem:
631631 apfLHS.mod(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
632 GV.IntVal = apfLHS.convertToAPInt();
632 GV.IntVal = apfLHS.bitcastToAPInt();
633633 break;
634634 }
635635 }
655655 case Type::X86_FP80TyID:
656656 case Type::FP128TyID:
657657 case Type::PPC_FP128TyID:
658 Result.IntVal = cast (C)->getValueAPF().convertToAPInt();
658 Result.IntVal = cast (C)->getValueAPF().bitcastToAPInt();
659659 break;
660660 case Type::IntegerTyID:
661661 Result.IntVal = cast(C)->getValue();
694694
695695 // Profile - This method 'profiles' an APFloat for use with FoldingSet.
696696 void APFloat::Profile(FoldingSetNodeID& ID) const {
697 ID.Add(convertToAPInt());
697 ID.Add(bitcastToAPInt());
698698 }
699699
700700 unsigned int
26162616 // and treating the result as a normal integer is unlikely to be useful.
26172617
26182618 APInt
2619 APFloat::convertToAPInt() const
2619 APFloat::bitcastToAPInt() const
26202620 {
26212621 if (semantics == (const llvm::fltSemantics*)&IEEEsingle)
26222622 return convertFloatAPFloatToAPInt();
26362636 APFloat::convertToFloat() const
26372637 {
26382638 assert(semantics == (const llvm::fltSemantics*)&IEEEsingle);
2639 APInt api = convertToAPInt();
2639 APInt api = bitcastToAPInt();
26402640 return api.bitsToFloat();
26412641 }
26422642
26442644 APFloat::convertToDouble() const
26452645 {
26462646 assert(semantics == (const llvm::fltSemantics*)&IEEEdouble);
2647 APInt api = convertToAPInt();
2647 APInt api = bitcastToAPInt();
26482648 return api.bitsToDouble();
26492649 }
26502650
20272027
20282028 if (FPC->getType() == Type::DoubleTy) {
20292029 double Val = FPC->getValueAPF().convertToDouble();
2030 uint64_t i = FPC->getValueAPF().convertToAPInt().getZExtValue();
2030 uint64_t i = FPC->getValueAPF().bitcastToAPInt().getZExtValue();
20312031 Out << "static const ConstantDoubleTy FPConstant" << FPCounter++
20322032 << " = 0x" << utohexstr(i)
20332033 << "ULL; /* " << Val << " */\n";
20342034 } else if (FPC->getType() == Type::FloatTy) {
20352035 float Val = FPC->getValueAPF().convertToFloat();
2036 uint32_t i = (uint32_t)FPC->getValueAPF().convertToAPInt().
2036 uint32_t i = (uint32_t)FPC->getValueAPF().bitcastToAPInt().
20372037 getZExtValue();
20382038 Out << "static const ConstantFloatTy FPConstant" << FPCounter++
20392039 << " = 0x" << utohexstr(i)
20402040 << "U; /* " << Val << " */\n";
20412041 } else if (FPC->getType() == Type::X86_FP80Ty) {
20422042 // api needed to prevent premature destruction
2043 APInt api = FPC->getValueAPF().convertToAPInt();
2043 APInt api = FPC->getValueAPF().bitcastToAPInt();
20442044 const uint64_t *p = api.getRawData();
20452045 Out << "static const ConstantFP80Ty FPConstant" << FPCounter++
20462046 << " = { 0x"
20482048 << "ULL, 0x" << utohexstr((uint16_t)(p[0] >> 48)) << ",{0,0,0}"
20492049 << "}; /* Long double constant */\n";
20502050 } else if (FPC->getType() == Type::PPC_FP128Ty) {
2051 APInt api = FPC->getValueAPF().convertToAPInt();
2051 APInt api = FPC->getValueAPF().bitcastToAPInt();
20522052 const uint64_t *p = api.getRawData();
20532053 Out << "static const ConstantFP128Ty FPConstant" << FPCounter++
20542054 << " = { 0x"
253253 Out << StrVal << "f";
254254 } else if (CFP->getType() == Type::DoubleTy)
255255 Out << "BitsToDouble(0x"
256 << utohexstr(CFP->getValueAPF().convertToAPInt().getZExtValue())
256 << utohexstr(CFP->getValueAPF().bitcastToAPInt().getZExtValue())
257257 << "ULL) /* " << StrVal << " */";
258258 else
259259 Out << "BitsToFloat(0x"
260 << utohexstr((uint32_t)CFP->getValueAPF().convertToAPInt().getZExtValue())
260 << utohexstr((uint32_t)CFP->getValueAPF().
261 bitcastToAPInt().getZExtValue())
261262 << "U) /* " << StrVal << " */";
262263 Out << ")";
263264 #if HAVE_PRINTF_A
431431 uint64_t X;
432432 unsigned Size;
433433 if (FP->getType()->getTypeID()==Type::FloatTyID) {
434 X = (uint32_t)FP->getValueAPF().convertToAPInt().getZExtValue();
434 X = (uint32_t)FP->getValueAPF().bitcastToAPInt().getZExtValue();
435435 Size = 4;
436436 } else {
437 X = FP->getValueAPF().convertToAPInt().getZExtValue();
437 X = FP->getValueAPF().bitcastToAPInt().getZExtValue();
438438 Size = 8;
439439 }
440440 Out << "\tldc.r" << Size << "\t( " << utohexstr(X) << ')';
14761476 const ConstantFP* FP = cast(C);
14771477 if (Ty->getTypeID() == Type::FloatTyID)
14781478 Out << "int32 (" <<
1479 (uint32_t)FP->getValueAPF().convertToAPInt().getZExtValue() << ')';
1479 (uint32_t)FP->getValueAPF().bitcastToAPInt().getZExtValue() << ')';
14801480 else
14811481 Out << "int64 (" <<
1482 FP->getValueAPF().convertToAPInt().getZExtValue() << ')';
1482 FP->getValueAPF().bitcastToAPInt().getZExtValue() << ')';
14831483 break;
14841484 }
14851485 case Type::ArrayTyID:
737737 else
738738 assert(0 && "Unsupported floating point type");
739739 // api needed to prevent premature destruction
740 APInt api = CFP->getValueAPF().convertToAPInt();
740 APInt api = CFP->getValueAPF().bitcastToAPInt();
741741 const uint64_t* p = api.getRawData();
742742 uint64_t word = *p;
743743 int shiftcount=60;
159159 if (const ConstantFP *FP = dyn_cast(V)) {
160160 // FP -> Integral.
161161 if (DestTy == Type::Int32Ty) {
162 return ConstantInt::get(FP->getValueAPF().convertToAPInt());
162 return ConstantInt::get(FP->getValueAPF().bitcastToAPInt());
163163 } else {
164164 assert(DestTy == Type::Int64Ty && "only support f32/f64 for now!");
165 return ConstantInt::get(FP->getValueAPF().convertToAPInt());
165 return ConstantInt::get(FP->getValueAPF().bitcastToAPInt());
166166 }
167167 }
168168 return 0;