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 4D3526DB05; Fri, 1 Oct 2021 15:50:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4D3526DB05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633092604; bh=HKKjGY7D0afecsimS3JbkOWNXk1lmvtwEiUJQXsv/lk=; 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=n7AKe3fn86489JMVSrYPkmy1xWmw4GE8pawWMci77IYNiK2I1Pr7QN7lsmpwTDcYY E9NuOD4cgI4ylqn6W9dCDPHMofXeIqc2DjL+PkJAtsGvWL0XpUopXXZm+tF3nfZLyG UmczhPCEb0ue2iMcpdItFrkX/7pl/HI1fBfTAn0I= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 2D48674144 for ; Fri, 1 Oct 2021 15:48:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2D48674144 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mWHxr-0003sl-C1; Fri, 01 Oct 2021 15:48:35 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 1 Oct 2021 15:48:35 +0300 Message-Id: <1de9ac6e6ed9ee827c2ecb07c51b9eda95547804.1633092363.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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD96A58C36AA2E9964976B67DC8394C8DAB0EDC1900E6C7EF8D182A05F53808504005D87B501C08837E5BA23DBE516F8445B350D1C7509E70FA54BCC965783A2A08 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D31CF4E13A5F8DDAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AD4B8DECD34330378638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80CB2EB880BA4C9F8B4BFBBF65A6B971F117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C289736CE4F78F08343847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBBB17C150BCA6793A6A9A2303675C7B1D68C5A652C34639D9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF783E2B6F79C23BED699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3482189E76C6218D8F3B78D7330CBE292A18A5737A4BE81DD96E540175321E416234A362C095B40F151D7E09C32AA3244CEB6486235E0BCADE6F458CE6E766A16633C9DC155518937F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojJNmX3owDPmExTZa0SJr7fg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D1BDF9C6FA8B462F83FBE545FCD55C29A83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 03/16] 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 86550541b..af97b0499 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; @@ -4177,26 +4170,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, @@ -4220,7 +4213,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; @@ -4229,6 +4221,7 @@ case OP_AggStep0: { } case OP_AggStep: { int i; + int argc = pOp->p1; sql_context *pCtx; Mem *pMem; Mem t; @@ -4244,11 +4237,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]); } @@ -4261,7 +4255,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