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 453386EFF6; Fri, 5 Jun 2026 18:14:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 453386EFF6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1780672493; bh=8VMBgxc1qQ8mXWWht7Iklk5stkxonS5nQyDAmULN2g8=; 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=l4iNxvPrTavZ3+sL+9s7LAAVs8byJ6T1ovUutmDp9X/mrKPy84HEJEEFtVTQPvMT4 /ZMqsEURJbj/AkAQv31FWWxppBn7FAfYN/ytT9lFBRHhscfzqbcAF3pD1ep9TAtTYT FLVmB/fWl9+uMJMq6kXFlBK/JTC+FJJ90X+zD8R4= Received: from send81.i.mail.ru (send81.i.mail.ru [89.221.237.176]) (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 993356EFF6 for ; Fri, 5 Jun 2026 18:14:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 993356EFF6 Received: by exim-smtp-85dd497b6-plzt7 with esmtpa (envelope-from ) id 1wVWG2-00000000IEO-2VRl; Fri, 05 Jun 2026 18:14:51 +0300 Content-Type: multipart/alternative; boundary="------------9ZfXP6SytcWx83XyIX1RiG3s" Message-ID: <580f113a-a176-4b57-a81a-4bcf105f6876@tarantool.org> Date: Fri, 5 Jun 2026 18:14:49 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Evgeniy Temirgaleev Cc: tarantool-patches@dev.tarantool.org References: <20260605124909.2709341-1-skaplun@tarantool.org> In-Reply-To: <20260605124909.2709341-1-skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9FAD06046D747065BA79DE29C7F6902231ABDD09BBCC3CDE2182A05F5380850405807C22F25D8192A3DE06ABAFEAF6705092F1CE4A660478A6F09AD58D3BD14387351BD83221AC723 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F35A5D86BDFCC4EDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756660A56BB7F6F20B603805C4414F8100BDA53BC7BCB783BDF2FF9F7838C0543533389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B652D31B9D28593E51CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE78DD9044B304389D4731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5F62CC1C501D58A205002B1117B3ED696FC6101DBD0A9633DD57BAD45EC4C5DE1823CB91A9FED034534781492E4B8EEAD14747542773C033FBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D65909B8B3E93B1FA5A46C9C88A6E1759688F96F18F095720DFF6B917A885919B1AD9F18370958D9DA84B8341EE9D5BE9A0A9273F6FB4004FB34FB17E9D2AD9E5FA3ADEEB2532D4F3B786536EB022892E5344C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVRI2994ruhLUFZ/xhKqAGyY= X-DA7885C5: DBDED8D57F681254F255D290C0D534F9277AF0199B61D8237EAB34242B877C3B50ACB86BF9BB25505B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393520AF17B8A65FDE27745046381B42EBF5660EFEE07C4FA2D59299812EADF8457EF86D5F70DA33880E41E8EF7A07863ECB274557F927329BE2DDF8182D28ACDB545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [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 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. --------------9ZfXP6SytcWx83XyIX1RiG3s Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey, thanks for the patch! LGTM with a minor comment(s). Sergey On 6/5/26 15:49, Sergey Kaplun wrote: > 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 s/Vanilla/PUC Rio/ feel free to ignore > 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 > | movTAB: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) --------------9ZfXP6SytcWx83XyIX1RiG3s Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey,

thanks for the patch! LGTM with a minor comment(s).

Sergey

On 6/5/26 15:49, Sergey Kaplun wrote:
From: Mike Pall <mike>

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

s/Vanilla/PUC Rio/

feel free to ignore

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)
--------------9ZfXP6SytcWx83XyIX1RiG3s--