/ Check-in [ce8177e3]
Login

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

Overview
Comment:Only use __builtin_bswap16() with GCC 4.8 and later.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bswap-functions
Files: files | file ages | folders
SHA1: ce8177e3e64d2ac4cd5d9e7757cdd5fcecd7d0ea
User & Date: drh 2015-06-30 14:01:20
Context
2015-06-30
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
14:01
Only use __builtin_bswap16() with GCC 4.8 and later. Closed-Leaf check-in: ce8177e3 user: drh tags: bswap-functions
13:28
Remove the use of htonl() in the previous check-in due to linkage issues. Add the get2byteAligned() macro and use it for access to the cell offsets on btree pages for about a 1% performance gain. check-in: 79ff36b7 user: drh tags: bswap-functions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/btreeInt.h.

695
696
697
698
699
700
701
702
703
704
705
706
/*
** get2byteAligned(), unlike get2byte(), requires that its argument point to a
** two-byte aligned address.  get2bytea() is only used for accessing the
** cell addresses in a btree header.
*/
#if SQLITE_BYTEORDER==4321
# define get2byteAligned(x)  (*(u16*)(x))
#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__)
# define get2byteAligned(x)  __builtin_bswap16(*(u16*)(x))
#else
# define get2byteAligned(x)  ((x)[0]<<8 | (x)[1])
#endif







|




695
696
697
698
699
700
701
702
703
704
705
706
/*
** get2byteAligned(), unlike get2byte(), requires that its argument point to a
** two-byte aligned address.  get2bytea() is only used for accessing the
** cell addresses in a btree header.
*/
#if SQLITE_BYTEORDER==4321
# define get2byteAligned(x)  (*(u16*)(x))
#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
# define get2byteAligned(x)  __builtin_bswap16(*(u16*)(x))
#else
# define get2byteAligned(x)  ((x)[0]<<8 | (x)[1])
#endif

Changes to src/sqliteInt.h.

55
56
57
58
59
60
61







62
63
64
65
66
67
68
#ifndef SQLITE_DISABLE_LFS
# define _LARGE_FILE       1
# ifndef _FILE_OFFSET_BITS
#   define _FILE_OFFSET_BITS 64
# endif
# define _LARGEFILE_SOURCE 1
#endif








/* Needed for various definitions... */
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
#endif

#if defined(__OpenBSD__) && !defined(_BSD_SOURCE)







>
>
>
>
>
>
>







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef SQLITE_DISABLE_LFS
# define _LARGE_FILE       1
# ifndef _FILE_OFFSET_BITS
#   define _FILE_OFFSET_BITS 64
# endif
# define _LARGEFILE_SOURCE 1
#endif

/* What version of GCC is being used.  0 means GCC is not being used */
#ifdef __GNUC__
# define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
#else
# define GCC_VERSION 0
#endif

/* Needed for various definitions... */
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
#endif

#if defined(__OpenBSD__) && !defined(_BSD_SOURCE)