/ Check-in [010c48f6]
Login

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

Overview
Comment:Faster implementation for sqlite3MulInt64().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 010c48f671e909cb406f3716102a0032bc72a592
User & Date: drh 2014-02-10 12:59:15
Context
2014-02-10
15:56
Improvements to a "Synopsis:" comment in the VDBE engine. check-in: 0dfa7ee9 user: drh tags: trunk
12:59
Faster implementation for sqlite3MulInt64(). check-in: 010c48f6 user: drh tags: trunk
03:21
Faster and smaller implementation of sqlite3_value_type(). check-in: 5708bc24 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/util.c.

  1119   1119     i64 iA = *pA;
  1120   1120     testcase( iA==0 ); testcase( iA==1 );
  1121   1121     testcase( iB==-1 ); testcase( iB==0 );
  1122   1122     if( iB>=0 ){
  1123   1123       testcase( iA>0 && LARGEST_INT64 - iA == iB );
  1124   1124       testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
  1125   1125       if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
  1126         -    *pA += iB;
  1127   1126     }else{
  1128   1127       testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
  1129   1128       testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
  1130   1129       if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
  1131         -    *pA += iB;
  1132   1130     }
         1131  +  *pA += iB;
  1133   1132     return 0; 
  1134   1133   }
  1135   1134   int sqlite3SubInt64(i64 *pA, i64 iB){
  1136   1135     testcase( iB==SMALLEST_INT64+1 );
  1137   1136     if( iB==SMALLEST_INT64 ){
  1138   1137       testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
  1139   1138       if( (*pA)>=0 ) return 1;
................................................................................
  1149   1148     i64 iA = *pA;
  1150   1149     i64 iA1, iA0, iB1, iB0, r;
  1151   1150   
  1152   1151     iA1 = iA/TWOPOWER32;
  1153   1152     iA0 = iA % TWOPOWER32;
  1154   1153     iB1 = iB/TWOPOWER32;
  1155   1154     iB0 = iB % TWOPOWER32;
  1156         -  if( iA1*iB1 != 0 ) return 1;
  1157         -  assert( iA1*iB0==0 || iA0*iB1==0 );
  1158         -  r = iA1*iB0 + iA0*iB1;
         1155  +  if( iA1==0 ){
         1156  +    if( iB1==0 ){
         1157  +      *pA *= iB;
         1158  +      return 0;
         1159  +    }
         1160  +    r = iA0*iB1;
         1161  +  }else if( iB1==0 ){
         1162  +    r = iA1*iB0;
         1163  +  }else{
         1164  +    /* If both iA1 and iB1 are non-zero, overflow will result */
         1165  +    return 1;
         1166  +  }
  1159   1167     testcase( r==(-TWOPOWER31)-1 );
  1160   1168     testcase( r==(-TWOPOWER31) );
  1161   1169     testcase( r==TWOPOWER31 );
  1162   1170     testcase( r==TWOPOWER31-1 );
  1163   1171     if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
  1164   1172     r *= TWOPOWER32;
  1165   1173     if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;