llvm.org GIT mirror llvm / a471c2e
Next PPC long double bits. First cut at constants. No compile-time support for constant operations yet, just format transformations. Make readers and writers work. Split constants into 2 doubles in Legalize. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42865 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 13 years ago
10 changed file(s) with 197 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
125125 static const fltSemantics IEEEsingle;
126126 static const fltSemantics IEEEdouble;
127127 static const fltSemantics IEEEquad;
128 static const fltSemantics PPCDoubleDouble;
128129 static const fltSemantics x87DoubleExtended;
129130 /* And this psuedo, used to construct APFloats that cannot
130131 conflict with anything real. */
174175 APFloat(const fltSemantics &, fltCategory, bool negative);
175176 explicit APFloat(double d);
176177 explicit APFloat(float f);
177 explicit APFloat(const APInt &);
178 explicit APFloat(const APInt &, bool isIEEE = false);
178179 APFloat(const APFloat &);
179180 ~APFloat();
180181
275276 APInt convertFloatAPFloatToAPInt() const;
276277 APInt convertDoubleAPFloatToAPInt() const;
277278 APInt convertF80LongDoubleAPFloatToAPInt() const;
278 void initFromAPInt(const APInt& api);
279 APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
280 void initFromAPInt(const APInt& api, bool isIEEE = false);
279281 void initFromFloatAPInt(const APInt& api);
280282 void initFromDoubleAPInt(const APInt& api);
281283 void initFromF80LongDoubleAPInt(const APInt& api);
284 void initFromPPCDoubleDoubleAPInt(const APInt& api);
282285
283286 void assign(const APFloat &);
284287 void copySignificand(const APFloat &);
305308
306309 /* The sign bit of this number. */
307310 unsigned int sign: 1;
311
312 /* For PPCDoubleDouble, we have a second exponent and sign (the second
313 significand is appended to the first one, although it would be wrong to
314 regard these as a single number for arithmetic purposes). These fields
315 are not meaningful for any other type. */
316 exponent_t exponent2 : 11;
317 unsigned int sign2: 1;
308318 };
309319 } /* namespace llvm */
310320
21982198 #line 488 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
21992199 { uint64_t Pair[2];
22002200 HexToIntPair(yytext+3, Pair);
2201 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
2201 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair), true);
22022202 return FPVAL;
22032203 }
22042204 YY_BREAK
486486 }
487487 {HexFP128Constant} { uint64_t Pair[2];
488488 HexToIntPair(yytext+3, Pair);
489 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
489 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair), true);
490490 return FPVAL;
491491 }
492492 {HexPPC128Constant} { uint64_t Pair[2];
486486 }
487487 {HexFP128Constant} { uint64_t Pair[2];
488488 HexToIntPair(yytext+3, Pair);
489 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
489 llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair), true);
490490 return FPVAL;
491491 }
492492 {HexPPC128Constant} { uint64_t Pair[2];
631631 else if (CurTy == Type::X86_FP80Ty)
632632 V = ConstantFP::get(CurTy, APFloat(APInt(80, 2, &Record[0])));
633633 else if (CurTy == Type::FP128Ty)
634 V = ConstantFP::get(CurTy, APFloat(APInt(128, 2, &Record[0]), true));
635 else if (CurTy == Type::PPC_FP128Ty)
634636 V = ConstantFP::get(CurTy, APFloat(APInt(128, 2, &Record[0])));
635 else if (CurTy == Type::PPC_FP128Ty)
636 assert(0 && "PowerPC long double constants not handled yet.");
637637 else
638638 V = UndefValue::get(CurTy);
639639 break;
533533 const uint64_t *p = api.getRawData();
534534 Record.push_back(p[0]);
535535 Record.push_back((uint16_t)p[1]);
536 } else if (Ty == Type::FP128Ty) {
536 } else if (Ty == Type::FP128Ty || Ty == Type::PPC_FP128Ty) {
537537 APInt api = CFP->getValueAPF().convertToAPInt();
538538 const uint64_t *p = api.getRawData();
539539 Record.push_back(p[0]);
540540 Record.push_back(p[1]);
541 } else if (Ty == Type::PPC_FP128Ty) {
542 assert(0 && "PowerPC long double constants not handled yet.");
543541 } else {
544542 assert (0 && "Unknown FP type!");
545543 }
51955195 }
51965196 case ISD::ConstantFP: {
51975197 ConstantFPSDNode *CFP = cast(Node);
5198 if (CFP->getValueType(0) == MVT::ppcf128) {
5199 APInt api = CFP->getValueAPF().convertToAPInt();
5200 Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])),
5201 MVT::f64);
5202 Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])),
5203 MVT::f64);
5204 break;
5205 }
51985206 Lo = ExpandConstantFP(CFP, false, DAG, TLI);
51995207 if (getTypeAction(Lo.getValueType()) == Expand)
52005208 ExpandOp(Lo, Lo, Hi);
4949 const fltSemantics APFloat::IEEEquad = { 16383, -16382, 113, true };
5050 const fltSemantics APFloat::x87DoubleExtended = { 16383, -16382, 64, false };
5151 const fltSemantics APFloat::Bogus = { 0, 0, 0, false };
52
53 // The PowerPC format consists of two doubles. It does not map cleanly
54 // onto the usual format above. For now only storage of constants of
55 // this type is supported, no arithmetic.
56 const fltSemantics APFloat::PPCDoubleDouble = { 1023, -1022, 106, true };
5257 }
5358
5459 /* Put a bunch of private, handy routines in an anonymous namespace. */
324329 sign = rhs.sign;
325330 category = rhs.category;
326331 exponent = rhs.exponent;
332 sign2 = rhs.sign2;
333 exponent2 = rhs.exponent2;
327334 if(category == fcNormal || category == fcNaN)
328335 copySignificand(rhs);
329336 }
360367 category != rhs.category ||
361368 sign != rhs.sign)
362369 return false;
370 if (semantics==(const llvm::fltSemantics* const)&PPCDoubleDouble &&
371 sign2 != rhs.sign2)
372 return false;
363373 if (category==fcZero || category==fcInfinity)
364374 return true;
365375 else if (category==fcNormal && exponent!=rhs.exponent)
376 return false;
377 else if (semantics==(const llvm::fltSemantics* const)&PPCDoubleDouble &&
378 exponent2!=rhs.exponent2)
366379 return false;
367380 else {
368381 int i= partCount();
378391
379392 APFloat::APFloat(const fltSemantics &ourSemantics, integerPart value)
380393 {
394 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
395 "Compile-time arithmetic on PPC long double not supported yet");
381396 initialize(&ourSemantics);
382397 sign = 0;
383398 zeroSignificand();
389404 APFloat::APFloat(const fltSemantics &ourSemantics,
390405 fltCategory ourCategory, bool negative)
391406 {
407 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
408 "Compile-time arithmetic on PPC long double not supported yet");
392409 initialize(&ourSemantics);
393410 category = ourCategory;
394411 sign = negative;
398415
399416 APFloat::APFloat(const fltSemantics &ourSemantics, const char *text)
400417 {
418 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
419 "Compile-time arithmetic on PPC long double not supported yet");
401420 initialize(&ourSemantics);
402421 convertFromString(text, rmNearestTiesToEven);
403422 }
11801199 APFloat::opStatus
11811200 APFloat::add(const APFloat &rhs, roundingMode rounding_mode)
11821201 {
1202 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1203 "Compile-time arithmetic on PPC long double not supported yet");
11831204 return addOrSubtract(rhs, rounding_mode, false);
11841205 }
11851206
11871208 APFloat::opStatus
11881209 APFloat::subtract(const APFloat &rhs, roundingMode rounding_mode)
11891210 {
1211 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1212 "Compile-time arithmetic on PPC long double not supported yet");
11901213 return addOrSubtract(rhs, rounding_mode, true);
11911214 }
11921215
11941217 APFloat::opStatus
11951218 APFloat::multiply(const APFloat &rhs, roundingMode rounding_mode)
11961219 {
1220 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1221 "Compile-time arithmetic on PPC long double not supported yet");
11971222 opStatus fs;
11981223
11991224 sign ^= rhs.sign;
12131238 APFloat::opStatus
12141239 APFloat::divide(const APFloat &rhs, roundingMode rounding_mode)
12151240 {
1241 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1242 "Compile-time arithmetic on PPC long double not supported yet");
12161243 opStatus fs;
12171244
12181245 sign ^= rhs.sign;
12321259 APFloat::opStatus
12331260 APFloat::mod(const APFloat &rhs, roundingMode rounding_mode)
12341261 {
1262 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1263 "Compile-time arithmetic on PPC long double not supported yet");
12351264 opStatus fs;
12361265 APFloat V = *this;
12371266 unsigned int origSign = sign;
12681297 const APFloat &addend,
12691298 roundingMode rounding_mode)
12701299 {
1300 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1301 "Compile-time arithmetic on PPC long double not supported yet");
12711302 opStatus fs;
12721303
12731304 /* Post-multiplication sign, before addition. */
13111342 APFloat::cmpResult
13121343 APFloat::compare(const APFloat &rhs) const
13131344 {
1345 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1346 "Compile-time arithmetic on PPC long double not supported yet");
13141347 cmpResult result;
13151348
13161349 assert(semantics == rhs.semantics);
13841417 APFloat::convert(const fltSemantics &toSemantics,
13851418 roundingMode rounding_mode)
13861419 {
1420 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1421 "Compile-time arithmetic on PPC long double not supported yet");
13871422 lostFraction lostFraction;
13881423 unsigned int newPartCount, oldPartCount;
13891424 opStatus fs;
14611496 bool isSigned,
14621497 roundingMode rounding_mode) const
14631498 {
1499 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1500 "Compile-time arithmetic on PPC long double not supported yet");
14641501 lostFraction lost_fraction;
14651502 unsigned int msb, partsCount;
14661503 int bits;
15901627 bool isSigned,
15911628 roundingMode rounding_mode)
15921629 {
1630 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1631 "Compile-time arithmetic on PPC long double not supported yet");
15931632 opStatus status;
15941633
15951634 if (isSigned
16171656 unsigned int width, bool isSigned,
16181657 roundingMode rounding_mode)
16191658 {
1659 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1660 "Compile-time arithmetic on PPC long double not supported yet");
16201661 unsigned int partCount = partCountForBits(width);
16211662 APInt api = APInt(width, partCount, parts);
16221663
16331674 APFloat::convertFromHexadecimalString(const char *p,
16341675 roundingMode rounding_mode)
16351676 {
1677 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1678 "Compile-time arithmetic on PPC long double not supported yet");
16361679 lostFraction lost_fraction;
16371680 integerPart *significand;
16381681 unsigned int bitPos, partsCount;
17121755 APFloat::opStatus
17131756 APFloat::convertFromString(const char *p, roundingMode rounding_mode)
17141757 {
1758 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1759 "Compile-time arithmetic on PPC long double not supported yet");
17151760 /* Handle a leading minus sign. */
17161761 if(*p == '-')
17171762 sign = 1, p++;
17531798 APFloat::convertToHexString(char *dst, unsigned int hexDigits,
17541799 bool upperCase, roundingMode rounding_mode) const
17551800 {
1801 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1802 "Compile-time arithmetic on PPC long double not supported yet");
17561803 char *p;
17571804
17581805 p = dst;
19612008 }
19622009
19632010 APInt
2011 APFloat::convertPPCDoubleDoubleAPFloatToAPInt() const
2012 {
2013 assert(semantics == (const llvm::fltSemantics* const)&PPCDoubleDouble);
2014 assert (partCount()==2);
2015
2016 uint64_t myexponent, mysignificand, myexponent2, mysignificand2;
2017
2018 if (category==fcNormal) {
2019 myexponent = exponent + 1023; //bias
2020 myexponent2 = exponent2 + 1023;
2021 mysignificand = significandParts()[0];
2022 mysignificand2 = significandParts()[1];
2023 if (myexponent==1 && !(mysignificand & 0x10000000000000LL))
2024 myexponent = 0; // denormal
2025 if (myexponent2==1 && !(mysignificand2 & 0x10000000000000LL))
2026 myexponent2 = 0; // denormal
2027 } else if (category==fcZero) {
2028 myexponent = 0;
2029 mysignificand = 0;
2030 myexponent2 = 0;
2031 mysignificand2 = 0;
2032 } else if (category==fcInfinity) {
2033 myexponent = 0x7ff;
2034 myexponent2 = 0;
2035 mysignificand = 0;
2036 mysignificand2 = 0;
2037 } else {
2038 assert(category == fcNaN && "Unknown category");
2039 myexponent = 0x7ff;
2040 mysignificand = significandParts()[0];
2041 myexponent2 = exponent2;
2042 mysignificand2 = significandParts()[1];
2043 }
2044
2045 uint64_t words[2];
2046 words[0] = (((uint64_t)sign & 1) << 63) |
2047 ((myexponent & 0x7ff) << 52) |
2048 (mysignificand & 0xfffffffffffffLL);
2049 words[1] = (((uint64_t)sign2 & 1) << 63) |
2050 ((myexponent2 & 0x7ff) << 52) |
2051 (mysignificand2 & 0xfffffffffffffLL);
2052 return APInt(128, 2, words);
2053 }
2054
2055 APInt
19642056 APFloat::convertDoubleAPFloatToAPInt() const
19652057 {
19662058 assert(semantics == (const llvm::fltSemantics*)&IEEEdouble);
20192111 (mysignificand & 0x7fffff)));
20202112 }
20212113
2114 // This function creates an APInt that is just a bit map of the floating
2115 // point constant as it would appear in memory. It is not a conversion,
2116 // and treating the result as a normal integer is unlikely to be useful.
2117
20222118 APInt
20232119 APFloat::convertToAPInt() const
20242120 {
20272123
20282124 if (semantics == (const llvm::fltSemantics* const)&IEEEdouble)
20292125 return convertDoubleAPFloatToAPInt();
2126
2127 if (semantics == (const llvm::fltSemantics* const)&PPCDoubleDouble)
2128 return convertPPCDoubleDoubleAPFloatToAPInt();
20302129
20312130 assert(semantics == (const llvm::fltSemantics* const)&x87DoubleExtended &&
20322131 "unknown format!");
20902189 }
20912190
20922191 void
2192 APFloat::initFromPPCDoubleDoubleAPInt(const APInt &api)
2193 {
2194 assert(api.getBitWidth()==128);
2195 uint64_t i1 = api.getRawData()[0];
2196 uint64_t i2 = api.getRawData()[1];
2197 uint64_t myexponent = (i1 >> 52) & 0x7ff;
2198 uint64_t mysignificand = i1 & 0xfffffffffffffLL;
2199 uint64_t myexponent2 = (i2 >> 52) & 0x7ff;
2200 uint64_t mysignificand2 = i2 & 0xfffffffffffffLL;
2201
2202 initialize(&APFloat::PPCDoubleDouble);
2203 assert(partCount()==2);
2204
2205 sign = i1>>63;
2206 sign2 = i2>>63;
2207 if (myexponent==0 && mysignificand==0) {
2208 // exponent, significand meaningless
2209 // exponent2 and significand2 are required to be 0; we don't check
2210 category = fcZero;
2211 } else if (myexponent==0x7ff && mysignificand==0) {
2212 // exponent, significand meaningless
2213 // exponent2 and significand2 are required to be 0; we don't check
2214 category = fcInfinity;
2215 } else if (myexponent==0x7ff && mysignificand!=0) {
2216 // exponent meaningless. So is the whole second word, but keep it
2217 // for determinism.
2218 category = fcNaN;
2219 exponent2 = myexponent2;
2220 significandParts()[0] = mysignificand;
2221 significandParts()[1] = mysignificand2;
2222 } else {
2223 category = fcNormal;
2224 // Note there is no category2; the second word is treated as if it is
2225 // fcNormal, although it might be something else considered by itself.
2226 exponent = myexponent - 1023;
2227 exponent2 = myexponent2 - 1023;
2228 significandParts()[0] = mysignificand;
2229 significandParts()[1] = mysignificand2;
2230 if (myexponent==0) // denormal
2231 exponent = -1022;
2232 else
2233 significandParts()[0] |= 0x10000000000000LL; // integer bit
2234 if (myexponent2==0)
2235 exponent2 = -1022;
2236 else
2237 significandParts()[1] |= 0x10000000000000LL; // integer bit
2238 }
2239 }
2240
2241 void
20932242 APFloat::initFromDoubleAPInt(const APInt &api)
20942243 {
20952244 assert(api.getBitWidth()==64);
21562305 }
21572306
21582307 /// Treat api as containing the bits of a floating point number. Currently
2159 /// we infer the floating point type from the size of the APInt. FIXME: This
2160 /// breaks when we get to PPC128 and IEEE128 (but both cannot exist in the
2161 /// same compile...)
2308 /// we infer the floating point type from the size of the APInt. The
2309 /// isIEEE argument distinguishes between PPC128 and IEEE128 (not meaningful
2310 /// when the size is anything else).
21622311 void
2163 APFloat::initFromAPInt(const APInt& api)
2312 APFloat::initFromAPInt(const APInt& api, bool isIEEE)
21642313 {
21652314 if (api.getBitWidth() == 32)
21662315 return initFromFloatAPInt(api);
21682317 return initFromDoubleAPInt(api);
21692318 else if (api.getBitWidth()==80)
21702319 return initFromF80LongDoubleAPInt(api);
2320 else if (api.getBitWidth()==128 && !isIEEE)
2321 return initFromPPCDoubleDoubleAPInt(api);
21712322 else
21722323 assert(0);
21732324 }
21742325
2175 APFloat::APFloat(const APInt& api)
2176 {
2177 initFromAPInt(api);
2326 APFloat::APFloat(const APInt& api, bool isIEEE)
2327 {
2328 initFromAPInt(api, isIEEE);
21782329 }
21792330
21802331 APFloat::APFloat(float f)
518518 Out << 'K';
519519 else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad)
520520 Out << 'L';
521 else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
522 Out << 'M';
521523 else
522524 assert(0 && "Unsupported floating point type");
523525 // api needed to prevent premature destruction
525527 const uint64_t* p = api.getRawData();
526528 uint64_t word = *p;
527529 int shiftcount=60;
528 int width = CFP->getValueAPF().convertToAPInt().getBitWidth();
530 int width = api.getBitWidth();
529531 for (int j=0; j
530532 unsigned int nibble = (word>>shiftcount) & 15;
531533 if (nibble < 10)
534536 Out << (unsigned char)(nibble - 10 + 'A');
535537 if (shiftcount == 0) {
536538 word = *(++p);
537 shiftcount = 60;
539 shiftcount = 64;
538540 if (width-j-4 < 64)
539541 shiftcount = width-j-4;
540542 }
113113 case Type::X86_FP80TyID:
114114 return ConstantFP::get(Ty, APFloat(APInt(80, 2, zero)));
115115 case Type::FP128TyID:
116 return ConstantFP::get(Ty, APFloat(APInt(128, 2, zero), true));
116117 case Type::PPC_FP128TyID:
117118 return ConstantFP::get(Ty, APFloat(APInt(128, 2, zero)));
118119 case Type::PointerTyID:
255256 assert(&V.getSemantics()==&APFloat::x87DoubleExtended);
256257 else if (Ty==Type::FP128Ty)
257258 assert(&V.getSemantics()==&APFloat::IEEEquad);
259 else if (Ty==Type::PPC_FP128Ty)
260 assert(&V.getSemantics()==&APFloat::PPCDoubleDouble);
258261 else
259262 assert(0);
260263 }
319322 assert(&V.getSemantics()==&APFloat::x87DoubleExtended);
320323 else if (Ty==Type::FP128Ty)
321324 assert(&V.getSemantics()==&APFloat::IEEEquad);
325 else if (Ty==Type::PPC_FP128Ty)
326 assert(&V.getSemantics()==&APFloat::PPCDoubleDouble);
322327 else
323328 assert(0);
324329
746751 return &Val2.getSemantics() == &APFloat::IEEEsingle ||
747752 &Val2.getSemantics() == &APFloat::IEEEdouble ||
748753 &Val2.getSemantics() == &APFloat::IEEEquad;
754 case Type::PPC_FP128TyID:
755 return &Val2.getSemantics() == &APFloat::IEEEsingle ||
756 &Val2.getSemantics() == &APFloat::IEEEdouble ||
757 &Val2.getSemantics() == &APFloat::PPCDoubleDouble;
749758 }
750759 }
751760