Test versions of getVarint functions. The updates essentially utilize loop unrolling and some shifting/anding tricks to minimize the number of logical operations required. (CVS 5072)

FossilOrigin-Name: 682dc24dbe82d0326377e27c5ff97db3499873b0
This commit is contained in:
shane 2008-05-01 02:47:03 +00:00
parent 4697988687
commit 356574e97a
3 changed files with 258 additions and 51 deletions

View File

@ -1,5 +1,5 @@
C Add\scomment\sto\sspeculate\swhen\ssetting\sjournal_mode=OFF\son\sVACUUM\sdoes\snot\nhelp\sperformance.\s\sNo\schanges\sto\scode.\s(CVS\s5071)
D 2008-04-30T16:38:23
C Test\sversions\sof\sgetVarint\sfunctions.\sThe\supdates\sessentially\sutilize\sloop\sunrolling\sand\ssome\sshifting/anding\stricks\sto\sminimize\sthe\snumber\sof\slogical\soperations\srequired.\s(CVS\s5072)
D 2008-05-01T02:47:04
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 25b3282a4ac39388632c2fb0e044ff494d490952
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -167,7 +167,7 @@ F src/tokenize.c 8d77af8584cf027dc21375f0efa5818cb303c995
F src/trigger.c 9bd3b6fa0beff4a02d262c96466f752ec15a7fc3
F src/update.c 2d7143b9014e955509cc4f323f9a9584fb898f34
F src/utf.c 8c94fa10efc78c2568d08d436acc59df4df7191b
F src/util.c a3907b05dcc3720a6d71bb39e61d67b0d994b51f
F src/util.c 43a77ab79275991b819428ded8ac8dc868604ac7
F src/vacuum.c c3b2b70677f874102b8753bf494c232e777f3998
F src/vdbe.c 26964ba7ed76d2a1c52747d601aaf2dc5b09b651
F src/vdbe.h bfd84bda447f39cb599302c7ec85067dae20453c
@ -633,7 +633,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P aa59974ec15508d69c5b65ab89ec7bc32690018c
R 75f14acd3f2bae6b9a939b5711d86e5b
U drh
Z 924c040e6c27c40e097c580fa3feeda2
P 9c8b4babb2222a5e0c2ecf7a116b7df90084c81d
R 329903c79b08ceeef301067fa9d79cfe
U shane
Z 34ccf6f71b1f112c4e41d623ea9e6a2c

View File

@ -1 +1 @@
9c8b4babb2222a5e0c2ecf7a116b7df90084c81d
682dc24dbe82d0326377e27c5ff97db3499873b0

View File

@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.224 2008/04/28 17:41:31 shane Exp $
** $Id: util.c,v 1.225 2008/05/01 02:47:04 shane Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@ -533,41 +533,158 @@ int sqlite3PutVarint32(unsigned char *p, u32 v){
** Return the number of bytes read. The value is stored in *v.
*/
int sqlite3GetVarint(const unsigned char *p, u64 *v){
u32 x;
u64 x64;
int n;
unsigned char c;
if( ((c = p[0]) & 0x80)==0 ){
*v = c;
u32 a,b,s;
a = *p;
// a: p0 (unmasked)
if (!(a&0x80))
{
*v = a;
return 1;
}
x = c & 0x7f;
if( ((c = p[1]) & 0x80)==0 ){
*v = (x<<7) | c;
p++;
b = *p;
// b: p1 (unmasked)
if (!(b&0x80))
{
a &= 0x7f;
a = a<<7;
a |= b;
*v = a;
return 2;
}
x = (x<<7) | (c&0x7f);
if( ((c = p[2]) & 0x80)==0 ){
*v = (x<<7) | c;
p++;
a = a<<14;
a |= *p;
// a: p0<<14 | p2 (unmasked)
if (!(a&0x80))
{
a &= (0x7f<<14)|(0x7f);
b &= 0x7f;
b = b<<7;
a |= b;
*v = a;
return 3;
}
x = (x<<7) | (c&0x7f);
if( ((c = p[3]) & 0x80)==0 ){
*v = (x<<7) | c;
// CSE1 from below
a &= (0x7f<<14)|(0x7f);
p++;
b = b<<14;
b |= *p;
// b: p1<<14 | p3 (unmasked)
if (!(b&0x80))
{
b &= (0x7f<<14)|(0x7f);
// moved CSE1 up
// a &= (0x7f<<14)|(0x7f);
a = a<<7;
a |= b;
*v = a;
return 4;
}
x64 = (x<<7) | (c&0x7f);
n = 4;
do{
c = p[n++];
if( n==9 ){
x64 = (x64<<8) | c;
break;
}
x64 = (x64<<7) | (c&0x7f);
}while( (c & 0x80)!=0 );
*v = x64;
return n;
// a: p0<<14 | p2 (masked)
// b: p1<<14 | p3 (unmasked)
// 1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked)
// moved CSE1 up
// a &= (0x7f<<14)|(0x7f);
b &= (0x7f<<14)|(0x7f);
s = a;
// s: p0<<14 | p2 (masked)
p++;
a = a<<14;
a |= *p;
// a: p0<<28 | p2<<14 | p4 (unmasked)
if (!(a&0x80))
{
// we can skip these cause they were (effectively) done above in calc'ing s
// a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
// b &= (0x7f<<14)|(0x7f);
b = b<<7;
a |= b;
s = s>>18;
*v = ((u64)s)<<32 | a;
return 5;
}
// 2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked)
s = s<<7;
s |= b;
// s: p0<<21 | p1<<14 | p2<<7 | p3 (masked)
p++;
b = b<<14;
b |= *p;
// b: p1<<28 | p3<<14 | p5 (unmasked)
if (!(b&0x80))
{
// we can skip this cause it was (effectively) done above in calc'ing s
// b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
a &= (0x7f<<14)|(0x7f);
a = a<<7;
a |= b;
s = s>>18;
*v = ((u64)s)<<32 | a;
return 6;
}
p++;
a = a<<14;
a |= *p;
// a: p2<<28 | p4<<14 | p6 (unmasked)
if (!(a&0x80))
{
a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
b &= (0x7f<<14)|(0x7f);
b = b<<7;
a |= b;
s = s>>11;
*v = ((u64)s)<<32 | a;
return 7;
}
// CSE2 from below
a &= (0x7f<<14)|(0x7f);
p++;
b = b<<14;
b |= *p;
// b: p3<<28 | p5<<14 | p7 (unmasked)
if (!(b&0x80))
{
b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
// moved CSE2 up
// a &= (0x7f<<14)|(0x7f);
a = a<<7;
a |= b;
s = s>>4;
*v = ((u64)s)<<32 | a;
return 8;
}
p++;
a = a<<15;
a |= *p;
// a: p4<<29 | p6<<15 | p8 (unmasked)
// moved CSE2 up
// a &= (0x7f<<29)|(0x7f<<15)|(0xff);
b &= (0x7f<<14)|(0x7f);
b = b<<8;
a |= b;
s = s<<4;
b = p[-4];
b &= 0x7f;
b = b>>3;
s |= b;
*v = ((u64)s)<<32 | a;
return 9;
}
/*
@ -578,27 +695,117 @@ int sqlite3GetVarint(const unsigned char *p, u64 *v){
** this function assumes the single-byte case has already been handled.
*/
int sqlite3GetVarint32(const unsigned char *p, u32 *v){
u32 x;
int n;
unsigned char c;
u32 a,b;
a = *p;
// a: p0 (unmasked)
#ifndef getVarint32
if( ((signed char*)p)[0]>=0 ){
*v = p[0];
if (!(a&0x80))
{
*v = a;
return 1;
}
#endif
x = p[0] & 0x7f;
if( ((signed char*)p)[1]>=0 ){
*v = (x<<7) | p[1];
p++;
b = *p;
// b: p1 (unmasked)
if (!(b&0x80))
{
a &= 0x7f;
a = a<<7;
*v = a | b;
return 2;
}
x = (x<<7) | (p[1] & 0x7f);
n = 2;
do{
x = (x<<7) | ((c = p[n++])&0x7f);
}while( (c & 0x80)!=0 && n<9 );
*v = x;
return n;
p++;
a = a<<14;
a |= *p;
// a: p0<<14 | p2 (unmasked)
if (!(a&0x80))
{
a &= (0x7f<<14)|(0x7f);
b &= 0x7f;
b = b<<7;
*v = a | b;
return 3;
}
p++;
b = b<<14;
b |= *p;
// b: p1<<14 | p3 (unmasked)
if (!(b&0x80))
{
b &= (0x7f<<14)|(0x7f);
a &= (0x7f<<14)|(0x7f);
a = a<<7;
*v = a | b;
return 4;
}
p++;
a = a<<14;
a |= *p;
// a: p0<<28 | p2<<14 | p4 (unmasked)
if (!(a&0x80))
{
a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
b = b<<7;
*v = a | b;
return 5;
}
p++;
b = b<<14;
b |= *p;
// b: p1<<28 | p3<<14 | p5 (unmasked)
if (!(b&0x80))
{
b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
a = a<<7;
*v = a | b;
return 6;
}
p++;
a = a<<14;
a |= *p;
// a: p2<<28 | p4<<14 | p6 (unmasked)
if (!(a&0x80))
{
a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
b = b<<7;
*v = a | b;
return 7;
}
p++;
b = b<<14;
b |= *p;
// b: p3<<28 | p5<<14 | p7 (unmasked)
if (!(b&0x80))
{
b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
a = a<<7;
*v = a | b;
return 8;
}
p++;
a = a<<14;
a |= *p;
// a: p4<<28 | p6<<14 | p8 (unmasked)
a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
b = b<<7;
*v = a | b;
return 9;
}
/*