From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id CEEAE6EC42; Tue, 21 Sep 2021 14:00:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CEEAE6EC42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1632222002; bh=QQrq+TSVy3YrN/KBMA8zioOI65soW9wO/rLJfomGVR4=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ylEvc5OvB/E7rJ6WCzX7Qlsbb8OgbWZPYD9EzROCm5bfvVb+66ZEe1i0DpMm3SQoc riWh/N6V3SbYRsVYT9PgFIs7e9WYNYfG58WzkcIuuphd0goKn+/L+qdDByq3HfUa0m BvOIbnXPBuV0eizQXr06NumVDGtjYZycILNFyq6s= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 66A946EC42 for ; Tue, 21 Sep 2021 13:59:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 66A946EC42 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mSdUN-0002QL-OD; Tue, 21 Sep 2021 13:59:04 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 21 Sep 2021 13:59:03 +0300 Message-Id: <675f594ddd87d69270eed967b9c3b2d6318d15a2.1632220375.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD91AE02D33A9C88A2FF3F790D2CFB1565D68082CE688654CB400894C459B0CD1B9EDAB256FDB6BE043DE3E18B1173C8824994D8960CDEEF0A8067A636123F0E402 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE767C624BFB9C76AC3EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374146C1300AF3DC028638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80C47E91D6FB97A2AE8F4767B342AB003117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CD1D040B6C1ECEA3F43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CB382FA991BF7A44CD1BAD0901FE55F27B52D15EFD76CBE9D9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF520746E264B47742F36E2E0160E5C5538A5251AA20633D2658C12E6D310A6D5330AF80C8B6E6FB9115E2725BA614EAEA1EF972C1F679AE1C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34753B45383CEFF2048C59C596FA4ECDD03EFF76B842A02BC5BC3A919308039B7C3983AEFBBB6653E11D7E09C32AA3244CF09E3F2DCD81E37F74408A6BD8AA9B31725D5B54B2FE4575729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojnvI84oHUDXBhI7DxnWdwZQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D29E8B10CFB4CBC17E7B52A6D1EB8BF1C83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 02/15] sql: use register P1 for number of arguments X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch makes OP_FunctionByName, OP_AggStep and OP_BuiltinFunction to use register P1 for the number of arguments instead of register P5. This makes it easier to use these opcodes. Needed for #4145 --- src/box/sql/expr.c | 5 ++-- src/box/sql/select.c | 3 +- src/box/sql/vdbe.c | 64 ++++++++++++++++++++----------------------- src/box/sql/vdbeInt.h | 1 - 4 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index ee21c1ede..3b5df5292 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -4107,18 +4107,17 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) (char *)coll, P4_COLLSEQ); } if (func->def->language == FUNC_LANGUAGE_SQL_BUILTIN) { - sqlVdbeAddOp4(v, OP_BuiltinFunction0, constMask, + sqlVdbeAddOp4(v, OP_BuiltinFunction0, nFarg, r1, target, (char *)func, P4_FUNC); } else { - sqlVdbeAddOp4(v, OP_FunctionByName, constMask, + sqlVdbeAddOp4(v, OP_FunctionByName, nFarg, r1, target, sqlDbStrNDup(pParse->db, func->def->name, func->def->name_len), P4_DYNAMIC); } - sqlVdbeChangeP5(v, (u8) nFarg); if (nFarg && constMask == 0) { sqlReleaseTempRange(pParse, r1, nFarg); } diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 2fe38e319..92e40aef6 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -5639,9 +5639,8 @@ updateAccumulator(Parse * pParse, AggInfo * pAggInfo) sqlVdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)coll, P4_COLLSEQ); } - sqlVdbeAddOp3(v, OP_AggStep0, 0, regAgg, pF->iMem); + sqlVdbeAddOp3(v, OP_AggStep0, nArg, regAgg, pF->iMem); sqlVdbeAppendP4(v, pF->func, P4_FUNC); - sqlVdbeChangeP5(v, (u8) nArg); sql_expr_type_cache_change(pParse, regAgg, nArg); sqlReleaseTempRange(pParse, regAgg, nArg); if (addrNext) { diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 44533fb3e..a0f1be454 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -1182,32 +1182,24 @@ case OP_CollSeq: { break; } -/* Opcode: BuiltinFunction0 P1 P2 P3 P4 P5 - * Synopsis: r[P3]=func(r[P2@P5]) +/* Opcode: BuiltinFunction0 P1 P2 P3 P4 * + * Synopsis: r[P3]=func(r[P2@P1]) * * Invoke a user function (P4 is a pointer to a FuncDef object that - * defines the function) with P5 arguments taken from register P2 and + * defines the function) with P1 arguments taken from register P2 and * successors. The result of the function is stored in register P3. * Register P3 must not be one of the function inputs. * - * P1 is a 32-bit bitmask indicating whether or not each argument to the - * function was determined to be constant at compile time. If the first - * argument was constant then bit 0 of P1 is set. - * * See also: BuiltinFunction, AggStep, AggFinal */ -/* Opcode: BuiltinFunction P1 P2 P3 P4 P5 - * Synopsis: r[P3]=func(r[P2@P5]) +/* Opcode: BuiltinFunction P1 P2 P3 P4 * + * Synopsis: r[P3]=func(r[P2@P1]) * * Invoke a user function (P4 is a pointer to an sql_context object that - * contains a pointer to the function to be run) with P5 arguments taken + * contains a pointer to the function to be run) with P1 arguments taken * from register P2 and successors. The result of the function is stored * in register P3. Register P3 must not be one of the function inputs. * - * P1 is a 32-bit bitmask indicating whether or not each argument to the - * function was determined to be constant at compile time. If the first - * argument was constant then bit 0 of P1 is set. - * * SQL functions are initially coded as OP_BuiltinFunction0 with * P4 pointing to a FuncDef object. But on first evaluation, * the P4 operand is automatically converted into an sql_context @@ -1223,7 +1215,7 @@ case OP_BuiltinFunction0: { sql_context *pCtx; assert(pOp->p4type == P4_FUNC); - n = pOp->p5; + n = pOp->p1; assert(pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor)); assert(n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1)); assert(pOp->p3p2 || pOp->p3>=pOp->p2+n); @@ -1233,7 +1225,6 @@ case OP_BuiltinFunction0: { pCtx->func = pOp->p4.func; pCtx->iOp = (int)(pOp - aOp); pCtx->pVdbe = p; - pCtx->argc = n; pOp->p4type = P4_FUNCCTX; pOp->p4.pCtx = pCtx; pOp->opcode = OP_BuiltinFunction; @@ -1242,6 +1233,7 @@ case OP_BuiltinFunction0: { } case OP_BuiltinFunction: { int i; + int argc = pOp->p1; sql_context *pCtx; assert(pOp->p4type==P4_FUNCCTX); @@ -1255,11 +1247,12 @@ case OP_BuiltinFunction: { pOut = vdbe_prepare_null_out(p, pOp->p3); if (pCtx->pOut != pOut) { pCtx->pOut = pOut; - for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; + for(i = 0; i < argc; ++i) + pCtx->argv[i] = &aMem[pOp->p2 + i]; } #ifdef SQL_DEBUG - for(i=0; iargc; i++) { + for(i = 0; i < argc; i++) { assert(memIsValid(pCtx->argv[i])); REGISTER_TRACE(p, pOp->p2+i, pCtx->argv[i]); } @@ -1267,7 +1260,7 @@ case OP_BuiltinFunction: { pCtx->is_aborted = false; assert(pCtx->func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); struct func_sql_builtin *func = (struct func_sql_builtin *)pCtx->func; - func->call(pCtx, pCtx->argc, pCtx->argv); + func->call(pCtx, argc, pCtx->argv); /* If the function returned an error, throw an exception */ if (pCtx->is_aborted) @@ -1283,11 +1276,11 @@ case OP_BuiltinFunction: { break; } -/* Opcode: FunctionByName * P2 P3 P4 P5 - * Synopsis: r[P3]=func(r[P2@P5]) +/* Opcode: FunctionByName P1 P2 P3 P4 * + * Synopsis: r[P3]=func(r[P2@P1]) * * Invoke a user function (P4 is a pointer to a function object - * that defines the function) with P5 arguments taken from + * that defines the function) with P1 arguments taken from * register P2 and successors. The result of the function is * stored in register P3. */ @@ -1303,7 +1296,7 @@ case OP_FunctionByName: { * turn out to be invalid after call. */ enum field_type returns = func->def->returns; - int argc = pOp->p5; + int argc = pOp->p1; struct Mem *argv = &aMem[pOp->p2]; struct port args, ret; @@ -4185,26 +4178,26 @@ case OP_DecrJumpZero: { /* jump, in1 */ } -/* Opcode: AggStep0 * P2 P3 P4 P5 - * Synopsis: accum=r[P3] step(r[P2@P5]) +/* Opcode: AggStep0 P1 P2 P3 P4 * + * Synopsis: accum=r[P3] step(r[P2@P1]) * * Execute the step function for an aggregate. The - * function has P5 arguments. P4 is a pointer to the FuncDef + * function has P1 arguments. P4 is a pointer to the FuncDef * structure that specifies the function. Register P3 is the * accumulator. * - * The P5 arguments are taken from register P2 and its + * The P1 arguments are taken from register P2 and its * successors. */ -/* Opcode: AggStep * P2 P3 P4 P5 - * Synopsis: accum=r[P3] step(r[P2@P5]) +/* Opcode: AggStep P1 P2 P3 P4 * + * Synopsis: accum=r[P3] step(r[P2@P1]) * * Execute the step function for an aggregate. The - * function has P5 arguments. P4 is a pointer to an sql_context + * function has P1 arguments. P4 is a pointer to an sql_context * object that is used to run the function. Register P3 is * as the accumulator. * - * The P5 arguments are taken from register P2 and its + * The P1 arguments are taken from register P2 and its * successors. * * This opcode is initially coded as OP_AggStep0. On first evaluation, @@ -4228,7 +4221,6 @@ case OP_AggStep0: { pCtx->func = pOp->p4.func; pCtx->iOp = (int)(pOp - aOp); pCtx->pVdbe = p; - pCtx->argc = n; pOp->p4type = P4_FUNCCTX; pOp->p4.pCtx = pCtx; pOp->opcode = OP_AggStep; @@ -4237,6 +4229,7 @@ case OP_AggStep0: { } case OP_AggStep: { int i; + int argc = pOp->p1; sql_context *pCtx; Mem *pMem; Mem t; @@ -4252,11 +4245,12 @@ case OP_AggStep: { */ if (pCtx->pMem != pMem) { pCtx->pMem = pMem; - for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; + for(i = 0; i < argc; ++i) + pCtx->argv[i] = &aMem[pOp->p2 + i]; } #ifdef SQL_DEBUG - for(i=0; iargc; i++) { + for(i = 0; i < argc; i++) { assert(memIsValid(pCtx->argv[i])); REGISTER_TRACE(p, pOp->p2+i, pCtx->argv[i]); } @@ -4269,7 +4263,7 @@ case OP_AggStep: { pCtx->skipFlag = 0; assert(pCtx->func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); struct func_sql_builtin *func = (struct func_sql_builtin *)pCtx->func; - func->call(pCtx, pCtx->argc, pCtx->argv); + func->call(pCtx, argc, pCtx->argv); if (pCtx->is_aborted) { mem_destroy(&t); goto abort_due_to_error; diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h index cfe743b94..575ab3f3d 100644 --- a/src/box/sql/vdbeInt.h +++ b/src/box/sql/vdbeInt.h @@ -182,7 +182,6 @@ struct sql_context { */ bool is_aborted; u8 skipFlag; /* Skip accumulator loading if true */ - u8 argc; /* Number of arguments */ sql_value *argv[1]; /* Argument set */ }; -- 2.25.1