/ Check-in [fe144dd7]
Login

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

Overview
Comment:Make use of the _byteswap_ushort() and _byteswap_ulong() compiler intrinsics for MSVC, when available.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fe144dd73f7097a17c24c7812c2a1cc40466e6da
User & Date: mistachkin 2015-06-30 17:28:40
Context
2015-07-01
01:31
Change integrity_check to analyze the cells of a page in reverse order, as this will tend to insert the cells into the analysis heap in increasing order by address, which is the most efficient way to load a min-heap. check-in: 59ad912c user: drh tags: trunk
2015-06-30
17:28
Make use of the _byteswap_ushort() and _byteswap_ulong() compiler intrinsics for MSVC, when available. check-in: fe144dd7 user: mistachkin tags: trunk
15:10
Make use of built-in bswap32() and bswap16() functions in GCC/Clang for a significant performance improvement there. check-in: 8bfcda3d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btreeInt.h.

   697    697   ** two-byte aligned address.  get2bytea() is only used for accessing the
   698    698   ** cell addresses in a btree header.
   699    699   */
   700    700   #if SQLITE_BYTEORDER==4321
   701    701   # define get2byteAligned(x)  (*(u16*)(x))
   702    702   #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
   703    703   # define get2byteAligned(x)  __builtin_bswap16(*(u16*)(x))
          704  +#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
          705  +# define get2byteAligned(x)  _byteswap_ushort(*(u16*)(x))
   704    706   #else
   705    707   # define get2byteAligned(x)  ((x)[0]<<8 | (x)[1])
   706    708   #endif

Changes to src/sqliteInt.h.

   181    181   #  define SQLITE_NOINLINE  __attribute__((noinline))
   182    182   #elif defined(_MSC_VER) && _MSC_VER>=1310
   183    183   #  define SQLITE_NOINLINE  __declspec(noinline)
   184    184   #else
   185    185   #  define SQLITE_NOINLINE
   186    186   #endif
   187    187   
          188  +/*
          189  +** Make sure that the compiler intrinsics we desire are enabled when
          190  +** compiling with an appropriate version of MSVC.
          191  +*/
          192  +#if defined(_MSC_VER) && _MSC_VER>=1300
          193  +#  include <intrin.h>
          194  +#  pragma intrinsic(_byteswap_ushort)
          195  +#  pragma intrinsic(_byteswap_ulong)
          196  +#endif
          197  +
   188    198   /*
   189    199   ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
   190    200   ** 0 means mutexes are permanently disable and the library is never
   191    201   ** threadsafe.  1 means the library is serialized which is the highest
   192    202   ** level of threadsafety.  2 means the library is multithreaded - multiple
   193    203   ** threads can use SQLite as long as no two threads try to use the same
   194    204   ** database connection at the same time.

Changes to src/util.c.

  1082   1082     u32 x;
  1083   1083     memcpy(&x,p,4);
  1084   1084     return x;
  1085   1085   #elif SQLITE_BYTEORDER==1234 && defined(__GNUC__)
  1086   1086     u32 x;
  1087   1087     memcpy(&x,p,4);
  1088   1088     return __builtin_bswap32(x);
         1089  +#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
         1090  +  u32 x;
         1091  +  memcpy(&x,p,4);
         1092  +  return _byteswap_ulong(x);
  1089   1093   #else
  1090   1094     testcase( p[0]&0x80 );
  1091   1095     return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
  1092   1096   #endif
  1093   1097   }
  1094   1098   void sqlite3Put4byte(unsigned char *p, u32 v){
  1095   1099   #if SQLITE_BYTEORDER==4321
  1096   1100     memcpy(p,&v,4);
  1097   1101   #elif SQLITE_BYTEORDER==1234 && defined(__GNUC__)
  1098   1102     u32 x = __builtin_bswap32(v);
         1103  +  memcpy(p,&x,4);
         1104  +#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
         1105  +  u32 x = _byteswap_ulong(v);
  1099   1106     memcpy(p,&x,4);
  1100   1107   #else
  1101   1108     p[0] = (u8)(v>>24);
  1102   1109     p[1] = (u8)(v>>16);
  1103   1110     p[2] = (u8)(v>>8);
  1104   1111     p[3] = (u8)v;
  1105   1112   #endif