From: drh Date: Mon, 15 Dec 2008 15:27:51 +0000 (+0000) Subject: Convert the "~" and "NOT" operators to be two-address instructions. X-Git-Tag: version-3.6.10~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e99fa2af71b25fd822c576bc3f8e1c6ce1665120;p=thirdparty%2Fsqlite.git Convert the "~" and "NOT" operators to be two-address instructions. Ticket #3541. (CVS 6028) FossilOrigin-Name: ea9b747efb22fd3f679c3ef86ed51986c5ad9436 --- diff --git a/manifest b/manifest index 3779e5cc5a..f075582f21 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sexample\sfrom\s#3359\sto\sthe\stest\ssuite.\s(CVS\s6027) -D 2008-12-14T14:45:21 +C Convert\sthe\s"~"\sand\s"NOT"\soperators\sto\sbe\stwo-address\sinstructions.\nTicket\s#3541.\s(CVS\s6028) +D 2008-12-15T15:27:52 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in f7e4c81c347b04f7b0f1c1b081a168645d7b8af7 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -108,7 +108,7 @@ F src/callback.c bee8949d619b1b7b1e4dfac8a19c5116ae1dd12a F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c F src/date.c 3dbac3eac2848af416786b6e1e3150f7c740dac6 F src/delete.c e2392b6808496fc0a7f54662af3ba677a3e8e44a -F src/expr.c f13ad5563470481eaa1e8016bfa9ed1b4c996574 +F src/expr.c a385202af56d622b11d05e8d386def256155152b F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff F src/func.c b0e1c61301f33d67b72ab15d85c80ed76e7c98ac F src/global.c 91723e45a2ad03ae5bb97a0a0d2dbb1a0e69527b @@ -194,7 +194,7 @@ F src/update.c 080889d241e4dcd1c545c8051eb6de86f4939295 F src/utf.c 1da9c832dba0fa8f865b5b902d93f420a1ee4245 F src/util.c ea62608f66f33a7e8322de83024ae37c415c0c7f F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9 -F src/vdbe.c ee98938f76a3d9e513aca9696391c6e19fa2cafe +F src/vdbe.c 3fd1fe6408598121213e19e1808e5de882c7b636 F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6 F src/vdbeInt.h e6e80a99ce634983b7cc2498843b4d2e5540900a F src/vdbeapi.c 85c33cfbfa56249cbe627831610afafba754477d @@ -592,6 +592,7 @@ F test/tkt3493.test 8472b3464e49a27ff7271308eec46154209e667b F test/tkt3508.test d9e285ff91731247d4673f9252fe5934639d7f0d F test/tkt3522.test 22ce2ebbcb04a6be56c0977d405c207967318fd6 F test/tkt3527.test ee4af96183579565987e58873a7490bc04934ffb +F test/tkt3541.test 5dc257bde9bc833ab9cc6844bf170b998dbb950a F test/tkt35xx.test 53bca895091e968126a858ee7da186f59f328994 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/trace.test 951cd0f5f571e7f36bf7bfe04be70f90fb16fb00 @@ -672,7 +673,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P adba0f3c01ba2407466d0120c411c398218bdaeb -R fad0d590913fe8f9e5e994000a8088be -U danielk1977 -Z 4887ada2d24d472ddc8849201ce49da5 +P 84f8417c0794d3e5cec88f59ea71a7d557044409 +R af3b4538f82d88370566c291a9daf4a7 +U drh +Z 98bd9dcbaef571a6a1bb6e3794861e9a diff --git a/manifest.uuid b/manifest.uuid index 5f631ea19c..7bbdc5ed9f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -84f8417c0794d3e5cec88f59ea71a7d557044409 \ No newline at end of file +ea9b747efb22fd3f679c3ef86ed51986c5ad9436 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index f221a519ac..1b59a4cf86 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.407 2008/12/10 21:19:57 drh Exp $ +** $Id: expr.c,v 1.408 2008/12/15 15:27:52 drh Exp $ */ #include "sqliteInt.h" #include @@ -1975,11 +1975,10 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ assert( TK_NOT==OP_Not ); testcase( op==TK_BITNOT ); testcase( op==TK_NOT ); - inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); - testcase( inReg==target ); - testcase( usedAsColumnCache(pParse, inReg, inReg) ); - inReg = sqlite3ExprWritableRegister(pParse, inReg, target); - sqlite3VdbeAddOp1(v, op, inReg); + r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); + testcase( regFree1==0 ); + inReg = target; + sqlite3VdbeAddOp2(v, op, r1, inReg); break; } case TK_ISNULL: diff --git a/src/vdbe.c b/src/vdbe.c index dcf6a2713b..2bc26d3b38 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.802 2008/12/12 17:56:16 drh Exp $ +** $Id: vdbe.c,v 1.803 2008/12/15 15:27:52 drh Exp $ */ #include "sqliteInt.h" #include @@ -1810,31 +1810,35 @@ case OP_Or: { /* same as TK_OR, in1, in2, out3 */ break; } -/* Opcode: Not P1 * * * * +/* Opcode: Not P1 P2 * * * ** -** Interpret the value in register P1 as a boolean value. Replace it -** with its complement. If the value in register P1 is NULL its value -** is unchanged. +** Interpret the value in register P1 as a boolean value. Store the +** boolean complement in register P2. If the value in register P1 is +** NULL, then a NULL is stored in P2. */ case OP_Not: { /* same as TK_NOT, in1 */ - if( pIn1->flags & MEM_Null ) break; /* Do nothing to NULLs */ - sqlite3VdbeMemIntegerify(pIn1); - pIn1->u.i = !pIn1->u.i; - assert( pIn1->flags&MEM_Int ); + pOut = &p->aMem[pOp->p2]; + if( pIn1->flags & MEM_Null ){ + sqlite3VdbeMemSetNull(pOut); + }else{ + sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeIntValue(pIn1)); + } break; } -/* Opcode: BitNot P1 * * * * +/* Opcode: BitNot P1 P2 * * * ** -** Interpret the content of register P1 as an integer. Replace it -** with its ones-complement. If the value is originally NULL, leave -** it unchanged. +** Interpret the content of register P1 as an integer. Store the +** ones-complement of the P1 value into register P2. If P1 holds +** a NULL then store a NULL in P2. */ case OP_BitNot: { /* same as TK_BITNOT, in1 */ - if( pIn1->flags & MEM_Null ) break; /* Do nothing to NULLs */ - sqlite3VdbeMemIntegerify(pIn1); - pIn1->u.i = ~pIn1->u.i; - assert( pIn1->flags&MEM_Int ); + pOut = &p->aMem[pOp->p2]; + if( pIn1->flags & MEM_Null ){ + sqlite3VdbeMemSetNull(pOut); + }else{ + sqlite3VdbeMemSetInt64(pOut, ~sqlite3VdbeIntValue(pIn1)); + } break; } diff --git a/test/tkt3541.test b/test/tkt3541.test new file mode 100644 index 0000000000..f0597cfa10 --- /dev/null +++ b/test/tkt3541.test @@ -0,0 +1,35 @@ +# 2008 December 16 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is a verification that the bugs identified in ticket +# #3541 have been fixed. +# +# $Id: tkt3541.test,v 1.1 2008/12/15 15:27:52 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test tkt3541-1.1 { + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(123); + SELECT CASE ~max(x) WHEN min(x) THEN 1 ELSE max(x) END FROM t1; + } +} {123} +do_test tkt3541-1.2 { + db eval { + SELECT CASE NOT max(x) WHEN min(x) THEN 1 ELSE max(x) END FROM t1; + } +} {123} + + +finish_test