aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-08-17 20:53:07 +0000
committerdrh <drh@noemail.net>2017-08-17 20:53:07 +0000
commitceb4b1dbdde735e851b3bf0d8656cfbe3c29b11a (patch)
tree5fb309e0db55ceae92269aac6a92a892c5c4a6b3 /src
parentdceed86d07146bedbe8b54a613601d2db0d937f8 (diff)
downloadsqlite-ceb4b1dbdde735e851b3bf0d8656cfbe3c29b11a.tar.gz
sqlite-ceb4b1dbdde735e851b3bf0d8656cfbe3c29b11a.zip
Use the __builtin_clzll() function of gcc to improve the performance and
reduce the size of the sqlite3LogEst() routine. FossilOrigin-Name: a42a438cbbd721765ca55e71c464552dbaa494050cf472593599b8c7f0249516
Diffstat (limited to 'src')
-rw-r--r--src/util.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 7c9c5f54b..a6d349296 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1413,8 +1413,14 @@ LogEst sqlite3LogEst(u64 x){
if( x<2 ) return 0;
while( x<8 ){ y -= 10; x <<= 1; }
}else{
+#if GCC_VERSION>=5004000
+ int i = 60 - __builtin_clzll(x);
+ y += i*10;
+ x >>= i;
+#else
while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
while( x>15 ){ y += 10; x >>= 1; }
+#endif
}
return a[x&7] + y - 10;
}