[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp
Reid Spencer
reid at x10sys.com
Thu Mar 1 20:57:13 PST 2007
Changes in directory llvm-test/SingleSource/UnitTests/Integer/APInt:
gptest.cpp updated: 1.8 -> 1.9
---
Log message:
Don't let the run time grow geometrically with the bit width.
Get rid of a useless 3rd parameter on the print function.
---
Diffs of the changes: (+30 -28)
gptest.cpp | 58 ++++++++++++++++++++++++++++++----------------------------
1 files changed, 30 insertions(+), 28 deletions(-)
Index: llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp
diff -u llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp:1.8 llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp:1.9
--- llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp:1.8 Thu Mar 1 19:11:27 2007
+++ llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp Thu Mar 1 22:56:56 2007
@@ -22,15 +22,13 @@
static int input = 0, output = 0;
-void print(const APInt& X, bool wantSigned = false, bool withNL = true) {
+void print(const APInt& X, bool wantSigned = false) {
std::string decstr;
if (wantSigned)
decstr = X.toStringSigned(10);
else
decstr = X.toString(10);
printf("%s", decstr.c_str());
- if (withNL)
- printf("\n");
}
APInt randomAPInt(unsigned bits) {
@@ -84,9 +82,9 @@
void report(const APInt &v1, const APInt &v2, const std::string& op,
const std::string& result, const std::string& apresult) {
- print(v1, false, false);
+ print(v1, false);
printf(op.c_str());
- print(v2, false, false);
+ print(v2, false);
printf(" = %s (not %s)\n", result.c_str(), apresult.c_str());
fflush(stdout);
}
@@ -201,7 +199,7 @@
std::string apresult = r.toString(10, false);
if (result != apresult) {
printf("~ ");
- print(v1, false, false);
+ print(v1, false);
printf(" = %s (not %s)\n", result.c_str(), apresult.c_str());
fflush(stdout);
}
@@ -216,13 +214,14 @@
std::string apresult = rslt.toString(10, false);
if (gpresult != apresult) {
printf("sqrt(");
- print(v1, false, false);
+ print(v1, false);
printf(") = %s (not %s)\n", gpresult.c_str(), apresult.c_str());
}
}
void doBitTest(const APInt &v1) {
- for (int i = 0; i < v1.getBitWidth(); i++) {
+ int increment = (v1.getBitWidth() <= 64) ? 1 : v1.getBitWidth() / 64;
+ for (int i = 0; i < v1.getBitWidth(); i += increment) {
std::string cmd;
cmd += "bittest(";
cmd += v1.toString(10,false);
@@ -230,7 +229,7 @@
bool gpresult = atoi(getResult(cmd).c_str());
bool apresult = v1[i];
if (gpresult != apresult) {
- print(v1, false, false);
+ print(v1, false);
printf("[%d] = %s (not %s)\n", i,
(gpresult?"true":"false"), (apresult?"true":"false"));
fflush(stdout);
@@ -239,7 +238,8 @@
}
void doShift(const APInt &v1) {
- for (int i = 1; i <= v1.getBitWidth(); i++) {
+ int increment = (v1.getBitWidth() <= 64) ? 1 : v1.getBitWidth() / 64;
+ for (int i = 1; i < v1.getBitWidth(); i += increment) {
std::string cmd;
cmd += "bitand(truncate(shift(";
cmd += v1.toString(10,false);
@@ -249,7 +249,7 @@
APInt R1 = v1.shl(i);
std::string apresult = R1.toString(10,false);
if (gpresult != apresult) {
- print(v1, false, false);
+ print(v1, false);
printf(" << %d = %s (not %s)\n", i, gpresult.c_str(), apresult.c_str());
fflush(stdout);
}
@@ -261,25 +261,25 @@
R1 = v1.lshr(i);
apresult = R1.toString(10,false);
if (gpresult != apresult) {
- print(v1, false, false);
+ print(v1, false);
printf(" u>> %d = %s (not %s)\n", i, gpresult.c_str(), apresult.c_str());
fflush(stdout);
}
- if (v1.isNegative())
- cmd = "shift(" + v1.toString(10,true) + ",-" + utostr(i) + ")-1\n";
- else
- cmd = "shift(" + v1.toString(10,false) + ",-" + utostr(i) + ")\n";
- gpresult = getResult(cmd);
- R1 = v1.ashr(i);
- if (v1.isNegative())
+ if (v1.isNegative()) {
+ cmd = "shift(" + v1.toString(10,true) + ",-" + utostr(i-1) + ")\n";
+ R1 = v1.ashr(i-1);
apresult = R1.toString(10,true);
- else
+ } else {
+ cmd = "shift(" + v1.toString(10,false) + ",-" + utostr(i) + ")\n";
+ R1 = v1.ashr(i);
apresult = R1.toString(10,false);
+ }
+ gpresult = getResult(cmd);
if (gpresult != apresult) {
if (v1.isNegative())
- print(v1, true, false);
+ print(v1, true);
else
- print(v1, false, false);
+ print(v1, false);
printf(" s>> %d = %s (not %s)\n", i, gpresult.c_str(), apresult.c_str());
fflush(stdout);
}
@@ -298,12 +298,12 @@
V1.trunc(i);
std::string apresult = V1.toString(10,false);
if (gpresult != apresult) {
- print(v1, false, false);
+ print(v1, false);
printf(".trunc(%d) = %s (not %s)\n", i, gpresult.c_str(), apresult.c_str());
fflush(stdout);
}
}
- for (int i = v1.getBitWidth()+1; i < v1.getBitWidth()*2+2; ++i) {
+ for (int i = v1.getBitWidth()+1; i < v1.getBitWidth()+128; ++i) {
cmd = "bitand(" + v1.toString(10,false) + ",bitneg(0,";
cmd += utostr(unsigned(i)) + "))\n";
std::string gpresult = getResult(cmd);
@@ -311,7 +311,7 @@
V1.zext(i);
std::string apresult = V1.toString(10,false);
if (gpresult != apresult) {
- print(v1, false, false);
+ print(v1, false);
printf(".zext(%d) = %s (not %s)\n", i, gpresult.c_str(), apresult.c_str());
fflush(stdout);
}
@@ -320,7 +320,7 @@
V2.sext(i);
apresult = V2.toString(10,true);
if (before != apresult) {
- print(v1, true, false);
+ print(v1, true);
printf(".sext(%d) = %s (not %s)\n", i, before.c_str(), apresult.c_str());
fflush(stdout);
}
@@ -422,8 +422,10 @@
}
doComplement(*(list[i]));
doBitTest(*(list[i]));
- doShift(*(list[i]));
- doTruncExt(*(list[i]));
+ if (bits > 1) {
+ doShift(*(list[i]));
+ doTruncExt(*(list[i]));
+ }
doSqrt(*(list[i]));
}
}
More information about the llvm-commits
mailing list