/ Check-in [444084fd]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Performance optimization on byte-swapping in R-Tree.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rtree-enhancements
Files: files | file ages | folders
SHA1:444084fd620fc3f45cfb87b83f532d76bd2744e7
User & Date: drh 2014-04-17 23:23:29
Context
2014-04-18
01:14
Merge the latest changes from sessions. check-in: d9eef5b0 user: drh tags: rtree-enhancements
2014-04-17
23:23
Performance optimization on byte-swapping in R-Tree. check-in: 444084fd user: drh tags: rtree-enhancements
15:34
More test cases with very long priority queues. check-in: 71692aa9 user: drh tags: rtree-enhancements
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

239
240
241
242
243
244
245

246
247
248
249
250
251
252
...
898
899
900
901
902
903
904
905

906
907
908




909

910
911
912








913
914
915
916
917

918
919
920
921
922
923
924
/*
** A coordinate can be either a floating point number or a integer.  All
** coordinates within a single R-Tree are always of the same time.
*/
union RtreeCoord {
  RtreeValue f;      /* Floating point value */
  int i;             /* Integer value */

};

/*
** The argument is an RtreeCoord. Return the value stored within the RtreeCoord
** formatted as a RtreeDValue (double or int64). This macro assumes that local
** variable pRtree points to the Rtree structure associated with the
** RtreeCoord.
................................................................................
*/
static int rtreeEof(sqlite3_vtab_cursor *cur){
  RtreeCursor *pCsr = (RtreeCursor *)cur;
  return pCsr->atEOF;
}

/*
** 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
** bytes of the on-disk record to be decoded.  Store the results in "r".




*/

#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)                       \
           +((u32)a[2]<<8) + a[3];                              \
    c.i = *(int*)&x;                                            \
    r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
}

   

/*
** Check the RTree node or entry given by pCellData and p against the MATCH
** constraint pConstraint.  
*/
static int rtreeCallbackConstraint(







>







 







|
>
|
|

>
>
>
>

>

<

>
>
>
>
>
>
>
>
|

<


>







239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
...
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917

918
919
920
921
922
923
924
925
926
927
928

929
930
931
932
933
934
935
936
937
938
/*
** A coordinate can be either a floating point number or a integer.  All
** coordinates within a single R-Tree are always of the same time.
*/
union RtreeCoord {
  RtreeValue f;      /* Floating point value */
  int i;             /* Integer value */
  u32 u;             /* Unsigned for byte-order conversions */
};

/*
** The argument is an RtreeCoord. Return the value stored within the RtreeCoord
** formatted as a RtreeDValue (double or int64). This macro assumes that local
** variable pRtree points to the Rtree structure associated with the
** RtreeCoord.
................................................................................
*/
static int rtreeEof(sqlite3_vtab_cursor *cur){
  RtreeCursor *pCsr = (RtreeCursor *)cur;
  return pCsr->atEOF;
}

/*
** 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) {                        \

    RtreeCoord c;    /* Coordinate decoded */                   \
    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];                              \

    r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
}
#endif
   

/*
** Check the RTree node or entry given by pCellData and p against the MATCH
** constraint pConstraint.  
*/
static int rtreeCallbackConstraint(