/*
- * Copyright (C) 2012-2019 Free Software Foundation, Inc.
+ * Copyright (C) 2012-2022 Free Software Foundation, Inc.
*
* This file is part of GNU lightning.
*
#include <stdarg.h>
#include <lightning.h>
#include <dlfcn.h>
+#include <math.h>
#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
# include <fpu_control.h>
static jit_word_t get_imm(void);
static void live(void);
static void align(void); static void name(void);
+static void skip(void);
static void prolog(void);
static void frame(void); static void tramp(void);
static void ellipsis(void);
static void allocai(void); static void allocar(void);
+static void arg_c(void); static void arg_s(void);
+static void arg_i(void);
+#if __WORDSIZE == 64
+static void arg_l(void);
+#endif
static void arg(void);
static void getarg_c(void); static void getarg_uc(void);
static void getarg_s(void); static void getarg_us(void);
static void getarg_ui(void); static void getarg_l(void);
#endif
static void getarg(void);
+static void putargr_c(void); static void putargi_c(void);
+static void putargr_uc(void); static void putargi_uc(void);
+static void putargr_s(void); static void putargi_s(void);
+static void putargr_us(void); static void putargi_us(void);
+static void putargr_i(void); static void putargi_i(void);
+#if __WORDSIZE == 64
+static void putargr_ui(void); static void putargi_ui(void);
+static void putargr_l(void); static void putargi_l(void);
+#endif
static void putargr(void); static void putargi(void);
static void addr(void); static void addi(void);
static void addxr(void); static void addxi(void);
static void rshr(void); static void rshi(void);
static void rshr_u(void); static void rshi_u(void);
static void negr(void); static void comr(void);
+static void clor(void); static void clzr(void);
+static void ctor(void); static void ctzr(void);
static void ltr(void); static void lti(void);
static void ltr_u(void); static void lti_u(void);
static void ler(void); static void lei(void);
static void gtr(void); static void gti(void);
static void gtr_u(void); static void gti_u(void);
static void ner(void); static void nei(void);
+static void casr(void); static void casi(void);
static void movr(void); static void movi(void);
static void extr_c(void); static void extr_uc(void);
static void extr_s(void); static void extr_us(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);
static void ldr_s(void); static void ldi_s(void);
static void jmpr(void); static void jmpi(void);
static void callr(void); static void calli(void);
static void prepare(void);
+
+static void pushargr_c(void); static void pushargi_c(void);
+static void pushargr_uc(void); static void pushargi_uc(void);
+static void pushargr_s(void); static void pushargi_s(void);
+static void pushargr_us(void); static void pushargi_us(void);
+static void pushargr_i(void); static void pushargi_i(void);
+#if __WORDSIZE == 64
+static void pushargr_ui(void); static void pushargi_ui(void);
+static void pushargr_l(void); static void pushargi_l(void);
+#endif
static void pushargr(void); static void pushargi(void);
+
static void finishr(void); static void finishi(void);
static void ret(void);
+
+static void retr_c(void); static void reti_c(void);
+static void retr_uc(void); static void reti_uc(void);
+static void retr_s(void); static void reti_s(void);
+static void retr_us(void); static void reti_us(void);
+static void retr_i(void); static void reti_i(void);
+#if __WORDSIZE == 64
+static void retr_ui(void); static void reti_ui(void);
+static void retr_l(void); static void reti_l(void);
+#endif
static void retr(void); static void reti(void);
static void retval_c(void); static void retval_uc(void);
static void retval_s(void); static void retval_us(void);
#define entry2(name, function) { NULL, name, function }
entry(live),
entry(align), entry(name),
+ entry(skip),
entry(prolog),
entry(frame), entry(tramp),
entry(ellipsis),
entry(allocai), entry(allocar),
+ entry(arg_c), entry(arg_s),
+ entry(arg_i),
+#if __WORDSIZE == 64
+ entry(arg_l),
+#endif
entry(arg),
entry(getarg_c), entry(getarg_uc),
entry(getarg_s), entry(getarg_us),
entry(getarg_ui), entry(getarg_l),
#endif
entry(getarg),
+
+ entry(putargr_c), entry(putargi_c),
+ entry(putargr_uc), entry(putargi_uc),
+ entry(putargr_s), entry(putargi_s),
+ entry(putargr_us), entry(putargi_us),
+ entry(putargr_i), entry(putargi_i),
+#if __WORDSIZE == 64
+ entry(putargr_ui), entry(putargi_ui),
+ entry(putargr_l), entry(putargi_l),
+#endif
entry(putargr), entry(putargi),
entry(addr), entry(addi),
entry(addxr), entry(addxi),
entry(rshr), entry(rshi),
entry(rshr_u), entry(rshi_u),
entry(negr), entry(comr),
+ entry(clor), entry(clzr),
+ entry(ctor), entry(ctzr),
entry(ltr), entry(lti),
entry(ltr_u), entry(lti_u),
entry(ler), entry(lei),
entry(gtr), entry(gti),
entry(gtr_u), entry(gti_u),
entry(ner), entry(nei),
+ entry(casr), entry(casi),
entry(movr), entry(movi),
entry(extr_c), entry(extr_uc),
entry(extr_s), entry(extr_us),
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),
entry(ldr_s), entry(ldi_s),
entry(jmpr), entry(jmpi),
entry(callr), entry(calli),
entry(prepare),
+ entry(pushargr_c), entry(pushargi_c),
+ entry(pushargr_uc), entry(pushargi_uc),
+ entry(pushargr_s), entry(pushargi_s),
+ entry(pushargr_us), entry(pushargi_us),
+ entry(pushargr_i), entry(pushargi_i),
+#if __WORDSIZE == 64
+ entry(pushargr_ui), entry(pushargi_ui),
+ entry(pushargr_l), entry(pushargi_l),
+#endif
entry(pushargr), entry(pushargi),
entry(finishr), entry(finishi),
entry(ret),
+ entry(retr_c), entry(reti_c),
+ entry(retr_uc), entry(reti_uc),
+ entry(retr_s), entry(reti_s),
+ entry(retr_us), entry(reti_us),
+ entry(retr_i), entry(reti_i),
+#if __WORDSIZE == 64
+ entry(retr_ui), entry(reti_ui),
+ entry(retr_l), entry(reti_l),
+#endif
entry(retr), entry(reti),
entry(retval_c), entry(retval_uc),
entry(retval_s), entry(retval_us),
jit_word_t im = get_imm(); \
jit_##name(r0, r1, r2, im); \
}
+#define entry_ir_im_ir_ir(name) \
+static void \
+name(void) \
+{ \
+ jit_gpr_t r0 = get_ireg(); \
+ jit_word_t im = get_imm(); \
+ jit_gpr_t r1 = get_ireg(), r2 = get_ireg(); \
+ jit_##name(r0, im, r1, r2); \
+}
+
#define entry_ir_ir(name) \
static void \
name(void) \
jit_live(parser.regval);
}
entry_im(align)
+entry_im(skip)
entry(prolog)
entry_im(frame) entry_im(tramp)
entry(ellipsis)
symbol->value.i = i;
}
entry_ir_ir(allocar)
+entry_ca(arg_c) entry_ca(arg_s)
+entry_ca(arg_i)
+#if __WORDSIZE == 64
+entry_ca(arg_l)
+#endif
entry_ca(arg)
entry_ia(getarg_c) entry_ia(getarg_uc)
entry_ia(getarg_s) entry_ia(getarg_us)
entry_ia(getarg_ui) entry_ia(getarg_l)
#endif
entry_ia(getarg)
+entry_ia(putargr_c) entry_ima(putargi_c)
+entry_ia(putargr_uc) entry_ima(putargi_uc)
+entry_ia(putargr_s) entry_ima(putargi_s)
+entry_ia(putargr_us) entry_ima(putargi_us)
+entry_ia(putargr_i) entry_ima(putargi_i)
+#if __WORDSIZE == 64
+entry_ia(putargr_ui) entry_ima(putargi_ui)
+entry_ia(putargr_l) entry_ima(putargi_l)
+#endif
entry_ia(putargr) entry_ima(putargi)
entry_ir_ir_ir(addr) entry_ir_ir_im(addi)
entry_ir_ir_ir(addxr) entry_ir_ir_im(addxi)
entry_ir_ir_ir(rshr) entry_ir_ir_im(rshi)
entry_ir_ir_ir(rshr_u) entry_ir_ir_im(rshi_u)
entry_ir_ir(negr) entry_ir_ir(comr)
+entry_ir_ir(clor) entry_ir_ir(clzr)
+entry_ir_ir(ctor) entry_ir_ir(ctzr)
entry_ir_ir_ir(ltr) entry_ir_ir_im(lti)
entry_ir_ir_ir(ltr_u) entry_ir_ir_im(lti_u)
entry_ir_ir_ir(ler) entry_ir_ir_im(lei)
entry_ir_ir_ir(gtr) entry_ir_ir_im(gti)
entry_ir_ir_ir(gtr_u) entry_ir_ir_im(gti_u)
entry_ir_ir_ir(ner) entry_ir_ir_im(nei)
+entry_ir_ir_ir_ir(casr) entry_ir_im_ir_ir(casi)
entry_ir_ir(movr)
static void
movi(void)
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)
entry_ir_ir(ldr_s) entry_ir_pm(ldi_s)
entry_ir(jmpr) entry_lb(jmpi)
entry_ir(callr) entry_fn(calli)
entry(prepare)
+entry_ir(pushargr_c) entry_im(pushargi_c)
+entry_ir(pushargr_uc) entry_im(pushargi_uc)
+entry_ir(pushargr_s) entry_im(pushargi_s)
+entry_ir(pushargr_us) entry_im(pushargi_us)
+entry_ir(pushargr_i) entry_im(pushargi_i)
+#if __WORDSIZE == 64
+entry_ir(pushargr_ui) entry_im(pushargi_ui)
+entry_ir(pushargr_l) entry_im(pushargi_l)
+#endif
entry_ir(pushargr) entry_im(pushargi)
entry_ir(finishr) entry_fn(finishi)
entry(ret)
+entry_ir(retr_c) entry_im(reti_c)
+entry_ir(retr_uc) entry_im(reti_uc)
+entry_ir(retr_s) entry_im(reti_s)
+entry_ir(retr_us) entry_im(reti_us)
+entry_ir(retr_i) entry_im(reti_i)
+#if __WORDSIZE == 64
+entry_ir(retr_ui) entry_im(reti_ui)
+entry_ir(retr_l) entry_im(reti_l)
+#endif
entry_ir(retr) entry_im(reti)
entry_ir(retval_c) entry_ir(retval_uc)
entry_ir(retval_s) entry_ir(retval_us)
function = jit_emit();
if (flag_verbose > 1 || flag_disasm) {
jit_print();
- fprintf(stdout, " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
+ fprintf(stderr, " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
}
if (flag_verbose > 0 || flag_disasm) {
jit_disassemble();
- fprintf(stdout, " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
+ fprintf(stderr, " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
+ }
+ if (flag_verbose && argc) {
+ for (result = 0; result < argc; result++)
+ printf("argv[%d] = %s\n", result, argv[result]);
+ fprintf(stderr, " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
}
jit_clear_state();
{
#if HAVE_GETOPT_LONG_ONLY
fprintf(stderr, "\
-Usage: %s [jit assembler options] file [jit program options]\n\
+Usage: %s [jit assembler options] file [--] [jit program options]\n\
Jit assembler options:\n\
-help Display this information\n\
-v[0-3] Verbose output level\n\
- -d Do not use a data buffer\n\
- -D<macro>[=<val>] Preprocessor options\n"
+ -d Do not use a data buffer\n"
# if defined(__i386__) && __WORDSIZE == 32
" -mx87=1 Force using x87 when sse2 available\n"
# endif
, progname);
#else
fprintf(stderr, "\
-Usage: %s [jit assembler options] file [jit program options]\n\
+Usage: %s [jit assembler options] file [--] [jit program options]\n\
Jit assembler options:\n\
-h Display this information\n\
- -v Verbose output level\n\
- -D<macro>[=<val>] Preprocessor options\n", progname);
+ -v Verbose output level\n", progname);
#endif
finish_jit();
exit(1);
# define cc "gcc"
#endif
opt_short = snprintf(cmdline, sizeof(cmdline), cc " -E -x c %s", argv[opt_index]);
- for (++opt_index; opt_index < argc; opt_index++) {
- if (argv[opt_index][0] == '-')
- opt_short += snprintf(cmdline + opt_short,
- sizeof(cmdline) - opt_short,
- " %s", argv[opt_index]);
- else {
- --opt_index;
- break;
- }
- }
opt_short += snprintf(cmdline + opt_short,
sizeof(cmdline) - opt_short,
" -D__WORDSIZE=%d", __WORDSIZE);
opt_short += snprintf(cmdline + opt_short,
sizeof(cmdline) - opt_short,
" -D__mips__=1");
+ opt_short += snprintf(cmdline + opt_short,
+ sizeof(cmdline) - opt_short,
+ " -D__mips_isa_rev=%d", jit_cpu.release);
#endif
#if defined(__arm__)
opt_short += snprintf(cmdline + opt_short,
opt_short += snprintf(cmdline + opt_short,
sizeof(cmdline) - opt_short,
" -D__alpha__=1");
+#endif
+#if defined(__loongarch__)
+ opt_short += snprintf(cmdline + opt_short,
+ sizeof(cmdline) - opt_short,
+ " -D__loongarch__=1");
#endif
if ((parser.fp = popen(cmdline, "r")) == NULL)
error("cannot execute %s", cmdline);