<HTML><BODY><div class="cl-0g0xp602eo"><div>Hi, Sergey!</div><div> </div><div>Thanks for the patch!</div><div> </div><div>LGTM<br><br> </div><div data-signature-widget="container"><div data-signature-widget="content"><div>--<br>Best regards,</div><div>Evgeniy Temirgaleev</div></div></div><br><div class="mail-quote-collapse"><blockquote style="border-left:1px solid #0857A6;margin:10px;padding:0 0 0 10px"><span>From: Sergey Kaplun <<a href="mailto:skaplun@tarantool.org">skaplun@tarantool.org</a>><br>To: Sergey Bronnikov <<a href="mailto:sergeyb@tarantool.org">sergeyb@tarantool.org</a>>, Evgeniy Temirgaleev <<a href="mailto:e.temirgaleev@tarantool.org">e.temirgaleev@tarantool.org</a>><br>Cc: tarantool-patches@dev.tarantool.org, Sergey Kaplun <<a href="mailto:skaplun@tarantool.org">skaplun@tarantool.org</a>><br>Date: Friday, June 5, 2026 3:49 PM +03:00</span><br> <div><div id=""><div class="cl-6is03gh8lk"><div class="js-helper_mr_css_attr js-readmsg-msg_mr_css_attr"><div id="style_17806637850476802815_mr_css_attr"><div id="style_17806637850476802815_BODY_mr_css_attr">From: Mike Pall <mike><br><br>Thanks to Sergey Kaplun.<br><br>(cherry picked from commit 64b1f10835acc18bf8923adf248dce4894867882)<br><br>In the single-number VM, `ipairs_aux()` first adds the 1 to the given<br>number and only after casts it to an integer. This leads to results<br>different from Vanilla Lua 5.1 and inconsistent with JIT engine<br>recording.<br><br>This patch fixes it by casting the value to an integer before addition.<br><br>Sergey Kaplun:<br>* added the description and the test for the problem<br><br>Part of tarantool/tarantool#12480<br>---<br><br>Branch: <a href="https://github.com/tarantool/luajit/tree/skaplun/lj-1463-ipairs-aux-consistency">https://github.com/tarantool/luajit/tree/skaplun/lj-1463-ipairs-aux-consistency</a><br>Related issues:<br>* <a href="https://github.com/LuaJIT/LuaJIT/issues/1463">https://github.com/LuaJIT/LuaJIT/issues/1463</a><br>* <a href="https://github.com/tarantool/tarantool/issues/12480">https://github.com/tarantool/tarantool/issues/12480</a><br><br>src/vm_x64.dasc | 8 ++---<br>src/vm_x86.dasc | 7 ++--<br>.../lj-1463-ipairs-aux-consistency.test.lua | 32 +++++++++++++++++++<br>3 files changed, 38 insertions(+), 9 deletions(-)<br>create mode 100644 test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua<br><br>diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc<br>index 6ac88d70..1bd3c855 100644<br>--- a/src/vm_x64.dasc<br>+++ b/src/vm_x64.dasc<br>@@ -1476,17 +1476,15 @@ static void build_subroutines(BuildCtx *ctx)<br>| checkint RA, ->fff_fallback<br>|.else<br>| checknumtp [BASE+8], ->fff_fallback<br>- | movsd xmm0, qword [BASE+8]<br>+ | cvttsd2si RAd, qword [BASE+8]<br>|.endif<br>| mov PC, [BASE-8]<br>- |.if DUALNUM<br>| add RAd, 1<br>+ |.if DUALNUM<br>| setint ITYPE, RA<br>| mov [BASE-16], ITYPE<br>|.else<br>- | sseconst_1 xmm1, TMPR<br>- | addsd xmm0, xmm1<br>- | cvttsd2si RAd, xmm0<br>+ | cvtsi2sd xmm0, RAd<br>| movsd qword [BASE-16], xmm0<br>|.endif<br>| cmp RAd, TAB:RB->asize; jae >2 // Not in array part?<br>diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc<br>index d9234f3b..dcfb0a8b 100644<br>--- a/src/vm_x86.dasc<br>+++ b/src/vm_x86.dasc<br>@@ -1853,10 +1853,9 @@ static void build_subroutines(BuildCtx *ctx)<br>| mov dword [BASE-4], LJ_TISNUM<br>| mov dword [BASE-8], RD<br>|.else<br>- | movsd xmm0, qword [BASE+8]<br>- | sseconst_1 xmm1, RBa<br>- | addsd xmm0, xmm1<br>- | cvttsd2si RD, xmm0<br>+ | cvttsd2si RD, qword [BASE+8]<br>+ | add RD, 1<br>+ | cvtsi2sd xmm0, RD<br>| movsd qword [BASE-8], xmm0<br>|.endif<br>| mov TAB:RB, [BASE]<br>diff --git a/test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua b/test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua<br>new file mode 100644<br>index 00000000..1da3a76e<br>--- /dev/null<br>+++ b/test/tarantool-tests/lj-1463-ipairs-aux-consistency.test.lua<br>@@ -0,0 +1,32 @@<br>+local tap = require('tap')<br>+<br>+-- The test file to demonstrate the inconsistent behaviour between<br>+-- the JIT compiler and the VM for the `ipairs_aux()` function on<br>+-- x86 and x86_64 arches.<br>+-- See also: <a href="https://github.com/LuaJIT/LuaJIT/issues/1463">https://github.com/LuaJIT/LuaJIT/issues/1463</a>.<br>+<br>+local test = tap.test('lj-1463-ipairs-aux-consistency'):skipcond({<br>+ ['Test requires JIT enabled'] = not jit.status(),<br>+})<br>+<br>+test:plan(4)<br>+<br>+jit.opt.start('hotloop=1')<br>+<br>+local ipairs_aux = ipairs({})<br>+<br>+local rkeys = {}<br>+local rvals = {}<br>+<br>+for i = 1, 4 do<br>+ local key, val = ipairs_aux({[0] = 0, [1] = 1}, -0.1)<br>+ rkeys[i] = key<br>+ rvals[i] = val<br>+end<br>+<br>+test:is(rkeys[1], 1, 'correct key result')<br>+test:is(rvals[1], 1, 'correct value result')<br>+test:samevalues(rkeys, 'consistent JIT and VM behaviour for keys')<br>+test:samevalues(rvals, 'consistent JIT and VM behaviour for values')<br>+<br>+test:done(true)<br>--<br>2.54.0</div></div></div></div></div></div></blockquote></div></div></BODY></HTML>