lightning
[Top][All Lists]
Advanced

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

Re: Two entry points for a function


From: Paul Cercueil
Subject: Re: Two entry points for a function
Date: Mon, 08 Aug 2022 22:53:41 +0200

Hi Marc,

I don't think you can have multiple entry points of a function (or maybe with jit_indirect()?) but you can cheese things a bit with a trampoline.

Here's what I do, more or less:

----

jit_prolog();
jit_tramp(256);

for (i = 0; i < nb_entry_points; i++) {
   jit_addi(JIT_R0, 1);
   jit_align(8);
}

jit_epilog();
jit_prolog();

/* Read JIT_R0, its value give us what entry point was taken */

jit_epilog();

----

In that example my JIT_R0 is always 0 on entry. The jit_align() makes sure that each one of your entry points is aligned to 8 bytes. There is still some decoding needed (I read a C function pointer from a table at the index pointed by JIT_R0), but the decoding is done in that function and not in the callers.

Cheers,
-Paul

Le lun., août 8 2022 at 22:16:28 +0200, Marc Nieper-Wißkirchen <marc.nieper+gnu@gmail.com> a écrit :
I am looking for a way to implement a function (pointer) with GNU lightning that has two entry points.

In native assembly, I would code something like this:

        .align 16
entry1: jmp L0
        .align 16
entry2: ...
        ...
L0:     ...

The function would be represented by a pointer to entry1. If I wanted to jump to the second entry point, I would just add 16 to the pointer.

How can a similar thing be achieved with GNU lightning? So far, the best that has come to my mind is to use one more indirection. The "function pointer" points to a structure having the addresses of entry1 and entry2 as fields. (Let us assume we are in a trampoline so that the stack is already set up). But this is less efficient due to the extra indirection.

Is there a way to emulate the above native code with GNU lightning? And, if not, what would have to be added?

Marc





reply via email to

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