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 37CFDCE3D4F; Tue, 8 Oct 2024 13:12:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 37CFDCE3D4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1728382361; bh=j4k8RyR84v6ixaBu4I/AXIULQqZc+wo/VsS1NjedcK8=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=E7xAeJF/GVGOrWPscmC+g5qKxke226QHsf6HyfoCbPvpNBYw1OjOGrR6chgRt99oL wSApBQ2CB6UYTVw3U/51gIpnylbMxzXFHcr3mATBLziB+Pt1djS9Q7ZePrBDMsQjiR s9VcwP5+wPK3IAiT+HJyUaMx/+oZ4GF8yU1BkXrw= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [95.163.41.85]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2026C65AD01 for ; Tue, 8 Oct 2024 13:12:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2026C65AD01 Received: by exim-smtp-57dbb65494-qnzxs with esmtpa (envelope-from ) id 1sy7Cm-00000000STv-34i0; Tue, 08 Oct 2024 13:12:38 +0300 Content-Type: multipart/alternative; boundary="------------rf80DkDmrnXrByVmnJfUCkh0" Message-ID: <0bb51dce-95cc-4dcd-892c-062ca9b8c18c@tarantool.org> Date: Tue, 8 Oct 2024 13:12:36 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <7efd063772135322abfcc8de1214d20ebea69bad.1727855711.git.skaplun@tarantool.org> Content-Language: en-US In-Reply-To: <7efd063772135322abfcc8de1214d20ebea69bad.1727855711.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9B01871A0ED523BBFF2944416096D9CA3AE14DD4C63332AA4182A05F538085040539176FDB01D74733DE06ABAFEAF6705C8A74D1DC953EFF6FAA1D43217AC41C4C95EF9F5A0584B93 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DB45732B85BEE83BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CF05F7050DCA185A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E1889FF9324A7799EF64D94C1F28019AA9888E149D1DB637CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F6B57BC7E64490618DEB871D839B7333395957E7521B51C2DFABB839C843B9C08941B15DA834481F8AA50765F7900637DCE3DBD6F8E38AFD389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F790063764D99B6458681F42D81D268191BDAD3DBD4B6F7A4D31EC0BE2F48590F00D11D6D81D268191BDAD3D78DA827A17800CE78F84DE33370BE723EC76A7562686271ED91E3A1F190DE8FD2E808ACE2090B5E14AD6D5ED66289B5278DA827A17800CE754F43A495B1ACFC12EB15956EA79C166176DF2183F8FC7C0E4A630A5B664A4FF725E5C173C3A84C37952320C71F5F86735872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A57330693C6E8871955002B1117B3ED69614313CB7A16E4DAB4869453249F34FA4823CB91A9FED034534781492E4B8EEAD47A3109F1ACFD409BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF2B0CFB6FA6E44F2919278A4EEDA0F049839C47B7334E2FEEF5C0ADDA844296561F5011C79ABBA8E7AF66815EE7BDF79044C3577831FCCDD809DA326C0584A9F523C38DBE29B3C0C75F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj/pBY5inp/EaYNwBymvGv2A== X-Mailru-Sender: 520A125C2F17F0B1E52FEF5D219D61403D92B473D7513D1CEDF1CDDB2C83CE56EF20E1EE44A110360152A3D17938EB451EB5A0BCEC6A560B3DDE9B364B0DF289BE2DA36745F2EEB5CEBA01FB949A1F1EEAB4BC95F72C04283CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix bit op coercion in DUALNUM builds. 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: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------rf80DkDmrnXrByVmnJfUCkh0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hello, Sergey, thanks for the patch! LGTM On 02.10.2024 11:09, Sergey Kaplun wrote: > From: Mike Pall > > Thanks to Sergey Kaplun. > > (cherry picked from commit f5fd22203eadf57ccbaa4a298010d23974b22fc0) > > The `lj_carith_check64()` function coerces the given number value to the > 32-bit wide value. In this case, the 64-bit-wide operands will lose > upper bits. > > This patch removes the excess coercion for the DUALNUM mode. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#10199 > --- > src/lj_carith.c | 4 +--- > .../lj-1273-dualnum-bit-coercion.test.lua | 19 +++++++++++++++++++ > 2 files changed, 20 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua > > diff --git a/src/lj_carith.c b/src/lj_carith.c > index 90b3220f..eb56d552 100644 > --- a/src/lj_carith.c > +++ b/src/lj_carith.c > @@ -349,9 +349,7 @@ uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id) > if (LJ_LIKELY(tvisint(o))) { > return (uint32_t)intV(o); > } else { > - int32_t i = lj_num2bit(numV(o)); > - if (LJ_DUALNUM) setintV(o, i); > - return (uint32_t)i; > + return (uint32_t)lj_num2bit(numV(o)); > } > } > > diff --git a/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua b/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua > new file mode 100644 > index 00000000..e83dbbcd > --- /dev/null > +++ b/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua > @@ -0,0 +1,19 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate LuaJIT misbehaviour on operating > +-- for 64-bit operands in built-in `bit` library in DUALNUM mode. > +-- See also,https://github.com/LuaJIT/LuaJIT/issues/1273. > + > +local test = tap.test('lj-1273-dualnum-bit-coercion') > +test:plan(1) > + > +local bit = require('bit') > + > +-- The cdata value for 2 ^ 33. > +local EXPECTED = 2 ^ 33 + 0LL > +-- Same value is used as mask for `bit.band()`. > +local MASK = EXPECTED > + > +test:is(bit.band(2 ^ 33, MASK), EXPECTED, 'correct bit.band result') > + > +test:done(true) --------------rf80DkDmrnXrByVmnJfUCkh0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hello, Sergey,

thanks for the patch! LGTM

On 02.10.2024 11:09, Sergey Kaplun wrote:
From: Mike Pall <mike>

Thanks to Sergey Kaplun.

(cherry picked from commit f5fd22203eadf57ccbaa4a298010d23974b22fc0)

The `lj_carith_check64()` function coerces the given number value to the
32-bit wide value. In this case, the 64-bit-wide operands will lose
upper bits.

This patch removes the excess coercion for the DUALNUM mode.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#10199
---
 src/lj_carith.c                               |  4 +---
 .../lj-1273-dualnum-bit-coercion.test.lua     | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua

diff --git a/src/lj_carith.c b/src/lj_carith.c
index 90b3220f..eb56d552 100644
--- a/src/lj_carith.c
+++ b/src/lj_carith.c
@@ -349,9 +349,7 @@ uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id)
   if (LJ_LIKELY(tvisint(o))) {
     return (uint32_t)intV(o);
   } else {
-    int32_t i = lj_num2bit(numV(o));
-    if (LJ_DUALNUM) setintV(o, i);
-    return (uint32_t)i;
+    return (uint32_t)lj_num2bit(numV(o));
   }
 }
 
diff --git a/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua b/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua
new file mode 100644
index 00000000..e83dbbcd
--- /dev/null
+++ b/test/tarantool-tests/lj-1273-dualnum-bit-coercion.test.lua
@@ -0,0 +1,19 @@
+local tap = require('tap')
+
+-- Test file to demonstrate LuaJIT misbehaviour on operating
+-- for 64-bit operands in built-in `bit` library in DUALNUM mode.
+-- See also, https://github.com/LuaJIT/LuaJIT/issues/1273.
+
+local test = tap.test('lj-1273-dualnum-bit-coercion')
+test:plan(1)
+
+local bit = require('bit')
+
+-- The cdata value for 2 ^ 33.
+local EXPECTED = 2 ^ 33 + 0LL
+-- Same value is used as mask for `bit.band()`.
+local MASK = EXPECTED
+
+test:is(bit.band(2 ^ 33, MASK), EXPECTED, 'correct bit.band result')
+
+test:done(true)
--------------rf80DkDmrnXrByVmnJfUCkh0--