[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp
Reid Spencer
reid at x10sys.com
Sat Feb 17 00:18:40 PST 2007
Changes in directory llvm-test/SingleSource/UnitTests/Integer/APInt:
arith.cpp updated: 1.7 -> 1.8
---
Log message:
Update for changes in APInt interface.
---
Diffs of the changes: (+53 -51)
arith.cpp | 104 +++++++++++++++++++++++++++++++-------------------------------
1 files changed, 53 insertions(+), 51 deletions(-)
Index: llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp
diff -u llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.7 llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.8
--- llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.7 Thu Feb 15 00:29:21 2007
+++ llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp Sat Feb 17 02:18:20 2007
@@ -15,26 +15,26 @@
using namespace llvm;
-APInt x(0x1fffff, 21);
+APInt x(21, 0x1fffff);
-APInt y(0x0fffff, 21);
+APInt y(21, 0x0fffff);
static std::string temp_str;
const char* str(const APInt& X) {
- temp_str = X.to_string();
+ temp_str = X.toString();
return temp_str.c_str();
}
void test_interface(const APInt &val) {
printf("INTERFACE TEST: val = %s\n", str(val));
- unsigned bitwidth = val.getNumBits();
+ unsigned bitwidth = val.getBitWidth();
unsigned pos = rand() % bitwidth;
printf("val[%u] = %d\n", pos, val[pos]);
- APInt smax = APInt::getMaxValue(bitwidth, true);
- APInt umax = APInt::getMaxValue(bitwidth, false);
- APInt smin = APInt::getMinValue(bitwidth, true);
- APInt umin = APInt::getMinValue(bitwidth, false);
+ APInt smax(APInt::getMaxValue(bitwidth, true));
+ APInt umax(APInt::getMaxValue(bitwidth, false));
+ APInt smin(APInt::getMinValue(bitwidth, true));
+ APInt umin(APInt::getMinValue(bitwidth, false));
printf("APInt::getMaxValue(%d, true) = %s\n", bitwidth, str(smax));
printf("APInt::getMaxValue(%d, false) = %s\n", bitwidth, str(umax));
printf("APInt::getMinValue(%d, true) = %s\n", bitwidth, str(smin));
@@ -60,9 +60,9 @@
x.flip();
printf("val.flip() = %s\n", str(x));
unsigned bitsize = bitwidth / 2;
- printf("val.HiBits(%d) = %s\n", bitsize, str(val.HiBits(bitsize)));
- printf("val.LoBits(%d) = %s\n", bitsize, str(val.LoBits(bitsize)));
- printf("val.IsIntN(%d) = %d\n", bitwidth, val.IsIntN(bitwidth));
+ printf("val.getHiBits(%d) = %s\n", bitsize, str(val.getHiBits(bitsize)));
+ printf("val.getLoBits(%d) = %s\n", bitsize, str(val.getLoBits(bitsize)));
+ printf("val.isIntN(%d) = %d\n", bitwidth, val.isIntN(bitwidth));
}
void test_unops(const APInt &val) {
@@ -85,18 +85,18 @@
printf("~val = %s\n", str(x));
printf("!val = %d\n", !val);
printf("val.isPowerOf2() = %d\n", val.isPowerOf2());
- printf("val.LogBase2() = %d\n", val.getNumBits());
- printf("val.CountLeadingZeros() = %d\n", val.CountLeadingZeros());
- printf("val.CountTrailingZeros() = %d\n", val.CountTrailingZeros());
- printf("val.CountPopulation() = %d\n", val.CountPopulation());
- printf("val.getNumBits() = %d\n", val.getNumBits());
- if (val.getNumBits() >= 16 && val.getNumBits() % 16 == 0) {
- x = val.ByteSwap();
- printf("val.ByteSwap() = %d\n", str(x));
+ printf("val.logBase2() = %d\n", val.logBase2());
+ printf("val.countLeadingZeros() = %d\n", val.countLeadingZeros());
+ printf("val.countTrailingZeros() = %d\n", val.countTrailingZeros());
+ printf("val.countPopulation() = %d\n", val.countPopulation());
+ printf("val.getBitWidth() = %d\n", val.getBitWidth());
+ if (val.getBitWidth() >= 16 && val.getBitWidth() % 16 == 0) {
+ x = val.byteSwap();
+ printf("val.byteSwap() = %d\n", str(x));
}
- printf("val.RoundToDouble(true) %d = %f\n", val.RoundToDouble(true));
+ printf("val.roundToDouble(true) %d = %f\n", val.roundToDouble(true));
printf("val.getValue() = ");
- if (val.getNumBits() > 64)
+ if (val.getBitWidth() > 64)
printf("too wide\n");
else
printf("%lu\n", val.getValue());
@@ -129,10 +129,6 @@
printf("v1 | v2: %s\n", str(result));
result = v1 ^ v2;
printf("v1 ^ v2: %s\n", str(result));
- result = v1 && v2;
- printf("v1 && v2: %s\n", str(result));
- result = v1 || v2;
- printf("v1 || v2: %s\n", str(result));
result = v1 * v2;
printf("v1 * v2: %s\n", str(result));
result = v1 + v2;
@@ -141,30 +137,36 @@
printf("v1 - v2: %s\n", str(result));
printf("v1 == v2: %d\n", v1 == v2);
printf("v1 != v2: %d\n", v1 == v2);
- printf("v1 < v2: %d\n", v1 == v2);
- printf("v1 <= v2: %d\n", v1 == v2);
- printf("v1 > v2: %d\n", v1 == v2);
- printf("v1 >= v2: %d\n", v1 == v2);
+ printf("v1.eq(v2): %d\n", v1.eq(v2));
+ printf("v1.ne(v2): %d\n", v1.ne(v2));
+ printf("v1.ult(v2): %d\n", v1.ult(v2));
+ printf("v1.slt(v2): %d\n", v1.slt(v2));
+ printf("v1.ule(v2): %d\n", v1.ule(v2));
+ printf("v1.sle(v2): %d\n", v1.sle(v2));
+ printf("v1.ugt(v2): %d\n", v1.ugt(v2));
+ printf("v1.sgt(v2): %d\n", v1.sgt(v2));
+ printf("v1.uge(v2): %d\n", v1.uge(v2));
+ printf("v1.sge(v2): %d\n", v1.sge(v2));
{
using namespace APIntOps;
- unsigned shiftAmt = rand() % v1.getNumBits();
- result = AShr(v1,shiftAmt);
- printf("AShr(v1,%d) = %s\n", shiftAmt, str(result));
- result = LShr(v1,shiftAmt);
- printf("LShr(v1,%d) = %s\n", shiftAmt, str(result));
- result = Shl(v1,shiftAmt);
- printf("Shl(v1,%d) = %s\n", shiftAmt, str(result));
+ unsigned shiftAmt = rand() % v1.getBitWidth();
+ result = ashr(v1,shiftAmt);
+ printf("ashr(v1,%d) = %s\n", shiftAmt, str(result));
+ result = lshr(v1,shiftAmt);
+ printf("lshr(v1,%d) = %s\n", shiftAmt, str(result));
+ result = shl(v1,shiftAmt);
+ printf("shl(v1,%d) = %s\n", shiftAmt, str(result));
if (v2 == 0)
- printf("SDiv/UDiv/SRem/URem not tested, v2 == 0\n");
+ printf("sdiv/udiv/srem/urem not tested, v2 == 0\n");
else {
- result = SDiv(v1,v2);
- printf("SDiv(v1,v2) = %s\n", str(result));
- result = UDiv(v1,v2);
- printf("UDiv(v1,v2) = %s\n", str(result));
- result = SRem(v1,v2);
- printf("SRem(v1,v2) = %s\n", str(result));
- result = URem(v1,v2);
- printf("URem(v1,v2) = %s\n", str(result));
+ result = sdiv(v1,v2);
+ printf("sdiv(v1,v2) = %s\n", str(result));
+ result = udiv(v1,v2);
+ printf("udiv(v1,v2) = %s\n", str(result));
+ result = srem(v1,v2);
+ printf("srem(v1,v2) = %s\n", str(result));
+ result = urem(v1,v2);
+ printf("urem(v1,v2) = %s\n", str(result));
}
}
}
@@ -172,17 +174,17 @@
void test_multiple() {
srand(0);
for (unsigned bits = 1; bits <= 1024; ++bits) {
- APInt v1(0u, bits);
- APInt v2(0u, bits);
+ APInt v1(bits, 0u);
+ APInt v2(bits, 0u);
for (unsigned i = 0; i < bits; ++i) {
unsigned bit = rand() % 2;
- v1 = v1.Shl(1);
- v1 |= bit;
+ v1 = v1.shl(1);
+ v1 |= APInt(bits, bit);
}
for (unsigned i = 0; i < bits; ++i) {
unsigned bit = rand() % 2;
- v2 = v2.Shl(1);
- v2 |= bit;
+ v2 = v2.shl(1);
+ v2 |= APInt(bits, bit);
}
printf("\nTEST CASE: %d bits\n\n", bits);
test_interface(v1);
More information about the llvm-commits
mailing list