lightning
[Top][All Lists]
Advanced

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

Re: [PATCH] Document jit_align.


From: Marc Nieper-Wißkirchen
Subject: Re: [PATCH] Document jit_align.
Date: Fri, 12 Aug 2022 18:43:11 +0200



Am Fr., 12. Aug. 2022 um 16:49 Uhr schrieb Paulo César Pereira de Andrade <paulo.cesar.pereira.de.andrade@gmail.com>:
Em sex., 12 de ago. de 2022 às 10:45, Marc Nieper-Wißkirchen
<marc@nieper-wisskirchen.de> escreveu:

  Hi,

  Just commited it and a small change after it.

  The jit_align() interface was added indeed to align labels
(jump targets), but it might be useful on other uses, like the
one you presented, or if for some reason needs to add
embedded, and aligned, data to the code.
  Other uses of noops are internal. Like possibly misaligned
prolog in arm thumb mode, or implicit alignment of labels in
s390 and x86 backends.

Thanks!  I hope the constant of 16 was correct for all ports (i.e. for no port and for no instruction, lightning issues an alignment larger than 16).

Unfortunately, I have found one error in my example code.  In this line


`entry1` must be renamed to `forward`.  Could you correct it on occasion?

Thanks,

Marc

> * doc/body.texi: Add documentation for jit_align.
> ---
>  ChangeLog     |  5 +++++
>  doc/body.texi | 38 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
>
> diff --git a/ChangeLog b/ChangeLog
> index a842040..d18c8f8 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2022-08-12  Marc Nieper-Wißkirchen  <marc@nieper-wisskirchen.de>
> +
> +       Document jit_align.
> +       * doc/body.texi: Add documentation for jit_align.
> +
>  2022-05-14 Paulo Andrade <pcpa@gnu.org>
>
>         * include/lightning.h.in: Reorder jit_mov{n,z}r in instruction list.
> diff --git a/doc/body.texi b/doc/body.texi
> index c174fcf..677afd8 100644
> --- a/doc/body.texi
> +++ b/doc/body.texi
> @@ -597,6 +597,12 @@ forward   (not specified)                @r{forward label}
>  indirect  (not specified)                @r{special simple label}
>  @end example
>
> +The following instruction is used to specify a minimal alignment for a
> +label:
> +@example
> +align     (not specified)                @r{align code}
> +@end example
> +
>  @code{label} is normally used as @code{patch_at} argument for backward
>  jumps.
>
> @@ -649,6 +655,38 @@ that automatically binds the implicit label added by @code{patch} with
>  the @code{movi}, but on some special conditions it is required to create
>  an "unbound" label.
>
> +@code{align} is useful for creating multiple entry points to a
> +(trampoline) function that are all accessible through a single
> +function pointer.  @code{align} receives an integer argument that
> +defines the minimal alignment of the address of a label directly
> +following the @code{align} instruction.  The integer argument must be
> +a power of two and the effective alignment will be a power of two no
> +less than the argument to @code{align}.  If the argument to
> +@code{align} is 16 or more, the effective alignment will match the
> +specified minimal alignment exactly.
> +
> +@example
> +          jit_node_t *forward, *label1, *label2, jump;
> +          unsigned char *addr1, *addr2;
> +forward = jit_forward();
> +          jit_align(16);
> +label1  = jit_indirect();                @rem{/* first entry point */}
> +jump    = jit_jmpi();                    @rem{/* jump to first handler */}
> +          jit_patch_at(jump, entry1);
> +          jit_align(16);
> +label2  = jit_indirect();                @rem{/* second entry point */}
> +          ...                            @rem{/* second handler */}
> +          jit_jmpr(...);
> +          jit_link(forward);
> +          ...                            @rem{/* first handler /*}
> +          jit_jmpr(...);
> +          ...
> +          jit_emit();
> +          addr1 = jit_address(label1);
> +          addr2 = jit_address(label2);
> +          assert(addr2 - addr1 == 16);   @rem{/* only one of the addresses needs to be remembered */}
> +@end example
> +
>  @item Function prolog
>
>  These macros are used to set up a function prolog.  The @code{allocai}
> --
> 2.34.1
>
>

reply via email to

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