Commit Graph

124 Commits

Author SHA1 Message Date
Dale Johannesen
9e3d3abd93 Remove the assumption that FP's are either float or
double from some of the many places in the optimizers
it appears, and do something reasonable with x86
long double.
Make APInt::dump() public, remove newline, use it to
dump ConstantSDNode's.
Allow APFloats in FoldingSet.
Expand X86 backend handling of long doubles (conversions
to/from int, mostly).



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41967 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-14 22:26:36 +00:00
Chris Lattner
cd3c4cac6e getMinSignedBits needs to take into consider the sign bit when the value is positive.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41566 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-29 16:21:18 +00:00
Chris Lattner
9132a2b818 rename APInt::toString -> toStringUnsigned for symmetry with toStringSigned()
Add an APSInt::toString() method.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41309 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-23 05:15:32 +00:00
Chris Lattner
b39cdde41d initial checkin of Neil's APFloat work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41203 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-20 22:49:32 +00:00
Chris Lattner
fe8e14a6c9 This adds a bunch of static functions that implement unsigned
two's complement bignum arithmetic.  They could be used to
implement much of APInt, but the idea is they are enough to
implement APFloat as well, which the current APInt interface
is not suited for.

Patch by Neil Booth!



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41124 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-16 15:56:55 +00:00
Reid Spencer
f094f81d36 Document a missing parameter.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40852 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-05 19:36:39 +00:00
Reid Spencer
19dc32a2d4 Add some things needed by the llvm-gcc version supporting bit accurate integer
types:
1. Functions to compute div/rem at the same time.
2. Further assurance that an APInt with 0 bitwidth cannot be constructed.
3. Left and right rotate operations.
4. An exactLogBase2 function which requires an exact power of two or it
   returns -1.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37025 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-13 23:44:59 +00:00
Chris Lattner
49e1580214 remove useless type qualifiers
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36676 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-03 17:09:36 +00:00
Reid Spencer
57ae4f5f01 Implement a getBitsNeeded method to determine how many bits are needed to
represent a string in binary form by an APInt.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35968 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-13 19:19:07 +00:00
Chris Lattner
2b4c234388 fix a comment bug Reid noticed
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35864 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-10 16:33:06 +00:00
Chris Lattner
4bda52d6b5 add a method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35860 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-10 06:43:18 +00:00
Chris Lattner
6401260af2 trivial optimization
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35648 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-04 06:18:21 +00:00
Chris Lattner
ef65293dc2 add missing operator
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35613 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-03 04:25:46 +00:00
Chris Lattner
febabcc02a add a helper function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35585 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-02 05:41:00 +00:00
Zhou Sheng
770e1798e1 Remove unused methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35553 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-01 12:45:33 +00:00
Duncan Sands
48a3e98c27 Correct typo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35504 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-30 06:39:42 +00:00
Reid Spencer
f6bef488ee Compute getLowBitsSet correctly. Using the complement of a 64-bit value
and shifting down without regard for the bitwidth of the APInt can lead
to incorrect initialization values. Instead, check for the word size case
(to avoid undef results from shift) and then do (1 << loBitsSet) - 1


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35344 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-25 21:58:42 +00:00
Reid Spencer
5b9f2d6186 Fix a typo in a comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35316 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-25 01:13:46 +00:00
Reid Spencer
a1689ea60e Actually, for getHighBitsSet and getLowBitsSet, don't make a 0 bit size
illegal. Instead do the 0 valued construction for the user. This is because
the caller may not know (or care to check) that the number of bits set is
zero.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35315 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-25 00:01:47 +00:00
Reid Spencer
758d1bc919 Make it illegal to set 0 bits in getHighBitsSet and getLowBitsSet. For that
they should have used the uint64_t constructor. This avoids causing
undefined results via shifts by the word size when the bit width is an
exact multiple of the word size.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35313 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 23:47:58 +00:00
Reid Spencer
5b7e659e22 In the getBitsSet function, don't optimize for a common case that is
already covered by getLowBitsSet (i.e. when loBits==0). Consequently, remove
the default value for loBits and reorder the arguments to the more natural
loBits, hiBits order. This makes it more clear that this function is for bit
groups in the middle of the bit width and not towards one end or the other.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35312 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 23:42:47 +00:00
Reid Spencer
ca76fc2cd3 Don't invoke undefined behavior in shifts in the functions getHighBitsSet
and getLowBitsSet.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35311 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 23:35:54 +00:00
Reid Spencer
8f969ee62c Implement the getBitsSet function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35310 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 23:27:48 +00:00
Reid Spencer
8da7d65b83 Implement the getHighBitsSet and getLowBitsSet functions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35308 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 23:05:35 +00:00
Reid Spencer
013263f7b0 Get the signs in the right place!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35307 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 22:50:43 +00:00
Reid Spencer
d3af825d29 Undo the last change and make this really implement remainder and not
modulus. The previous change was a result of incorrect documentation in
the LangRef.html.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35305 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 22:37:23 +00:00
Reid Spencer
53c9520b23 Correct the implementation of srem to be remainder, not modulus. The sign of
the result must follow the sign of the divisor.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35302 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 21:56:22 +00:00
Reid Spencer
7ac2f81e49 Clean up this interface:
1. Group similar methods into doxygen groups
2. Reorganize the groups into a consist flow.
3. Significantly improve the quality of the documentation on several methods
4. Rewrite srem and sdiv to eliminate a copy and improve readability.
5. Eliminate unneeded forward references.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35300 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-24 18:09:18 +00:00
Reid Spencer
3a3aacfe10 Fix a comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35246 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-21 22:22:19 +00:00
Zhou Sheng
e51ffcf27f Correct the name: isStrictPositive --> isStrictlyPositive.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35201 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-20 02:18:16 +00:00
Reid Spencer
95da121395 Add an indication of signedness to the uint64_t constructor so sign bits
can be extended. This helps fix test/Assembler/2007-03-19-NegValue.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35179 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-19 20:36:48 +00:00
Zhou Sheng
fdcd5a7740 Add isStrictPositive() to APInt to determine if this APInt Value > 0.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35156 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-19 05:22:18 +00:00
Zhou Sheng
b991dfeae7 Add zextOrCopy() into APInt for convenience.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35079 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-13 06:16:26 +00:00
Zhou Sheng
8db6a445e6 Add getSignBit() and operator<<= into APInt for convenience.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35059 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-11 07:16:10 +00:00
Zhou Sheng
3130835bdf Correct the calculation in APInt::logBase2().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34929 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-05 16:42:58 +00:00
Reid Spencer
52f32d5566 Regularize the interface for conversion functions to/from float/double.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34881 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-03 08:34:02 +00:00
Reid Spencer
28bb83625a Make getNumWords public so that those using getRawData stand a chance of
not reading beyond the end of the buffer returned.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34873 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-03 06:17:23 +00:00
Reid Spencer
da347141ec Add names for some of the operators. This is needed for the macros in
the Interpreter.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34872 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-03 05:37:23 +00:00
Reid Spencer
239e4021ce Add isPositive for symmetry with isNegative.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34862 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-03 00:24:39 +00:00
Reid Spencer
b45a221348 Add an abs() function to get the absolute value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34819 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 23:37:09 +00:00
Reid Spencer
53ee4f9d40 Add doubleToBits and floatToBits methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34807 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 20:39:01 +00:00
Reid Spencer
ab2ed8ec85 Add bitsToDouble and bitsToFloat methods for re-interpretation of bits as FP.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34800 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 20:06:51 +00:00
Reid Spencer
68e2300ad9 Add methods for bit width modification: sextOrTrunc, zextOrTrunc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34789 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 17:15:32 +00:00
Reid Spencer
af8fb19846 Add a square root function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34775 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 05:39:56 +00:00
Reid Spencer
f2253449e2 Make APInt a little more friendly to its users:
* Add support for + and - of a uint64_t.
  * Make trunc/sext/zext return *this so it can be chained with other ops
  * Add smin, smax, umin, umax functions for getting min/max values.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34742 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-28 17:33:36 +00:00
Reid Spencer
84b4eeccc7 getActiveWords should return the number of words, not the index of the
highest active words. Increment its result by one.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34713 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-28 02:20:49 +00:00
Reid Spencer
9d3c519233 Add some syntactic sugar.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34704 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 23:47:33 +00:00
Reid Spencer
681dcd14e9 Implement countLeadingOnes() and getMinSignedBits(). This helps to minimize
the bit width of negative numbers by computing the minimum bit width for a
negative value. E.g. 0x1800000000000000 could be just 0x8000000000000000


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34695 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 21:59:26 +00:00
Reid Spencer
66ed1099ff Improve APInt interface:
1. Add unsigned and signed versions of methods so a "bool" argument doesn't
   need to be passed in.
2. Make the various getMin/getMax functions all be inline since they are
   so simple.
3. Simplify sdiv and srem code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34680 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 20:24:31 +00:00
Reid Spencer
409f092766 Allow the RoundDoubleToAPInt function to specify a width to use.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34672 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 18:22:31 +00:00
Reid Spencer
946bca5bae Fix indentation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34643 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 21:06:05 +00:00
Reid Spencer
31a81f0190 1. Split getValue() into getSExtValue() and getZExtValue() to match
ConstantInt better.
2. Add a getHashValue() method.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34641 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 20:57:12 +00:00
Reid Spencer
f99705e898 Implement inline methods that make transition of ConstantInt to use APInt
easier to comprehend and might be useful elsewhere.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34635 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 17:50:32 +00:00
Reid Spencer
ebf4ebd691 Make isNegative() a const function since it doesn't modify the APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34630 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 07:45:40 +00:00
Reid Spencer
dcffd5c3d9 Add an isNegative method to determine if the APInt's value is negative.
This is much less expensive than a test against zero.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34619 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 01:20:59 +00:00
Reid Spencer
c68c2243dc Fix clearUnusedBits to not depend on "undefined behavior" of >> operator
when the bit size is equal to the word size. This happens to work out okay
on x86, but might not on other platforms. The change just detects when
there are no bits to clear (because BitWidth is a multiple of the word size)
and returns early.

Also, move some comments from .cpp file into header.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34602 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 19:26:01 +00:00
Reid Spencer
20b1f5db1e Add a private constructor for efficiency.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34580 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 07:29:03 +00:00
Reid Spencer
d03d012ad9 Improve documentation.
Make divide function internal (it was briefly external for testing).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34557 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-24 09:50:13 +00:00
Reid Spencer
f31c784f27 Add a dump() method for debugging.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34464 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-21 03:56:12 +00:00
Reid Spencer
e91f7847e6 Add an internal convenience method for division that urem and udiv use.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34448 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-20 08:43:42 +00:00
Reid Spencer
d81b065950 Add some new constants.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34398 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-19 03:18:22 +00:00
Reid Spencer
a932e3f799 1. "unsigned" -> "uint32_t" to gaurantee its bit width on all platforms.
Size matters in this case.
2. Remove the unused whichByte private function, which was also broken.
3. Remove the non-const overload of the getWord function, getWord() is
   never used as an lvalue.
4. Rename some local variables for clarity (e.g. API -> Result).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34390 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-18 18:42:35 +00:00
Reid Spencer
443b570149 Implement signed output for toString.
Fix bugs in countLeadingZeros and countTrailingZeros.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34386 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-18 00:44:22 +00:00
Reid Spencer
cd6f2bfc26 Fix bugs introduced by constructor parameter order change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34357 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-17 00:18:01 +00:00
Reid Spencer
e81d2dad2c Review changes:
1. Function style changes.
2. 80-col violations.
3. Better names for things.
4. Arrange constructors so they all take bit width first.
5. Add named signed and unsigned comparison functions and remove the
   corresponding operators.
6. Remove operator&& and operator|| but provide a getBoolValue function which
   converts to bool as comparison against 0. This allows the normal && and
   || operators to be used as if (X.getBoolValue() && Y.getBoolValue())

Note: this still doesn't function 100% yet. I'm working on the bugs now.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34353 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-16 22:36:51 +00:00
Zhou Sheng
b04973edfa Fix some buges:
1. Make getMinValue() returns the right value.
2. Fix the ByteSwap() crash problem.
3. Make Postfix increment work correctly.
4. Fix some bugs in LogBase2, Hi/LoBits and UDiv.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34304 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-15 06:36:31 +00:00
Reid Spencer
db3faa64ee Make some minor improvements to APInt:
1. Make all the operators use uppercase
2. Rename APIntRoundToDouble method just RoundToDouble, the APInt is
   redundant.
3. Turn the class on for compilation.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34253 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-13 22:41:58 +00:00
Zhou Sheng
d93f00c35d 1. Make APInt::shl work correctly and more efficiently.
2. Add functions to support the numberical conversion between APInt and
   double/float.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34201 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-12 20:02:55 +00:00
Zhou Sheng
ff4304f824 Eliminates friend function declaration inside APInt, instead, adds public
methods as those global function's internal implementation.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34083 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-09 07:48:24 +00:00
Zhou Sheng
0b706b18bd As Chris and Reid suggested, remove "isSigned" field from APInt, instead,
add some signed/unsigned arithmetic operation functions into APInt.h to
handle the signed/unsigned issue. These functions will be defined inside a
namespace "APIntOps" which is inside llvm namespace.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34053 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-08 14:35:19 +00:00
Lauro Ramos Venancio
58a0d64fae Fix build error.
include/llvm/ADT/APInt.h:326: error: ‘assert’ was not declared in this scope


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34002 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-07 16:59:17 +00:00
Zhou Sheng
f29a09d627 As Chris suggested, fixed some problems. (This is the first part.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33986 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-07 05:58:38 +00:00
Zhou Sheng
7406dcdc29 As Reid suggested, fixed some problems.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33954 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-06 05:59:47 +00:00
Zhou Sheng
d0f285e212 Add a class APInt to represent arbitrary precision constant integral values.
It is a functional replacement for common case integer type like "unsigned",
"uint64_t", but also allows non-byte-width integer type and large integer
value types such as 3-bits, 15-bits, or more than 64-bits of precision. For
more details, see pr1043.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33913 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-05 17:29:16 +00:00