[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

Reid Spencer reid at x10sys.com
Wed Feb 28 22:23:49 PST 2007



Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.60 -> 1.61
---
Log message:

Use a real table in sqrt to shorten and quicken the code. 
Thanks for the idea Chris.


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

 APInt.cpp |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.60 llvm/lib/Support/APInt.cpp:1.61
--- llvm/lib/Support/APInt.cpp:1.60	Wed Feb 28 23:39:56 2007
+++ llvm/lib/Support/APInt.cpp	Thu Mar  1 00:23:32 2007
@@ -1174,20 +1174,16 @@
   // Use a fast table for some small values. This also gets rid of some
   // rounding errors in libc sqrt for small values.
   if (magnitude <= 5) {
-    uint64_t result = 0;
-    switch (isSingleWord() ? VAL : pVal[0]) {
-      case 0 : break;
-      case 1 : case 2 : result = 1; break;
-      case 3 : case 4 : case 5: case 6: result = 2; break;
-      case 7 : case 8 : case 9: case 10: case 11: case 12: 
-        result = 3; break;
-      case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20:
-        result = 4; break;
-      case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28:
-      case 29: case 30: result = 5; break;
-      case 31: result = 6; break;
-    }
-    return APInt(BitWidth, result);
+    static uint8_t results[32] = {
+      /*     0 */ 0,
+      /*  1- 2 */ 1, 1,
+      /*  3- 6 */ 2, 2, 2, 2, 
+      /*  7-12 */ 3, 3, 3, 3, 3, 3,
+      /* 13-20 */ 4, 4, 4, 4, 4, 4, 4, 4,
+      /* 21-30 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+      /*    31 */ 6
+    };
+    return APInt(BitWidth, results[ (isSingleWord() ? VAL : pVal[0]) ]);
   }
 
   // If the magnitude of the value fits in less than 52 bits (the precision of






More information about the llvm-commits mailing list