diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 06:23:32 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 06:23:32 +0000 |
commit | b5ca2cd5095b61c17f89edc10bf2fc63a7e22824 (patch) | |
tree | 33c39e5bd2ca583c557af3c6469bfa876825df61 /lib/Support/APInt.cpp | |
parent | f1d6006ad60e0eb28f5089a5bb407ada6bb7ef4e (diff) |
Use a real table in sqrt to shorten and quicken the code.
Thanks for the idea Chris.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r-- | lib/Support/APInt.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 810fd9ee17..93442f344c 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -1174,20 +1174,16 @@ APInt APInt::sqrt() const { // 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 |