git subrepo pull --force deps/lightning
authorPaul Cercueil <paul@crapouillou.net>
Sun, 29 May 2022 11:48:50 +0000 (12:48 +0100)
committerPaul Cercueil <paul@crapouillou.net>
Mon, 30 May 2022 17:26:10 +0000 (18:26 +0100)
subrepo:
  subdir:   "deps/lightning"
  merged:   "2a199e4d"
upstream:
  origin:   "https://github.com/pcercuei/gnu_lightning.git"
  branch:   "pcsx_rearmed"
  commit:   "2a199e4d"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

54 files changed:
deps/lightning/.gitignore
deps/lightning/.gitrepo
deps/lightning/ChangeLog
deps/lightning/README
deps/lightning/README-hacking
deps/lightning/check/.gitignore [new file with mode: 0644]
deps/lightning/check/Makefile.am
deps/lightning/check/bswap.ok [new file with mode: 0644]
deps/lightning/check/bswap.tst [new file with mode: 0644]
deps/lightning/check/lightning.c
deps/lightning/configure.ac
deps/lightning/doc/.gitignore
deps/lightning/doc/body.texi
deps/lightning/include/lightning.h.in
deps/lightning/include/lightning/jit_private.h
deps/lightning/lib/jit_aarch64-cpu.c
deps/lightning/lib/jit_aarch64-sz.c
deps/lightning/lib/jit_aarch64.c
deps/lightning/lib/jit_alpha-cpu.c
deps/lightning/lib/jit_alpha-sz.c
deps/lightning/lib/jit_alpha.c
deps/lightning/lib/jit_arm-cpu.c
deps/lightning/lib/jit_arm-sz.c
deps/lightning/lib/jit_arm.c
deps/lightning/lib/jit_disasm.c
deps/lightning/lib/jit_hppa-cpu.c
deps/lightning/lib/jit_hppa-sz.c
deps/lightning/lib/jit_hppa.c
deps/lightning/lib/jit_ia64-cpu.c
deps/lightning/lib/jit_ia64-sz.c
deps/lightning/lib/jit_ia64.c
deps/lightning/lib/jit_memory.c
deps/lightning/lib/jit_mips-cpu.c
deps/lightning/lib/jit_mips-sz.c
deps/lightning/lib/jit_mips.c
deps/lightning/lib/jit_names.c
deps/lightning/lib/jit_ppc-cpu.c
deps/lightning/lib/jit_ppc-fpu.c
deps/lightning/lib/jit_ppc-sz.c
deps/lightning/lib/jit_ppc.c
deps/lightning/lib/jit_print.c
deps/lightning/lib/jit_riscv-cpu.c
deps/lightning/lib/jit_riscv-sz.c
deps/lightning/lib/jit_riscv.c
deps/lightning/lib/jit_s390-cpu.c
deps/lightning/lib/jit_s390-sz.c
deps/lightning/lib/jit_s390.c
deps/lightning/lib/jit_sparc-cpu.c
deps/lightning/lib/jit_sparc-sz.c
deps/lightning/lib/jit_sparc.c
deps/lightning/lib/jit_x86-cpu.c
deps/lightning/lib/jit_x86-sz.c
deps/lightning/lib/jit_x86.c
deps/lightning/lib/lightning.c

index 62ca42a..6fc5bf9 100644 (file)
@@ -1,4 +1,14 @@
 +*
+
+*.o
+*.lo
+*.la
+
+.libs/
+.deps/
+*/.libs/
+*/.deps/
+
 autom4te.cache
 aclocal.m4
 depcomp
@@ -20,14 +30,14 @@ missing
 size
 stamp-h1
 test-driver
-check/.deps
-doc/.deps
-lib/.deps
+
 m4/libtool.m4
 m4/lt~obsolete.m4
 m4/ltoptions.m4
 m4/ltsugar.m4
 m4/ltversion.m4
-doc/mdate-sh
-doc/texinfo.tex
+
 lightning.pc
+include/lightning.h
+
+build-aux/
index f0ed7b5..05d58f3 100644 (file)
@@ -6,7 +6,7 @@
 [subrepo]
        remote = https://github.com/pcercuei/gnu_lightning.git
        branch = pcsx_rearmed
-       commit = 6f101bf8eccef737d60bf7e6ba85558db49e7908
-       parent = 02dbc8694f303728f19734328166a1c6dfef289c
+       commit = 2a199e4d3cb250a76bd91f42eaf56f6233d34663
+       parent = db4140baf19c727fa1a705236130edfc6f363ce0
        method = merge
        cmdver = 0.4.3
index 9964207..a842040 100644 (file)
@@ -1,3 +1,24 @@
+2022-05-14 Paulo Andrade <pcpa@gnu.org>
+
+       * include/lightning.h.in: Reorder jit_mov{n,z}r in instruction list.
+       * lib/jit_alpha.c, lib/jit_alpha-cpu.c, lib/jit_hppa.c,
+       lib/jit_hppa-cpu.c, lib/jit_ia64.c, lib/jit_ia64-cpu.c,
+       lib/jit_riscv.c, lib/jit_riscv-cpu.c, lib/jit_s390.c,
+       lib/jit_s390-cpu.c, lib/jit_sparc.c, lib/jit_sparc-cpu.c:
+       Implement fallback jit_mov{n,z}r. These are a somewhat cheap
+       implementation, but should be reviewed for the arches that already
+       have a proper conditional move.
+       * lib/jit_arm-sz.c, lib/jit_mips-sz.c: Add missing maximum size
+       estimative and reorder.
+       * lib/jit_aarch64-sz.c, lib/jit_x86-sz.c, lib/jit_ppc-sz.c:
+       Reorder entry to match definition order.
+       * lib/jit_aarch64-sz.c, lib/jit_alpha-sz.c, lib/jit_hppa-sz.c,
+       lib/jit_ia64-sz.c, lib/jit_riscv-sz.c, lib/jit_s390-sz.c,
+       lib/jit_sparc-sz.c: Add heuristic value, basically the sum of
+       the cost of a movr + beqr.
+       * lib/jit_names.c: Add entries for debug output of mov{n,z}r.
+       * lib/lightning.c: Use proper bitmask in jit_classify.
+
 2021-04-03  Marc Nieper-Wißkirchen  <marc@nieper-wisskirchen.de>
 
        * check/Makefile.am: Add test for the live instruction.
index ae36ea5..7e3df42 100644 (file)
@@ -1,3 +1,5 @@
 GNU lightning is a library to aid in making portable programs
 that compile assembly code at run time.  For more information,
 look at the info documentation.
+
+For help building lightning, see README-hacking.
index 285f3c9..cc61598 100644 (file)
@@ -22,6 +22,12 @@ for Debian-based systems such as Ubuntu:
 
 ** Building
 
+If you intend to do development work with lightning, it's useful to build
+lightning with its disassembler feature enabled.  This optional feature
+requires additional dependencies.  On Ubuntu, this command should work:
+
+    $ sudo apt-get install binutils-dev libiberty-dev zlib1g-dev
+
 After getting the git sources, and installing the tools above, you can run
 
     $ ./bootstrap
@@ -38,6 +44,10 @@ should output no difference.
 
 After that first time, running make should suffice.
 
+To install lightning:
+
+    $ sudo make install
+
 ** Gnulib
 
 This distribution also uses Gnulib (https://www.gnu.org/software/gnulib) to
diff --git a/deps/lightning/check/.gitignore b/deps/lightning/check/.gitignore
new file mode 100644 (file)
index 0000000..a0047bb
--- /dev/null
@@ -0,0 +1,65 @@
+*.nodata
+nodata
+*.log
+*.trs
+
+3to2
+bswap
+add
+align
+allocai
+allocar
+alu_add
+alu_and
+alu_com
+alu_div
+alu_lsh
+alu_mul
+alu_neg
+alu_or
+alu_rem
+alu_rsb
+alu_rsh
+alu_sub
+alu_xor
+alux_add
+alux_sub
+bp
+branch
+call
+carg
+carry
+ccall
+clobber
+ctramp
+cva_list
+cvt
+divi
+fib
+float
+fop_abs
+fop_sqrt
+hton
+jmpr
+ldsti
+ldstr
+ldstr-c
+ldstxi
+ldstxi-c
+ldstxr
+ldstxr-c
+lightning
+live
+put
+qalu_div
+qalu_mul
+range
+ranger
+ret
+rpn
+self
+setcode
+stack
+tramp
+va_list
+varargs
index f1155d7..fc9f232 100644 (file)
@@ -65,6 +65,7 @@ EXTRA_DIST =                          \
        ldstxi-c.tst    ldstxi-c.ok     \
        cvt.tst         cvt.ok          \
        hton.tst        hton.ok         \
+       bswap.tst       bswap.ok        \
        branch.tst      branch.ok       \
        alu.inc                         \
        alu_add.tst     alu_add.ok      \
@@ -117,7 +118,7 @@ base_TESTS =                                \
        ldstr ldsti                     \
        ldstxr ldstxi                   \
        ldstr-c ldstxr-c ldstxi-c       \
-       cvt hton branch                 \
+       cvt hton bswap branch           \
        alu_add alux_add                \
        alu_sub alux_sub alu_rsb        \
        alu_mul alu_div alu_rem         \
@@ -196,7 +197,7 @@ arm_TESTS =                                 \
        rpn.arm ldstr.arm ldsti.arm             \
        ldstxr.arm ldstxi.arm                   \
        ldstr-c.arm ldstxr-c.arm ldstxi-c.arm   \
-       cvt.arm hton.arm branch.arm             \
+       cvt.arm hton.arm bswap.arm branch.arm   \
        alu_add.arm alux_add.arm                \
        alu_sub.arm alux_sub.arm alu_rsb.arm    \
        alu_mul.arm alu_div.arm alu_rem.arm     \
@@ -222,7 +223,7 @@ swf_TESTS =                                 \
        rpn.swf ldstr.swf ldsti.swf             \
        ldstxr.swf ldstxi.swf                   \
        ldstr-c.swf ldstxr-c.swf ldstxi-c.swf   \
-       cvt.swf hton.swf branch.swf             \
+       cvt.swf hton.swf bswap.swf branch.swf   \
        alu_add.swf alux_add.swf                \
        alu_sub.swf alux_sub.swf alu_rsb.swf    \
        alu_mul.swf alu_div.swf alu_rem.swf     \
@@ -246,7 +247,7 @@ arm_swf_TESTS =                                                     \
        rpn.arm.swf ldstr.arm.swf ldsti.arm.swf                 \
        ldstxr.arm.swf ldstxi.arm.swf                           \
        ldstr-c.arm.swf ldstxr-c.arm.swf ldstxi-c.arm.swf       \
-       cvt.arm.swf hton.arm.swf branch.arm.swf                 \
+       cvt.arm.swf hton.arm.swf bswap.arm.swf branch.arm.swf   \
        alu_add.arm.swf alux_add.arm.swf                        \
        alu_sub.arm.swf alux_sub.arm.swf alu_rsb.arm.swf        \
        alu_mul.arm.swf alu_div.arm.swf alu_rem.arm.swf         \
@@ -271,8 +272,8 @@ arm4_swf_TESTS =                                            \
        rpn.arm4.swf ldstr.arm4.swf ldsti.arm4.swf              \
        ldstxr.arm4.swf ldstxi.arm4.swf                         \
        ldstr-c.arm4.swf ldstxr-c.arm4.swf ldstxi-c.arm4.swf    \
-       cvt.arm4.swf hton.arm4.swf branch.arm4.swf              \
-       alu_add.arm4.swf alux_add.arm4.swf                      \
+       cvt.arm4.swf hton.arm4.swf bswap.arm4.swf               \
+       branch.arm4.swf alu_add.arm4.swf alux_add.arm4.swf      \
        alu_sub.arm4.swf alux_sub.arm4.swf alu_rsb.arm4.swf     \
        alu_mul.arm4.swf alu_div.arm4.swf alu_rem.arm4.swf      \
        alu_and.arm4.swf alu_or.arm4.swf alu_xor.arm4.swf       \
diff --git a/deps/lightning/check/bswap.ok b/deps/lightning/check/bswap.ok
new file mode 100644 (file)
index 0000000..9766475
--- /dev/null
@@ -0,0 +1 @@
+ok
diff --git a/deps/lightning/check/bswap.tst b/deps/lightning/check/bswap.tst
new file mode 100644 (file)
index 0000000..f123e95
--- /dev/null
@@ -0,0 +1,154 @@
+.data  16
+ok:
+.c     "ok\n"
+
+#define us12_i         0x1234
+#define us7f_i         0x7ff7
+#define us80_i         0x8008
+#define usff_i         0xffff
+#define ui12_i         0x01234567
+#define ui7f_i         0x7f7ff7f7
+#define ui80_i         0x80800808
+#define uiff_i         0xffffffff
+#define ul12_i         0x0123456789abcdef
+#define ul7f_i         0x7f7f7f7ff7f7f7f7
+#define ul80_i         0x8080808008080808
+#define ulff_i         0xffffffffffffffff
+
+#if __WORDSIZE == 32
+#  define xus12_i      0xffff1234
+#  define xus7f_i      0x10107ff7
+#  define xus80_i      0x81188008
+#  define xusff_i      0xeaaeffff
+#else
+#  define xus12_i      0xffffffffffff1234
+#  define xus7f_i      0x1010100101017ff7
+#  define xus80_i      0x8181811818818008
+#  define xusff_i      0xeaeaeaaeaeaeffff
+#  define xui12_i      0xffffffff01234567
+#  define xui7f_i      0x101001017f7ff7f7
+#  define xui80_i      0x8181181880800808
+#  define xuiff_i      0xeaeaaeaeffffffff
+#endif
+
+#  define us12_o       0x3412
+#  define us7f_o       0xf77f
+#  define us80_o       0x0880
+#  define usff_o       0xffff
+#  define ui12_o       0x67452301
+#  define ui7f_o       0xf7f77f7f
+#  define ui80_o       0x08088080
+#  define uiff_o       0xffffffff
+#  define ul12_o       0xefcdab8967452301
+#  define ul7f_o       0xf7f7f7f77f7f7f7f
+#  define ul80_o       0x0808080880808080
+#  define ulff_o       0xffffffffffffffff
+
+#define BSWAP4(I, O, T, R0, R1)                                \
+       movi %R0 I                                      \
+       bswapr_##T %R1 %R0                              \
+       beqi T##R0##R1##I %R1 O                         \
+       calli @abort                                    \
+T##R0##R1##I:
+
+#define BSWAP3(T, R0, R1)                              \
+       BSWAP4(T##12_i, T##12_o, T, R0, R1)             \
+       BSWAP4(x##T##12_i, T##12_o, T, R0, R1)          \
+       BSWAP4(T##7f_i, T##7f_o, T, R0, R1)             \
+       BSWAP4(x##T##7f_i, T##7f_o, T, R0, R1)          \
+       BSWAP4(T##80_i, T##80_o, T, R0, R1)             \
+       BSWAP4(x##T##80_i, T##80_o, T, R0, R1)          \
+       BSWAP4(T##ff_i, T##ff_o, T, R0, R1)             \
+       BSWAP4(x##T##ff_i, T##ff_o, T, R0, R1)
+
+#define BSWAP3x(T, R0, R1)                             \
+       BSWAP4(T##12_i, T##12_o, T, R0, R1)             \
+       BSWAP4(T##7f_i, T##7f_o, T, R0, R1)             \
+       BSWAP4(T##80_i, T##80_o, T, R0, R1)             \
+       BSWAP4(T##ff_i, T##ff_o, T, R0, R1)
+
+#define BSWAP2(T, V0, V1, V2, R0, R1, R2)              \
+       BSWAP3(T, V0, V0)                               \
+       BSWAP3(T, V0, V1)                               \
+       BSWAP3(T, V0, V2)                               \
+       BSWAP3(T, V0, R0)                               \
+       BSWAP3(T, V0, R1)                               \
+       BSWAP3(T, V0, R2)                               \
+
+#define BSWAP2x(T, V0, V1, V2, R0, R1, R2)             \
+       BSWAP3x(T, V0, V0)                              \
+       BSWAP3x(T, V0, V1)                              \
+       BSWAP3x(T, V0, V2)                              \
+       BSWAP3x(T, V0, R0)                              \
+       BSWAP3x(T, V0, R1)                              \
+       BSWAP3x(T, V0, R2)                              \
+
+#define BSWAP1(T, V0, V1, V2, R0, R1, R2)              \
+       BSWAP2(T, V0, V1, V2, R0, R1, R2)               \
+       BSWAP2(T, V1, V2, R0, R1, R2, V0)               \
+       BSWAP2(T, V2, R0, R1, R2, V0, V1)               \
+       BSWAP2(T, R0, R1, R2, V0, V1, V2)               \
+       BSWAP2(T, R1, R2, V0, V1, V2, R0)               \
+       BSWAP2(T, R2, V0, V1, V2, R0, R1)
+
+#define BSWAP1x(T, V0, V1, V2, R0, R1, R2)             \
+       BSWAP2x(T, V0, V1, V2, R0, R1, R2)              \
+       BSWAP2x(T, V1, V2, R0, R1, R2, V0)              \
+       BSWAP2x(T, V2, R0, R1, R2, V0, V1)              \
+       BSWAP2x(T, R0, R1, R2, V0, V1, V2)              \
+       BSWAP2x(T, R1, R2, V0, V1, V2, R0)              \
+       BSWAP2x(T, R2, V0, V1, V2, R0, R1)
+
+#if __WORDSIZE == 32
+#  define BSWAP(V0, V1, V2, R0, R1, R2)                        \
+       BSWAP1(us, V0, V1, V2, R0, R1, R2)              \
+       BSWAP1x(ui, V0, V1, V2, R0, R1, R2)
+#else
+#  define BSWAP(V0, V1, V2, R0, R1, R2)                        \
+       BSWAP1(us, V0, V1, V2, R0, R1, R2)              \
+       BSWAP1(ui, V0, V1, V2, R0, R1, R2)              \
+       BSWAP1x(ul, V0, V1, V2, R0, R1, R2)
+#endif
+
+.code
+       prolog
+       /* simple sequence for easier disassembly reading and encoding check */
+       movi %r0 us12_i
+       bswapr_us %r1 %r0
+       beqi us %r1 us12_o
+       calli @abort
+us:
+
+       movi %r0 xus12_i
+       bswapr_us %r1 %r0
+       beqi xus %r1 us12_o
+       calli @abort
+xus:
+       movi %r0 ui12_i
+       bswapr_ui %r1 %r0
+       beqi ui %r1 ui12_o
+       calli @abort
+ui:
+#if __WORDSIZE == 64
+       movi %r0 xui12_i
+       bswapr_ui %r1 %r0
+       beqi xui %r1 ui12_o
+       calli @abort
+xui:
+       movi %r0 ul12_i
+       bswapr_ul %r1 %r0
+       beqi ul %r1 ul12_o
+       calli @abort
+ul:
+#endif
+
+       BSWAP(v0, v1, v2, r0, r1, r2)
+
+       // just to know did not abort
+       prepare
+               pushargi ok
+               ellipsis
+       finishi @printf
+
+       ret
+       epilog
index c92364a..3cf3e70 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdarg.h>
 #include <lightning.h>
 #include <dlfcn.h>
+#include <math.h>
 
 #if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
 #  include <fpu_control.h>
@@ -327,6 +328,11 @@ static void htonr_ui(void);        static void ntohr_ui(void);
 static void htonr_ul(void);    static void ntohr_ul(void);
 #endif
 static void htonr(void);       static void ntohr(void);
+static void bswapr_us(void);   static void bswapr_ui(void);
+#if __WORDSIZE == 64
+static void bswapr_ul(void);
+#endif
+static void bswapr(void);
 static void movnr(void);       static void movzr(void);
 static void ldr_c(void);       static void ldi_c(void);
 static void ldr_uc(void);      static void ldi_uc(void);
@@ -642,6 +648,11 @@ static instr_t               instr_vector[] = {
     entry(htonr_ul),   entry(ntohr_ul),
 #endif
     entry(htonr),      entry(ntohr),
+    entry(bswapr_us),  entry(bswapr_ui),
+#if __WORDSIZE == 64
+    entry(bswapr_ul),
+#endif
+    entry(bswapr),
     entry(movnr),      entry(movzr),
     entry(ldr_c),      entry(ldi_c),
     entry(ldr_uc),     entry(ldi_uc),
@@ -1491,6 +1502,11 @@ entry_ir_ir(htonr_ui)            entry_ir_ir(ntohr_ui)
 entry_ir_ir(htonr_ul)          entry_ir_ir(ntohr_ul)
 #endif
 entry_ir_ir(htonr)             entry_ir_ir(ntohr)
+entry_ir_ir(bswapr_us)         entry_ir_ir(bswapr_ui)
+#if __WORDSIZE == 64
+entry_ir_ir(bswapr_ul)
+#endif
+entry_ir_ir(bswapr)
 entry_ir_ir_ir(movnr)          entry_ir_ir_ir(movzr)
 entry_ir_ir(ldr_c)             entry_ir_pm(ldi_c)
 entry_ir_ir(ldr_uc)            entry_ir_pm(ldi_uc)
index 1f2c6b4..5b582d2 100644 (file)
@@ -63,7 +63,7 @@ case "$target_cpu" in
     *)                                         ;;
 esac
 
-AC_CHECK_FUNCS(mremap ffsl getopt_long_only isnan isinf,,)
+AC_CHECK_FUNCS(mmap mremap ffsl getopt_long_only isnan isinf,,)
 
 AC_CHECK_HEADERS([getopt.h stdint.h],,,)
 
@@ -72,7 +72,7 @@ AC_ARG_ENABLE(disassembler,
                             [Enable jit disassembler using binutils]),
              [DISASSEMBLER=$enableval], [DISASSEMBLER=auto])
 if test "x$DISASSEMBLER" != "xno"; then
-    # FIXME need to check for libiberty first or will fail to link
+
     AC_CHECK_LIB(iberty, htab_try_create, ,
                 [HAVE_IBERTY="no"])
     AC_CHECK_LIB(bfd, bfd_init, ,
@@ -81,17 +81,43 @@ if test "x$DISASSEMBLER" != "xno"; then
                 [HAVE_Z="no"])
     AC_CHECK_LIB(opcodes, init_disassemble_info, ,
                 [HAVE_OPCODES="no"])
-    if test "x$HAVE_IBERTY"  = "xno" -o \
-           "x$HAVE_BFD"     = "xno" -o \
-           "x$HAVE_Z"       = "xno" -o \
-           "x$HAVE_OPCODES" = "xno"; then
-       if test "x$DISASSEMBLER" != "xauto"; then
-           AC_MSG_ERROR([binutils not found, see http://www.gnu.org/software/binutils/])
-       else
-           AC_MSG_WARN([binutils not found, see http://www.gnu.org/software/binutils/])
-           DISASSEMBLER="no"
-       fi
+
+    if test "x$HAVE_IBERTY" = "xno"; then
+        if test "x$DISASSEMBLER" = "xyes"; then
+            AC_MSG_ERROR([libiberty not found])
+        else
+            AC_MSG_WARN([libiberty not found])
+            DISASSEMBLER="no"
+        fi
     fi
+
+    if test "x$HAVE_BFD" = "xno"; then
+        if test "x$DISASSEMBLER" = "xyes"; then
+            AC_MSG_ERROR([binutils BFD not found, see http://www.gnu.org/software/binutils/])
+        else
+            AC_MSG_WARN([binutils BFD not found, see http://www.gnu.org/software/binutils/])
+            DISASSEMBLER="no"
+        fi
+    fi
+
+    if test "x$HAVE_Z" = "xno"; then
+        if test "x$DISASSEMBLER" = "xyes"; then
+            AC_MSG_ERROR([zlib not found, see https://zlib.net/])
+        else
+            AC_MSG_WARN([zlib not found, see https://zlib.net/])
+            DISASSEMBLER="no"
+        fi
+    fi
+
+    if test "x$HAVE_OPCODES" = "xno"; then
+        if test "x$DISASSEMBLER" = "xyes"; then
+            AC_MSG_ERROR([binutils opcodes not found, see https://www.gnu.org/software/binutils/])
+        else
+            AC_MSG_WARN([binutils opcodes not found, see https://www.gnu.org/software/binutils/])
+            DISASSEMBLER="no"
+        fi
+    fi
+
 fi
 AM_CONDITIONAL(with_disassembler, [test "x$DISASSEMBLER" != "xno"])
 if test "x$DISASSEMBLER" != "xno"; then
index ae3678f..0e0a6da 100644 (file)
@@ -1,3 +1,13 @@
 *.info*
 stamp-*
 /version.texi
+
+texinfo.tex
+mdate-sh
+
+fact
+ifib
+incr
+printf
+rfib
+rpn
index 51c08d3..c174fcf 100644 (file)
@@ -89,7 +89,11 @@ assembles machine instructions without further tests.
 @node Installation
 @chapter Configuring and installing @lightning{}
 
-The first thing to do to use @lightning{} is to configure the
+Here we will assume that your system already has the dependencies
+necessary to build @lightning{}. For more on dependencies, see
+@lightning{}'s @file{README-hacking} file.
+
+The first thing to do to build @lightning{} is to configure the
 program, picking the set of macros to be used on the host
 architecture; this configuration is automatically performed by
 the @file{configure} shell script; to run it, merely type:
@@ -368,6 +372,14 @@ htonr    _us _ui _ul @r{Host-to-network (big endian) order}
 ntohr    _us _ui _ul @r{Network-to-host order }
 @end example
 
+@code{bswapr} can be used to unconditionally byte-swap an operand.
+On little-endian architectures, @code{htonr} and @code{ntohr} resolve
+to this.
+The @code{_ul} variant is only available in 64-bit architectures.
+@example
+bswapr    _us _ui _ul  01 = byte_swap(02)
+@end example
+
 @item Load operations
 @code{ld} accepts two operands while @code{ldx} accepts three;
 in both cases, the last can be either a register or an immediate
index 422fc13..887a951 100644 (file)
@@ -123,6 +123,11 @@ typedef jit_int32_t                jit_bool_t;
 typedef jit_int32_t            jit_gpr_t;
 typedef jit_int32_t            jit_fpr_t;
 
+#if !defined(__powerpc__) && \
+       (defined(__POWERPC__) || defined(__ppc__) || defined(__PPC__))
+#define __powerpc__ 1
+#endif
+
 #if defined(__i386__) || defined(__x86_64__)
 #  include <lightning/jit_x86.h>
 #elif defined(__mips__)
@@ -339,6 +344,11 @@ typedef enum {
 #define jit_movr(u,v)          jit_new_node_ww(jit_code_movr,u,v)
 #define jit_movi(u,v)          jit_new_node_ww(jit_code_movi,u,v)
     jit_code_movr,             jit_code_movi,
+
+#define jit_movnr(u,v,w)       jit_new_node_www(jit_code_movnr,u,v,w)
+#define jit_movzr(u,v,w)       jit_new_node_www(jit_code_movzr,u,v,w)
+    jit_code_movnr,            jit_code_movzr,
+
 #define jit_extr_c(u,v)                jit_new_node_ww(jit_code_extr_c,u,v)
 #define jit_extr_uc(u,v)       jit_new_node_ww(jit_code_extr_uc,u,v)
     jit_code_extr_c,           jit_code_extr_uc,
@@ -891,9 +901,17 @@ typedef enum {
 #define jit_movr_d_w(u, v)     jit_new_node_ww(jit_code_movr_d_w, u, v)
 #define jit_movi_d_w(u, v)     jit_new_node_wd(jit_code_movi_d_w, u, v)
 
-#define jit_movnr(u,v,w)       jit_new_node_www(jit_code_movnr,u,v,w)
-#define jit_movzr(u,v,w)       jit_new_node_www(jit_code_movzr,u,v,w)
-    jit_code_movnr,            jit_code_movzr,
+#define jit_bswapr_us(u,v)     jit_new_node_ww(jit_code_bswapr_us,u,v)
+    jit_code_bswapr_us,
+#define jit_bswapr_ui(u,v)     jit_new_node_ww(jit_code_bswapr_ui,u,v)
+    jit_code_bswapr_ui,
+#define jit_bswapr_ul(u,v)     jit_new_node_ww(jit_code_bswapr_ul,u,v)
+    jit_code_bswapr_ul,
+#if __WORDSIZE == 32
+#define jit_bswapr(u,v)                jit_new_node_ww(jit_code_bswapr_ui,u,v)
+#else
+#define jit_bswapr(u,v)                jit_new_node_ww(jit_code_bswapr_ul,u,v)
+#endif
 
     jit_code_last_code
 } jit_code_t;
index e00e74d..0af24cb 100644 (file)
@@ -264,8 +264,9 @@ extern jit_node_t *_jit_data(jit_state_t*, const void*,
 #define jit_cc_a0_flt          0x00000020      /* arg0 is immediate float */
 #define jit_cc_a0_dbl          0x00000040      /* arg0 is immediate double */
 #define jit_cc_a0_arg          0x00000080      /* arg1 is an argument int id */
-#define jit_cc_a1_reg          0x00000100      /* arg1 is a register */
-#define jit_cc_a1_chg          0x00000200      /* arg1 is modified */
+#define jit_cc_a0_cnd          0x00000100      /* arg1 is a conditinally set register */
+#define jit_cc_a1_reg          0x00000200      /* arg1 is a register */
+#define jit_cc_a1_chg          0x00000400      /* arg1 is modified */
 #define jit_cc_a1_int          0x00001000      /* arg1 is immediate word */
 #define jit_cc_a1_flt          0x00002000      /* arg1 is immediate float */
 #define jit_cc_a1_dbl          0x00004000      /* arg1 is immediate double */
@@ -718,6 +719,7 @@ _emit_ldxi_d(jit_state_t*, jit_int32_t, jit_int32_t, jit_word_t);
 extern void
 _emit_stxi_d(jit_state_t*, jit_word_t, jit_int32_t, jit_int32_t);
 
+extern void jit_init_print(void);
 extern void jit_init_debug(const char*);
 extern void jit_finish_debug(void);
 
index 53698b0..7d2a99d 100644 (file)
@@ -663,17 +663,11 @@ static void _stxi_i(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
 #  define stxr_l(r0,r1,r2)             STR(r2,r1,r0)
 #  define stxi_l(i0,r0,r1)             _stxi_l(_jit,i0,r0,r1)
 static void _stxi_l(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define htonr_us(r0,r1)              _htonr_us(_jit,r0,r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#  define htonr_ui(r0,r1)              _htonr_ui(_jit,r0,r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#    define htonr_ul(r0,r1)            REV(r0,r1)
-#  else
-#    define htonr_us(r0,r1)            extr_us(r0,r1)
-#    define htonr_ui(r0,r1)            extr_ui(r0,r1)
-#    define htonr_ul(r0,r1)            movr(r0,r1)
-#  endif
+#  define bswapr_us(r0,r1)             _bswapr_us(_jit,r0,r1)
+static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ui(r0,r1)             _bswapr_ui(_jit,r0,r1)
+static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ul(r0,r1)             REV(r0,r1)
 #  define extr_c(r0,r1)                        SXTB(r0,r1)
 #  define extr_uc(r0,r1)               UXTB(r0,r1)
 #  define extr_s(r0,r1)                        SXTH(r0,r1)
@@ -1461,21 +1455,19 @@ _xori(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
     }
 }
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
 static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
-    htonr_ul(r0, r1);
+    bswapr_ul(r0, r1);
     rshi_u(r0, r0, 48);
 }
 
 static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
-    htonr_ul(r0, r1);
+    bswapr_ul(r0, r1);
     rshi_u(r0, r0, 32);
 }
-#endif
 
 static void
 _ldi_c(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
index 4fa7a42..e1f6d96 100644 (file)
@@ -95,6 +95,8 @@
     8, /* nei */
     4, /* movr */
     16,        /* movi */
+    8, /* movnr */
+    8, /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    8, /* movnr */
-    8, /* movzr */
+    8, /* bswapr_us */
+    8, /* bswapr_ui */
+    4, /* bswapr_ul */
 #endif /* __WORDSIZE */
index 369408c..f0be046 100644 (file)
@@ -1128,6 +1128,9 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _us);
                case_rr(hton, _ui);
                case_rr(hton, _ul);
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+               case_rr(bswap, _ul);
                case_rr(ext, _c);
                case_rr(ext, _uc);
                case_rr(ext, _s);
index 8bfef9c..2dd701d 100644 (file)
@@ -311,6 +311,10 @@ static void _movr(jit_state_t*,jit_int32_t,jit_int32_t);
 static void _movi(jit_state_t*,jit_int32_t,jit_word_t);
 #  define movi_p(r0,i0)                        _movi_p(_jit,r0,i0)
 static jit_word_t _movi_p(jit_state_t*,jit_int32_t,jit_word_t);
+#  define movnr(r0,r1,r2)              _movnr(_jit,r0,r1,r2)
+static void _movnr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define movzr(r0,r1,r2)              _movzr(_jit,r0,r1,r2)
+static void _movzr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define negr(r0,r1)                  NEGQ(r1,r0)
 #  define comr(r0,r1)                  NOT(r1,r0)
 #  define addr(r0,r1,r2)               ADDQ(r1,r2,r0)
@@ -622,18 +626,12 @@ static void _extr_us(jit_state_t*,jit_int32_t,jit_int32_t);
 static void _extr_i(jit_state_t*,jit_int32_t,jit_int32_t);
 #  define extr_ui(r0,r1)               _extr_ui(_jit,r0,r1)
 static void _extr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
-#    define htonr_us(r0,r1)            _htonr_us(_jit,r0,r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#    define htonr_ui(r0,r1)            _htonr_ui(_jit,r0,r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#    define htonr_ul(r0,r1)            _htonr_ul(_jit,r0,r1)
-static void _htonr_ul(jit_state_t*,jit_int32_t,jit_int32_t);
-#  else
-#    define htonr_us(r0,r1)            extr_us(r0,r1)
-#    define htonr_ui(r0,r1)            extr_ui(r0,r1)
-#    define htonr_ul(r0,r1)            movr(r0,r1)
-#  endif
+#  define bswapr_us(r0,r1)             _bswapr_us(_jit,r0,r1)
+static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ui(r0,r1)             _bswapr_ui(_jit,r0,r1)
+static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ul(r0,r1)             _bswapr_ul(_jit,r0,r1)
+static void _bswapr_ul(jit_state_t*,jit_int32_t,jit_int32_t);
 #  define jmpr(r0)                     JMP(_R31_REGNO,r0,0)
 #  define jmpi(i0)                     _jmpi(_jit,i0)
 static void _jmpi(jit_state_t*, jit_word_t);
@@ -811,6 +809,24 @@ _movi_p(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
     return (w);
 }
 
+static void
+_movnr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = beqi(_jit->pc.w, r2, 0);
+    MOV(r1, r0);
+    patch_at(w, _jit->pc.w);
+}
+
+static void
+_movzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = bnei(_jit->pc.w, r2, 0);
+    MOV(r1, r0);
+    patch_at(w, _jit->pc.w);
+}
+
 static void
 _addi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
@@ -2453,7 +2469,7 @@ _extr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 }
 
 static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     jit_int32_t                t0;
     t0 = jit_get_reg(jit_class_gpr);
@@ -2465,7 +2481,7 @@ _htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 }
 
 static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     jit_int32_t                t0;
     jit_int32_t                t1;
@@ -2491,7 +2507,7 @@ _htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 }
 
 static void
-_htonr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     jit_int32_t                t0;
     jit_int32_t                t1;
index e1a572a..ecfeba3 100644 (file)
@@ -95,6 +95,8 @@
     12,        /* nei */
     4, /* movr */
     32,        /* movi */
+    12, /* movnr */
+    12, /* movzr */
     8, /* extr_c */
     8, /* extr_uc */
     8, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    16,        /* bswapr_us */
+    36,        /* bswapr_ui */
+    36,        /* bswapr_ul */
 #endif /* __WORDSIZE */
index 9a067aa..d7bb3ec 100644 (file)
@@ -1086,12 +1086,17 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _us);
                case_rr(hton, _ui);
                case_rr(hton, _ul);
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+               case_rr(bswap, _ul);
                case_rr(ext, _c);
                case_rr(ext, _uc);
                case_rr(ext, _s);
                case_rr(ext, _us);
                case_rr(ext, _i);
                case_rr(ext, _ui);
+               case_rrr(movn,);
+               case_rrr(movz,);
                case_rr(mov,);
            case jit_code_movi:
                if (node->flag & jit_flag_node) {
index 1cf36e0..14ba36b 100644 (file)
@@ -612,7 +612,7 @@ static void _torl(jit_state_t*,int,int,int) maybe_unused;
 #  define CMNI(rn,im)                  CC_CMNI(ARM_CC_AL,rn,im)
 #  define T2_CMNI(rn,im)               torri(THUMB2_CMNI,rn,_R15_REGNO,im)
 #  define CC_TST(cc,rn,rm)             corrr(cc,ARM_TST,rn,r0,rm)
-#  define TST(rn,rm)                   CC_TST(ARM_CC_AL,rn,rm)
+#  define TST(rn,rm)                   corrr(ARM_CC_AL,ARM_TST,rn,0,rm)
 #  define T1_TST(rn,rm)                        is(THUMB_TST|(_u3(rm)<<3)|_u3(rn))
 #  define T2_TST(rn,rm)                        torrr(THUMB2_TST,rn,_R15_REGNO,rm)
 #  define CC_TSTI(cc,rn,im)            corri(cc,ARM_TST|ARM_I,rn,0,im)
@@ -1095,15 +1095,10 @@ static void _sti_i(jit_state_t*,jit_word_t,jit_int32_t);
 static void _stxr_i(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
 #  define stxi_i(r0,r1,i0)             _stxi_i(_jit,r0,r1,i0)
 static void _stxi_i(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define htonr_us(r0,r1)              _htonr_us(_jit,r0,r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#  define htonr_ui(r0,r1)              _htonr_ui(_jit,r0,r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#  else
-#    define htonr_us(r0,r1)            extr_us(r0,r1)
-#    define htonr(r0,r1)               movr(r0,r1)
-#  endif
+#  define bswapr_us(r0,r1)             _bswapr_us(_jit,r0,r1)
+static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ui(r0,r1)             _bswapr_ui(_jit,r0,r1)
+static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
 #  define extr_c(r0,r1)                        _extr_c(_jit,r0,r1)
 static void _extr_c(jit_state_t*,jit_int32_t,jit_int32_t);
 #  define extr_uc(r0,r1)               _extr_uc(_jit,r0,r1)
@@ -3609,11 +3604,9 @@ _stxi_i(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
     }
 }
 
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
 static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
-    jit_int32_t                t0;
     if (jit_thumb_p()) {
        if ((r0|r1) < 8)
            T1_REV(r0, r1);
@@ -3627,20 +3620,14 @@ _htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
            rshi_u(r0, r0, 16);
        }
        else {
-           t0 = jit_get_reg(jit_class_gpr);
-           rshi(rn(t0), r1, 8);
-           andi(r0, r1, 0xff);
-           andi(rn(t0), rn(t0), 0xff);
-           lshi(r0, r0, 8);
-           orr(r0, r0, rn(t0));
-           jit_unget_reg(t0);
+               generic_bswapr_us(_jit, r0, r1);
        }
     }
 }
 
 /* inline glibc htonl (without register clobber) */
 static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     jit_int32_t                reg;
     if (jit_thumb_p()) {
@@ -3662,7 +3649,6 @@ _htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
        }
     }
 }
-#endif
 
 static void
 _extr_c(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
index 6368c13..293d306 100644 (file)
@@ -96,6 +96,8 @@
     14,        /* nei */
     4, /* movr */
     8, /* movi */
+    8, /* movnr */
+    8, /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     12,        /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    8, /* bswapr_us */
+    4, /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* __ARM_PCS_VFP */
 #endif /* __WORDSIZE */
 
     14,        /* nei */
     4, /* movr */
     8, /* movi */
+    22,        /* movnr */
+    22,        /* movzr */
     8, /* extr_c */
     4, /* extr_uc */
     8, /* extr_s */
     12,        /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    8, /* movnr */
-    8, /* movzr */
+    20,        /* bswapr_us */
+    16,        /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* __ARM_PCS_VFP */
 #endif /* __WORDSIZE */
index 051f84d..0fdd1a7 100644 (file)
@@ -1498,6 +1498,8 @@ _emit_code(jit_state_t *_jit)
                case_wrr(stx, _i);
                case_rr(hton, _us);
                case_rr(hton, _ui);
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
                case_rr(ext, _c);
                case_rr(ext, _uc);
                case_rr(ext, _s);
index 27a3ed1..25983a6 100644 (file)
@@ -59,6 +59,7 @@ static FILE                    *disasm_stream;
 void
 jit_init_debug(const char *progname)
 {
+    jit_init_print();
 #if DISASSEMBLER
     bfd_init();
 
@@ -74,65 +75,24 @@ jit_init_debug(const char *progname)
     bfd_check_format(disasm_bfd, bfd_object);
     bfd_check_format(disasm_bfd, bfd_archive);
     if (!disasm_stream)
-       disasm_stream = stderr;
+       disasm_stream = stdout;
+
     INIT_DISASSEMBLE_INFO(disasm_info, disasm_stream, fprintf);
-#  if defined(__i386__) || defined(__x86_64__)
-    disasm_info.arch = bfd_arch_i386;
-#    if defined(__x86_64__)
-#      if __WORDSIZE == 32
-    disasm_info.mach = bfd_mach_x64_32;
-#      else
-    disasm_info.mach = bfd_mach_x86_64;
-#      endif
-#    else
-    disasm_info.mach = bfd_mach_i386_i386;
-#    endif
-#  endif
-#  if defined(__powerpc__)
-    disasm_info.arch = bfd_arch_powerpc;
-    disasm_info.mach = bfd_mach_ppc64;
-#    if HAVE_DISASSEMBLE_INIT_FOR_TARGET
+    disasm_info.arch = bfd_get_arch(disasm_bfd);
+    disasm_info.mach = bfd_get_mach(disasm_bfd);
+
+#  if HAVE_DISASSEMBLE_INIT_FOR_TARGET
     disassemble_init_for_target(&disasm_info);
-#    elif HAVE_DISASSEMBLE_INIT_POWERPC
-    disassemble_init_powerpc(&disasm_info);
-#    endif
-#    if defined(__powerpc64__)
+#  endif
+
+#  if defined(__powerpc64__)
     disasm_info.disassembler_options = "64";
-#    endif
-#    if HAVE_DISASSEMBLE_INIT_FOR_TARGET
-    disassemble_init_for_target(&disasm_info);
-#    elif HAVE_DISASSEMBLE_INIT_POWERPC
-    disassemble_init_powerpc(&disasm_info);
-#    endif
 #  endif
-#  if defined(__sparc__)
+#  if defined(__sparc__) || defined(__s390__) || defined(__s390x__)
     disasm_info.endian = disasm_info.display_endian = BFD_ENDIAN_BIG;
 #  endif
 #  if defined(__s390__) || defined(__s390x__)
-    disasm_info.arch = bfd_arch_s390;
-#    if __WORDSIZE == 32
-    disasm_info.mach = bfd_mach_s390_31;
-#    else
-    disasm_info.mach = bfd_mach_s390_64;
-#    endif
-    disasm_info.endian = disasm_info.display_endian = BFD_ENDIAN_BIG;
     disasm_info.disassembler_options = "zarch";
-#  endif
-#  if defined(__alpha__)
-    disasm_info.arch = bfd_arch_alpha;
-    disasm_info.mach = bfd_mach_alpha_ev6;
-#  endif
-#  if defined(__hppa__)
-    disasm_info.arch = bfd_arch_hppa;
-    disasm_info.mach = bfd_mach_hppa10;
-#  endif
-#  if defined(__riscv)
-    disasm_info.arch = bfd_arch_riscv;
-#  if __WORDSIZE == 32
-    disasm_info.mach = bfd_mach_riscv32;
-#  else
-    disasm_info.mach = bfd_mach_riscv64;
-#  endif
 #  endif
     disasm_info.print_address_func = disasm_print_address;
 
index db5a36a..6ca54f3 100644 (file)
@@ -648,18 +648,18 @@ static void _movr(jit_state_t*,jit_int32_t,jit_int32_t);
 static void _movi(jit_state_t*,jit_int32_t,jit_word_t);
 #define movi_p(r0,i0)          _movi_p(_jit,r0,i0)
 static jit_word_t _movi_p(jit_state_t*,jit_int32_t,jit_word_t);
+#  define movnr(r0,r1,r2)              _movnr(_jit,r0,r1,r2)
+static void _movnr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define movzr(r0,r1,r2)              _movzr(_jit,r0,r1,r2)
+static void _movzr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #define comr(r0,r1)            UADDCM(_R0_REGNO,r1,r0)
 #define negr(r0,r1)            SUB(_R0_REGNO,r1,r0)
 #define extr_c(r0,r1)          EXTRWR(r1,31,8,r0)
 #define extr_uc(r0,r1)         EXTRWR_U(r1,31,8,r0)
 #define extr_s(r0,r1)          EXTRWR(r1,31,16,r0)
 #define extr_us(r0,r1)         EXTRWR_U(r1,31,16,r0)
-#if __BYTE_ORDER == __BIG_ENDIAN
-#  define htonr_us(r0,r1)      extr_us(r0,r1)
-#  define htonr_ui(r0,r1)      movr(r0,r1)
-#else
-#  error need htonr implementation
-#endif
+#define bswapr_us(r0,r1)       generic_bswapr_us(_jit,r0,r1)
+#define bswapr_ui(r0,r1)       generic_bswapr_ui(_jit,r0,r1)
 #define addr(r0,r1,r2)         ADD(r1,r2,r0)
 #define addi(r0,r1,i0)         _addi(_jit,r0,r1,i0)
 static void _addi(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t);
@@ -1633,6 +1633,24 @@ _movi_p(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
     return (w);
 }
 
+static void
+_movnr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = beqi(_jit->pc.w, r2, 0);
+    COPY(r1, r0);
+    patch_at(w, _jit->pc.w);
+}
+
+static void
+_movzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = bnei(_jit->pc.w, r2, 0);
+    COPY(r1, r0);
+    patch_at(w, _jit->pc.w);
+}
+
 static void
 _addi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
index 3c04f63..1bfb7e6 100644 (file)
@@ -95,6 +95,8 @@
     8, /* nei */
     4, /* movr */
     8, /* movi */
+    16, /* movnr */
+    16, /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    36,        /* bswapr_us */
+    80,        /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* __WORDSIZE */
index 21fe20c..2668842 100644 (file)
@@ -1026,6 +1026,8 @@ _emit_code(jit_state_t *_jit)
                case_rrw(rsh,);
                case_rrr(rsh, _u);
                case_rrw(rsh, _u);
+               case_rrr(movn,);
+               case_rrr(movz,);
                case_rr(mov,);
            case jit_code_movi:
                if (node->flag & jit_flag_node) {
@@ -1052,6 +1054,8 @@ _emit_code(jit_state_t *_jit)
                case_rr(ext, _us);
                case_rr(hton, _us);
                case_rr(hton, _ui);
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
                case_rrr(lt,);
                case_rrw(lt,);
                case_rrr(lt, _u);
index dec1465..63bb92d 100644 (file)
@@ -1307,17 +1307,15 @@ static void _movr(jit_state_t*,jit_int32_t,jit_int32_t);
 static void _movi(jit_state_t*,jit_int32_t,jit_word_t);
 #define movi_p(r0,i0)                  _movi_p(_jit,r0,i0)
 static jit_word_t _movi_p(jit_state_t*,jit_int32_t,jit_word_t);
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define htonr_us(r0,r1)              _htonr_us(_jit,r0,r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#  define htonr_ui(r0,r1)              _htonr_ui(_jit,r0,r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#  define htonr_ul(r0,r1)              MUX1(r0,r1,MUX_REV)
-#else
-#  define htonr_us(r0,r1)              extr_us(r0,r1)
-#  define htonr_ui(r0,r1)              extr_ui(r0,r1)
-#  define htonr_ul(r0,r1)              movr(r0,r1)
-#endif
+#  define movnr(r0,r1,r2)              _movnr(_jit,r0,r1,r2)
+static void _movnr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define movzr(r0,r1,r2)              _movzr(_jit,r0,r1,r2)
+static void _movzr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define bswapr_us(r0,r1)             _bswapr_us(_jit,r0,r1)
+static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ui(r0,r1)             _bswapr_ui(_jit,r0,r1)
+static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ul(r0,r1)             MUX1(r0,r1,MUX_REV)
 #define extr_c(r0,r1)                  SXT1(r0,r1)
 #define extr_uc(r0,r1)                 ZXT1(r0,r1)
 #define extr_s(r0,r1)                  SXT2(r0,r1)
@@ -3483,6 +3481,38 @@ _movi_p(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
     return (w);
 }
 
+static void
+_movnr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = beqi(_jit->pc.w, r2, 0);
+    movr(r0, r1);
+    patch_at(w, _jit->pc.w);
+}
+
+static void
+_movzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = bnei(_jit->pc.w, r2, 0);
+    movr(r0, r1);
+    patch_at(w, _jit->pc.w);
+}
+
+static void
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+{
+       bswapr_ul(r0, r1);
+       rshi_u(r0, r0, 48);
+}
+
+static void
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+{
+       bswapr_ul(r0, r1);
+       rshi_u(r0, r0, 32);
+}
+
 static void
 _addi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
@@ -3949,48 +3979,6 @@ _xori(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
     }
 }
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                t0;
-    t0 = jit_get_reg(jit_class_gpr);
-    rshi(rn(t0), r1, 8);
-    andi(r0, r1, 0xff);
-    andi(rn(t0), rn(t0), 0xff);
-    lshi(r0, r0, 8);
-    orr(r0, r0, rn(t0));
-    jit_unget_reg(t0);
-}
-
-static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                t0;
-    jit_int32_t                t1;
-    jit_int32_t                t2;
-    t0 = jit_get_reg(jit_class_gpr);
-    t1 = jit_get_reg(jit_class_gpr);
-    t2 = jit_get_reg(jit_class_gpr);
-    rshi(rn(t0), r1, 24);
-    rshi(rn(t1), r1, 16);
-    rshi(rn(t2), r1,  8);
-    andi(rn(t0), rn(t0), 0xff);
-    andi(rn(t1), rn(t1), 0xff);
-    andi(rn(t2), rn(t2), 0xff);
-    andi(r0, r1, 0xff);
-    lshi(r0, r0, 24);
-    lshi(rn(t1), rn(t1), 8);
-    orr(r0, r0, rn(t0));
-    lshi(rn(t2), rn(t2), 16);
-    orr(r0, r0, rn(t1));
-    orr(r0, r0, rn(t2));
-    jit_unget_reg(t2);
-    jit_unget_reg(t1);
-    jit_unget_reg(t0);
-}
-#endif
-
 static void
 _lshi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
index 59826d9..c81b3ea 100644 (file)
@@ -68,9 +68,9 @@
     16,        /* lshr */
     16,        /* lshi */
     16,        /* rshr */
-    16,        /* rshi */
+    32,        /* rshi */
     16,        /* rshr_u */
-    16,        /* rshi_u */
+    32,        /* rshi_u */
     16,        /* negr */
     16,        /* comr */
     32,        /* ltr */
     32,        /* nei */
     16,        /* movr */
     16,        /* movi */
+    48, /* movnr */
+    48, /* movzr */
     16,        /* extr_c */
     16,        /* extr_uc */
     16,        /* extr_s */
     16,        /* extr_us */
     16,        /* extr_i */
     16,        /* extr_ui */
-    64,        /* htonr_us */
-    160,       /* htonr_ui */
+    48,        /* htonr_us */
+    48,        /* htonr_ui */
     16,        /* htonr_ul */
     16,        /* ldr_c */
     32,        /* ldi_c */
     0, /* movi_d_ww */
     16,        /* movr_d_w */
     32,        /* movi_d_w */
+    48,        /* bswapr_us */
+    48,        /* bswapr_ui */
+    16,        /* bswapr_ul */
 #endif /* __WORDSIZE */
index 9207d81..8b4cd00 100644 (file)
@@ -1175,6 +1175,8 @@ _emit_code(jit_state_t *_jit)
                case_rrw(rsh, _u);
                case_rr(neg,);
                case_rr(com,);
+               case_rrr(movn,);
+               case_rrr(movz,);
                case_rr(mov,);
            case jit_code_movi:
                if (node->flag & jit_flag_node) {
@@ -1196,6 +1198,9 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _us);
                case_rr(hton, _ui);
                case_rr(hton, _ul);
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+               case_rr(bswap, _ul);
                case_rr(ext, _c);
                case_rr(ext, _uc);
                case_rr(ext, _s);
index 4d7f92d..d1e3a14 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <lightning.h>
 #include <lightning/jit_private.h>
-#include <sys/mman.h>
 
 /*
  * Prototypes
index 119547d..0625589 100644 (file)
@@ -54,8 +54,11 @@ typedef union {
 #endif
     int                                        op;
 } jit_instr_t;
-/* FIXME */
+#if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
+#  define jit_mips2_p()                        1
+#else
 #  define jit_mips2_p()                        0
+#endif
 #  define _ZERO_REGNO                  0
 #  define _T0_REGNO                    0x08
 #  define _T1_REGNO                    0x09
@@ -107,7 +110,8 @@ typedef union {
 #  endif
 #  define can_sign_extend_short_p(im)  ((im) >= -32678 && (im) <= 32767)
 #  define can_zero_extend_short_p(im)  ((im) >= 0 && (im) <= 65535)
-#  define is_low_mask(im)              (((im) & 1) ? (__builtin_popcountl((im) + 1) == 1) : 0)
+#  define is_low_mask(im)              (((im) & 1) ? (__builtin_popcountl((im) + 1) <= 1) : 0)
+#  define is_middle_mask(im)           ((im) ? (__builtin_popcountl((im) + (1 << __builtin_ctzl(im))) <= 1) : 0)
 #  define is_high_mask(im)             ((im) ? (__builtin_popcountl((im) + (1 << __builtin_ctzl(im))) == 0) : 0)
 #  define masked_bits_count(im)                __builtin_popcountl(im)
 #  define unmasked_bits_count(im)      (__WORDSIZE - masked_bits_count(im))
@@ -321,6 +325,7 @@ static void _nop(jit_state_t*,jit_int32_t);
 #  define DADDIU(rt,rs,im)             hrri(MIPS_DADDIU,rs,rt,im)
 #  define SUBU(rd,rs,rt)               rrr_t(rs,rt,rd,MIPS_SUBU)
 #  define DSUBU(rd,rs,rt)              rrr_t(rs,rt,rd,MIPS_DSUBU)
+#  define MUL(rd,rs,rt)                        hrrr_t(MIPS_SPECIAL2,rs,rt,rd,MIPS_MUL)
 #  define MULT(rs,rt)                  rrr_t(rs,rt,_ZERO_REGNO,MIPS_MULT)
 #  define MULTU(rs,rt)                 rrr_t(rs,rt,_ZERO_REGNO,MIPS_MULTU)
 #  define DMULT(rs,rt)                 rrr_t(rs,rt,_ZERO_REGNO,MIPS_DMULT)
@@ -346,8 +351,12 @@ static void _nop(jit_state_t*,jit_int32_t);
 #  define DSRL32(rd,rt,sa)             rrit(rt,rd,sa,MIPS_DSRL32)
 #  define INS(rt,rs,pos,size)          hrrrit(MIPS_SPECIAL3,rs,rt,pos+size-1,pos,MIPS_INS)
 #  define DINS(rt,rs,pos,size)         hrrrit(MIPS_SPECIAL3,rs,rt,pos+size-1,pos,MIPS_DINS)
+#  define DINSU(rt,rs,pos,size)                hrrrit(MIPS_SPECIAL3,rs,rt,pos+size-32-1,pos-32,MIPS_DINSU)
+#  define DINSM(rt,rs,pos,size)                hrrrit(MIPS_SPECIAL3,rs,rt,pos+size-32-1,pos,MIPS_DINSM)
 #  define EXT(rt,rs,pos,size)          hrrrit(MIPS_SPECIAL3,rs,rt,size-1,pos,MIPS_EXT)
 #  define DEXT(rt,rs,pos,size)         hrrrit(MIPS_SPECIAL3,rs,rt,size-1,pos,MIPS_DEXT)
+#  define DEXTU(rt,rs,pos,size)                hrrrit(MIPS_SPECIAL3,rs,rt,size-1,pos-32,MIPS_DEXTU)
+#  define DEXTM(rt,rs,pos,size)                hrrrit(MIPS_SPECIAL3,rs,rt,size-32-1,pos,MIPS_DEXTM)
 #  define ROTR(rd,rt,sa)               hrrrit(MIPS_SPECIAL,1,rt,rd,sa,MIPS_SRL)
 #  define DROTR(rd,rt,sa)              hrrrit(MIPS_SPECIAL,1,rt,rd,sa,MIPS_DSRL)
 #  define MFHI(rd)                     rrr_t(_ZERO_REGNO,_ZERO_REGNO,rd,MIPS_MFHI)
@@ -412,6 +421,10 @@ static void _nop(jit_state_t*,jit_int32_t);
 #    define div(rs,rt)                 DDIV(rs,rt)
 #    define divu(rs,rt)                        DDIVU(rs,rt)
 #  endif
+#  define extr(rd,rt,lsb,nb)   _extr(_jit,rd,rt,lsb,nb)
+static void _extr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define insr(rd,rt,lsb,nb)   _insr(_jit,rd,rt,lsb,nb)
+static void _insr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define addi(r0,r1,i0)               _addi(_jit,r0,r1,i0)
 static void _addi(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t);
 #define addcr(r0,r1,r2)                        _addcr(_jit,r0,r1,r2)
@@ -594,23 +607,12 @@ static void _stxr_l(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #    define stxi_l(i0,r0,r1)           _stxi_l(_jit,i0,r0,r1)
 static void _stxi_l(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
 #  endif
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
-#    define htonr_us(r0,r1)            _htonr_us(_jit,r0,r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#    define htonr_ui(r0,r1)            _htonr_ui(_jit,r0,r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#    if __WORDSIZE == 64
-#      define htonr_ul(r0,r1)          _htonr_ul(_jit,r0,r1)
-static void _htonr_ul(jit_state_t*,jit_int32_t,jit_int32_t);
-#    endif
-#  else
-#    define htonr_us(r0,r1)            extr_us(r0,r1)
-#    if __WORDSIZE == 32
-#      define htonr_ui(r0,r1)          movr(r0,r1)
-#    else
-#      define htonr_ui(r0,r1)          extr_ui(r0,r1)
-#      define htonr_ul(r0,r1)          movr(r0,r1)
-#    endif
+#  define bswapr_us(r0,r1)             _bswapr_us(_jit,r0,r1)
+static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ui(r0,r1)             _bswapr_ui(_jit,r0,r1)
+static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
+#  if __WORDSIZE == 64
+#    define bswapr_ul(r0,r1)           generic_bswapr_ul(_jit,r0,r1)
 #  endif
 #  define extr_c(r0,r1)                        _extr_c(_jit,r0,r1)
 static void _extr_c(jit_state_t*,jit_int32_t,jit_int32_t);
@@ -809,6 +811,38 @@ _nop(jit_state_t *_jit, jit_int32_t i0)
     assert(i0 == 0);
 }
 
+static void
+_extr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1,
+      jit_int32_t pos, jit_int32_t size)
+{
+    assert(size > 0);
+
+    if (__WORDSIZE == 32)
+        EXT(r0, r1, pos, size);
+    else if (pos >= 32)
+        DEXTU(r0, r1, pos, size);
+    else if (size > 32)
+        DEXTM(r0, r1, pos, size);
+    else
+        DEXT(r0, r1, pos, size);
+}
+
+static void
+_insr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1,
+      jit_int32_t pos, jit_int32_t size)
+{
+    assert(size > 0);
+
+    if (__WORDSIZE == 32)
+        INS(r0, r1, pos, size);
+    else if (pos >= 32)
+        DINSU(r0, r1, pos, size);
+    else if (size > 32)
+        DINSM(r0, r1, pos, size);
+    else
+        DINS(r0, r1, pos, size);
+}
+
 static void
 _addi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
@@ -1003,8 +1037,12 @@ _rsbi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 static void
 _mulr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
 {
-    multu(r1, r2);
-    MFLO(r0);
+    if (__WORDSIZE == 32)
+        MUL(r0, r1, r2);
+    else {
+        multu(r1, r2);
+        MFLO(r0);
+    }
 }
 
 static void
@@ -1169,25 +1207,33 @@ _andi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     jit_int32_t                reg;
     if (can_zero_extend_short_p(i0))
-       ANDI(r0, r1, i0);
+        ANDI(r0, r1, i0);
     else if (is_low_mask(i0)) {
-#if defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)
-       if (masked_bits_count(i0) <= 32)
-           EXT(r0, r1, 0, masked_bits_count(i0));
-       else
-#endif
-       {
-               lshi(r0, r1, unmasked_bits_count(i0));
-               rshi_u(r0, r0, unmasked_bits_count(i0));
-       }
+        if (jit_mips2_p())
+            extr(r0, r1, 0, masked_bits_count(i0));
+        else {
+            lshi(r0, r1, unmasked_bits_count(i0));
+            rshi_u(r0, r0, unmasked_bits_count(i0));
+        }
     } else if (is_high_mask(i0)) {
-       rshi(r0, r1, unmasked_bits_count(i0));
-       lshi(r0, r0, unmasked_bits_count(i0));
+        if (jit_mips2_p() && r0 == r1)
+            insr(r0, _ZERO_REGNO, 0, unmasked_bits_count(i0));
+        else {
+            rshi(r0, r1, unmasked_bits_count(i0));
+            lshi(r0, r0, unmasked_bits_count(i0));
+        }
+    } else if (jit_mips2_p() && is_middle_mask(i0)) {
+        extr(r0, r1, __builtin_ctzl(i0), masked_bits_count(i0));
+        lshi(r0, r0, __builtin_ctzl(i0));
+    } else if (jit_mips2_p() && is_middle_mask(~i0)) {
+        if (r0 != r1)
+            movr(r0, r1);
+        insr(r0, _ZERO_REGNO, __builtin_ctzl(~i0), masked_bits_count(~i0));
     } else {
-       reg = jit_get_reg(jit_class_gpr);
-       movi(rn(reg), i0);
-       AND(r0, r1, rn(reg));
-       jit_unget_reg(reg);
+        reg = jit_get_reg(jit_class_gpr);
+        movi(rn(reg), i0);
+        AND(r0, r1, rn(reg));
+        jit_unget_reg(reg);
     }
 }
 
@@ -1708,60 +1754,34 @@ _stxi_l(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
 }
 #endif
 
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
 static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
-    jit_int32_t                t0;
-    t0 = jit_get_reg(jit_class_gpr);
-    rshi(rn(t0), r1, 8);
-    andi(r0, r1, 0xff);
-    andi(rn(t0), rn(t0), 0xff);
-    lshi(r0, r0, 8);
-    orr(r0, r0, rn(t0));
-    jit_unget_reg(t0);
-}
-
-static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                t0;
-    jit_int32_t                t1;
-    jit_int32_t                t2;
-    t0 = jit_get_reg(jit_class_gpr);
-    t1 = jit_get_reg(jit_class_gpr);
-    t2 = jit_get_reg(jit_class_gpr);
-    rshi(rn(t0), r1, 24);
-    rshi(rn(t1), r1, 16);
-    rshi(rn(t2), r1,  8);
-    andi(rn(t0), rn(t0), 0xff);
-    andi(rn(t1), rn(t1), 0xff);
-    andi(rn(t2), rn(t2), 0xff);
-    andi(r0, r1, 0xff);
-    lshi(r0, r0, 24);
-    lshi(rn(t1), rn(t1), 8);
-    orr(r0, r0, rn(t0));
-    lshi(rn(t2), rn(t2), 16);
-    orr(r0, r0, rn(t1));
-    orr(r0, r0, rn(t2));
-    jit_unget_reg(t2);
-    jit_unget_reg(t1);
-    jit_unget_reg(t0);
+    if (jit_mips2_p()) {
+        extr_us(r0, r1);
+        WSBH(r0, r0);
+    } else {
+        generic_bswapr_us(_jit, r0, r1);
+    }
 }
 
 static void
-_htonr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
-    jit_int32_t                reg;
-    reg = jit_get_reg(jit_class_gpr);
-    rshi_u(rn(reg), r1, 32);
-    htonr_ui(r0, r1);
-    htonr_ui(rn(reg), rn(reg));
-    lshi(r0, r0, 32);
-    orr(r0, r0, rn(reg));
-    jit_unget_reg(reg);
+    if (jit_mips2_p()) {
+        if (__WORDSIZE == 64) {
+            SLL(r0, r1, 0);
+            WSBH(r0, r0);
+            ROTR(r0, r0, 16);
+            extr(r0, r0, 0, 32);
+        } else {
+            WSBH(r0, r1);
+            ROTR(r0, r0, 16);
+        }
+    } else {
+        generic_bswapr_ui(_jit, r0, r1);
+    }
 }
-#  endif
 
 static void
 _extr_c(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
@@ -1789,8 +1809,12 @@ _extr_s(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 static void
 _extr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
-    lshi(r0, r1, 32);
-    rshi_u(r0, r0, 32);
+    if (jit_mips2_p())
+        DEXT(r0, r1, 0, 32);
+    else {
+        lshi(r0, r1, 32);
+        rshi_u(r0, r0, 32);
+    }
 }
 #  endif
 
@@ -1836,10 +1860,8 @@ _lei(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     jit_int32_t                reg;
 
-    if (i0 == 0) {
-       SLT(r0, _ZERO_REGNO, r1);
-       XORI(r0, r0, 1);
-    }
+    if (can_sign_extend_short_p(i0 + 1))
+        SLTI(r0, r1, i0 + 1);
     else {
        reg = jit_get_reg(jit_class_gpr);
        movi(rn(reg), i0);
@@ -1860,10 +1882,8 @@ _lei_u(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     jit_int32_t                reg;
 
-    if (i0 == 0) {
-       SLTU(r0, _ZERO_REGNO, r1);
-       XORI(r0, r0, 1);
-    }
+    if (can_sign_extend_short_p(i0 + 1))
+        SLTIU(r0, r1, i0 + 1);
     else {
        reg = jit_get_reg(jit_class_gpr);
        movi(rn(reg), i0);
@@ -1904,10 +1924,15 @@ _gei(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     jit_int32_t                reg;
 
-    reg = jit_get_reg(jit_class_gpr);
-    movi(rn(reg), i0);
-    ger(r0, r1, rn(reg));
-    jit_unget_reg(reg);
+    if (can_sign_extend_short_p(i0)) {
+        SLTI(r0, r1, i0);
+        XORI(r0, r0, 1);
+    } else {
+        reg = jit_get_reg(jit_class_gpr);
+        movi(rn(reg), i0);
+        ger(r0, r1, rn(reg));
+        jit_unget_reg(reg);
+    }
 }
 
 static void
@@ -1922,10 +1947,15 @@ _gei_u(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
     jit_int32_t                reg;
 
-    reg = jit_get_reg(jit_class_gpr);
-    movi(rn(reg), i0);
-    ger_u(r0, r1, rn(reg));
-    jit_unget_reg(reg);
+    if (can_sign_extend_short_p(i0)) {
+        SLTIU(r0, r1, i0);
+        XORI(r0, r0, 1);
+    } else {
+        reg = jit_get_reg(jit_class_gpr);
+        movi(rn(reg), i0);
+        ger_u(r0, r1, rn(reg));
+        jit_unget_reg(reg);
+    }
 }
 
 static void
@@ -2848,16 +2878,12 @@ _bmsi(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_word_t i1)
     jit_word_t         w;
     jit_int32_t                t0;
     t0 = jit_get_reg(jit_class_gpr|jit_class_nospill);
-    if (can_zero_extend_short_p(i1)) {
-       ANDI(rn(t0), r0, i1);
-       w = _jit->pc.w;
-       BNE(_ZERO_REGNO, rn(t0), ((i0 - w) >> 2) - 1);
-       NOP(1);
-    }
-    else {
-       movi(rn(t0), i1);
-       w = bmsr(i0, r0, rn(t0));
-    }
+
+    andi(rn(t0), r0, i1);
+    w = _jit->pc.w;
+    BNE(_ZERO_REGNO, rn(t0), ((i0 - w) >> 2) - 1);
+    NOP(1);
+
     jit_unget_reg(t0);
     return (w);
 }
@@ -2882,16 +2908,12 @@ _bmci(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_word_t i1)
     jit_word_t         w;
     jit_int32_t                t0;
     t0 = jit_get_reg(jit_class_gpr|jit_class_nospill);
-    if (can_zero_extend_short_p(i1)) {
-       ANDI(rn(t0), r0, i1);
-       w = _jit->pc.w;
-       BEQ(_ZERO_REGNO, rn(t0), ((i0 - w) >> 2) - 1);
-       NOP(1);
-    }
-    else {
-       movi(rn(t0), i1);
-       w = bmcr(i0, r0, rn(t0));
-    }
+
+    andi(rn(t0), r0, i1);
+    w = _jit->pc.w;
+    BEQ(_ZERO_REGNO, rn(t0), ((i0 - w) >> 2) - 1);
+    NOP(1);
+
     jit_unget_reg(t0);
     return (w);
 }
index b33fef2..b4642fa 100644 (file)
@@ -1,7 +1,7 @@
 
 #if __WORDSIZE == 32
 #if NEW_ABI
-#define JIT_INSTR_MAX 44
+#define JIT_INSTR_MAX 52
     0, /* data */
     0, /* live */
     0, /* align */
@@ -42,8 +42,8 @@
     28,        /* subxr */
     28,        /* subxi */
     16,        /* rsbi */
-    8, /* mulr */
-    16,        /* muli */
+    4, /* mulr */
+    12,        /* muli */
     12,        /* qmulr */
     20,        /* qmuli */
     12,        /* qmulr_u */
@@ -96,6 +96,8 @@
     8, /* nei */
     4, /* movr */
     8, /* movi */
+    4, /* movnr */
+    4, /* movzr */
     8, /* extr_c */
     4, /* extr_uc */
     8, /* extr_s */
     0, /* movi_d_ww */
     4, /* movr_d_w */
     12,        /* movi_d_w */
+    20,        /* bswapr_us */
+    52,        /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* NEW_ABI */
 #endif /* __WORDSIZE */
 
     28,        /* subxr */
     28,        /* subxi */
     16,        /* rsbi */
-    8, /* mulr */
-    16,        /* muli */
+    4, /* mulr */
+    12,        /* muli */
     12,        /* qmulr */
     20,        /* qmuli */
     12,        /* qmulr_u */
     8, /* nei */
     4, /* movr */
     8, /* movi */
+    4, /* movnr */
+    4, /* movzr */
     8, /* extr_c */
     4, /* extr_uc */
     8, /* extr_s */
     8, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    20,        /* bswapr_us */
+    52,        /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* NEW_ABI */
 #endif /* __WORDSIZE */
 
 #if __WORDSIZE == 64
-#define JIT_INSTR_MAX 44
+#define JIT_INSTR_MAX 116
     0, /* data */
     0, /* live */
     4, /* align */
     8, /* nei */
     4, /* movr */
     28,        /* movi */
+    4, /* movnr */
+    4, /* movzr */
     8, /* extr_c */
     4, /* extr_uc */
     8, /* extr_s */
     0, /* movi_d_ww */
     4, /* movr_d_w */
     12,        /* movi_d_w */
-    4, /* movnr */
-    4, /* movzr */
+    20,        /* bswapr_us */
+    52,        /* bswapr_ui */
+    116,       /* bswapr_ul */
 #endif /* __WORDSIZE */
index 5ffad2b..94fe797 100644 (file)
@@ -1419,6 +1419,11 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _ui);
 #if __WORDSIZE == 64
                case_rr(hton, _ul);
+#endif
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+#if __WORDSIZE == 64
+               case_rr(bswap, _ul);
 #endif
                case_rr(ext, _c);
                case_rr(ext, _uc);
index 475bc96..ebd3d56 100644 (file)
@@ -69,6 +69,7 @@ static char *code_name[] = {
     "gtr_u",           "gti_u",
     "ner",             "nei",
     "movr",            "movi",
+    "movnr",           "movzr",
     "extr_c",          "extr_uc",
     "extr_s",          "extr_us",
     "extr_i",          "extr_ui",
@@ -227,4 +228,6 @@ static char *code_name[] = {
     "movr_f_w",                "movi_f_w",
     "movr_d_ww",       "movi_d_ww",
     "movr_d_w",                "movi_d_w",
+    "bswapr_us",
+    "bswapr_ui",               "bswapr_ul",
 };
index 0046a05..cab085f 100644 (file)
@@ -521,23 +521,12 @@ static jit_word_t _movi_p(jit_state_t*,jit_int32_t,jit_word_t);
 #    define extr_i(r0,r1)              EXTSW(r0,r1)
 #    define extr_ui(r0,r1)             CLRLDI(r0,r1,32)
 #  endif
-#  if __BYTE_ORDER == __BIG_ENDIAN
-#    define htonr_us(r0,r1)            extr_us(r0,r1)
-#    if __WORDSIZE == 32
-#      define htonr_ui(r0,r1)          movr(r0,r1)
-#    else
-#      define htonr_ui(r0,r1)          extr_ui(r0,r1)
-#      define htonr_ul(r0,r1)          movr(r0,r1)
-#    endif
-#  else
-#    define htonr_us(r0,r1)            _htonr_us(_jit,r0,r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#    define htonr_ui(r0,r1)            _htonr_ui(_jit,r0,r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#    if __WORDSIZE == 64
-#      define htonr_ul(r0,r1)          _htonr_ul(_jit,r0,r1)
-static void _htonr_ul(jit_state_t*,jit_int32_t,jit_int32_t);
-#    endif
+#  define bswapr_us(r0,r1)             _bswapr_us(_jit,r0,r1)
+static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ui(r0,r1)             _bswapr_ui(_jit,r0,r1)
+static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
+#  if __WORDSIZE == 64
+#    define bswapr_ul(r0,r1)           generic_bswapr_ul(_jit,r0,r1)
 #  endif
 #  define addr(r0,r1,r2)               ADD(r0,r1,r2)
 #  define addi(r0,r1,i0)               _addi(_jit,r0,r1,i0)
@@ -1158,22 +1147,20 @@ _movi_p(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
     return (word);
 }
 
-#  if __BYTE_ORDER == __LITTLE_ENDIAN
 static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
-    jit_int32_t                t0;
-    t0 = jit_get_reg(jit_class_gpr);
-    rshi(rn(t0), r1, 8);
-    andi(r0, r1, 0xff);
-    andi(rn(t0), rn(t0), 0xff);
-    lshi(r0, r0, 8);
-    orr(r0, r0, rn(t0));
-    jit_unget_reg(t0);
+    if (r0 == r1) {
+        RLWIMI(r0, r0, 16, 8, 15);
+        RLWINM(r0, r0, 24, 16, 31);
+    } else {
+        RLWINM(r0, r1, 8, 16, 23);
+        RLWIMI(r0, r1, 24, 24, 31);
+    }
 }
 
 static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     jit_int32_t                reg;
     reg = jit_get_reg(jit_class_gpr);
@@ -1188,22 +1175,6 @@ _htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
     jit_unget_reg(reg);
 }
 
-#    if __WORDSIZE == 64
-static void
-_htonr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                reg;
-    reg = jit_get_reg(jit_class_gpr);
-    rshi_u(rn(reg), r1, 32);
-    htonr_ui(r0, r1);
-    htonr_ui(rn(reg), rn(reg));
-    lshi(r0, r0, 32);
-    orr(r0, r0, rn(reg));
-    jit_unget_reg(reg);
-}
-#    endif
-#  endif
-
 static void
 _addi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
index 1e84f8e..387cc6f 100644 (file)
@@ -511,7 +511,11 @@ _truncr_d_i(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
     FCTIWZ(rn(reg), r1);
     /* use reserved 8 bytes area */
     stxi_d(alloca_offset - 8, _FP_REGNO, rn(reg));
+#  if __BYTE_ORDER == __BIG_ENDIAN
     ldxi_i(r0, _FP_REGNO, alloca_offset - 4);
+#  else
+    ldxi_i(r0, _FP_REGNO, alloca_offset - 8);
+#  endif
     jit_unget_reg(reg);
 }
 
index 28251b4..0be7047 100644 (file)
@@ -97,6 +97,8 @@
     16,        /* nei */
     4, /* movr */
     8, /* movi */
+    12,  /* movnr */
+    12,  /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    12,  /* movnr */
-    12,  /* movzr */
+    20,        /* bswapr_us */
+    16,        /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* _CALL_SYV */
 #endif /* __BYTE_ORDER */
 #endif /* __powerpc__ */
     16,        /* nei */
     4, /* movr */
     8, /* movi */
+    12,  /* movnr */
+    12,  /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    12,  /* movnr */
-    12,  /* movzr */
+    20,        /* bswapr_us */
+    16,        /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* _CALL_AIX */
 #endif /* __BYTEORDER */
 #endif /* __powerpc__ */
     16,        /* nei */
     4, /* movr */
     36,        /* movi */
+    12,  /* movnr */
+    12,  /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    12,  /* movnr */
-    12,  /* movzr */
+    20,        /* bswapr_us */
+    16,        /* bswapr_ui */
+    44,        /* bswapr_ul */
 #endif /* __BYTEORDER */
 #endif /* __powerpc__ */
 #endif /* __WORDSIZE */
     16,        /* nei */
     4, /* movr */
     36,        /* movi */
+    12,  /* movnr */
+    12,  /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    12,  /* movnr */
-    12,  /* movzr */
+    20,        /* bswapr_us */
+    16,        /* bswapr_ui */
+    44,        /* bswapr_ul */
 #endif /* __BYTE_ORDER */
 #endif /* __powerpc__ */
 #endif /* __WORDSIZE */
index d05d4b1..e94d1a5 100644 (file)
@@ -1355,6 +1355,11 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _ui);
 #  if __WORDSIZE == 64
                case_rr(hton, _ul);
+#  endif
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+#  if __WORDSIZE == 64
+               case_rr(bswap, _ul);
 #  endif
                case_rr(neg,);
                case_rr(com,);
index c44623a..61d9650 100644 (file)
@@ -55,12 +55,16 @@ static FILE *print_stream;
  * Implementation
  */
 void
-_jit_print(jit_state_t *_jit)
+jit_init_print(void)
 {
-    jit_node_t         *node;
-
     if (!print_stream)
        print_stream = stderr;
+}
+
+void
+_jit_print(jit_state_t *_jit)
+{
+    jit_node_t         *node;
 
     if ((node = _jitc->head)) {
        jit_print_node(node);
index 388489f..9f029c0 100644 (file)
@@ -434,12 +434,9 @@ static void _stxi_i(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
 static void _stxr_l(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define stxi_l(i0, r0, r1)           _stxi_l(_jit, i0, r0, r1)
 static void _stxi_l(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
-#  define htonr_us(r0, r1)             _htonr_us(_jit, r0, r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#  define htonr_ui(r0, r1)             _htonr_ui(_jit, r0, r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
-#  define htonr_ul(r0, r1)             _htonr_ul(_jit, r0, r1)
-static void _htonr_ul(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_us(r0, r1)            generic_bswapr_us(_jit, r0, r1)
+#  define bswapr_ui(r0, r1)            generic_bswapr_ui(_jit, r0, r1)
+#  define bswapr_ul(r0, r1)            generic_bswapr_ul(_jit, r0, r1)
 #  define extr_c(r0, r1)               _extr_c(_jit, r0, r1)
 static void _extr_c(jit_state_t*,jit_int32_t,jit_int32_t);
 #  define extr_uc(r0, r1)              andi(r0, r1, 0xff)
@@ -455,6 +452,10 @@ static void _extr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
 static void _movi(jit_state_t*,jit_int32_t,jit_word_t);
 #  define movi_p(r0, im)               _movi_p(_jit, r0, im)
 static jit_word_t _movi_p(jit_state_t*,jit_int32_t,jit_word_t);
+#  define movnr(r0,r1,r2)              _movnr(_jit,r0,r1,r2)
+static void _movnr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define movzr(r0,r1,r2)              _movzr(_jit,r0,r1,r2)
+static void _movzr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define ltr(r0, r1, r2)              SLT(r0, r1, r2)
 #  define lti(r0, r1, im)              _lti(_jit, r0, r1, im)
 static void _lti(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t);
@@ -1243,59 +1244,6 @@ DEFST(s, H)
 DEFST(i, W)
 DEFST(l, D)
 
-static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                t0;
-    t0 = jit_get_reg(jit_class_gpr);
-    rshi(rn(t0), r1, 8);
-    andi(r0, r1, 0xff);
-    andi(rn(t0), rn(t0), 0xff);
-    lshi(r0, r0, 8);
-    orr(r0, r0, rn(t0));
-    jit_unget_reg(t0);
-}
-
-static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                t0;
-    jit_int32_t                t1;
-    jit_int32_t                t2;
-    t0 = jit_get_reg(jit_class_gpr);
-    t1 = jit_get_reg(jit_class_gpr);
-    t2 = jit_get_reg(jit_class_gpr);
-    rshi(rn(t0), r1, 24);
-    rshi(rn(t1), r1, 16);
-    rshi(rn(t2), r1,  8);
-    andi(rn(t0), rn(t0), 0xff);
-    andi(rn(t1), rn(t1), 0xff);
-    andi(rn(t2), rn(t2), 0xff);
-    andi(r0, r1, 0xff);
-    lshi(r0, r0, 24);
-    lshi(rn(t1), rn(t1), 8);
-    orr(r0, r0, rn(t0));
-    lshi(rn(t2), rn(t2), 16);
-    orr(r0, r0, rn(t1));
-    orr(r0, r0, rn(t2));
-    jit_unget_reg(t2);
-    jit_unget_reg(t1);
-    jit_unget_reg(t0);
-}
-
-static void
-_htonr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                t0;
-    t0 = jit_get_reg(jit_class_gpr);
-    rshi_u(rn(t0), r1, 32);
-    htonr_ui(r0, r1);
-    htonr_ui(rn(t0), rn(t0));
-    lshi(r0, r0, 32);
-    orr(r0, r0, rn(t0));
-    jit_unget_reg(t0);
-}
-
 static void
 _extr_c(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
@@ -1373,6 +1321,24 @@ _movi_p(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
     return (w);
 }
 
+static void
+_movnr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = beqi(_jit->pc.w, r2, 0);
+    movr(r1, r0);
+    patch_at(w, _jit->pc.w);
+}
+
+static void
+_movzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = bnei(_jit->pc.w, r2, 0);
+    movr(r1, r0);
+    patch_at(w, _jit->pc.w);
+}
+
 static void
 _lti(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
index 2f1d725..c8908d8 100644 (file)
@@ -94,6 +94,8 @@
     8, /* nei */
     4, /* movr */
     24,        /* movi */
+    8,  /* movnr */
+    8,  /* movzr */
     8, /* extr_c */
     4, /* extr_uc */
     8, /* extr_s */
     0, /* movi_d_ww */
     4, /* movr_d_w */
     16,        /* movi_d_w */
+    20,        /* bswapr_us */
+    52,        /* bswapr_ui */
+    116,       /* bswapr_ul */
 #endif /* __WORDSIZE */
index 55b2391..1dc3c9e 100644 (file)
@@ -1125,12 +1125,17 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _us);
                case_rr(hton, _ui);
                case_rr(hton, _ul);
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+               case_rr(bswap, _ul);
                case_rr(ext, _c);
                case_rr(ext, _uc);
                case_rr(ext, _s);
                case_rr(ext, _us);
                case_rr(ext, _i);
                case_rr(ext, _ui);
+               case_rrr(movn,);
+               case_rrr(movz,);
                case_rr(mov,);
            case jit_code_movi:
                if (node->flag & jit_flag_node) {
index 02cac60..619ab15 100644 (file)
@@ -966,6 +966,13 @@ static void _movr(jit_state_t*,jit_int32_t,jit_int32_t);
 static void _movi(jit_state_t*,jit_int32_t,jit_word_t);
 #  define movi_p(r0,i0)                        _movi_p(_jit,r0,i0)
 static jit_word_t _movi_p(jit_state_t*,jit_int32_t,jit_word_t);
+#  define bswapr_us(r0, r1)            generic_bswapr_us(_jit, r0, r1)
+#  define bswapr_ui(r0, r1)            generic_bswapr_ui(_jit, r0, r1)
+#  define bswapr_ul(r0, r1)            generic_bswapr_ul(_jit, r0, r1)
+#  define movnr(r0,r1,r2)              _movnr(_jit,r0,r1,r2)
+static void _movnr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define movzr(r0,r1,r2)              _movzr(_jit,r0,r1,r2)
+static void _movzr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define addr(r0,r1,r2)               _addr(_jit,r0,r1,r2)
 static void _addr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define addi(r0,r1,i0)               _addi(_jit,r0,r1,i0)
@@ -1079,13 +1086,6 @@ static void _ori(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t);
 static void _xorr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define xori(r0,r1,i0)               _xori(_jit,r0,r1,i0)
 static void _xori(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t);
-#  define htonr_us(r0,r1)              extr_us(r0,r1)
-#  if __WORDSIZE == 32
-#    define htonr_ui(r0,r1)            movr(r0,r1)
-#  else
-#    define htonr_ui(r0,r1)            extr_ui(r0,r1)
-#    define htonr_ul(r0,r1)            movr(r0,r1)
-#  endif
 #  define extr_c(r0,r1)                        LGBR(r0,r1)
 #  define extr_uc(r0,r1)               LLGCR(r0,r1)
 #  define extr_s(r0,r1)                        LGHR(r0,r1)
@@ -2442,6 +2442,32 @@ _movi_p(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
     return (w);
 }
 
+static void
+_movnr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = beqi_p(_jit->pc.w, r2, 0);
+#if __WORDSIZE == 32
+    LR(r0, r1);
+#else
+    LGR(r0, r1);
+#endif
+    patch_at(w, _jit->pc.w);
+}
+
+static void
+_movzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = bnei_p(_jit->pc.w, r2, 0);
+#if __WORDSIZE == 32
+    LR(r0, r1);
+#else
+    LGR(r0, r1);
+#endif
+    patch_at(w, _jit->pc.w);
+}
+
 static void
 _addr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
 {
index bb8b2dc..bb9071d 100644 (file)
@@ -1,6 +1,6 @@
 
 #if __WORDSIZE == 32
-#define JIT_INSTR_MAX 104
+#define JIT_INSTR_MAX 128
     0, /* data */
     0, /* live */
     6, /* align */
@@ -95,6 +95,8 @@
     24,        /* nei */
     4, /* movr */
     16,        /* movi */
+    14, /* movnr */
+    14, /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    52,        /* bswapr_us */
+    128,       /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* __WORDSIZE */
 
 #if __WORDSIZE == 64
-#define JIT_INSTR_MAX 104
+#define JIT_INSTR_MAX 344
     0, /* data */
     0, /* live */
     6, /* align */
     24,        /* nei */
     4, /* movr */
     16,        /* movi */
+    14, /* movnr */
+    14, /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    68,        /* bswapr_us */
+    160,       /* bswapr_ui */
+    344,       /* bswapr_ul */
 #endif /* __WORDSIZE */
index 7cd1d7f..4b89bea 100644 (file)
@@ -1151,6 +1151,11 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _ui);
 #if __WORDSIZE == 64
                case_rr(hton, _ul);
+#endif
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+#if __WORDSIZE == 64
+               case_rr(bswap, _ul);
 #endif
                case_rr(ext, _c);
                case_rr(ext, _uc);
@@ -1160,6 +1165,8 @@ _emit_code(jit_state_t *_jit)
                case_rr(ext, _i);
                case_rr(ext, _ui);
 #endif
+               case_rrr(movn,);
+               case_rrr(movz,);
                case_rr(mov,);
            case jit_code_movi:
                if (node->flag & jit_flag_node) {
index 051647a..90c3767 100644 (file)
@@ -545,6 +545,13 @@ static void _movr(jit_state_t*, jit_int32_t, jit_int32_t);
 static void _movi(jit_state_t*, jit_int32_t, jit_word_t);
 #  define movi_p(r0, i0)               _movi_p(_jit, r0, i0)
 static jit_word_t _movi_p(jit_state_t*, jit_int32_t, jit_word_t);
+#  define bswapr_us(r0, r1)            generic_bswapr_us(_jit, r0, r1)
+#  define bswapr_ui(r0, r1)            generic_bswapr_ui(_jit, r0, r1)
+#  define bswapr_ul(r0, r1)            generic_bswapr_ul(_jit, r0, r1)
+#  define movnr(r0,r1,r2)              _movnr(_jit,r0,r1,r2)
+static void _movnr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
+#  define movzr(r0,r1,r2)              _movzr(_jit,r0,r1,r2)
+static void _movzr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t);
 #  define comr(r0, r1)                 XNOR(r1, 0, r0)
 #  define negr(r0, r1)                 NEG(r1, r0)
 #  define addr(r0, r1, r2)             ADD(r1, r2, r0)
@@ -669,7 +676,6 @@ static void _xori(jit_state_t*, jit_int32_t, jit_int32_t, jit_word_t);
 #    define rshr_u(r0, r1, r2)         SRLX(r1, r2, r0)
 #    define rshi_u(r0, r1, i0)         SRLXI(r1, i0, r0)
 #  endif
-#  define htonr_us(r0,r1)              extr_us(r0,r1)
 #  define extr_c(r0,r1)                        _extr_c(_jit,r0,r1)
 static void _extr_c(jit_state_t*,jit_int32_t,jit_int32_t);
 #  define extr_uc(r0,r1)               andi(r0, r1, 0xff)
@@ -677,11 +683,7 @@ static void _extr_c(jit_state_t*,jit_int32_t,jit_int32_t);
 static void _extr_s(jit_state_t*,jit_int32_t,jit_int32_t);
 #  define extr_us(r0,r1)               _extr_us(_jit,r0,r1)
 static void _extr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#  if __WORDSIZE == 32
-#    define htonr_ui(r0,r1)            movr(r0,r1)
-#  else
-#    define htonr_ui(r0,r1)            extr_ui(r0,r1)
-#    define htonr_ul(r0,r1)            movr(r0,r1)
+#  if __WORDSIZE == 64
 #    define extr_i(r0,r1)              _extr_i(_jit,r0,r1)
 static void _extr_i(jit_state_t*,jit_int32_t,jit_int32_t);
 #    define extr_ui(r0,r1)             _extr_ui(_jit,r0,r1)
@@ -1213,6 +1215,24 @@ _movi_p(jit_state_t *_jit, jit_int32_t r0, jit_word_t i0)
     return (w);
 }
 
+static void
+_movnr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = beqi(_jit->pc.w, r2, 0);
+    ORI(r1, 0, r0);
+    patch_at(w, _jit->pc.w);
+}
+
+static void
+_movzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2)
+{
+    jit_word_t w;
+    w = bnei(_jit->pc.w, r2, 0);
+    ORI(r1, 0, r0);
+    patch_at(w, _jit->pc.w);
+}
+
 static void
 _addi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
 {
index ac683b6..5ec051d 100644 (file)
@@ -1,5 +1,5 @@
 #if __WORDSIZE == 32
-#define JIT_INSTR_MAX 44
+#define JIT_INSTR_MAX 52
     0, /* data */
     0, /* live */
     0, /* align */
@@ -94,6 +94,8 @@
     16,        /* nei */
     4, /* movr */
     8, /* movi */
+    20, /* movnr */
+    20, /* movzr */
     8, /* extr_c */
     4, /* extr_uc */
     8, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    20,        /* bswapr_us */
+    52,        /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif /* __WORDSIZE */
 
 #if __WORDSIZE == 64
-#define JIT_INSTR_MAX 64
+#define JIT_INSTR_MAX 116
     0, /* data */
     0, /* live */
     4, /* align */
     16,        /* nei */
     4, /* movr */
     24,        /* movi */
+    20, /* movnr */
+    20, /* movzr */
     8, /* extr_c */
     4, /* extr_uc */
     8, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
+    20,        /* bswapr_us */
+    52,        /* bswapr_ui */
+    116,       /* bswapr_ul */
 #endif /* __WORDSIZE */
index 158c09d..23d4442 100644 (file)
@@ -1463,6 +1463,11 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _ui);
 #if __WORDSIZE == 64
                case_rr(hton, _ul);
+#endif
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+#if __WORDSIZE == 64
+               case_rr(bswap, _ul);
 #endif
                case_rr(ext, _c);
                case_rr(ext, _uc);
@@ -1472,6 +1477,8 @@ _emit_code(jit_state_t *_jit)
                case_rr(ext, _i);
                case_rr(ext, _ui);
 #endif
+               case_rrr(movn,);
+               case_rrr(movz,);
                case_rr(mov,);
            case jit_code_movi:
                if (node->flag & jit_flag_node) {
index 6dcf672..81534f0 100644 (file)
@@ -379,13 +379,13 @@ static void _movir(jit_state_t*,jit_int32_t,jit_int32_t);
 #    define movir_u(r0, r1)            _movir_u(_jit, r0, r1)
 static void _movir_u(jit_state_t*,jit_int32_t,jit_int32_t);
 #  endif
-#  define htonr_us(r0, r1)             _htonr_us(_jit, r0, r1)
-static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t);
-#  define htonr_ui(r0, r1)             _htonr_ui(_jit, r0, r1)
-static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_us(r0, r1)            _bswapr_us(_jit, r0, r1)
+static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t);
+#  define bswapr_ui(r0, r1)            _bswapr_ui(_jit, r0, r1)
+static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t);
 #  if __X64 && !__X64_32
-#define htonr_ul(r0, r1)               _htonr_ul(_jit, r0, r1)
-static void _htonr_ul(jit_state_t*,jit_int32_t,jit_int32_t);
+#define bswapr_ul(r0, r1)              _bswapr_ul(_jit, r0, r1)
+static void _bswapr_ul(jit_state_t*,jit_int32_t,jit_int32_t);
 #endif
 #  define extr_c(r0, r1)               _extr_c(_jit, r0, r1)
 static void _extr_c(jit_state_t*,jit_int32_t,jit_int32_t);
@@ -2263,7 +2263,7 @@ _movir_u(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 #endif
 
 static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     extr_us(r0, r1);
     ic(0x66);
@@ -2274,7 +2274,7 @@ _htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 }
 
 static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     movr(r0, r1);
     rex(0, 0, _NOREG, _NOREG, r0);
@@ -2284,7 +2284,7 @@ _htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 
 #if __X64 && !__X64_32
 static void
-_htonr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
 {
     movr(r0, r1);
     rex(0, 1, _NOREG, _NOREG, r0);
index 2cf8880..bd4b9a0 100644 (file)
@@ -95,6 +95,8 @@
     16,        /* nei */
     2, /* movr */
     5, /* movi */
+    7, /* movnr */
+    7, /* movzr */
     11,        /* extr_c */
     11,        /* extr_uc */
     3, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    7, /* movnr */
-    7, /* movzr */
+    7, /* bswapr_us */
+    4, /* bswapr_ui */
+    0, /* bswapr_ul */
 #endif
 
 #if __X64
     14,        /* nei */
     3, /* movr */
     10,        /* movi */
+    7, /* movnr */
+    7, /* movzr */
     7, /* extr_c */
     7, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    7, /* movnr */
-    7, /* movzr */
+    9, /* bswapr_us */
+    6, /* bswapr_ui */
+    6, /* bswapr_ul */
 #else
 
 #  if __X64_32
     14,        /* nei */
     3, /* movr */
     6, /* movi */
+    7, /* movnr */
+    7, /* movzr */
     7, /* extr_c */
     7, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    7, /* movnr */
-    7, /* movzr */
+    9, /* bswapr_us */
+    6, /* bswapr_ui */
+    0, /* bswapr_ul */
 
 #  else
 #define JIT_INSTR_MAX 115
     14,        /* nei */
     3, /* movr */
     10,        /* movi */
+    7, /* movnr */
+    7, /* movzr */
     4, /* extr_c */
     4, /* extr_uc */
     4, /* extr_s */
     0, /* movi_d_ww */
     0, /* movr_d_w */
     0, /* movi_d_w */
-    7, /* movnr */
-    7, /* movzr */
+    9, /* bswapr_us */
+    6, /* bswapr_ui */
+    6, /* bswapr_ul */
 #endif /* __CYGWIN__ || _WIN32 */
 #  endif /* __X64_32 */
 #endif /* __X64 */
index 133ee39..e3e1383 100644 (file)
@@ -1698,6 +1698,11 @@ _emit_code(jit_state_t *_jit)
                case_rr(hton, _ui);
 #if __X64 && !__X64_32
                case_rr(hton, _ul);
+#endif
+               case_rr(bswap, _us);
+               case_rr(bswap, _ui);
+#if __X64 && !__X64_32
+               case_rr(bswap, _ul);
 #endif
                case_rr(ext, _c);
                case_rr(ext, _uc);
index 3063293..b78bd07 100644 (file)
@@ -19,7 +19,9 @@
 
 #include <lightning.h>
 #include <lightning/jit_private.h>
-#include <sys/mman.h>
+#if HAVE_MMAP
+#  include <sys/mman.h>
+#endif
 #if defined(__sgi)
 #  include <fcntl.h>
 #endif
@@ -956,10 +958,12 @@ _jit_destroy_state(jit_state_t *_jit)
 #if DEVEL_DISASSEMBLER
     jit_really_clear_state();
 #endif
+#if HAVE_MMAP
     if (!_jit->user_code)
        munmap(_jit->code.ptr, _jit->code.length);
     if (!_jit->user_data)
        munmap(_jit->data.ptr, _jit->data.length);
+#endif
     jit_free((jit_pointer_t *)&_jit);
 }
 
@@ -1380,6 +1384,7 @@ _jit_classify(jit_state_t *_jit, jit_code_t code)
        case jit_code_truncr_f_i:                       case jit_code_truncr_f_l:
        case jit_code_truncr_d_i:                       case jit_code_truncr_d_l:
        case jit_code_htonr_us: case jit_code_htonr_ui: case jit_code_htonr_ul:
+       case jit_code_bswapr_us:        case jit_code_bswapr_ui:        case jit_code_bswapr_ul:
        case jit_code_ldr_c:    case jit_code_ldr_uc:
        case jit_code_ldr_s:    case jit_code_ldr_us:   case jit_code_ldr_i:
        case jit_code_ldr_ui:   case jit_code_ldr_l:    case jit_code_negr_f:
@@ -1435,7 +1440,6 @@ _jit_classify(jit_state_t *_jit, jit_code_t code)
        case jit_code_unordi_d:
            mask = jit_cc_a0_reg|jit_cc_a0_chg|jit_cc_a1_reg|jit_cc_a2_dbl;
            break;
-       case jit_code_movnr:    case jit_code_movzr:
        case jit_code_addr:     case jit_code_addxr:    case jit_code_addcr:
        case jit_code_subr:     case jit_code_subxr:    case jit_code_subcr:
        case jit_code_mulr:     case jit_code_divr:     case jit_code_divr_u:
@@ -1532,6 +1536,9 @@ _jit_classify(jit_state_t *_jit, jit_code_t code)
        case jit_code_bxsubr:   case jit_code_bxsubr_u:
            mask = jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a1_chg|jit_cc_a2_reg;
            break;
+       case jit_code_movnr:    case jit_code_movzr:
+           mask = jit_cc_a0_reg|jit_cc_a0_cnd|jit_cc_a1_reg|jit_cc_a2_reg;
+           break;
        default:
            abort();
     }
@@ -1892,6 +1899,9 @@ _jit_dataset(jit_state_t *_jit)
 #endif
 
     assert(!_jitc->dataset);
+#if !HAVE_MMAP
+    assert(_jit->user_data);
+#else
     if (!_jit->user_data) {
 
        /* create read only data buffer */
@@ -1909,6 +1919,7 @@ _jit_dataset(jit_state_t *_jit)
        close(mmap_fd);
 #endif
     }
+#endif /* !HAVE_MMAP */
 
     if (!_jitc->no_data)
        jit_memcpy(_jit->data.ptr, _jitc->data.ptr, _jitc->data.offset);
@@ -2023,6 +2034,9 @@ _jit_emit(jit_state_t *_jit)
 
     _jitc->emit = 1;
 
+#if !HAVE_MMAP
+    assert(_jit->user_code);
+#else
     if (!_jit->user_code) {
 #if defined(__sgi)
        mmap_fd = open("/dev/zero", O_RDWR);
@@ -2032,6 +2046,7 @@ _jit_emit(jit_state_t *_jit)
                              MAP_PRIVATE | MAP_ANON, mmap_fd, 0);
        assert(_jit->code.ptr != MAP_FAILED);
     }
+#endif /* !HAVE_MMAP */
     _jitc->code.end = _jit->code.ptr + _jit->code.length -
        jit_get_max_instr();
     _jit->pc.uc = _jit->code.ptr;
@@ -2045,6 +2060,9 @@ _jit_emit(jit_state_t *_jit)
                     node->code == jit_code_epilog))
                    node->flag &= ~jit_flag_patch;
            }
+#if !HAVE_MMAP
+           assert(_jit->user_code);
+#else
            if (_jit->user_code)
                goto fail;
 #if GET_JIT_SIZE
@@ -2078,6 +2096,7 @@ _jit_emit(jit_state_t *_jit)
            _jitc->code.end = _jit->code.ptr + _jit->code.length -
                jit_get_max_instr();
            _jit->pc.uc = _jit->code.ptr;
+#endif /* !HAVE_MMAP */
        }
        else
            break;
@@ -2094,6 +2113,7 @@ _jit_emit(jit_state_t *_jit)
 
     if (_jit->user_data)
        jit_free((jit_pointer_t *)&_jitc->data.ptr);
+#if HAVE_MMAP
     else {
        result = mprotect(_jit->data.ptr, _jit->data.length, PROT_READ);
        assert(result == 0);
@@ -2103,6 +2123,7 @@ _jit_emit(jit_state_t *_jit)
                          PROT_READ | PROT_EXEC);
        assert(result == 0);
     }
+#endif /* HAVE_MMAP */
 
     return (_jit->code.ptr);
 fail:
@@ -3304,7 +3325,7 @@ _register_change_p(jit_state_t *_jit, jit_node_t *node, jit_node_t *link,
            default:
                value = jit_classify(node->code);
                /* lack of extra information */
-               if (value & jit_cc_a0_jmp)
+               if (value & (jit_cc_a0_jmp|jit_cc_a0_cnd))
                    return (jit_reg_change);
                else if ((value & (jit_cc_a0_reg|jit_cc_a0_chg)) ==
                         (jit_cc_a0_reg|jit_cc_a0_chg) &&
@@ -3489,6 +3510,31 @@ _patch_register(jit_state_t *_jit, jit_node_t *node, jit_node_t *link,
     }
 }
 
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define htonr_us(r0,r1)              bswapr_us(r0,r1)
+#  define htonr_ui(r0,r1)              bswapr_ui(r0,r1)
+#  if __WORDSIZE == 64
+#    define htonr_ul(r0,r1)            bswapr_ul(r0,r1)
+#  endif
+#else
+#  define htonr_us(r0,r1)              extr_us(r0,r1)
+#  if __WORDSIZE == 32
+#    define htonr_ui(r0,r1)            movr(r0,r1)
+#  else
+#    define htonr_ui(r0,r1)            extr_ui(r0,r1)
+#    define htonr_ul(r0,r1)            movr(r0,r1)
+#  endif
+#endif
+
+static maybe_unused void
+generic_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1);
+static maybe_unused void
+generic_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1);
+#if __WORDSIZE == 64
+static maybe_unused void
+generic_bswapr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1);
+#endif
+
 #if defined(__i386__) || defined(__x86_64__)
 #  include "jit_x86.c"
 #elif defined(__mips__)
@@ -3512,3 +3558,47 @@ _patch_register(jit_state_t *_jit, jit_node_t *node, jit_node_t *link,
 #elif defined(__riscv)
 #  include "jit_riscv.c"
 #endif
+
+static maybe_unused void
+generic_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+{
+    jit_int32_t reg = jit_get_reg(jit_class_gpr);
+
+    rshi(rn(reg), r1, 8);
+    andi(r0, r1, 0xff);
+    andi(rn(reg), rn(reg), 0xff);
+    lshi(r0, r0, 8);
+    orr(r0, r0, rn(reg));
+
+    jit_unget_reg(reg);
+}
+
+static maybe_unused void
+generic_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+{
+    jit_int32_t reg = jit_get_reg(jit_class_gpr);
+
+       rshi(rn(reg), r1, 16);
+       bswapr_us(r0, r1);
+       bswapr_us(rn(reg), rn(reg));
+       lshi(r0, r0, 16);
+       orr(r0, r0, rn(reg));
+
+    jit_unget_reg(reg);
+}
+
+#if __WORDSIZE == 64
+static maybe_unused void
+generic_bswapr_ul(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+{
+    jit_int32_t reg = jit_get_reg(jit_class_gpr);
+
+    rshi_u(rn(reg), r1, 32);
+    bswapr_ui(r0, r1);
+    bswapr_ui(rn(reg), rn(reg));
+    lshi(r0, r0, 32);
+    orr(r0, r0, rn(reg));
+
+    jit_unget_reg(reg);
+}
+#endif