aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/APInt.cpp
AgeCommit message (Collapse)Author
2007-02-27Conform to single person attribution in file comment.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34678 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-271. Fix three serious bugs in the comparison code.Reid Spencer
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-27Get rid of extraneous // in file comment.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34662 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-27Simplify and document RoundDoubleToAPInt.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34648 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-261. Make sure all delete operators of arrays use the array form of delete.Reid Spencer
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-26Implement the getHashValue method.Reid Spencer
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-26Re-enable this. The header was committed.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34634 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-26another missing header :( :( :(Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34632 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-261. Remove redundant calls to clearUsedBits().Reid Spencer
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-26Rewrite lshr to not do bit by bit copy but to copy and shift whole words.Reid Spencer
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-25Fix sext operation. Shifting by zero would leave an incorrect mask.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34617 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-251. Fix the flip() method to correctly flip all words of the APInt.Reid Spencer
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-251. Provide more detail in file comment.Reid Spencer
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-25Allow this to compile now that the header file is checked in.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34581 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25this doesn't compile, disable itChris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34571 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25Clean up lshr and ashr to coding standards.Reid Spencer
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-25Whoops, last word with bits in large shift left wasn't correct.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34565 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-25Fix the > 64 bits case for left shift.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34564 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-24Fix the remainder shifting in KnuthDiv.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34562 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-241. Fix a bug in fromString for the <= 64bits caseReid Spencer
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-241. Fix last bug in KnuthDiv. All divide tests pass up to 1024 bits now.Reid Spencer
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-241. Make internal functions take const arguments where they should, justReid Spencer
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-231. Fix a carry out problem in add if destination and x point to the sameReid Spencer
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-22When converting from 64 to 32-bits, use the actual number of words toReid Spencer
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-22Fix countLeadingZeros in the case that the bitwidth evenly divides theReid Spencer
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-21Reorganize some code to make it clearer, avoid a few uninitialized memoryReid Spencer
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-21Fix the carry in addition.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34465 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-211. Add a dump() method for faster debugging.Reid Spencer
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-21Fix countLeadingZeros to actually return the correct number.Reid Spencer
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-20Make long addition and subtraction work. Speed things up by using internalReid Spencer
functions more. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34458 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-20Clean up variable names in operator*.Reid Spencer
Attempt #3 for getting a portable INFINITY value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34454 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-20Use INFINITY macro from math.h instead of constructing hex floating pointReid Spencer
constants (avoids warnings). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34452 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-20First version that can process arith.cpp test case up to 1024 bits:Reid Spencer
1. Ensure pVal is set to 0 in each constructor. 2. Fix roundToDouble to make correct calculations and not read beyond the end of allocated memory. 3. Implement Knuth's "classical algorithm" for division from scratch and eliminate buffer overflows and uninitialized mememory reads. Document it properly too. 4. Implement a wrapper function for KnuthDiv which handles the 64-bit to 32-bit conversion and back. It also implement short division for the n == 1 case that Knuth's algorithm can't handle. 5. Simplify the logic of udiv and urem a little, make them exit early, and have them use the "divide" wrapper function to perform the division or remainder operation. 6. Move the toString function to the end of the file, closer to where the division functions are located. Note: division is still broken for some > 64 bit values, but at least it doesn't crash any more. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34449 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-181. Fix some indentation and variable names in the get{Min,Max}Value methods.Reid Spencer
2. Implement toString for power-of-2 radix without using divide and always printing full words. This allows hex/binary to look at the bit respresentation of the APInt as well as avoid bugs in divide. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34396 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-181. Use APINT_WORD_SIZE instead of sizeof(uint64_t)Reid Spencer
2. Teach slt about signedness. 3. Teach roundToDouble to properly sign extend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34391 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-181. Remove dead code (lshift function).Reid Spencer
2. Consolidate memory allocation into just two inline functions. 3. Convert "unsigned" to uint32_t to gaurantee its size. 4. Eliminate magic constants and replace with symbolic equivalent. 5. Improve code documentation slightly. 6. Simplify the logical operator code because bitwidths must be the same. 7. Fix indentation per coding standards. 8. Use exit-early style to reduce indentation in several functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34389 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-18Make add_1 exit early if carry is 0.Reid Spencer
Fix line breaks and 80 cols violation. Simplify operator^= since bitwidths must be the same. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34388 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-18Implement signed output for toString.Reid Spencer
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-17Fix some bugs in division logic.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34384 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-17Move static functions closer to their usage.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34363 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-17Clean up the divide and remainder logic a bit (exit early). Use moreReid Spencer
meaningful variable names. Add comments to document the flow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34362 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-17Fix bugs introduced by constructor parameter order change.Reid Spencer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34357 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-16Review changes:Reid Spencer
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-15Fix some buges:Zhou Sheng
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-14Use brute-force algorithm for to_string. It doesn't have to be efficientReid Spencer
at this point, it just needs to work so we can test things reliably. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34262 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-13Make some minor improvements to APInt:Reid Spencer
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-121. Make APInt::shl work correctly and more efficiently.Zhou Sheng
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-09Eliminates friend function declaration inside APInt, instead, adds publicZhou Sheng
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-08Switched this file on accidently.Zhou Sheng
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34054 91177308-0d34-0410-b5e6-96231b3b80d8
2007-02-08As Chris and Reid suggested, remove "isSigned" field from APInt, instead,Zhou Sheng
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