Commit Graph

175 Commits

Author SHA1 Message Date
Stuart Hastings
d52ec65b6d Fix a hashing bug in APInt. A certain pathological testcase (too
large for the testsuite) took over six minutes to compile on my Mac.
The patched LLVM-GCC compiles that testcase in three seconds (GCC
takes less than one second).  This hash function is more complex
(about 35 instructions on x86) than what Chris wanted, but I expect it
will be well-behaved with arbitrary inputs.

Thank you to everyone who responded to my previous request for advice.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66962 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-13 21:51:13 +00:00
Torok Edwin
2d0f1c57c3 APInt's countLeadingOnes() was broken for negative i128 values,
causing assertion failures in getSExtValue().
Fix it by making highWordBits actually contain what its name says,
and add some more unit-tests for APInt.
This fixes PR3419.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63107 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-27 18:06:03 +00:00
Chris Lattner
455e9abf36 Remove uses of uint32_t in favor of 'unsigned' for better
compatibility with cygwin.  Patch by Jay Foad!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62695 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-21 18:09:24 +00:00
Nick Lewycky
4bd4787785 Fix typo, sentence fragment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62512 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-19 17:42:33 +00:00
Chris Lattner
119c30b955 rearrange some code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57384 91177308-0d34-0410-b5e6-96231b3b80d8
2008-10-11 22:07:19 +00:00
Chris Lattner
944fac71e0 Switch the asmprinter (.ll) and all the stuff it requires over to
use raw_ostream instead of std::ostream.  Among other goodness,
this speeds up llvm-dis of kc++ with a release build from 0.85s
to 0.49s (88% faster).

Other interesting changes:
 1) This makes Value::print be non-virtual.
 2) AP[S]Int and ConstantRange can no longer print to ostream directly, 
    use raw_ostream instead.
 3) This fixes a bug in raw_os_ostream where it didn't flush itself 
    when destroyed.
 4) This adds a new SDNode::print method, instead of only allowing "dump".


A lot of APIs have both std::ostream and raw_ostream versions, it would
be useful to go through and systematically anihilate the std::ostream 
versions.

This passes dejagnu, but there may be minor fallout, plz let me know if
so and I'll fix it.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55263 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-23 22:23:09 +00:00
Chris Lattner
98f8ccfad0 Move the fast-path (<=i64) cases of various APInt methods inline
and the slow-path cases out of line.  This speeds up instcombine
a bit in real world cases.  Patch contributed by m-s.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55063 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-20 17:02:31 +00:00
Dan Gohman
eace52f12d It's not necessary to check if a value is null before delete[].
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55053 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-20 14:55:37 +00:00
Chris Lattner
fad86b003a Rework the routines that convert AP[S]Int into a string. Now, instead of
returning an std::string by value, it fills in a SmallString/SmallVector
passed in.  This significantly reduces string thrashing in some cases.

More specifically, this:
 - Adds an operator<< and a print method for APInt that allows you to 
   directly send them to an ostream.
 - Reimplements APInt::toString to be much simpler and more efficient
   algorithmically in addition to not thrashing strings quite as much.

This speeds up llvm-dis on kc++ by 7%, and may also slightly speed up the
asmprinter.  This also fixes a bug I introduced into the asmwriter in a
previous patch w.r.t. alias printing.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54873 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-17 07:19:36 +00:00
Chris Lattner
9f17eb0b79 remove a dead APInt ctor.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54869 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-17 04:58:58 +00:00
Wojciech Matyjewicz
de0f2382e4 Fix PR2088. Use modulo linear equation solver to compute loop iteration
count.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53810 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-20 15:55:14 +00:00
Wojciech Matyjewicz
300c6c5167 First step to fix PR2088. Implement routine to compute the
multiplicative inverse of a given number. Modify udivrem to allow input and 
output pairs of arguments to overlap. Patch is based on the work by Chandler
Carruth.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52638 91177308-0d34-0410-b5e6-96231b3b80d8
2008-06-23 19:39:50 +00:00
Dan Gohman
95df6b3603 Avoid creating a redundant zero APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52602 91177308-0d34-0410-b5e6-96231b3b80d8
2008-06-21 22:03:12 +00:00
Zhou Sheng
bfde7d6b9e As comments said, for negative value, the arithmetic
over-shift-right should return -1. So here it should be signed-extended,
when bitwidth larger than 64.

test case: llvm/test/ExecutionEngine/2008-06-05-APInt-OverAShr.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51999 91177308-0d34-0410-b5e6-96231b3b80d8
2008-06-05 13:27:38 +00:00
Evan Cheng
48e8c80e17 Suppress -Wshorten-64-to-32 warnings for 64-bit hosts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50590 91177308-0d34-0410-b5e6-96231b3b80d8
2008-05-02 21:15:08 +00:00
Dan Gohman
3bd659ba20 Make several symbols static.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49496 91177308-0d34-0410-b5e6-96231b3b80d8
2008-04-10 21:11:47 +00:00
Dan Gohman
cfbb2f074d A quick nm audit turned up several fixed tables and objects that were
marked read-write. Use const so that they can be allocated in a
read-only segment.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48800 91177308-0d34-0410-b5e6-96231b3b80d8
2008-03-25 21:45:14 +00:00
Bill Wendling
f7a91e68a8 Add assert for non-hexadecimal radixes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48421 91177308-0d34-0410-b5e6-96231b3b80d8
2008-03-16 20:05:52 +00:00
Evan Cheng
a8de38f351 Fix a typo. It's causing consumer-typeset to miscompile. Perhaps more.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48035 91177308-0d34-0410-b5e6-96231b3b80d8
2008-03-07 22:39:49 +00:00
Dan Gohman
cf609575ef Add support to APInt for shift and rotate operations with APInt
instead of uint32_t for the shift/rotate count operand type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47741 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-29 01:40:47 +00:00
Ted Kremenek
a795aca96a Fixed bug in APInt::Profile() where the BitWidth field was not included in the
profile of the APSInt object. This caused unexpected Profile collisions where
none should have occurred.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47338 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-19 20:50:41 +00:00
Dan Gohman
5a0e7b41c1 Fix a warning about comparison between signed and unsigned,
being consistent with the rest of the APInt implementation.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47138 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-14 22:38:45 +00:00
Dan Gohman
42dd77f207 Add countTrailingOnes member functions to APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47086 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-13 21:11:05 +00:00
Ted Kremenek
e420debd26 Added FoldingSet style 'profiling' support for APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46188 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-19 04:23:33 +00:00
Chris Lattner
4ee451de36 Remove attribution from file headers, per discussion on llvmdev.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45418 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-29 20:36:04 +00:00
Anton Korobeynikov
97d37260df Cygwin defines uint32_t as unsigned long. Unbreak call to std::min in this case
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45342 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-24 11:16:47 +00:00
Reid Spencer
9af1887537 Don't have APInt.cpp depend upon DerivedTypes.h. This helps with splitting the
Support libraries separately into their own module.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44852 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-11 06:53:58 +00:00
Chris Lattner
9e513acd31 Fix PR1816, by correcting the broken definition of APInt::countTrailingZeros.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44296 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-23 22:42:31 +00:00
Chris Lattner
5e557123ad Fix APInt::countTrailingZeros to return BitWidth if the input is zero instead of returning some random large number.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44294 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-23 22:36:25 +00:00
Neil Booth
1e8390d8d6 Don't attempt to mask no bits
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42909 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-12 15:31:31 +00:00
Neil Booth
68e53ad6cb Add a new function tcExtract for extracting a bignum from an
arbitrary range of bits embedded in the middle of another bignum.
This kind of operation is desirable in many cases of software
floating point, e.g. converting bignum integers to floating point
numbers of fixed precision (you want to extract the precision most
significant bits).

Elsewhere, add an assertion, and exit the shift functions early if
the shift count is zero.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42745 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-08 13:47:12 +00:00
Neil Booth
055c0b3a8f Fix and clarify some comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42670 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-06 00:43:45 +00:00
Neil Booth
978661d053 Generalize tcFullMultiply so that the operands can be of differing
part widths.  Also, return the number of parts actually required to
hold the result's value.
Remove an over-cautious condition from rounding of float->hex conversion.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42669 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-06 00:24:48 +00:00
Dale Johannesen
910993e8dc Change APFloat::convertFromInteger to take the incoming
bit width instead of number of words allocated, which
makes it actually work for int->APF conversions.
Adjust callers.  Add const to one of the APInt constructors
to prevent surprising match when called with const
argument.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42210 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-21 22:09:37 +00:00
Devang Patel
8feb1f4467 Do not hide APInt::dump() inside #ifndef NDEBUG.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42068 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-17 22:24:00 +00:00
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
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
20a4c23bcc Fix an assertion introduced by my last change to the toString method. We
can't use getZExtValue() to extract the low order bits for each digit.
Instead, we need to access the low order word directly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37242 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-19 00:29:55 +00:00
Reid Spencer
fb0709a180 Get rid of leading zeros in the output of toString.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37175 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-17 19:23:02 +00:00
Reid Spencer
02ae8b78ff For lshr by 0 bits, just return *this as a short cut. This also prevents
undefined behavior when the width > 64 bits.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37153 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-17 06:26:29 +00:00
Reid Spencer
6551dcdd8a Fix a bug in the "fromString" method where radix 2,8 and 16 values were
not being generated correctly because the shl operator does not mutate its
object but returns a new value. Also, make the distinction between radix
16 and the others more clear.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37111 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-16 19:18:22 +00:00
Reid Spencer
69944e85aa Make the results for the rotate functions correct when rotateAmt == 0.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37026 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-14 00:15:28 +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
Reid Spencer
92c7283500 Fix shl to produce the correct result when the bitwidth is > 64 and the
shift amount is 0. Previously this code would do a lshr by the bit width
which can lead to incorrect results.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37010 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-12 18:01:57 +00:00
Chris Lattner
a5ae15ecb7 silence some annoying gcc 4.3 warnings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36680 91177308-0d34-0410-b5e6-96231b3b80d8
2007-05-03 18:15:36 +00:00
Reid Spencer
0468ab3025 We want the number of bits needed, not the power of 2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35977 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-14 00:00:10 +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
Reid Spencer
2cd43e402a Fix an approximate calculation in an assertion not to give false negatives.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35901 91177308-0d34-0410-b5e6-96231b3b80d8
2007-04-11 13:00:04 +00:00
Zhou Sheng
6dbe233959 Fix a bug in getAllOnesValue() which broke
some test cases for bitwidth > 64.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35232 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-21 04:34:37 +00:00
Jeff Cohen
09dfd8e19d Fix (and simplify) 48-bit byte swap.
Get pos/neg infinity the correct way.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35223 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-20 20:42:36 +00:00
Reid Spencer
adf2a206ec Fix coding standards violation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35189 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-19 21:19:02 +00:00
Reid Spencer
3a34137548 Implement extension of sign bits for negative values in the uint64_t
constructor. This helps to fix test/Assembler/2007-03-19-NegValue.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35180 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-19 20:37:47 +00:00
Reid Spencer
4fd8606791 Revert the last patch as it violates the conditions of sext/zext.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35068 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-12 18:37:25 +00:00
Zhou Sheng
7d820f57e2 For APInt::z/sext(width), if width == BitWidth, just return *this.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35065 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-12 17:47:45 +00:00
Jeff Cohen
ca5183d445 Unbreak VC++ build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34917 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-05 00:00:42 +00:00
Reid Spencer
46f9c94bdd Fix ashr for bitwidths > 64. This is now validated up to 1024 bits.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34852 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-02 22:39:11 +00:00
Reid Spencer
f09aef7698 Use a better algorithm for rounding sqrt results. Change the FIXME about
this to a NOTE: because pari/gp results start to get rounded incorrectly
after 192 bits of precision. APInt and pari/gp never differ by more than
1, but APInt is more accurate because it does not lose precision after 192
bits as does pari/gp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34834 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-02 04:21:55 +00:00
Reid Spencer
9bf94a4a9f Add a FIXME
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34828 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-02 02:01:34 +00:00
Reid Spencer
36184ed4cd Fix a problem where shifting by 64-bits leads to incorrect results on PPC
but not on X86 becuase shift by word size is "undefined".


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34825 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-02 01:19:42 +00:00
Reid Spencer
295e40aa5c Combine two lines that can be.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34818 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 23:30:25 +00:00
Reid Spencer
4e1e87f09c Make the static table of results in sqrt const.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34791 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 17:47:31 +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
b5ca2cd509 Use a real table in sqrt to shorten and quicken the code.
Thanks for the idea Chris.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34779 91177308-0d34-0410-b5e6-96231b3b80d8
2007-03-01 06:23: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
94900774ad Make the trunc/sext/zext methods return APInt& so that these operations
can be chained together with other operations.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34743 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-28 17:34:32 +00:00
Reid Spencer
ff60576646 Fix a bug in RoundDoubleToAPInt where it would force the size to 64 bits
instead of honoring the client's requested bit width.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34712 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-28 01:30:08 +00:00
Reid Spencer
f5c0fd9e16 Join two lines that can be joined.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34705 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 23:49:07 +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
96d91372fd Conform to single person attribution in file comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34678 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 19:31:09 +00:00
Reid Spencer
1fa111e8d4 1. Fix three serious bugs in the comparison code.
2. Change RoundDoubleToAPInt to take a bit width parameter. Use that
   parameter to limit the bit width of the result.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34673 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 18:23:40 +00:00
Reid Spencer
b4d8ae5dfb Get rid of extraneous // in file comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34662 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 07:35:18 +00:00
Reid Spencer
30f44f3287 Simplify and document RoundDoubleToAPInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34648 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27 01:28:10 +00:00
Reid Spencer
9ac44113a8 1. Make sure all delete operators of arrays use the array form of delete.
2. Rewrite operator=(const APInt& RHS) to allow the RHS to be a different
   bit width than the LHS. This makes it possible to use APInt as the key
   of a DenseMap, as needed for the IntConstants map in Constants.cpp
3. Fix operator=(uint64_t) to clear unused bits in case the client assigns
   a value that has more bits than the APInt allows.
4. Assert that bit widths are equal in operator==
5. Revise getHashValue() to put the bit width in the low order six bits.
   This should help to make i1 0, i2 0, ... i64 0 all distinct in the
   IntConstants DenseMap.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34646 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 23:38:21 +00:00
Reid Spencer
794f4725b8 Implement the getHashValue method.
Fix toString use of getValue to use getZExtValue()


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34642 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 21:02:27 +00:00
Reid Spencer
9d1ae8fabe Re-enable this. The header was committed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34634 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 08:10:54 +00:00
Chris Lattner
ab143beb93 another missing header :( :( :(
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34632 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 07:51:00 +00:00
Reid Spencer
47fbe9e00c 1. Remove redundant calls to clearUsedBits().
2. Fix countTrailingZeros to use a faster algorithm.
3. Simplify sext() slightly by using isNegative().
4. Implement ashr using word-at-a-time logic instead of bit-at-a-time
5. Rename locals named isNegative so they don't clash with method name.
6. Fix fromString to compute negated value correctly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34629 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 07:44:38 +00:00
Reid Spencer
ba81c2b871 Rewrite lshr to not do bit by bit copy but to copy and shift whole words.
This makes it much more efficient.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34618 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26 01:19:48 +00:00
Reid Spencer
f30b1885ae Fix sext operation. Shifting by zero would leave an incorrect mask.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34617 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 23:54:00 +00:00
Reid Spencer
9eec241347 1. Fix the flip() method to correctly flip all words of the APInt.
2. Implement the trunc, sext, and zext operations.
3. Improve fromString to accept negative values as input.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34616 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 23:44:53 +00:00
Reid Spencer
5d0d05c9b8 1. Provide more detail in file comment.
2. Move comments for methods to .h file, delete them in .cpp file.
3. All places that were doing manual clear of high order bits now call the
   clearUnusedBits() method in order to not depend on undefined behavior
   of the >> operator when the number of bits shifted equals the word size.
4. Reduced # of loc by using the new result of clearUnusedBits() method.
5. Simplified logic (decreased indentation) in a few places.
6. Added code comments to larger functions that needed them.
7. Added FIXME notes about weak implementations of things (e.g. bit-by-bit
   shift right is sub-optimal).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34603 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 19:32:03 +00:00
Reid Spencer
31d16b039a Allow this to compile now that the header file is checked in.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34581 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 07:30:14 +00:00
Chris Lattner
0f07e55312 this doesn't compile, disable it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34571 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 02:32:44 +00:00
Reid Spencer
24c4a8f548 Clean up lshr and ashr to coding standards.
Handle the single word cases for shiftAmt == BitWidth.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34569 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 01:56:07 +00:00
Reid Spencer
438d71eea4 Whoops, last word with bits in large shift left wasn't correct.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34565 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 01:08:58 +00:00
Reid Spencer
8755380fff Fix the > 64 bits case for left shift.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34564 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25 00:56:44 +00:00
Reid Spencer
1050ec5cc4 Fix the remainder shifting in KnuthDiv.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34562 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-24 20:38:01 +00:00
Reid Spencer
5bce8547f3 1. Fix a bug in fromString for the <= 64bits case
2. Fix shl when shiftAmount == BitWidth.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34560 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-24 20:19:37 +00:00
Reid Spencer
610fad85d2 1. Fix last bug in KnuthDiv. All divide tests pass up to 1024 bits now.
2. Clean up comments, style, coding standards, etc.
3. Simplify a constructor.

Extended testing revealed some additional bugs in shifting. I'll fix these
tomorrow.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34559 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-24 10:01:42 +00:00
Reid Spencer
9d6c919efe 1. Make internal functions take const arguments where they should, just
to be safe.
2. Make internal functions that return a carry/borrow return bool instead
   of uint64_t because the carry/borrow can only be in range [0,1].
3. Assert that the pointers to KnuthDiv are all different so that the
   result and operands can't overlap.
4. Add debug output to KnuthDiv function.
5. Fix a problem with KnuthDiv by separating the b's complement operation
   from the subtraction borrow operation. This fixes a wide range of
   division problems, but alas, not all of them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34554 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-24 03:58:46 +00:00
Reid Spencer
9290463760 1. Fix a carry out problem in add if destination and x point to the same
memory (as done in fromString).
2. Implement Knuth divide more closely to what is recommended in his book.
3. Fix computation of the remainder for Knuth Divide (bad shifting).
4. Remove some cruft from the file


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34518 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-23 01:57:13 +00:00
Reid Spencer
15aab8a723 When converting from 64 to 32-bits, use the actual number of words to
extract the value, not the number of words implied by the active bits.
This fixes numerous, but not all divide bugs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34484 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-22 00:58:45 +00:00
Reid Spencer
ab2b2c827c Fix countLeadingZeros in the case that the bitwidth evenly divides the
word size. This fixes all reads of uninitialized data (buffer over read)
and makes APInt.cpp memory clean, per valgrind. The only remaining
problem is division in a few cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34483 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-22 00:22:00 +00:00
Reid Spencer
e0cdd3349d Reorganize some code to make it clearer, avoid a few uninitialized memory
reads, and reduce the number of temporary APInt instances we construct.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34467 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-21 08:21:52 +00:00
Reid Spencer
60c0a6a74b Fix the carry in addition.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34465 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-21 05:44:56 +00:00
Reid Spencer
385f7547b9 1. Add a dump() method for faster debugging.
2. Change 0 initialization of union to larger component so all is zeroed.
3. Fix the borrow logic in subtraction so it works for > 128 bits.
4. Rewrite fromString to use a simpler but correct algorithm and also to
   not set the bit width contrary to the user's request.
5. Optimize toString a bit by making it only do one Knuth divide per
   iteration instead of two.

With these changes, all arithmetic passes (verified by pari/GP) up to
1024 bits except for certain division cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34463 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-21 03:55:44 +00:00
Reid Spencer
e549c4940c Fix countLeadingZeros to actually return the correct number.
Fix toString to correctly return "0" for zero valued APInts over 128 bits.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34459 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-21 00:29:48 +00:00