[Tarantool-patches] [PATCH luajit 1/2] ARM64: Make tobit conversions match JIT backend behavior.

Sergey Kaplun skaplun at tarantool.org
Wed Jul 29 10:31:49 MSK 2026


Hi, Evgeniy!
Thanks for the review.
Please consider my answers below.

On 28.07.26, Evgeniy Temirgaleev wrote:
> Hi, Sergey! Thanks for the patch!
> 
> LGTM with a comment, please see below.
> 
> --
> Best regards,
> Evgeniy Temirgaleev
> 
> > 
> > From: Sergey Kaplun <skaplun at tarantool.org>
> > To: Sergey Bronnikov <sergeyb at tarantool.org>, Evgeniy Temirgaleev <e.temirgaleev at tarantool.org
> > >
> > Cc: tarantool-patches at dev.tarantool.org, Sergey Kaplun <skaplun at tarantool.org
> > >
> > Date: Tuesday, July 21, 2026 5:53 PM +03:00
> > From: Mike Pall <mike>
> > 
> > Thanks to Peter Cawley.
> > 
> > (cherry picked from commit cdc2db3aeac442e139c3b1fda715fdfa78da8791)
> > 
> > On the aarch64 architecture, the `tobit()` function incorrectly
> > truncates instead of rounding to the nearest integer. This leads to
> > inconsistency between various VMs (comparing to x86/x64, for example)
> > and between the arm64 VM and JIT.
> > 
> > This patch uses an addition of 2^52 + 2^51 constant to the given
> > argument to convert it to the nearest integer value. After reading the
> > lowest 32 bits of the register, we get the expected result.
> > 
> > Sergey Kaplun:
> > * added the description and the test for the problem
> > 
> > Part of tarantool/tarantool#12880
> > ---
> > src/vm_arm64.dasc | 20 ++++---------
> > .../lj-1253-tobit-conversion.test.lua | 28 +++++++++++++++++++
> > 2 files changed, 34 insertions(+), 14 deletions(-)
> > create mode 100644 test/tarantool-tests/lj-1253-tobit-conversion.test.lua
> > 
> > diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
> > index 57131140..4ffd7378 100644
> > --- a/src/vm_arm64.dasc
> > +++ b/src/vm_arm64.dasc

<snipped>

> > diff --git a/test/tarantool-tests/lj-1253-tobit-conversion.test.lua
> > b/test/tarantool-tests/lj-1253-tobit-conversion.test.lua
> > new file mode 100644
> > index 00000000..31cf97ca
> > --- /dev/null
> > +++ b/test/tarantool-tests/lj-1253-tobit-conversion.test.lua
> > @@ -0,0 +1,28 @@
> > +local tap = require('tap')
> > +
> > +-- Test file to demonstrate LuaJIT's incorrect bit.tobit
> > +-- behaviour for arm64.
> > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1253.
> > +
> > +local test = tap.test('lj-1253-tobit-conversion')
> > +
> > +test:plan(2)
> > +
> > +test:is(bit.tobit(1.7), 2, 'correct bit.tobit rounding')
> > 
> 
> I suppose, what Sergey Bronnikov proposes adding parentheses in the messages also. Here,

Maybe, but we use parentheses only in the comments AFAICS:

| grep "test:\(ok\|is\|match\|samevalues\).*'.*\`" -R test/tarantool-tests/ | wc -l
| 0

And there are examples of mentioning the functions in the test names:
| test/tarantool-tests/lj-928-int-min-negation.test.lua:test:is(tonumber('-0x80000000'), INT32_MIN, 'no UB during strscan_hex')
| test/tarantool-tests/lj-928-int-min-negation.test.lua:test:is(tonumber('-0b10000000000000000000000000000000'), INT32_MIN,
| test/tarantool-tests/lj-928-int-min-negation.test.lua:test:is(tonumber('-2147483648'), INT32_MIN, 'no UB during strscan_scan')


So, this part is ignored.

> > 
> > +
> > +test:skipcond({
> > + ['Test requires JIT enabled'] = not jit.status(),
> > +})
> > +
> > +local results = {}
> > +
> > +jit.opt.start('hotloop=1')
> > +
> > +for i = 1, 4 do
> > + -- Use constants on trace.
> > + results[i] = bit.tobit(1.7)
> > +end
> > +
> > +test:samevalues(results, 'consistent JIT and VM behaviour for bit.tobit')
> > 
> > 
> 
> and here.

Ditto.

> 
> > 
> > +
> > +test:done(true)
> > --
> > 2.55.0
> >

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list