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 268645C3F0D; Tue, 8 Oct 2024 17:24:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 268645C3F0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1728397497; bh=LsdSjrLY/N8BZlBSnFAlhN3ulKat9HmRs7PzpvqRe6w=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RMbiiptNCsLb37KYcUynZy6iewYraWbIzr5f3+IJiusDpbWw41Pv6uJY8v4slc5q6 4cvpu56iNRXf+95s2QiN6P9HyWXVNq5OxdjnsQ7vGApBItUabLGlVG0qVf9PgIE6Sp 08j93D8y3GJJ3DU+QySIpdX9XVo7MtckXNqkmvPA= Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [95.163.41.88]) (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 B54345C3F0D for ; Tue, 8 Oct 2024 17:24:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B54345C3F0D Received: by exim-smtp-57dbb65494-69dtf with esmtpa (envelope-from ) id 1syB8w-00000000N93-1dTX; Tue, 08 Oct 2024 17:24:55 +0300 Date: Tue, 8 Oct 2024 17:24:23 +0300 To: Sergey Bronnikov Message-ID: References: <7531b1a6a3f39f8f2d83a54befdc67af987cebaf.1727855711.git.skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9B01871A0ED523BBFE8AA377AC0BA303F16C147DA899E7082182A05F538085040855F4D27AF95E6C33DE06ABAFEAF6705A32F1F9AE6DDFC872CD1D04B983676CFCAABEEF29940EAE0 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE705C173BDDADFC82AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637457C2806CBF873EDEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B043BF0FB74779F36EAED6A8511BFEDA7208106E711F775C3D17C2EC360EC51FAA471835C12D1D9774AD6D5ED66289B5278DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3A12191B5F2BB8629117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637FB177F6A8366F17BEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5E14E4B405889AD455002B1117B3ED69621BFBCAFA1ED5232886DC9BC01168B20823CB91A9FED034534781492E4B8EEAD0D89974173551D4FBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFB3373479F5E49B9A67B1E76986AB32C0BEE7BCA97741F72706C6EC48F6B8A25A6D10329F4AAC8FAEAF66815EE7BDF7909B5D53C9000F904717B81127434E5E24274C10D751ADA83E5F4332CA8FE04980913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj/pBY5inp/EagXXaHt5OJRw== X-DA7885C5: E1D951FC2C1DAC12F255D290C0D534F9831FDD5C546781011E92CE35760E007D424AC59BEDCFD8975B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393C6D0B12EA33CAA9B39AA5AC4559B7664D0BA08C6A22671512394D57F58F1BFC6E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] FFI: Fix 64 bit shift fold rules. 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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the review! Fixed your comments and force-pushed the branch. On 08.10.24, Sergey Bronnikov wrote: > Hello, Sergey, > > thanks for the patch! Please see my comments below. > > On 02.10.2024 11:09, Sergey Kaplun wrote: > > From: Mike Pall > > > > Thanks to Peter Cawley. > > > > (cherry picked from commit 9e0437240f1fb4bfa7248f6ec8be0e3181016119) > > > > For `IR_BSHR`, `IR_BROL`, `IR_BROR` during `kfold_int64arith()` the left > > argument is truncated down to 32 bits, which leads to incorrect results > > if the right argument is >= 32. > typo: is >= 2,147,483,647 Nice catch! Thanks! :) I replaced with 2^32. > > > > Also, `IR_BSAR` does an unsigned shift rather than a signed shift, but > > since this case branch is unreachable, it is harmless for now. > > > > This patch fixes all misbehaviours (including possible for `IR_BSAR`) to > > preserve IR semantics. > > > > Sergey Kaplun: > > * added the description and the test for the problem > > > > Part of tarantool/tarantool#10199 > > --- > > src/lj_opt_fold.c | 8 +- > > .../lj-1079-fix-64-bitshift-folds.test.lua | 74 +++++++++++++++++++ > > 2 files changed, 78 insertions(+), 4 deletions(-) > > create mode 100644 test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua > > > > diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c > > index e2171e1b..2702f79f 100644 > > --- a/src/lj_opt_fold.c > > +++ b/src/lj_opt_fold.c > > diff --git a/test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua b/test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua > > new file mode 100644 > > index 00000000..6cc0b319 > > --- /dev/null > > +++ b/test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua > > @@ -0,0 +1,74 @@ > > +local tap = require('tap') > > + > > +-- Test file to demonstrate LuaJIT misbehaviour on folding > > +-- for bitshift operations. > > +-- See also,https://github.com/LuaJIT/LuaJIT/issues/1079. > > + > > +local test = tap.test('lj-1079-fix-64-bitshift-folds'):skipcond({ > > + ['Test requires JIT enabled'] = not jit.status(), > > +}) > > + > > +local bit = require('bit') > > + > > +test:plan(4) > > + > > +-- Generic function for `bit.ror()`, `bit.rol()`. > > +local function bitop_rotation(bitop) > > I would rename arg `bitop` to `bitop_func` to highlight the type > > of the value. Renamed, see the iterational patch below. > > > + local r = {} > > + for i = 1, 4 do > > + -- (i & k1) o k2 ==> (i o k2) & (k1 o k2) > > + local int64 = bit.band(i, 7LL) > > + r[i] = tonumber(bitop(int64, 32)) > please add comments about magic constants here and below Added the corresponding comment. > > + end > > + return r > > +end > > + > > + > > +test:test('rol', test_64bitness, bitop_rotation, bit.rol) > > +test:test('ror', test_64bitness, bitop_rotation, bit.ror) > > +test:test('rshift signed', test_64bitness, bitop_rshift_signed) > > +test:test('rshift huge', test_64bitness, bitop_rshift_huge) > have you added additional whitespaces intentionally? Yes, I rearranged them a bit to avoid confusion. See the iterative patch below. =================================================================== diff --git a/test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua b/test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua index 6cc0b319..28383bf9 100644 --- a/test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua +++ b/test/tarantool-tests/lj-1079-fix-64-bitshift-folds.test.lua @@ -13,12 +13,15 @@ local bit = require('bit') test:plan(4) -- Generic function for `bit.ror()`, `bit.rol()`. -local function bitop_rotation(bitop) +local function bitop_rotation(bitop_func) local r = {} for i = 1, 4 do -- (i & k1) o k2 ==> (i o k2) & (k1 o k2) + -- XXX: Don't use named constants here to match folding rules. + -- `7LL` is just some mask, that doesn't change the `i` value. + -- `32` is used for the half bit-width rotation. local int64 = bit.band(i, 7LL) - r[i] = tonumber(bitop(int64, 32)) + r[i] = tonumber(bitop_func(int64, 32)) end return r end @@ -52,23 +55,23 @@ local function bitop_rshift_huge() return r end -local function test_64bitness(subtest, payload_func, bitop) +local function test_64bitness(subtest, payload_func, bitop_func) subtest:plan(1) jit.off() jit.flush() - local results_joff = payload_func(bitop) + local results_joff = payload_func(bitop_func) jit.on() -- Reset hotcounters. jit.opt.start('hotloop=1') - local results_jon = payload_func(bitop) + local results_jon = payload_func(bitop_func) subtest:is_deeply(results_jon, results_joff, 'same results for VM and JIT for ' .. subtest.name) end -test:test('rol', test_64bitness, bitop_rotation, bit.rol) -test:test('ror', test_64bitness, bitop_rotation, bit.ror) test:test('rshift signed', test_64bitness, bitop_rshift_signed) test:test('rshift huge', test_64bitness, bitop_rshift_huge) +test:test('rol', test_64bitness, bitop_rotation, bit.rol) +test:test('ror', test_64bitness, bitop_rotation, bit.ror) test:done(true) =================================================================== > > + > > +test:done(true) -- Best regards, Sergey Kaplun