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 E87B21463B15; Mon, 30 Jun 2025 10:26:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E87B21463B15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1751268385; bh=QnY0COvLkZORa8BeIycXKKmKyG/eay1V9ZHSdGy5vUk=; 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=mEhQ8qj9KZDiF9m1xu1lfmK8hKc1IiDLwt96SF6yU51eI/8xtBhh6pGR6R4old8fa UsnpxklSw7i1ygeoh3TbSApwhZjp/bFP6HDhZPk3t2F317saXt3Y9tVtnP9qsT6n55 iUD8Ph40FBeTOmHNtHmmrkvqWArnEyQux1SXKNEo= Received: from send103.i.mail.ru (send103.i.mail.ru [89.221.237.198]) (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 4AFE94A0C60 for ; Mon, 30 Jun 2025 10:26:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4AFE94A0C60 Received: by exim-smtp-666595b4bd-6n7b4 with esmtpa (envelope-from ) id 1uW8uE-0000000022J-14JW; Mon, 30 Jun 2025 10:26:22 +0300 Date: Mon, 30 Jun 2025 10:26:24 +0300 To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Message-ID: References: <20250626151224.27925-1-skaplun@tarantool.org> <63170032-dc7a-47e4-ad84-9627a02070e0@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <63170032-dc7a-47e4-ad84-9627a02070e0@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D919194CF4FC6604D62D9DA84B4DAEB1B9E7091CC8A9919700894C459B0CD1B9B3B9416C62118F55F378A8CA21F699D654C6B99B8F9E756862864A97FA8BBF4335AA1534FA60CA86 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75AD53DF1D86BACA3EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566560991A0683723AB17AEEC098B7608D1883A8629BD410221F3C8F986AC2C740B389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0A3E989B1926288338941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166176DF2183F8FC7C04E672349037D5FA5725E5C173C3A84C337FDC682149C2B9D35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5B1680B25D32D6EC25002B1117B3ED69674F36E8155C7235C1A1B8FE1FED62FE8823CB91A9FED034534781492E4B8EEADDFC043C56F70D752BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D340297C696F996E384F12F192FE1140CC07EAFC2FC6360270426AA0265652867936FEA9167E5882AB31D7E09C32AA3244C1EAD9C693D05023B77DD89D51EBB77427BC993495AB370AAEA455F16B58544A2E30DDF7C44BCB90DA5AE236DF995FB59829709634694AABAED6A17656DB59BCAD427812AF56FC65B X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVV45pMz5J5bNs1W2rPXOHjg= X-DA7885C5: 8B7FDFB3F31DCE3FF255D290C0D534F9C477DF17D403D05F665F3893F7DDF4D0BC85931C84AA20345B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393FE9E42A757851DB66BCE8DD91227A09FDE94D1B4A0C61E21DA7F32D1B28BA0A1E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] ARM64: Fix LDP/STP fusing for unaligned accesses. 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 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 27.06.25, Sergey Bronnikov wrote: > Hi, Sergey, > > thanks for the patch! LGTM with a minor two comments below. > > Sergey > > On 6/26/25 18:12, Sergey Kaplun wrote: > > From: Mike Pall > > > > Thanks to Peter Cawley. > > > > (cherry picked from commit 0fa2f1cbcf023ad0549f1428809e506fa2c78552) > > > > The arm64 emitting of load/store operation works incorrectly in the > > case when at least one offset of load/store to be fused into ldp/stp is > > misaligned. In this case this misaligning is ignored, and instructions > > are fused, which leads to loading/storing from/to at least one incorrect > > address. > > > > For example, the following instructions: > > | stur w0, [x1, #17] > > | stur w0, [x1, #21] > > > > May be fused to the following: > > | stp w0, w0, [x1, #16] > > > > This patch prevents fusion in this case by testing the alignment with > > the help of bitwise ROR by the alignment value. In case of misaligned > > offset, the value overflows the 7-bit length mask in the check. > > > > The negative immediate (7-bit width including sign bit) is limited by > > the corresponding addition of `64 << sc` (it is harmless in the case of > > positive values). > > > > Sergey Kaplun: > > * added the description and the test for the problem > > > > Part of tarantool/tarantool#11278 > > --- > > > > Related issues: > > *https://github.com/LuaJIT/LuaJIT/issues/1056 > > *https://github.com/tarantool/tarantool/issues/11278 > > Branch:https://github.com/tarantool/luajit/tree/skaplun/lj-1056-arm64-ldp-sdp-misaligned-fusing > > > > src/lj_emit_arm64.h | 2 +- > > ...6-arm64-ldp-sdp-misaligned-fusing.test.lua | 98 +++++++++++++++++++ > > 2 files changed, 99 insertions(+), 1 deletion(-) > > create mode 100644 test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua > > > > diff --git a/src/lj_emit_arm64.h b/src/lj_emit_arm64.h > > index 30cd3505..5c1bc372 100644 > > --- a/src/lj_emit_arm64.h > > +++ b/src/lj_emit_arm64.h > > diff --git a/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua b/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua > > new file mode 100644 > > index 00000000..5d03097e > > --- /dev/null > > +++ b/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua > > @@ -0,0 +1,98 @@ > > +local tap = require('tap') > > +local ffi = require('ffi') > > + > > +-- This test demonstrates LuaJIT's incorrect emitting of LDP/STP > > +-- instructions from LDUR/STUR instructions with misaligned offset > > +-- on arm64. > > +-- See alsohttps://github.com/LuaJIT/LuaJIT/issue/1056. > s/issue/issues/ Fixed, thanks! =================================================================== diff --git a/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua b/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua index 815da15d..5ff040e7 100644 --- a/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua +++ b/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua @@ -4,7 +4,7 @@ local ffi = require('ffi') -- This test demonstrates LuaJIT's incorrect emitting of LDP/STP -- instructions from LDUR/STUR instructions with misaligned offset -- on arm64. --- See also https://github.com/LuaJIT/LuaJIT/issue/1056. +-- See also https://github.com/LuaJIT/LuaJIT/issues/1056. local test = tap.test('lj-1056-arm64-ldp-sdp-misaligned-fusing'):skipcond({ ['Test requires JIT enabled'] = not jit.status(), }) =================================================================== > > +local test = tap.test('lj-1056-arm64-ldp-sdp-misaligned-fusing'):skipcond({ > > + ['Test requires JIT enabled'] = not jit.status(), > > +}) > > + > > + > > +test:is(resl, 0x4030201, 'pair of misaligned loads, left') > > +test:is(resr, 0x8070605, 'pair of misaligned loads, right') > > What does mean these magic numbers? Please add a comment or > > use a variable with self-explained name. Here and below. Added the comments nearby, see the corresponding patch below: =================================================================== diff --git a/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua b/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua index 5d03097e..815da15d 100644 --- a/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua +++ b/test/tarantool-tests/lj-1056-arm64-ldp-sdp-misaligned-fusing.test.lua @@ -81,6 +81,8 @@ for _ = 1, N_ITERATIONS do resr = ffi.cast('int32_t *', ptr + 5)[0] end +-- Values are resulted from the `init_buf()` function with the +-- corresponding offset. test:is(resl, 0x4030201, 'pair of misaligned loads, left') test:is(resr, 0x8070605, 'pair of misaligned loads, right') @@ -92,6 +94,8 @@ for _ = 1, N_ITERATIONS do resl = ffi.cast('int32_t *', ptr)[0] end +-- Values are resulted from the `init_buf()` function with the +-- corresponding offset. test:is(resl, 0x3020100, 'aligned / misaligned load, aligned') test:is(resr, 0x8070605, 'aligned / misaligned load, misaligned') =================================================================== -- Best regards, Sergey Kaplun