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 2C1176AAB3; Tue, 23 Mar 2021 12:45:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2C1176AAB3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492718; bh=KDHxtA2gxjm3a9WrHSERuaRKdNwmUD+266I8Y50JccY=; 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=M6wDdHd0xz4Lvms/OJ6xAY1k+RoASYAcHBL6sSLm5mmuCOapknP6gETIiwGuA6nRI iJLD3IYxP57pwCowyM6X5JIwhhcCxFNHIIHuZEoTeXansLTMgIBv+HnBJC9cR/uS7C afdImmX2BFoY1I1UoHoxVdhMeLlUAE0EBTODg5p4= Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (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 6765C68F4A for ; Tue, 23 Mar 2021 12:35:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6765C68F4A Received: by smtp50.i.mail.ru with esmtpa (envelope-from ) id 1lOdRu-00007m-Nx; Tue, 23 Mar 2021 12:35:43 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:35:42 +0300 Message-Id: <2686afeae6746dd466d988a9edcdceb719e6491b.1616491731.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-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F1C82687294EF6886B62CC997B0B8C95C4182A05F538085040433D48EB6F0E6CF0D1922661BEA401D31A9A33F555ECCA9E08597FCAD90566C3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FC60B152D67C945BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373DBA3D7E24987517EA1F7E6F0F101C67CDEEF6D7F21E0D1D174C73DBBBFC7664D54267400E4E38EC377188CD51E8C8D805FF374E89FE2654389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07734D68A6916D8318941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B68BFD6B1B042489ACCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C22495A888B72A9FC151C76E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8B1E2CB858746825BCD81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E14AD6D5ED66289B52BA9C0B312567BB23089D37D7C0E48F6CA18204E546F3947CB26E97DCB74E6252156CCFE7AF13BCA4C8A9BA7A39EFB7666BA297DBC24807EA089D37D7C0E48F6C8AA50765F7900637C69D4C8FA58DAC3AEFF80C71ABB335746BA297DBC24807EA27F269C8F02392CDC58410348177836E285124B2A10EEC6C00306258E7E6ABB4E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D3810B208799AECBE355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EA3C06F761EFF640E7F8450746973C7299C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349DAEDEF7DE8FDCFA56AB4990A695EDB3D621C61491CE3B8354354A88130FD9D95455B7281BFA445A1D7E09C32AA3244CE42EE72F2C0CE8266F7CC83D853B24FBF26BFA4C8A6946B8FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UiCPNYPn9Td5A== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED19C1F879F8325458D1922661BEA401D3BA0848438379BFCE5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 21/53] sql: introduce mem_bit_not() 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 introduces mem_bit_not(). Function mem_bit_not() executes bitwise not operation on the first MEM and writes the result to the second MEM. Part of #5818 --- src/box/sql/mem.c | 19 +++++++++++++++++++ src/box/sql/mem.h | 3 +++ src/box/sql/vdbe.c | 14 ++------------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 2b455e39f..c84b3775d 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -607,6 +607,25 @@ mem_bitwise(struct Mem *left, struct Mem *right, struct Mem *result, int op) return 0; } +int +mem_bit_not(struct Mem *mem, struct Mem *result) +{ + mem_clear(result); + result->field_type = FIELD_TYPE_INTEGER; + if ((mem->flags & MEM_Null) != 0) + return 0; + int64_t i; + bool unused; + if (sqlVdbeIntValue(mem, &i, &unused) != 0) { + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, + mem_str(mem), "integer"); + return -1; + } + i = ~i; + mem_set_int(result, i, i < 0); + return 0; +} + static int compare_blobs(const struct Mem *left, const struct Mem *right, int *result) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 8971e3d59..3561b49b1 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -199,6 +199,9 @@ mem_arithmetic(const struct Mem *left, const struct Mem *right, int mem_bitwise(struct Mem *left, struct Mem *right, struct Mem *result, int op); +int +mem_bit_not(struct Mem *mem, struct Mem *result); + int mem_compare(const struct Mem *left, const struct Mem *right, int *result, enum field_type type, struct coll *coll); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index cdcf7b2e8..80497b7b2 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -1792,18 +1792,8 @@ case OP_Not: { /* same as TK_NOT, in1, out2 */ case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */ pIn1 = &aMem[pOp->p1]; pOut = vdbe_prepare_null_out(p, pOp->p2); - /* Force NULL be of type INTEGER. */ - pOut->field_type = FIELD_TYPE_INTEGER; - if (!mem_is_null(pIn1)) { - int64_t i; - bool is_neg; - if (sqlVdbeIntValue(pIn1, &i, &is_neg) != 0) { - diag_set(ClientError, ER_SQL_TYPE_MISMATCH, - mem_str(pIn1), "integer"); - goto abort_due_to_error; - } - mem_set_i64(pOut, ~i); - } + if (mem_bit_not(pIn1, pOut) != 0) + goto abort_due_to_error; break; } -- 2.25.1