aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-02-18 22:29:05 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-02-18 22:29:05 +0000
commitf99a0ac0dcdce617df7af21596ceb8dc76b5839c (patch)
treebff50dc9e61c0e25850bc0d90e1c14e9163745ca /lib/Support/APInt.cpp
parent4a6f363491c37e0a31f462e72d640d9d4c63177e (diff)
1. Fix some indentation and variable names in the get{Min,Max}Value methods.
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
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r--lib/Support/APInt.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index bc6be8b1a1..ec47a69146 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -675,8 +675,22 @@ std::string APInt::toString(uint8_t radix, bool wantSigned) const {
return result;
}
+ if (radix != 10) {
+ uint64_t mask = radix - 1;
+ uint32_t shift = (radix == 16 ? 4 : radix == 8 ? 3 : 1);
+ uint32_t nibbles = APINT_BITS_PER_WORD / shift;
+ for (uint32_t i = 0; i < getNumWords(); ++i) {
+ uint64_t value = pVal[i];
+ for (uint32_t j = 0; j < nibbles; ++j) {
+ result.insert(0, digits[ value & mask ]);
+ value >>= shift;
+ }
+ }
+ return result;
+ }
+
APInt tmp(*this);
- APInt divisor(tmp.getBitWidth(), radix);
+ APInt divisor(tmp.getBitWidth(), 10);
APInt zero(tmp.getBitWidth(), 0);
size_t insert_at = 0;
if (wantSigned && tmp[BitWidth-1]) {
@@ -705,19 +719,21 @@ std::string APInt::toString(uint8_t radix, bool wantSigned) const {
/// for an APInt of the specified bit-width and if isSign == true,
/// it should be largest signed value, otherwise unsigned value.
APInt APInt::getMaxValue(uint32_t numBits, bool isSign) {
- APInt APIVal(numBits, 0);
- APIVal.set();
- if (isSign) APIVal.clear(numBits - 1);
- return APIVal;
+ APInt Result(numBits, 0);
+ Result.set();
+ if (isSign)
+ Result.clear(numBits - 1);
+ return Result;
}
/// getMinValue - This function returns the smallest value for
/// an APInt of the given bit-width and if isSign == true,
/// it should be smallest signed value, otherwise zero.
APInt APInt::getMinValue(uint32_t numBits, bool isSign) {
- APInt APIVal(numBits, 0);
- if (isSign) APIVal.set(numBits - 1);
- return APIVal;
+ APInt Result(numBits, 0);
+ if (isSign)
+ Result.set(numBits - 1);
+ return Result;
}
/// getAllOnesValue - This function returns an all-ones value for