lightning
[Top][All Lists]
Advanced

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

[PATCH] Document jit_align.


From: Marc Nieper-Wißkirchen
Subject: [PATCH] Document jit_align.
Date: Fri, 12 Aug 2022 13:41:24 +0200

* 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]