SQLite

Check-in [bc27ebd7f7]
Login

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

Overview
Comment:Make use of htonl() and __builtin_bswap32() for faster implementations of sqlite3Get4byte() and sqlite3Put4byte().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | bswap-functions
Files: files | file ages | folders
SHA1: bc27ebd7f73e9fc8e00da6ec82632e439fcce812
User & Date: drh 2015-06-30 12:47:09.735
Context
2015-06-30
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: 79ff36b717 user: drh tags: bswap-functions)
12:47
Make use of htonl() and __builtin_bswap32() for faster implementations of sqlite3Get4byte() and sqlite3Put4byte(). (check-in: bc27ebd7f7 user: drh tags: bswap-functions)
11:07
Change an unreachable branch into an assert() in sqlite3PagerAcquire() and optimize sqlite3PcacheOpenSavepoint() by factoring out rarely used code into a subroutine. (check-in: b406b20ecd user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/util.c.
1074
1075
1076
1077
1078
1079
1080













1081
1082

1083
1084









1085
1086
1087
1088

1089
1090
1091
1092
1093
1094
1095
}


/*
** Read or write a four-byte big-endian integer value.
*/
u32 sqlite3Get4byte(const u8 *p){













  testcase( p[0]&0x80 );
  return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];

}
void sqlite3Put4byte(unsigned char *p, u32 v){









  p[0] = (u8)(v>>24);
  p[1] = (u8)(v>>16);
  p[2] = (u8)(v>>8);
  p[3] = (u8)v;

}



/*
** Translate a single byte of Hex into an integer.
** This routine only works if h really is a valid hexadecimal







>
>
>
>
>
>
>
>
>
>
>
>
>


>


>
>
>
>
>
>
>
>
>




>







1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
}


/*
** Read or write a four-byte big-endian integer value.
*/
u32 sqlite3Get4byte(const u8 *p){
#if SQLITE_BYTEORDER==4321
  u32 x;
  memcpy(&x,p,4);
  return x;
#elif defined(_MSC_VER)
  u32 x;
  memcpy(&x,p,4);
  return htonl(x);
#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__)
  u32 x;
  memcpy(&x,p,4);
  return __builtin_bswap32(x);
#else
  testcase( p[0]&0x80 );
  return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
#endif
}
void sqlite3Put4byte(unsigned char *p, u32 v){
#if SQLITE_BYTEORDER==4321
  memcpy(p,&v,4);
#elif defined(_MSC_VER)
  u32 x = htonl(v);
  memcpy(&x,p,4);
#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__)
  u32 x = __builtin_bswap32(v);
  memcpy(p,&x,4);
#else
  p[0] = (u8)(v>>24);
  p[1] = (u8)(v>>16);
  p[2] = (u8)(v>>8);
  p[3] = (u8)v;
#endif
}



/*
** Translate a single byte of Hex into an integer.
** This routine only works if h really is a valid hexadecimal