llvm.org GIT mirror llvm / caf19d7
Whether arithmetic is supported is a property of the semantics. Make it so, and clean up the checks by putting them in an inline function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42965 91177308-0d34-0410-b5e6-96231b3b80d8 Neil Booth 13 years ago
1 changed file(s) with 36 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
3939 /* Number of bits in the significand. This includes the integer
4040 bit. */
4141 unsigned int precision;
42
43 /* True if arithmetic is supported. */
44 unsigned int arithmeticOK;
4245 };
4346
44 const fltSemantics APFloat::IEEEsingle = { 127, -126, 24 };
45 const fltSemantics APFloat::IEEEdouble = { 1023, -1022, 53 };
46 const fltSemantics APFloat::IEEEquad = { 16383, -16382, 113 };
47 const fltSemantics APFloat::x87DoubleExtended = { 16383, -16382, 64 };
48 const fltSemantics APFloat::Bogus = { 0, 0, 0 };
47 const fltSemantics APFloat::IEEEsingle = { 127, -126, 24, true };
48 const fltSemantics APFloat::IEEEdouble = { 1023, -1022, 53, true };
49 const fltSemantics APFloat::IEEEquad = { 16383, -16382, 113, true };
50 const fltSemantics APFloat::x87DoubleExtended = { 16383, -16382, 64, true };
51 const fltSemantics APFloat::Bogus = { 0, 0, 0, true };
4952
5053 // The PowerPC format consists of two doubles. It does not map cleanly
5154 // onto the usual format above. For now only storage of constants of
5255 // this type is supported, no arithmetic.
53 const fltSemantics APFloat::PPCDoubleDouble = { 1023, -1022, 106 };
56 const fltSemantics APFloat::PPCDoubleDouble = { 1023, -1022, 106, false };
5457
5558 /* A tight upper bound on number of parts required to hold the value
5659 pow(5, power) is
104107 return r + 10;
105108
106109 return -1U;
110 }
111
112 inline void
113 assertArithmeticOK(const llvm::fltSemantics &semantics) {
114 assert(semantics.arithmeticOK
115 && "Compile-time arithmetic does not support these semantics");
107116 }
108117
109118 /* Return the value of a decimal exponent of the form
622631
623632 APFloat::APFloat(const fltSemantics &ourSemantics, integerPart value)
624633 {
625 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
626 "Compile-time arithmetic on PPC long double not supported yet");
634 assertArithmeticOK(ourSemantics);
627635 initialize(&ourSemantics);
628636 sign = 0;
629637 zeroSignificand();
635643 APFloat::APFloat(const fltSemantics &ourSemantics,
636644 fltCategory ourCategory, bool negative)
637645 {
638 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
639 "Compile-time arithmetic on PPC long double not supported yet");
646 assertArithmeticOK(ourSemantics);
640647 initialize(&ourSemantics);
641648 category = ourCategory;
642649 sign = negative;
646653
647654 APFloat::APFloat(const fltSemantics &ourSemantics, const char *text)
648655 {
649 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
650 "Compile-time arithmetic on PPC long double not supported yet");
656 assertArithmeticOK(ourSemantics);
651657 initialize(&ourSemantics);
652658 convertFromString(text, rmNearestTiesToEven);
653659 }
14041410 {
14051411 opStatus fs;
14061412
1413 assertArithmeticOK(*semantics);
1414
14071415 fs = addOrSubtractSpecials(rhs, subtract);
14081416
14091417 /* This return code means it was not a simple case. */
14321440 APFloat::opStatus
14331441 APFloat::add(const APFloat &rhs, roundingMode rounding_mode)
14341442 {
1435 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1436 "Compile-time arithmetic on PPC long double not supported yet");
14371443 return addOrSubtract(rhs, rounding_mode, false);
14381444 }
14391445
14411447 APFloat::opStatus
14421448 APFloat::subtract(const APFloat &rhs, roundingMode rounding_mode)
14431449 {
1444 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1445 "Compile-time arithmetic on PPC long double not supported yet");
14461450 return addOrSubtract(rhs, rounding_mode, true);
14471451 }
14481452
14501454 APFloat::opStatus
14511455 APFloat::multiply(const APFloat &rhs, roundingMode rounding_mode)
14521456 {
1453 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1454 "Compile-time arithmetic on PPC long double not supported yet");
14551457 opStatus fs;
14561458
1459 assertArithmeticOK(*semantics);
14571460 sign ^= rhs.sign;
14581461 fs = multiplySpecials(rhs);
14591462
14711474 APFloat::opStatus
14721475 APFloat::divide(const APFloat &rhs, roundingMode rounding_mode)
14731476 {
1474 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1475 "Compile-time arithmetic on PPC long double not supported yet");
14761477 opStatus fs;
14771478
1479 assertArithmeticOK(*semantics);
14781480 sign ^= rhs.sign;
14791481 fs = divideSpecials(rhs);
14801482
14921494 APFloat::opStatus
14931495 APFloat::mod(const APFloat &rhs, roundingMode rounding_mode)
14941496 {
1495 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1496 "Compile-time arithmetic on PPC long double not supported yet");
14971497 opStatus fs;
14981498 APFloat V = *this;
14991499 unsigned int origSign = sign;
1500
1501 assertArithmeticOK(*semantics);
15001502 fs = V.divide(rhs, rmNearestTiesToEven);
15011503 if (fs == opDivByZero)
15021504 return fs;
15301532 const APFloat &addend,
15311533 roundingMode rounding_mode)
15321534 {
1533 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1534 "Compile-time arithmetic on PPC long double not supported yet");
15351535 opStatus fs;
1536
1537 assertArithmeticOK(*semantics);
15361538
15371539 /* Post-multiplication sign, before addition. */
15381540 sign ^= multiplicand.sign;
15751577 APFloat::cmpResult
15761578 APFloat::compare(const APFloat &rhs) const
15771579 {
1578 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1579 "Compile-time arithmetic on PPC long double not supported yet");
15801580 cmpResult result;
15811581
1582 assertArithmeticOK(*semantics);
15821583 assert(semantics == rhs.semantics);
15831584
15841585 switch(convolve(category, rhs.category)) {
16501651 APFloat::convert(const fltSemantics &toSemantics,
16511652 roundingMode rounding_mode)
16521653 {
1653 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1654 "Compile-time arithmetic on PPC long double not supported yet");
16551654 lostFraction lostFraction;
16561655 unsigned int newPartCount, oldPartCount;
16571656 opStatus fs;
16581657
1658 assertArithmeticOK(*semantics);
16591659 lostFraction = lfExactlyZero;
16601660 newPartCount = partCountForBits(toSemantics.precision + 1);
16611661 oldPartCount = partCount();
17291729 bool isSigned,
17301730 roundingMode rounding_mode) const
17311731 {
1732 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1733 "Compile-time arithmetic on PPC long double not supported yet");
17341732 lostFraction lost_fraction;
17351733 unsigned int msb, partsCount;
17361734 int bits;
17371735
1736 assertArithmeticOK(*semantics);
17381737 partsCount = partCountForBits(width);
17391738
17401739 /* Handle the three special cases first. We produce
18291828 integerPart *dst;
18301829 lostFraction lost_fraction;
18311830
1831 assertArithmeticOK(*semantics);
18321832 category = fcNormal;
18331833 omsb = APInt::tcMSB(src, srcCount) + 1;
18341834 dst = significandParts();
18601860 bool isSigned,
18611861 roundingMode rounding_mode)
18621862 {
1863 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1864 "Compile-time arithmetic on PPC long double not supported yet");
18651863 opStatus status;
18661864
1865 assertArithmeticOK(*semantics);
18671866 if (isSigned
18681867 && APInt::tcExtractBit(src, srcCount * integerPartWidth - 1)) {
18691868 integerPart *copy;
18891888 unsigned int width, bool isSigned,
18901889 roundingMode rounding_mode)
18911890 {
1892 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1893 "Compile-time arithmetic on PPC long double not supported yet");
18941891 unsigned int partCount = partCountForBits(width);
18951892 APInt api = APInt(width, partCount, parts);
18961893
19071904 APFloat::convertFromHexadecimalString(const char *p,
19081905 roundingMode rounding_mode)
19091906 {
1910 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
1911 "Compile-time arithmetic on PPC long double not supported yet");
19121907 lostFraction lost_fraction;
19131908 integerPart *significand;
19141909 unsigned int bitPos, partsCount;
19911986 roundingMode rounding_mode)
19921987 {
19931988 unsigned int parts, pow5PartCount;
1994 fltSemantics calcSemantics = { 32767, -32767, 0 };
1989 fltSemantics calcSemantics = { 32767, -32767, 0, true };
19951990 integerPart pow5Parts[maxPowerOfFiveParts];
19961991 bool isNearest;
19971992
21382133 APFloat::opStatus
21392134 APFloat::convertFromString(const char *p, roundingMode rounding_mode)
21402135 {
2141 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
2142 "Compile-time arithmetic on PPC long double not supported yet");
2136 assertArithmeticOK(*semantics);
2137
21432138 /* Handle a leading minus sign. */
21442139 if(*p == '-')
21452140 sign = 1, p++;
21802175 APFloat::convertToHexString(char *dst, unsigned int hexDigits,
21812176 bool upperCase, roundingMode rounding_mode) const
21822177 {
2183 assert(semantics != (const llvm::fltSemantics* const)&PPCDoubleDouble &&
2184 "Compile-time arithmetic on PPC long double not supported yet");
21852178 char *p;
2179
2180 assertArithmeticOK(*semantics);
21862181
21872182 p = dst;
21882183 if (sign)