/ Check-in [e42ed9b4]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:An example showing how to improve performance of sqlite3VdbeSerialPut() using the GCC intrinsic function __builtin_bswap64().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | builtin-bswap64
Files: files | file ages | folders
SHA1: e42ed9b4adbf4a5cd4ce572d1015f3d2414053aa
User & Date: drh 2017-01-16 11:54:30
Context
2017-01-16
11:54
An example showing how to improve performance of sqlite3VdbeSerialPut() using the GCC intrinsic function __builtin_bswap64(). Leaf check-in: e42ed9b4 user: drh tags: builtin-bswap64
2017-01-13
18:24
Fix a problem preventing resumption of RBU operations after recovering from a process or system failure that occurs during the incremental-checkpoint phase. check-in: 97914266 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

  3317   3317   **
  3318   3318   ** Return the number of bytes actually written into buf[].  The number
  3319   3319   ** of bytes in the zero-filled tail is included in the return value only
  3320   3320   ** if those bytes were zeroed in buf[].
  3321   3321   */ 
  3322   3322   u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
  3323   3323     u32 len;
  3324         -
  3325         -  /* Integer and Real */
  3326         -  if( serial_type<=7 && serial_type>0 ){
  3327         -    u64 v;
  3328         -    u32 i;
  3329         -    if( serial_type==7 ){
  3330         -      assert( sizeof(v)==sizeof(pMem->u.r) );
  3331         -      memcpy(&v, &pMem->u.r, sizeof(v));
  3332         -      swapMixedEndianFloat(v);
  3333         -    }else{
  3334         -      v = pMem->u.i;
  3335         -    }
  3336         -    len = i = sqlite3SmallTypeSizes[serial_type];
  3337         -    assert( i>0 );
  3338         -    do{
  3339         -      buf[--i] = (u8)(v&0xFF);
  3340         -      v >>= 8;
  3341         -    }while( i );
  3342         -    return len;
  3343         -  }
         3324  +  u64 v;
         3325  +  u32 i;
  3344   3326   
  3345   3327     /* String or blob */
  3346   3328     if( serial_type>=12 ){
  3347   3329       assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
  3348   3330                == (int)sqlite3VdbeSerialTypeLen(serial_type) );
  3349   3331       len = pMem->n;
  3350   3332       if( len>0 ) memcpy(buf, pMem->z, len);
  3351   3333       return len;
  3352   3334     }
  3353   3335   
  3354         -  /* NULL or constants 0 or 1 */
  3355         -  return 0;
         3336  +  /* Integer and Real */
         3337  +  if( serial_type==7 ){
         3338  +    assert( sizeof(v)==sizeof(pMem->u.r) );
         3339  +    memcpy(&v, &pMem->u.r, sizeof(v));
         3340  +    swapMixedEndianFloat(v);
         3341  +  }else{
         3342  +    v = pMem->u.i;
         3343  +  }
         3344  +  len = i = sqlite3SmallTypeSizes[serial_type];
         3345  +  v = __builtin_bswap64(v);
         3346  +  memcpy(buf, &((char*)&v)[8-i], i);
         3347  +  return len;
  3356   3348   }
  3357   3349   
  3358   3350   /* Input "x" is a sequence of unsigned characters that represent a
  3359   3351   ** big-endian integer.  Return the equivalent native integer
  3360   3352   */
  3361   3353   #define ONE_BYTE_INT(x)    ((i8)(x)[0])
  3362   3354   #define TWO_BYTE_INT(x)    (256*(i8)((x)[0])|(x)[1])