lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: returning two values (Linux AMD64)


From: Basile Starynkevitch
Subject: Re: returning two values (Linux AMD64)
Date: Sat, 21 Sep 2024 14:39:12 +0200

Hello all,
The x86-64 ABI conventions on Linux says that a function returning two word-values -e.g two pointers- have them passed in two processor registers.

You can check by compiling the below C function with optimizations (and GCC 14):

#include <stdint.h>
struct twost {
  void*x;
  intptr_t y;
};

struct twost f(void*xx, intptr_t yy) {
  struct twost r;
  r.x = xx;
  r.y = yy;
  return r;
}

which is compiled by gcc-14 -O2 -fverbose-asm -S test2.c into:

        .file   "test2.c"
# GNU C17 (Debian 14.2.0-3) version 14.2.0 (x86_64-linux-gnu)
#       compiled by GNU C version 14.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.27-GMP

# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
# options passed: -mtune=generic -march=x86-64 -O2 -fasynchronous-unwind-tables
        .text
        .p2align 4
        .globl  f
        .type   f, @function
f:
.LFB0:
        .cfi_startproc
# test2.c:12:   return r;
        movq    %rdi, %rax      # tmp103, D.2870
        movq    %rsi, %rdx      # tmp104, D.2870
# test2.c:13: }
        ret
        .cfi_endproc
.LFE0:
        .size   f, .-f
        .ident  "GCC: (Debian 14.2.0-3) 14.2.0"
        .section        .note.GNU-stack,"",@progbits

Observe that no stack allocated memory is returned.

We use this behavior in the RefPerSys open source (GPLv3+) inference engine project on http://refpersys.org/ and https://github.com/RefPerSys/RefPerSys/

My question is then how to generate the above function n GNU lightning without using stack allocated data?

Regards.

--
Basile STARYNKEVITCH
8 rue de la Faïencerie
92340 Bourg-la-Reine
France
email b.starynkevitch@gmail.com (and sometimes also basile@starynkevitch.net)

Le sam. 21 sept. 2024 à 13:47, Basile Starynkevitch <bstarynkevitch@gmail.com> a écrit :
Hello all,
The x86-64 ABI conventions on Linux says that a function returning two word-values -e.g two pointers- have them passed in two processor registers.

You can check by compiling the below C function with optimizations (and GCC 14):

#include <stdint.h>
struct twost {
  void*x;
  intptr_t y;
};

struct twost f(void*xx, intptr_t yy) {
  struct twost r;
  r.x = xx;
  r.y = yy;
  return r;
}

which is compiled by gcc-14 -O2 -fverbose-asm -S test2.c into:

        .file   "test2.c"
# GNU C17 (Debian 14.2.0-3) version 14.2.0 (x86_64-linux-gnu)
#       compiled by GNU C version 14.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.27-GMP

# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
# options passed: -mtune=generic -march=x86-64 -O2 -fasynchronous-unwind-tables
        .text
        .p2align 4
        .globl  f
        .type   f, @function
f:
.LFB0:
        .cfi_startproc
# test2.c:12:   return r;
        movq    %rdi, %rax      # tmp103, D.2870
        movq    %rsi, %rdx      # tmp104, D.2870
# test2.c:13: }
        ret
        .cfi_endproc
.LFE0:
        .size   f, .-f
        .ident  "GCC: (Debian 14.2.0-3) 14.2.0"
        .section        .note.GNU-stack,"",@progbits

Observe that no stack allocated memory is returned.

We use this behavior in the RefPerSys open source (GPLv3+) inference engine project on http://refpersys.org/ and https://github.com/RefPerSys/RefPerSys/

My question is then how to generate the above function n GNU lightning without using stack allocated data?

Regards.

--
Basile STARYNKEVITCH
8 rue de la Faïencerie
92340 Bourg-la-Reine
France
email b.starynkevitch@gmail.com (and sometimes also basile@starynkevitch.net)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]