diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-26 21:02:27 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-26 21:02:27 +0000 |
commit | b2bc985a4e5718907c3ee4e30e3dd65859618ff7 (patch) | |
tree | 123c0b4d4e21e5d496da186724f55782b6dd7561 /llvm/lib/Support/APInt.cpp | |
parent | eed186ee585ece01f877994cd4188518740362b5 (diff) | |
download | bcm5719-llvm-b2bc985a4e5718907c3ee4e30e3dd65859618ff7.tar.gz bcm5719-llvm-b2bc985a4e5718907c3ee4e30e3dd65859618ff7.zip |
Implement the getHashValue method.
Fix toString use of getValue to use getZExtValue()
llvm-svn: 34642
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 1a2f0e0b94c..44aed755491 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -661,6 +661,21 @@ APInt APInt::getNullValue(uint32_t numBits) { return getMinValue(numBits, false); } +uint64_t APInt::getHashValue() const { + // LLVM only supports bit widths up to 2^23 so shift the bitwidth into the + // high range. This makes the hash unique for integer values < 2^41 bits and + // doesn't hurt for larger values. + uint64_t hash = uint64_t(BitWidth) << (APINT_BITS_PER_WORD - 23); + + // Add the sum of the words to the hash. + if (isSingleWord()) + hash += VAL; + else + for (uint32_t i = 0; i < getNumWords(); ++i) + hash += pVal[i]; + return hash; +} + /// HiBits - This function returns the high "numBits" bits of this APInt. APInt APInt::getHiBits(uint32_t numBits) const { return APIntOps::lshr(*this, BitWidth - numBits); @@ -1660,7 +1675,7 @@ std::string APInt::toString(uint8_t radix, bool wantSigned) const { APInt tmp2(tmp.getBitWidth(), 0); divide(tmp, tmp.getNumWords(), divisor, divisor.getNumWords(), &tmp2, &APdigit); - uint32_t digit = APdigit.getValue(); + uint32_t digit = APdigit.getZExtValue(); assert(digit < radix && "divide failed"); result.insert(insert_at,digits[digit]); tmp = tmp2; |