1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
Commit Graph

116 Commits

Author SHA1 Message Date
Reid Spencer
6e7854339e Implement a getBitsNeeded method to determine how many bits are needed to
represent a string in binary form by an APInt.

llvm-svn: 35968
2007-04-13 19:19:07 +00:00
Chris Lattner
5af0826c0b fix a comment bug Reid noticed
llvm-svn: 35864
2007-04-10 16:33:06 +00:00
Chris Lattner
9359e7f928 add a method
llvm-svn: 35860
2007-04-10 06:43:18 +00:00
Chris Lattner
5d12d66728 trivial optimization
llvm-svn: 35648
2007-04-04 06:18:21 +00:00
Chris Lattner
b5e5784b28 add missing operator
llvm-svn: 35613
2007-04-03 04:25:46 +00:00
Chris Lattner
3ff8b2cf06 add a helper function.
llvm-svn: 35585
2007-04-02 05:41:00 +00:00
Zhou Sheng
551fa60212 Remove unused methods.
llvm-svn: 35553
2007-04-01 12:45:33 +00:00
Duncan Sands
def480579a Correct typo.
llvm-svn: 35504
2007-03-30 06:39:42 +00:00
Reid Spencer
4984ab6c01 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

llvm-svn: 35344
2007-03-25 21:58:42 +00:00
Reid Spencer
b5b291924a Fix a typo in a comment.
llvm-svn: 35316
2007-03-25 01:13:46 +00:00
Reid Spencer
16d08887ef 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.

llvm-svn: 35315
2007-03-25 00:01:47 +00:00
Reid Spencer
d24dc1f9a6 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.

llvm-svn: 35313
2007-03-24 23:47:58 +00:00
Reid Spencer
fb188ea881 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.

llvm-svn: 35312
2007-03-24 23:42:47 +00:00
Reid Spencer
091d6cf3b7 Don't invoke undefined behavior in shifts in the functions getHighBitsSet
and getLowBitsSet.

llvm-svn: 35311
2007-03-24 23:35:54 +00:00
Reid Spencer
0e466b183f Implement the getBitsSet function.
llvm-svn: 35310
2007-03-24 23:27:48 +00:00
Reid Spencer
1aa3f64ef4 Implement the getHighBitsSet and getLowBitsSet functions.
llvm-svn: 35308
2007-03-24 23:05:35 +00:00
Reid Spencer
30351837ca Get the signs in the right place!
llvm-svn: 35307
2007-03-24 22:50:43 +00:00
Reid Spencer
0ceb493ee2 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.

llvm-svn: 35305
2007-03-24 22:37:23 +00:00
Reid Spencer
c1dfceab8b Correct the implementation of srem to be remainder, not modulus. The sign of
the result must follow the sign of the divisor.

llvm-svn: 35302
2007-03-24 21:56:22 +00:00
Reid Spencer
52ea41bb97 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.

llvm-svn: 35300
2007-03-24 18:09:18 +00:00
Reid Spencer
76c1fef30a Fix a comment.
llvm-svn: 35246
2007-03-21 22:22:19 +00:00
Zhou Sheng
a9c0018850 Correct the name: isStrictPositive --> isStrictlyPositive.
llvm-svn: 35201
2007-03-20 02:18:16 +00:00
Reid Spencer
c3422e56d6 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

llvm-svn: 35179
2007-03-19 20:36:48 +00:00
Zhou Sheng
6ecf1045a6 Add isStrictPositive() to APInt to determine if this APInt Value > 0.
llvm-svn: 35156
2007-03-19 05:22:18 +00:00
Zhou Sheng
dfcf9376bc Add zextOrCopy() into APInt for convenience.
llvm-svn: 35079
2007-03-13 06:16:26 +00:00
Zhou Sheng
9643d0a422 Add getSignBit() and operator<<= into APInt for convenience.
llvm-svn: 35059
2007-03-11 07:16:10 +00:00
Zhou Sheng
b6d1ac8682 Correct the calculation in APInt::logBase2().
llvm-svn: 34929
2007-03-05 16:42:58 +00:00
Reid Spencer
e2bf55dfe8 Regularize the interface for conversion functions to/from float/double.
llvm-svn: 34881
2007-03-03 08:34:02 +00:00
Reid Spencer
503dda5840 Make getNumWords public so that those using getRawData stand a chance of
not reading beyond the end of the buffer returned.

llvm-svn: 34873
2007-03-03 06:17:23 +00:00
Reid Spencer
47b01d6acb Add names for some of the operators. This is needed for the macros in
the Interpreter.

llvm-svn: 34872
2007-03-03 05:37:23 +00:00
Reid Spencer
e5244b132b Add isPositive for symmetry with isNegative.
llvm-svn: 34862
2007-03-03 00:24:39 +00:00
Reid Spencer
d86182b19b Add an abs() function to get the absolute value.
llvm-svn: 34819
2007-03-01 23:37:09 +00:00
Reid Spencer
003170430b Add doubleToBits and floatToBits methods.
llvm-svn: 34807
2007-03-01 20:39:01 +00:00
Reid Spencer
90b6227b81 Add bitsToDouble and bitsToFloat methods for re-interpretation of bits as FP.
llvm-svn: 34800
2007-03-01 20:06:51 +00:00
Reid Spencer
6a95676875 Add methods for bit width modification: sextOrTrunc, zextOrTrunc.
llvm-svn: 34789
2007-03-01 17:15:32 +00:00
Reid Spencer
b6dd32889e Add a square root function.
llvm-svn: 34775
2007-03-01 05:39:56 +00:00
Reid Spencer
0f2d45e42c 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.

llvm-svn: 34742
2007-02-28 17:33:36 +00:00
Reid Spencer
949b3612a8 getActiveWords should return the number of words, not the index of the
highest active words. Increment its result by one.

llvm-svn: 34713
2007-02-28 02:20:49 +00:00
Reid Spencer
355cec42d1 Add some syntactic sugar.
llvm-svn: 34704
2007-02-27 23:47:33 +00:00
Reid Spencer
edbe747bab 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

llvm-svn: 34695
2007-02-27 21:59:26 +00:00
Reid Spencer
9e66d0921a 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.

llvm-svn: 34680
2007-02-27 20:24:31 +00:00
Reid Spencer
612dfe195b Allow the RoundDoubleToAPInt function to specify a width to use.
llvm-svn: 34672
2007-02-27 18:22:31 +00:00
Reid Spencer
9bc19eab08 Fix indentation.
llvm-svn: 34643
2007-02-26 21:06:05 +00:00
Reid Spencer
18629544d3 1. Split getValue() into getSExtValue() and getZExtValue() to match
ConstantInt better.
2. Add a getHashValue() method.

llvm-svn: 34641
2007-02-26 20:57:12 +00:00
Reid Spencer
11f19f730c Implement inline methods that make transition of ConstantInt to use APInt
easier to comprehend and might be useful elsewhere.

llvm-svn: 34635
2007-02-26 17:50:32 +00:00
Reid Spencer
1252a271a1 Make isNegative() a const function since it doesn't modify the APInt.
llvm-svn: 34630
2007-02-26 07:45:40 +00:00
Reid Spencer
e8e8ea4fba Add an isNegative method to determine if the APInt's value is negative.
This is much less expensive than a test against zero.

llvm-svn: 34619
2007-02-26 01:20:59 +00:00
Reid Spencer
a4ab1c36d2 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.

llvm-svn: 34602
2007-02-25 19:26:01 +00:00
Reid Spencer
e7d8a0e3b7 Add a private constructor for efficiency.
llvm-svn: 34580
2007-02-25 07:29:03 +00:00
Reid Spencer
a2a4a55915 Improve documentation.
Make divide function internal (it was briefly external for testing).

llvm-svn: 34557
2007-02-24 09:50:13 +00:00
Reid Spencer
807eadb51a Add a dump() method for debugging.
llvm-svn: 34464
2007-02-21 03:56:12 +00:00
Reid Spencer
2e50b9ed5b Add an internal convenience method for division that urem and udiv use.
llvm-svn: 34448
2007-02-20 08:43:42 +00:00
Reid Spencer
6eb099875c Add some new constants.
llvm-svn: 34398
2007-02-19 03:18:22 +00:00
Reid Spencer
79d2fad9f5 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).

llvm-svn: 34390
2007-02-18 18:42:35 +00:00
Reid Spencer
62b55a934b Implement signed output for toString.
Fix bugs in countLeadingZeros and countTrailingZeros.

llvm-svn: 34386
2007-02-18 00:44:22 +00:00
Reid Spencer
9c5efbcef2 Fix bugs introduced by constructor parameter order change.
llvm-svn: 34357
2007-02-17 00:18:01 +00:00
Reid Spencer
d22266f456 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.
llvm-svn: 34353
2007-02-16 22:36:51 +00:00
Zhou Sheng
9868d8d7db 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.

llvm-svn: 34304
2007-02-15 06:36:31 +00:00
Reid Spencer
80ac48cfdf 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.

llvm-svn: 34253
2007-02-13 22:41:58 +00:00
Zhou Sheng
7b47556f5c 1. Make APInt::shl work correctly and more efficiently.
2. Add functions to support the numberical conversion between APInt and
   double/float.

llvm-svn: 34201
2007-02-12 20:02:55 +00:00
Zhou Sheng
20d0f4e319 Eliminates friend function declaration inside APInt, instead, adds public
methods as those global function's internal implementation.

llvm-svn: 34083
2007-02-09 07:48:24 +00:00
Zhou Sheng
6efcdc8049 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.

llvm-svn: 34053
2007-02-08 14:35:19 +00:00
Lauro Ramos Venancio
30734ef2e7 Fix build error.
include/llvm/ADT/APInt.h:326: error: ‘assert’ was not declared in this scope

llvm-svn: 34002
2007-02-07 16:59:17 +00:00
Zhou Sheng
7881ec420f As Chris suggested, fixed some problems. (This is the first part.)
llvm-svn: 33986
2007-02-07 05:58:38 +00:00
Zhou Sheng
8eba14bd31 As Reid suggested, fixed some problems.
llvm-svn: 33954
2007-02-06 05:59:47 +00:00
Zhou Sheng
4967eb71b1 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.

llvm-svn: 33913
2007-02-05 17:29:16 +00:00