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 CEEAB6ECCC; Fri, 5 Jun 2026 15:49:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CEEAB6ECCC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1780663787; bh=bw8fct9hmmHl6B7h/FkO54wQZB9kJBGdcvgj9gXt8zk=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jznbbd7bxvcz8uneqVHKhZarg+G6tm+7tniuV3iXrWuCGUjM3H8QpozPnb1qwFVrp eB4CphIP4/9hI/ZS0g5w4d87t1nGepwwmZrHMB6oO19dUiF6JXXpPYTpFYO/Jbv9dt /I0QFOEIuH5tgsxJTK10yf2w9sYRjxLDJxtcmojc= Received: from send175.i.mail.ru (send175.i.mail.ru [95.163.59.14]) (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 D239E6ECCC for ; Fri, 5 Jun 2026 15:49:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D239E6ECCC Received: by exim-smtp-85dd497b6-jptbn with esmtpa (envelope-from ) id 1wVTzc-00000000DpJ-23OG; Fri, 05 Jun 2026 15:49:44 +0300 To: Sergey Bronnikov , Evgeniy Temirgaleev Date: Fri, 5 Jun 2026 15:49:09 +0300 Message-ID: <20260605124909.2709341-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9FAD06046D747065B404A9F3AEC84E3215DCC6686C3A5CB4E182A05F5380850403C96473DFCB520F43DE06ABAFEAF670516302A170D1556900CA858E3903BDE0D06C2FF732BBD157B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72E2D36A15E1833D8EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756660A56BB7F6F20B60834C44DD5B6D38F8E88D81CCF0615BF39C9D6CA15D2B8A08389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0DEC8C2C8BCD2534D8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B65FF0BFC5AEE34BE6CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE76D0F27F7E6A6C418731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5E06CCF8FA522BBF05002B1117B3ED696674A38171A511F38219207EC0A953D2C823CB91A9FED034534781492E4B8EEADC0A73878EBD0941BC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34C77DD89D51EBB774225B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659DC11DAC3E855BAC8F23B9F6C2F2C888CA323D1A3C7F1C0E26C0B11FDD864C4E78B24D92919A0D29EB8341EE9D5BE9A0ACD50FCE0E852B944C607CC3B348A42F5DB835C51971338E2C7CEAA0681F5848F4C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVRI2994ruhLUQACKiTKK/fE= X-DA7885C5: 178B9229F57482D3F255D290C0D534F9A5FBA79F6074CF3B0BDB2A8D45EFA5D27A1E4A499853635D5B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393520AF17B8A65FDE2ED5A513EDFC6E1B54906B1138BA96C864E9E19424AB6BAF4E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/1] x86/x64: Change ipairs_aux to match JIT backend behavior. 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" From: Mike Pall Thanks to Sergey Kaplun. (cherry picked from commit 64b1f10835acc18bf8923adf248dce4894867882) In the single-number VM, `ipairs_aux()` first adds the 1 to the given number and only after casts it to an integer. This leads to results different from Vanilla Lua 5.1 and inconsistent with JIT engine recording. This patch fixes it by casting the value to an integer before addition. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#12480 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1463-ipairs-aux-consistency Related issues: * https://github.com/LuaJIT/LuaJIT/issues/1463 * https://github.com/tarantool/tarantool/issues/12480 src/vm_x64.dasc | 8 ++--- src/vm_x86.dasc | 7 ++-- .../lj-1463-ipairs-aux-consistency.test.lua | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc index 6ac88d70..1bd3c855 100644 --- a/src/vm_x64.dasc +++ b/src/vm_x64.dasc @@ -1476,17 +1476,15 @@ static void build_subroutines(BuildCtx *ctx) | checkint RA, ->fff_fallback |.else | checknumtp [BASE+8], ->fff_fallback - | movsd xmm0, qword [BASE+8] + | cvttsd2si RAd, qword [BASE+8] |.endif | mov PC, [BASE-8] - |.if DUALNUM | add RAd, 1 + |.if DUALNUM | setint ITYPE, RA | mov [BASE-16], ITYPE |.else - | sseconst_1 xmm1, TMPR - | addsd xmm0, xmm1 - | cvttsd2si RAd, xmm0 + | cvtsi2sd xmm0, RAd | movsd qword [BASE-16], xmm0 |.endif | cmp RAd, TAB:RB->asize; jae >2 // Not in array part? diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index d9234f3b..dcfb0a8b 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc @@ -1853,10 +1853,9 @@ static void build_subroutines(BuildCtx *ctx) | mov dword [BASE-4], LJ_TISNUM | mov dword [BASE-8], RD |.else - | movsd xmm0, qword [BASE+8] - | sseconst_1 xmm1, RBa - | addsd xmm0, xmm1 - | cvttsd2si RD, xmm0 + | cvttsd2si RD, qword [BASE+8] + | add RD, 1 + | cvtsi2sd xmm0, RD | movsd qword [BASE-8], xmm0 |.endif | mov TAB:RB, [BASE] diff --git a/test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua b/test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua new file mode 100644 index 00000000..1da3a76e --- /dev/null +++ b/test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua @@ -0,0 +1,32 @@ +local tap = require('tap') + +-- The test file to demonstrate the inconsistent behaviour between +-- the JIT compiler and the VM for the `ipairs_aux()` function on +-- x86 and x86_64 arches. +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1463. + +local test = tap.test('lj-1463-ipairs-aux-consistency'):skipcond({ + ['Test requires JIT enabled'] = not jit.status(), +}) + +test:plan(4) + +jit.opt.start('hotloop=1') + +local ipairs_aux = ipairs({}) + +local rkeys = {} +local rvals = {} + +for i = 1, 4 do + local key, val = ipairs_aux({[0] = 0, [1] = 1}, -0.1) + rkeys[i] = key + rvals[i] = val +end + +test:is(rkeys[1], 1, 'correct key result') +test:is(rvals[1], 1, 'correct value result') +test:samevalues(rkeys, 'consistent JIT and VM behaviour for keys') +test:samevalues(rvals, 'consistent JIT and VM behaviour for values') + +test:done(true) -- 2.54.0