[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp

Reid Spencer reid at x10sys.com
Tue Feb 13 19:05:49 PST 2007



Changes in directory llvm-test/SingleSource/UnitTests/Integer/APInt:

arith.cpp updated: 1.4 -> 1.5
---
Log message:

1. Add a utility function for getting a printable string from an APInt
2. Comment out the ByteSwap function, it crashes.
3. Prevent divid by zero.
4. Test every bit width from 1 to 1024, not 1024 random bit widths.


---
Diffs of the changes:  (+20 -14)

 arith.cpp |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)


Index: llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp
diff -u llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.4 llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.5
--- llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.4	Tue Feb 13 16:40:41 2007
+++ llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp	Tue Feb 13 21:05:33 2007
@@ -19,8 +19,9 @@
 
 APInt y(0x0fffff, 21);
 
+static std::string temp_str;
+
 const char* str(const APInt& X) {
-  static std::string temp_str;
   temp_str = X.to_string();
   return temp_str.c_str(); 
 }
@@ -89,15 +90,17 @@
   printf("val.CountTrailingZeros() = %d\n", val.CountTrailingZeros());
   printf("val.CountPopulation() = %d\n", val.CountPopulation());
   printf("val.getNumBits() = %d\n", val.getNumBits());
-  x = val.ByteSwap();
-  printf("val.ByteSwap() = %d\n", str(x));
+  if (val.getNumBits() >= 16 && val.getNumBits() % 16 == 0) {
+    // FIXME: ByteSwap crashes!
+    // x = val.ByteSwap();
+    printf("val.ByteSwap() = %d\n", str(x));
+  }
   printf("val.RoundToDouble(true) %d = %f\n", val.RoundToDouble(true));
   printf("val.getValue() = ");
   if (val.getNumBits() > 64)
     printf("too wide\n");
   else
     printf("%ul\n", val.getValue());
-
 }
 
 void test_binops(const APInt &v1, const APInt &v2) {
@@ -151,21 +154,24 @@
     printf("LShr(v1,%d) = %s\n", shiftAmt, str(result));
     result = Shl(v1,shiftAmt);
     printf("Shl(v1,%d) = %s\n", shiftAmt, 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));
+    if (v2 == 0)
+      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));
+    }
   }
 }
 
 void test_multiple() {
   srand(0);
-  for (unsigned i = 0; i < 1024; ++i) {
-    unsigned bits = rand() % 1024;
+  for (unsigned bits = 1; bits <= 1024; ++bits) {
     APInt v1(0u, bits);
     APInt v2(0u, bits);
     for (unsigned i = 0; i < bits; ++i) {






More information about the llvm-commits mailing list