aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/APInt.cpp
Commit message (Collapse)AuthorAgeFilesLines
* We want the number of bits needed, not the power of 2.Reid Spencer2007-04-141-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35977 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement a getBitsNeeded method to determine how many bits are needed toReid Spencer2007-04-131-0/+37
| | | | | | | 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
* Fix an approximate calculation in an assertion not to give false negatives.Reid Spencer2007-04-111-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35901 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a bug in getAllOnesValue() which brokeZhou Sheng2007-03-211-1/+1
| | | | | | | some test cases for bitwidth > 64. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35232 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix (and simplify) 48-bit byte swap.Jeff Cohen2007-03-201-9/+8
| | | | | | | Get pos/neg infinity the correct way. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35223 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix coding standards violation.Reid Spencer2007-03-191-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35189 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement extension of sign bits for negative values in the uint64_tReid Spencer2007-03-191-1/+5
| | | | | | | 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
* Revert the last patch as it violates the conditions of sext/zext.Reid Spencer2007-03-121-4/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35068 91177308-0d34-0410-b5e6-96231b3b80d8
* For APInt::z/sext(width), if width == BitWidth, just return *this.Zhou Sheng2007-03-121-0/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35065 91177308-0d34-0410-b5e6-96231b3b80d8
* Unbreak VC++ build.Jeff Cohen2007-03-051-1/+9
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34917 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix ashr for bitwidths > 64. This is now validated up to 1024 bits.Reid Spencer2007-03-021-33/+49
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34852 91177308-0d34-0410-b5e6-96231b3b80d8
* Use a better algorithm for rounding sqrt results. Change the FIXME aboutReid Spencer2007-03-021-8/+12
| | | | | | | | | | 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
* Add a FIXMEReid Spencer2007-03-021-0/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34828 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a problem where shifting by 64-bits leads to incorrect results on PPCReid Spencer2007-03-021-1/+4
| | | | | | | 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
* Combine two lines that can be.Reid Spencer2007-03-011-2/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34818 91177308-0d34-0410-b5e6-96231b3b80d8
* Make the static table of results in sqrt const.Reid Spencer2007-03-011-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34791 91177308-0d34-0410-b5e6-96231b3b80d8
* Add methods for bit width modification: sextOrTrunc, zextOrTrunc.Reid Spencer2007-03-011-0/+16
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34789 91177308-0d34-0410-b5e6-96231b3b80d8
* Use a real table in sqrt to shorten and quicken the code.Reid Spencer2007-03-011-14/+10
| | | | | | | Thanks for the idea Chris. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34779 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a square root function.Reid Spencer2007-03-011-6/+87
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34775 91177308-0d34-0410-b5e6-96231b3b80d8
* Make the trunc/sext/zext methods return APInt& so that these operationsReid Spencer2007-02-281-7/+8
| | | | | | | can be chained together with other operations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34743 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a bug in RoundDoubleToAPInt where it would force the size to 64 bitsReid Spencer2007-02-281-1/+1
| | | | | | | 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
* Join two lines that can be joined.Reid Spencer2007-02-271-2/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34705 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement countLeadingOnes() and getMinSignedBits(). This helps to minimizeReid Spencer2007-02-271-1/+34
| | | | | | | | 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
* Improve APInt interface:Reid Spencer2007-02-271-34/+1
| | | | | | | | | | | 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
* Conform to single person attribution in file comment.Reid Spencer2007-02-271-3/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34678 91177308-0d34-0410-b5e6-96231b3b80d8
* 1. Fix three serious bugs in the comparison code.Reid Spencer2007-02-271-18/+22
| | | | | | | | 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
* Get rid of extraneous // in file comment.Reid Spencer2007-02-271-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34662 91177308-0d34-0410-b5e6-96231b3b80d8
* Simplify and document RoundDoubleToAPInt.Reid Spencer2007-02-271-3/+15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34648 91177308-0d34-0410-b5e6-96231b3b80d8
* 1. Make sure all delete operators of arrays use the array form of delete.Reid Spencer2007-02-261-19/+45
| | | | | | | | | | | | | | | 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
* Implement the getHashValue method.Reid Spencer2007-02-261-1/+16
| | | | | | | 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
* Re-enable this. The header was committed.Reid Spencer2007-02-261-4/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34634 91177308-0d34-0410-b5e6-96231b3b80d8
* another missing header :( :( :(Chris Lattner2007-02-261-0/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34632 91177308-0d34-0410-b5e6-96231b3b80d8
* 1. Remove redundant calls to clearUsedBits().Reid Spencer2007-02-261-44/+79
| | | | | | | | | | | 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
* Rewrite lshr to not do bit by bit copy but to copy and shift whole words.Reid Spencer2007-02-261-15/+42
| | | | | | | This makes it much more efficient. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34618 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix sext operation. Shifting by zero would leave an incorrect mask.Reid Spencer2007-02-251-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34617 91177308-0d34-0410-b5e6-96231b3b80d8
* 1. Fix the flip() method to correctly flip all words of the APInt.Reid Spencer2007-02-251-13/+89
| | | | | | | | 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
* 1. Provide more detail in file comment.Reid Spencer2007-02-251-189/+145
| | | | | | | | | | | | | | | 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
* Allow this to compile now that the header file is checked in.Reid Spencer2007-02-251-4/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34581 91177308-0d34-0410-b5e6-96231b3b80d8
* this doesn't compile, disable itChris Lattner2007-02-251-0/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34571 91177308-0d34-0410-b5e6-96231b3b80d8
* Clean up lshr and ashr to coding standards.Reid Spencer2007-02-251-53/+79
| | | | | | | 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
* Whoops, last word with bits in large shift left wasn't correct.Reid Spencer2007-02-251-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34565 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix the > 64 bits case for left shift.Reid Spencer2007-02-251-22/+47
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34564 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix the remainder shifting in KnuthDiv.Reid Spencer2007-02-241-6/+13
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34562 91177308-0d34-0410-b5e6-96231b3b80d8
* 1. Fix a bug in fromString for the <= 64bits caseReid Spencer2007-02-241-17/+29
| | | | | | | 2. Fix shl when shiftAmount == BitWidth. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34560 91177308-0d34-0410-b5e6-96231b3b80d8
* 1. Fix last bug in KnuthDiv. All divide tests pass up to 1024 bits now.Reid Spencer2007-02-241-63/+55
| | | | | | | | | | | 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
* 1. Make internal functions take const arguments where they should, justReid Spencer2007-02-241-21/+61
| | | | | | | | | | | | | | | 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
* 1. Fix a carry out problem in add if destination and x point to the sameReid Spencer2007-02-231-92/+43
| | | | | | | | | | 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
* When converting from 64 to 32-bits, use the actual number of words toReid Spencer2007-02-221-2/+2
| | | | | | | | 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
* Fix countLeadingZeros in the case that the bitwidth evenly divides theReid Spencer2007-02-221-1/+4
| | | | | | | | | 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
* Reorganize some code to make it clearer, avoid a few uninitialized memoryReid Spencer2007-02-211-56/+57
| | | | | | | 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