/ Check-in [654935c7]
Login

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

Overview
Comment:Optimization to the comparison opcodes in the byte-code engine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 654935c7737f1a9e08fde9b220c543e86ff6e05910e2f08973a2f93ab2b3e028
User & Date: drh 2017-08-03 00:29:23
Context
2017-08-03
15:43
Fix some problems in RBU test cases. Also update RBU source code to better handle the trivial case where an RBU update is applied to a database zero pages in size. check-in: 7676b39b user: dan tags: trunk
00:29
Optimization to the comparison opcodes in the byte-code engine. check-in: 654935c7 user: drh tags: trunk
2017-08-02
22:43
In the KeyInfo object, refactor the nField and nXField elements into nKeyField and nAllField, which are more useful and run a little faster. check-in: aea5990e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  1951   1951           flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask);
  1952   1952         }
  1953   1953       }
  1954   1954       assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
  1955   1955       res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
  1956   1956     }
  1957   1957   compare_op:
  1958         -  switch( pOp->opcode ){
  1959         -    case OP_Eq:    res2 = res==0;     break;
  1960         -    case OP_Ne:    res2 = res;        break;
  1961         -    case OP_Lt:    res2 = res<0;      break;
  1962         -    case OP_Le:    res2 = res<=0;     break;
  1963         -    case OP_Gt:    res2 = res>0;      break;
  1964         -    default:       res2 = res>=0;     break;
         1958  +  /* At this point, res is negative, zero, or positive if reg[P1] is
         1959  +  ** less than, equal to, or greater than reg[P3], respectively.  Compute
         1960  +  ** the answer to this operator in res2, depending on what the comparison
         1961  +  ** operator actually is.  The next block of code depends on the fact
         1962  +  ** that the 6 comparison operators are consecutive integers in this
         1963  +  ** order:  NE, EQ, GT, LE, LT, GE */
         1964  +  assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 );
         1965  +  assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 );
         1966  +  if( res<0 ){                        /* ne, eq, gt, le, lt, ge */
         1967  +    static const unsigned char aLTb[] = { 1,  0,  0,  1,  1,  0 };
         1968  +    res2 = aLTb[pOp->opcode - OP_Ne];
         1969  +  }else if( res==0 ){
         1970  +    static const unsigned char aEQb[] = { 0,  1,  0,  1,  0,  1 };
         1971  +    res2 = aEQb[pOp->opcode - OP_Ne];
         1972  +  }else{
         1973  +    static const unsigned char aGTb[] = { 1,  0,  1,  0,  0,  1 };
         1974  +    res2 = aGTb[pOp->opcode - OP_Ne];
  1965   1975     }
  1966   1976   
  1967   1977     /* Undo any changes made by applyAffinity() to the input registers. */
  1968   1978     assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
  1969   1979     pIn1->flags = flags1;
  1970   1980     assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
  1971   1981     pIn3->flags = flags3;
  1972   1982   
  1973   1983     if( pOp->p5 & SQLITE_STOREP2 ){
  1974   1984       pOut = &aMem[pOp->p2];
  1975   1985       iCompare = res;
  1976         -    res2 = res2!=0;  /* For this path res2 must be exactly 0 or 1 */
  1977   1986       if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
  1978   1987         /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
  1979   1988         ** and prevents OP_Ne from overwriting NULL with 0.  This flag
  1980   1989         ** is only used in contexts where either:
  1981   1990         **   (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
  1982   1991         **   (2) op==OP_Ne && (r[P2]==NULL || r[P2]==1)
  1983   1992         ** Therefore it is not necessary to check the content of r[P2] for