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
This commit is contained in:
Reid Spencer 2007-03-01 06:23:32 +00:00
parent f1d6006ad6
commit b5ca2cd509

View File

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