From: drh Date: Thu, 17 Apr 2014 23:23:29 +0000 (+0000) Subject: Performance optimization on byte-swapping in R-Tree. X-Git-Tag: version-3.13.0~148^2~145^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a5db90fc8ee2e7dfdd1093f9a6ed4dc27ad7f1c4;p=thirdparty%2Fsqlite.git Performance optimization on byte-swapping in R-Tree. FossilOrigin-Name: 444084fd620fc3f45cfb87b83f532d76bd2744e7 --- diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 53414af7ee..620c158288 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -243,6 +243,7 @@ struct RtreeCursor { union RtreeCoord { RtreeValue f; /* Floating point value */ int i; /* Integer value */ + u32 u; /* Unsigned for byte-order conversions */ }; /* @@ -902,19 +903,32 @@ static int rtreeEof(sqlite3_vtab_cursor *cur){ } /* -** Convert raw bits from the on-disk RTree record into a coordinate value -** The on-disk record stores integer coordinates if eInt is true and it -** stores 32-bit floating point records if eInt is false. a[] is the four +** Convert raw bits from the on-disk RTree record into a coordinate value. +** The on-disk format is big-endian and needs to be converted for little-endian +** platforms. The on-disk record stores integer coordinates if eInt is true +** and it stores 32-bit floating point records if eInt is false. a[] is the four ** bytes of the on-disk record to be decoded. Store the results in "r". +** +** The first version of this macro is fast on x86, x86_64 and ARM, all of which +** are little-endian. The second version of this macro is cross-platform but +** takes twice as long, according to valgrind on linux x64. */ +#if defined(__x86) || defined(__x86_64) || defined(__arm__) || defined(_MSC_VER) #define RTREE_DECODE_COORD(eInt, a, r) { \ - u32 x; /* Raw bits of the coordinate value */ \ RtreeCoord c; /* Coordinate decoded */ \ - x = ((u32)a[0]<<24) + ((u32)a[1]<<16) \ + memcpy(&c.u,a,4); \ + c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \ + ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \ + r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ +} +#else +#define RTREE_DECODE_COORD(eInt, a, r) { \ + RtreeCoord c; /* Coordinate decoded */ \ + c.u = ((u32)a[0]<<24) + ((u32)a[1]<<16) \ +((u32)a[2]<<8) + a[3]; \ - c.i = *(int*)&x; \ r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ } +#endif /* diff --git a/manifest b/manifest index 6eb3fbb265..f00e6668a6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\stest\scases\swith\svery\slong\spriority\squeues. -D 2014-04-17T15:34:58.372 +C Performance\soptimization\son\sbyte-swapping\sin\sR-Tree. +D 2014-04-17T23:23:29.676 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e4ee6d36cdf6136aee0158675a3b24dd3bf31a5a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -120,7 +120,7 @@ F ext/misc/vfslog.c fe40fab5c077a40477f7e5eba994309ecac6cc95 F ext/misc/vtshim.c babb0dc2bf116029e3e7c9a618b8a1377045303e F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 6a47918e44697dd32f5bba8a79d3490e56bd76c9 +F ext/rtree/rtree.c 5cf5ae21ca1742be863f025ce64e4262fc6def4c F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test cf679265ecafff494a768ac9c2f43a70915a6290 F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1176,7 +1176,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 1ccaaed6b516ec2ce953c1b31025a82ba76d00e7 -R 449eb9a5ce303ca34184a4306bd9d328 +P 71692aa97c78676f0ba80eaeec0ad9ac225f4427 +R f1ebd50a7930430ccdb2dd222ebc5021 U drh -Z 39039e877d4cb95ab625ec95bd5cc650 +Z 8e204d3bb697cd291df3586d6cea66ab diff --git a/manifest.uuid b/manifest.uuid index f923c4ba43..41369a2d98 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -71692aa97c78676f0ba80eaeec0ad9ac225f4427 \ No newline at end of file +444084fd620fc3f45cfb87b83f532d76bd2744e7 \ No newline at end of file