Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 3/5] ARM64: Fix pass-by-value struct calling conventions.
Date: Thu, 4 Jun 2026 13:05:52 +0300	[thread overview]
Message-ID: <aiFOAOz-rUfC5N8Y@root> (raw)
In-Reply-To: <bd7292be-1654-4e81-9f6d-9c2c41522683@tarantool.org>

Hi, Sergey!
Thanks for the review!
Fixed your comment and force-pushed the branch.

On 01.06.26, Sergey Bronnikov wrote:
> Hi, Sergey,
> 
> thanks for the patch! Please see my comments.
> 
> Sergey
> 
> On 5/30/26 19:04, Sergey Kaplun wrote:
> > From: Mike Pall <mike>

<snipped>

> > ---
> >   src/lj_ccall.c                                | 18 +++++++++++----
> >   test/tarantool-tests/ffi-ccall/CMakeLists.txt |  1 +
> >   test/tarantool-tests/ffi-ccall/libfficcall.c  | 12 ++++++++++
> >   ...57-arm64-struct-array-pass-by-val.test.lua | 23 +++++++++++++++++++
> >   4 files changed, 49 insertions(+), 5 deletions(-)
> >   create mode 100644 test/tarantool-tests/lj-1357-arm64-struct-array-pass-by-val.test.lua
> >
> > diff --git a/src/lj_ccall.c b/src/lj_ccall.c
> > index b2705de5..104c9d34 100644
> > --- a/src/lj_ccall.c
> > +++ b/src/lj_ccall.c
> > @@ -781,17 +781,24 @@ static unsigned int ccall_classify_struct(CTState *cts, CType *ct)
> >   {
> >     CTSize sz = ct->size;
> >     unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);
> > -  while (ct->sib) {
> > +  while (ct->sib && n <= 4) {
> 
> The patch adds a condition that strictly checks a number of elements 
> with the same type (n <= 4).

It just early return as for condition below.

> 
> I would also add a test for this with the following `n`: 3/4/5.

The n==3 is already checked in our tests. Do we need to test 5
specifically here? There are the similar tests for n > 4 in the next
commits as well.

> 
> > +    unsigned int m = 1;
> >       CType *sct;
> >       ct = ctype_get(cts, ct->sib);
> >       if (ctype_isfield(ct->info)) {
> >         sct = ctype_rawchild(cts, ct);
> > +      if (ctype_isarray(sct->info)) {
> > +	CType *cct = ctype_rawchild(cts, sct);
> > +	if (!cct->size) continue;
> > +	m = sct->size / cct->size;
> > +	sct = cct;
> > +      }
> >         if (ctype_isfp(sct->info)) {
> >   	r |= sct->size;
> > -	if (!isu) n++; else if (n == 0) n = 1;
> > +	if (!isu) n += m; else if (n < m) n = m;
> 
> The patch also touches a logic for unions (here and below), and it is 
> desired to test it as well.

Added the test for unions.

===================================================================
diff --git a/test/tarantool-tests/ffi-ccall/libfficcall.c b/test/tarantool-tests/ffi-ccall/libfficcall.c
index 60d30f3c..2145b556 100644
--- a/test/tarantool-tests/ffi-ccall/libfficcall.c
+++ b/test/tarantool-tests/ffi-ccall/libfficcall.c
@@ -94,6 +94,10 @@ typedef struct hfa_float2 {
 	float v[2];
 } hfa_float2;
 
+typedef union uhfa_float2 {
+	float v[2];
+} uhfa_float2;
+
 typedef struct hfa_float22 {
 	float v[2][2];
 } hfa_float22;
@@ -119,6 +123,11 @@ float hfa_float2_sum(hfa_float2 h)
 	return h.v[0] + h.v[1];
 }
 
+float uhfa_float2_sum(uhfa_float2 h)
+{
+	return h.v[0] + h.v[1];
+}
+
 float hfa_float22_sum(hfa_float22 h)
 {
 	return h.v[0][0] + h.v[0][1] + h.v[1][0] + h.v[1][1];
diff --git a/test/tarantool-tests/lj-1357-arm64-struct-array-pass-by-val.test.lua b/test/tarantool-tests/lj-1357-arm64-struct-array-pass-by-val.test.lua
index bb500de1..b67533cf 100644
--- a/test/tarantool-tests/lj-1357-arm64-struct-array-pass-by-val.test.lua
+++ b/test/tarantool-tests/lj-1357-arm64-struct-array-pass-by-val.test.lua
@@ -6,7 +6,7 @@ local tap = require('tap')
 -- See also: https://github.com/LuaJIT/LuaJIT/issues/1357.
 local test = tap.test('lj-1357-arm64-struct-array-pass-by-val')
 
-test:plan(1)
+test:plan(2)
 
 local ffi_ccall = ffi.load('libfficcall')
 
@@ -16,8 +16,15 @@ ffi.cdef[[
   } hfa_float2;
 
   float hfa_float2_sum(hfa_float2 h);
+
+  typedef union uhfa_float2 {
+    float v[2];
+  } uhfa_float2;
+
+  float uhfa_float2_sum(uhfa_float2 h);
 ]]
 
 test:is(ffi_ccall.hfa_float2_sum({{1, 2}}), 3, 'HFA float correct')
+test:is(ffi_ccall.uhfa_float2_sum({{1, 2}}), 3, 'union HFA float correct')
 
 test:done(true)
===================================================================

> 
> This change was not caught by our regression tests on Apple M2:
> 
> --- a/src/lj_ccall.c
> +++ b/src/lj_ccall.c
> @@ -742,7 +742,7 @@ static unsigned int ccall_classify_struct(CTState 
> *cts, CType *ct, CType *ctf)
>         sct = ctype_rawchild(cts, ct);
>         if (ctype_isfp(sct->info)) {
>          r |= sct->size;
> -       if (!isu) n++; else if (n == 0) n = 1;
> +       if (!isu) n--; else if (n == 0) n = 1;

This is weird, since it changes non-union behaviour.

>         } else if (ctype_iscomplex(sct->info)) {
>          r |= (sct->size >> 1);
>          if (!isu) n += 2; else if (n < 2) n = 2;
> 

<snipped>

-- 
Best regards,
Sergey Kaplun

  reply	other threads:[~2026-06-04 10:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-30 16:04 [Tarantool-patches] [PATCH luajit 0/5] Various FFI ABI calling conventions fixes Sergey Kaplun via Tarantool-patches
2026-05-30 16:04 ` [Tarantool-patches] [PATCH luajit 1/5] FFI: Unify stack setup for C calls in interpreter Sergey Kaplun via Tarantool-patches
2026-06-05 14:18   ` Sergey Bronnikov via Tarantool-patches
2026-05-30 16:04 ` [Tarantool-patches] [PATCH luajit 2/5] FFI/ARM64/OSX: Handle non-standard OSX C calling conventions Sergey Kaplun via Tarantool-patches
2026-06-01 11:40   ` Sergey Bronnikov via Tarantool-patches
2026-06-04  9:46     ` Sergey Kaplun via Tarantool-patches
2026-06-05 14:12       ` Sergey Bronnikov via Tarantool-patches
2026-05-30 16:04 ` [Tarantool-patches] [PATCH luajit 3/5] ARM64: Fix pass-by-value struct " Sergey Kaplun via Tarantool-patches
2026-06-01 12:27   ` Sergey Bronnikov via Tarantool-patches
2026-06-04 10:05     ` Sergey Kaplun via Tarantool-patches [this message]
2026-06-05 14:14       ` Sergey Bronnikov via Tarantool-patches
2026-05-30 16:04 ` [Tarantool-patches] [PATCH luajit 4/5] FFI: Various ABI and calling convention fixes Sergey Kaplun via Tarantool-patches
2026-06-01 13:02   ` Sergey Bronnikov via Tarantool-patches
2026-06-04 12:06     ` Sergey Kaplun via Tarantool-patches
2026-06-05 14:15       ` Sergey Bronnikov via Tarantool-patches
2026-05-30 16:04 ` [Tarantool-patches] [PATCH luajit 5/5] FFI/MacOS: Fix calling convention for enums Sergey Kaplun via Tarantool-patches
2026-06-01 13:07   ` Sergey Bronnikov via Tarantool-patches
2026-06-02 16:04 ` [Tarantool-patches] [PATCH luajit 0/5] Various FFI ABI calling conventions fixes Evgeniy Temirgaleev via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aiFOAOz-rUfC5N8Y@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 3/5] ARM64: Fix pass-by-value struct calling conventions.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox