From 068a251d9982d7f57694d5b901078b94dc5b0ad0 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 13 Jan 2015 21:26:17 +0000 Subject: [PATCH] Simplify some code in rtree, to avoid confusing the optimizer in GCC on some macs: gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00). Prior to these changes, compiling with -O3 would cause incorrect code to be generated. The change to the nodeGetCell() routine is key. The other changes are merely cosmetic details discovered while bug hunting. FossilOrigin-Name: 882181ff9dd75f32db266db6e476671021fc567b --- ext/rtree/rtree.c | 12 +++++------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 058dc96a4c..201d3cfff2 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -369,13 +369,12 @@ static int readInt16(u8 *p){ return (p[0]<<8) + p[1]; } static void readCoord(u8 *p, RtreeCoord *pCoord){ - u32 i = ( + pCoord->u = ( (((u32)p[0]) << 24) + (((u32)p[1]) << 16) + (((u32)p[2]) << 8) + (((u32)p[3]) << 0) ); - *(u32 *)pCoord = i; } static i64 readInt64(u8 *p){ return ( @@ -404,7 +403,7 @@ static int writeCoord(u8 *p, RtreeCoord *pCoord){ u32 i; assert( sizeof(RtreeCoord)==4 ); assert( sizeof(u32)==4 ); - i = *(u32 *)pCoord; + i = pCoord->u; p[0] = (i>>24)&0xFF; p[1] = (i>>16)&0xFF; p[2] = (i>> 8)&0xFF; @@ -735,14 +734,13 @@ static void nodeGetCell( RtreeCell *pCell /* OUT: Write the cell contents here */ ){ u8 *pData; - u8 *pEnd; RtreeCoord *pCoord; + int ii; pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell); pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell); - pEnd = pData + pRtree->nDim*8; pCoord = pCell->aCoord; - for(; pDatanDim*2; ii++){ + readCoord(&pData[ii*4], &pCoord[ii]); } } diff --git a/manifest b/manifest index 0ced843c65..d2eb0110ac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\se_walauto.test\stest\smodule\sso\sthat\sit\sworks\son\sboth\slittle-endian\sand\nbig-ending\smachines. -D 2015-01-13T01:12:43.817 +C Simplify\ssome\scode\sin\srtree,\sto\savoid\sconfusing\sthe\soptimizer\sin\sGCC\son\nsome\smacs:\ngcc\sversion\s4.2.1\s(Based\son\sApple\sInc.\sbuild\s5658)\s(LLVM\sbuild\s2335.15.00).\nPrior\sto\sthese\schanges,\scompiling\swith\s-O3\swould\scause\sincorrect\scode\sto\nbe\sgenerated.\s\sThe\schange\sto\sthe\snodeGetCell()\sroutine\sis\skey.\s\sThe\sother\nchanges\sare\smerely\scosmetic\sdetails\sdiscovered\swhile\sbug\shunting. +D 2015-01-13T21:26:17.584 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 9efcdb5c6025caea362cdfc38817451170fc6344 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -124,7 +124,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 b61e9eab7229a443d0d2029da7624299e19301a2 +F ext/rtree/rtree.c 14e6239434d4e3f65d3e90320713f26aa24e167f F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 541bbcab74613907fea08b2ecdcdd5b7aa724cc9 F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1236,7 +1236,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e693e11d1b9265974c32bddba873ea30a4d0b708 -R 5f43a97405384c08e7d2695a40688554 +P 5682db7b871689b9ee764afe070736f378e8ae1b +R dfd426dd4e5c9bb35969866ff363968f U drh -Z 3c1c71c98fb9cbeb713c59bb71069029 +Z bd5f3f08ebc84ee22d9c4c92ffb9e94c diff --git a/manifest.uuid b/manifest.uuid index c534efe236..4e9c91e56e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5682db7b871689b9ee764afe070736f378e8ae1b \ No newline at end of file +882181ff9dd75f32db266db6e476671021fc567b \ No newline at end of file