#include #include #include #include #include "common.h" static struct gpr_stat zero_gpr_stat() { return (struct gpr_stat){ .r = EJIT_GPR(0), .prio = 0, .rno = 0 }; } static struct fpr_stat zero_fpr_stat() { return (struct fpr_stat){ .f = EJIT_FPR(0), .prio = 0, .fno = 0 }; } static void update_gpr(struct ejit_func *f, struct ejit_gpr r0) { while (gpr_stats_len(&f->gpr) <= r0.r) gpr_stats_append(&f->gpr, zero_gpr_stat()); struct gpr_stat *gpr = gpr_stats_at(&f->gpr, r0.r); /* presumably first time we see this gpr */ /** @todo are branches faster than a memory write? */ if (gpr->prio == 0) gpr->r = r0; gpr->prio += f->prio; } static void update_fpr(struct ejit_func *f, struct ejit_fpr f0) { while (fpr_stats_len(&f->fpr) <= f0.f) fpr_stats_append(&f->fpr, zero_fpr_stat()); struct fpr_stat *fpr = fpr_stats_at(&f->fpr, f0.f); if (fpr->prio == 0) fpr->f = f0; fpr->prio += f->prio; } static void update_64(struct ejit_func *f, int64_t o) { if (f->use_64) return; int32_t x = o >> 32; f->use_64 = x != -1 && x != 0; } static void emit_insn_o(struct ejit_func *f, enum ejit_opcode op) { struct ejit_insn i = {.op = op}; insns_append(&f->insns, i); } static void emit_insn_oi(struct ejit_func *f, enum ejit_opcode op, int64_t o) { update_64(f, o); struct ejit_insn i = {.op = op, .o = o}; insns_append(&f->insns, i); } static void emit_insn_oF(struct ejit_func *f, enum ejit_opcode op, float o) { struct ejit_insn i = {.op = op, .f = o}; insns_append(&f->insns, i); } static void emit_insn_oD(struct ejit_func *f, enum ejit_opcode op, double o) { struct ejit_insn i = {.op = op, .d = o}; insns_append(&f->insns, i); } static void emit_insn_of(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0) { update_fpr(f, f0); struct ejit_insn i = {.op = op, .r0 = f0.f}; insns_append(&f->insns, i); } static void emit_insn_or(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0) { update_gpr(f, r0); struct ejit_insn i = {.op = op, .r0 = r0.r}; insns_append(&f->insns, i); } static void emit_insn_ori(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0, int64_t o) { update_gpr(f, r0); update_64(f, o); struct ejit_insn i = {.op = op, .r0 = r0.r, .o = o}; insns_append(&f->insns, i); } static void emit_insn_oxf(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f1) { update_fpr(f, f1); struct ejit_insn i = {.op = op, .r1 = f1.f}; insns_append(&f->insns, i); } static void emit_insn_orri(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { update_gpr(f, r0); update_gpr(f, r1); update_64(f, o); struct ejit_insn i = {.op = op, .r0 = r0.r, .r1 = r1.r, .o = o}; insns_append(&f->insns, i); } static void emit_insn_ar(struct ejit_func *f, enum ejit_opcode op, size_t idx, enum ejit_type type, struct ejit_gpr r0) { update_gpr(f, r0); struct ejit_insn i = {.op = op, .r0 = idx, .r1 = type, .r2 = r0.r}; insns_append(&f->insns, i); } static void emit_insn_ai(struct ejit_func *f, enum ejit_opcode op, size_t idx, enum ejit_type type, int64_t o) { update_64(f, o); struct ejit_insn i = {.op = op, .r0 = idx, .r1 = type, .o = o}; insns_append(&f->insns, i); } static void emit_insn_af(struct ejit_func *f, enum ejit_opcode op, size_t idx, enum ejit_type type, struct ejit_fpr f0) { update_fpr(f, f0); struct ejit_insn i = {.op = op, .r0 = idx, .r1 = type, .r2 = f0.f}; insns_append(&f->insns, i); } static void emit_insn_ad(struct ejit_func *f, enum ejit_opcode op, size_t idx, enum ejit_type type, double d) { struct ejit_insn i = {.op = op, .r0 = idx, .r1 = type, .d = d}; insns_append(&f->insns, i); } static void emit_insn_orr(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0, struct ejit_gpr r1) { update_gpr(f, r0); update_gpr(f, r1); struct ejit_insn i = {.op = op, .r0 = r0.r, .r1 = r1.r}; insns_append(&f->insns, i); } static void emit_insn_orrr(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { update_gpr(f, r0); update_gpr(f, r1); update_gpr(f, r2); struct ejit_insn i = {.op = op, .r0 = r0.r, .r1 = r1.r, .r2 = r2.r}; insns_append(&f->insns, i); } static void emit_insn_off(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, struct ejit_fpr f1) { update_fpr(f, f0); update_fpr(f, f1); struct ejit_insn i = {.op = op, .r0 = f0.f, .r1 = f1.f}; insns_append(&f->insns, i); } static void emit_insn_offf(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { update_fpr(f, f0); update_fpr(f, f1); update_fpr(f, f2); struct ejit_insn i = {.op = op, .r0 = f0.f, .r1 = f1.f, .r2 = f2.f}; insns_append(&f->insns, i); } static void emit_insn_orf(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0, struct ejit_fpr f1) { update_gpr(f, r0); update_fpr(f, f1); struct ejit_insn i = {.op = op, .r0 = r0.r, .r1 = f1.f}; insns_append(&f->insns, i); } static void emit_insn_oxr(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r1) { update_gpr(f, r1); struct ejit_insn i = {.op = op, .r1 = r1.r}; insns_append(&f->insns, i); } static void emit_insn_oxrr(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r1, struct ejit_gpr r2) { update_gpr(f, r1); update_gpr(f, r2); struct ejit_insn i = {.op = op, .r1 = r1.r, .r2 = r2.r}; insns_append(&f->insns, i); } static void emit_insn_oxri(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r1, int64_t o) { update_gpr(f, r1); update_64(f, o); struct ejit_insn i = {.op = op, .r1 = r1.r, .o = o}; insns_append(&f->insns, i); } static void emit_insn_ofr(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, struct ejit_gpr r1) { update_fpr(f, f0); update_gpr(f, r1); struct ejit_insn i = {.op = op, .r0 = f0.f, .r1 = r1.r}; insns_append(&f->insns, i); } static void emit_insn_ofrr(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, struct ejit_gpr r1, struct ejit_gpr r2) { update_fpr(f, f0); update_gpr(f, r1); update_gpr(f, r2); struct ejit_insn i = {.op = op, .r0 = f0.f, .r1 = r1.r, .r2 = r2.r}; insns_append(&f->insns, i); } static void emit_insn_ofri(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, struct ejit_gpr r1, int64_t o) { update_fpr(f, f0); update_gpr(f, r1); update_64(f, o); struct ejit_insn i = {.op = op, .r0 = f0.f, .r1 = r1.r, .o = o}; insns_append(&f->insns, i); } static void emit_insn_orff(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { update_gpr(f, r0); update_fpr(f, f1); update_fpr(f, f2); struct ejit_insn i = {.op = op, .r0 = r0.r, .r1 = f1.f, .r2 = f2.f}; insns_append(&f->insns, i); } static void emit_insn_oxff(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f1, struct ejit_fpr f2) { update_fpr(f, f1); update_fpr(f, f2); struct ejit_insn i = {.op = op, .r1 = f1.f, .r2 = f2.f}; insns_append(&f->insns, i); } static void emit_insn_op(struct ejit_func *f, enum ejit_opcode op, void *p) { struct ejit_insn i = {.op = op, .p = p}; insns_append(&f->insns, i); } static void emit_insn_orp(struct ejit_func *f, enum ejit_opcode op, struct ejit_gpr r0, void *p) { update_gpr(f, r0); struct ejit_insn i = {.op = op, .r0 = r0.r, .p = p}; insns_append(&f->insns, i); } static void emit_insn_ofp(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, void *p) { update_fpr(f, f0); struct ejit_insn i = {.op = op, .r0 = f0.f, .p = p}; insns_append(&f->insns, i); } static void emit_insn_ofF(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, float d) { update_fpr(f, f0); struct ejit_insn i = {.op = op, .r0 = f0.f, .f = d}; insns_append(&f->insns, i); } static void emit_insn_ofD(struct ejit_func *f, enum ejit_opcode op, struct ejit_fpr f0, double d) { update_fpr(f, f0); struct ejit_insn i = {.op = op, .r0 = f0.f, .d = d}; insns_append(&f->insns, i); } struct ejit_func *ejit_create_func(enum ejit_type rtype, size_t argc, const struct ejit_operand args[argc]) { struct ejit_func *f = malloc(sizeof(struct ejit_func)); assert(f); f->rtype = rtype; f->insns = insns_create(); f->labels = labels_create(); f->gpr = gpr_stats_create(); f->fpr = fpr_stats_create(); f->arena = NULL; f->direct_call = NULL; f->size = 0; f->prio = 1; f->use_64 = false; for (size_t i = 0; i < argc; ++i) { switch (args[i].kind) { case EJIT_OPERAND_GPR: { assert(ejit_int_type(args[i].type)); emit_insn_ar(f, PARAM, i, args[i].type, EJIT_GPR(args[i].r)); break; } case EJIT_OPERAND_FPR: { assert(ejit_float_type(args[i].type)); emit_insn_af(f, PARAM_F, i, args[i].type, EJIT_FPR(args[i].r)); break; } default: abort(); } } emit_insn_o(f, START); return f; } void ejit_compile_func(struct ejit_func *f) { ejit_select_compile_func(f, gpr_stats_len(&f->gpr), fpr_stats_len(&f->fpr), f->use_64, true); } void ejit_select_compile_func(struct ejit_func *f, size_t gpr, size_t fpr, bool use_64, bool try_jit) { /* emit a final end instruction in case user didn't do a return */ emit_insn_o(f, END); /* user can get some sanity checking done by passing these explicitly */ assert(gpr >= gpr_stats_len(&f->gpr)); assert(fpr >= fpr_stats_len(&f->fpr)); assert(!f->use_64 || (use_64 == f->use_64)); /* try to jit compile if possible */ if (try_jit && ejit_compile(f, use_64)) return; /* otherwise, convert opcodes to address labels */ void **labels; /* just get labels, don't actually run anything yet */ if (ejit_float_type(f->rtype)) ejit_run_interp_f(f, 0, NULL, NULL, false, &labels); else ejit_run_interp(f, 0, NULL, NULL, false, &labels); foreach_vec(ii, f->insns) { struct ejit_insn i = *insns_at(&f->insns, ii); void *addr = labels[i.op]; assert(addr); i.addr = addr; *insns_at(&f->insns, ii) = i; } /* doesn't really matter what we put here as long as it isn't 0 */ f->size = 1; } void ejit_destroy_func(struct ejit_func *f) { if (f->arena) munmap(f->arena, f->size); insns_destroy(&f->insns); labels_destroy(&f->labels); gpr_stats_destroy(&f->gpr); fpr_stats_destroy(&f->fpr); free(f); } struct ejit_label ejit_label(struct ejit_func *f) { size_t addr = insns_len(&f->insns); labels_append(&f->labels, addr); return (struct ejit_label){.addr = addr}; } void ejit_patch(struct ejit_func *f, struct ejit_reloc r, struct ejit_label l) { struct ejit_insn i = *insns_at(&f->insns, r.insn); /** @todo some assert that checks the opcode? */ i.r0 = l.addr; *insns_at(&f->insns, r.insn) = i; } void ejit_calli(struct ejit_func *s, struct ejit_func *f, size_t argc, const struct ejit_operand args[argc]) { for (size_t i = 0; i < argc; ++i) { switch (args[i].kind) { case EJIT_OPERAND_GPR: emit_insn_ar(s, ARG, i, args[i].type, EJIT_GPR(args[i].r)); break; case EJIT_OPERAND_FPR: emit_insn_af(s, ARG_F, i, args[i].type, EJIT_FPR(args[i].r)); break; case EJIT_OPERAND_IMM: emit_insn_ai(s, ARG_I, i, args[i].type, args[i].r); break; case EJIT_OPERAND_FLT: emit_insn_ad(s, ARG_FI, i, args[i].type, args[i].d); break; default: abort(); } } emit_insn_op(s, CALLI, f); } void ejit_escapei(struct ejit_func *s, ejit_escape_t f, size_t argc, const struct ejit_operand args[argc]) { for (size_t i = 0; i < argc; ++i) { switch (args[i].kind) { case EJIT_OPERAND_GPR: emit_insn_ar(s, ARG, i, args[i].type, EJIT_GPR(args[i].r)); break; case EJIT_OPERAND_FPR: emit_insn_af(s, ARG_F, i, args[i].type, EJIT_FPR(args[i].r)); break; case EJIT_OPERAND_IMM: emit_insn_ai(s, ARG_I, i, args[i].type, args[i].r); break; case EJIT_OPERAND_FLT: emit_insn_ad(s, ARG_FI, i, args[i].type, args[i].d); break; default: abort(); } } emit_insn_op(s, ESCAPEI, f); } void ejit_escapei_f(struct ejit_func *s, ejit_escape_f_t f, size_t argc, const struct ejit_operand args[argc]) { for (size_t i = 0; i < argc; ++i) { switch (args[i].kind) { case EJIT_OPERAND_GPR: emit_insn_ar(s, ARG, i, args[i].type, EJIT_GPR(args[i].r)); break; case EJIT_OPERAND_FPR: emit_insn_af(s, ARG_F, i, args[i].type, EJIT_FPR(args[i].r)); break; case EJIT_OPERAND_IMM: emit_insn_ai(s, ARG_I, i, args[i].type, args[i].r); break; case EJIT_OPERAND_FLT: emit_insn_ad(s, ARG_FI, i, args[i].type, args[i].d); break; default: abort(); } } emit_insn_op(s, ESCAPEI_F, f); } void ejit_retval(struct ejit_func *s, struct ejit_gpr r0) { emit_insn_or(s, RETVAL, r0); } void ejit_retval_f(struct ejit_func *s, struct ejit_fpr f0) { emit_insn_of(s, RETVAL_F, f0); } void ejit_retval_d(struct ejit_func *s, struct ejit_fpr f0) { emit_insn_of(s, RETVAL_D, f0); } void ejit_sti_8(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, STI8, r0, p); } void ejit_sti_16(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, STI16, r0, p); } void ejit_sti_32(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, STI32, r0, p); } void ejit_sti_64(struct ejit_func *s, struct ejit_gpr r0, void *p) { s->use_64 = true; emit_insn_orp(s, STI64, r0, p); } void ejit_sti_f(struct ejit_func *s, struct ejit_fpr f0, void *p) { emit_insn_ofp(s, STIF, f0, p); } void ejit_sti_d(struct ejit_func *s, struct ejit_fpr f0, void *p) { emit_insn_ofp(s, STID, f0, p); } void ejit_stxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, STXI8, r0, r1, o); } void ejit_stxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, STXI16, r0, r1, o); } void ejit_stxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, STXI32, r0, r1, o); } void ejit_stxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { s->use_64 = true; emit_insn_orri(s, STXI64, r0, r1, o); } void ejit_stxi_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, int64_t o) { emit_insn_ofri(s, STXIF, f0, r1, o); } void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, int64_t o) { emit_insn_ofri(s, STXID, f0, r1, o); } void ejit_stxr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, STXR8, r0, r1, r2); } void ejit_stxr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, STXR16, r0, r1, r2); } void ejit_stxr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, STXR32, r0, r1, r2); } void ejit_stxr_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { s->use_64 = true; emit_insn_orrr(s, STXR64, r0, r1, r2); } void ejit_stxr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_ofrr(s, STXRF, f0, r1, r2); } void ejit_stxr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_ofrr(s, STXRD, f0, r1, r2); } void ejit_ldi_i8(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDI8, r0, p); } void ejit_ldi_i16(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDI16, r0, p); } void ejit_ldi_i32(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDI32, r0, p); } void ejit_ldi_i64(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDI64, r0, p); } void ejit_ldi_u8(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDIU8, r0, p); } void ejit_ldi_u16(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDIU16, r0, p); } void ejit_ldi_u32(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDIU32, r0, p); } void ejit_ldi_u64(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_orp(s, LDIU64, r0, p); } void ejit_ldi_f(struct ejit_func *s, struct ejit_fpr f0, void *p) { emit_insn_ofp(s, LDIF, f0, p); } void ejit_ldi_d(struct ejit_func *s, struct ejit_fpr f0, void *p) { emit_insn_ofp(s, LDID, f0, p); } void ejit_ldxi_i8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXI8, r0, r1, o); } void ejit_ldxi_i16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXI16, r0, r1, o); } void ejit_ldxi_i32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXI32, r0, r1, o); } void ejit_ldxi_i64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXI64, r0, r1, o); } void ejit_ldxi_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXIU8, r0, r1, o); } void ejit_ldxi_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXIU16, r0, r1, o); } void ejit_ldxi_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXIU32, r0, r1, o); } void ejit_ldxi_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LDXIU64, r0, r1, o); } void ejit_ldxi_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, int64_t o) { emit_insn_ofri(s, LDXIF, f0, r1, o); } void ejit_ldxi_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, int64_t o) { emit_insn_ofri(s, LDXID, f0, r1, o); } void ejit_ldxr_i8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXR8, r0, r1, r2); } void ejit_ldxr_i16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXR16, r0, r1, r2); } void ejit_ldxr_i32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXR32, r0, r1, r2); } void ejit_ldxr_i64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXR64, r0, r1, r2); } void ejit_ldxr_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXRU8, r0, r1, r2); } void ejit_ldxr_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXRU16, r0, r1, r2); } void ejit_ldxr_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXRU32, r0, r1, r2); } void ejit_ldxr_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LDXIU64, r0, r1, r2); } void ejit_ldxr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_ofrr(s, LDXRF, f0, r1, r2); } void ejit_ldxr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_ofrr(s, LDXRD, f0, r1, r2); } void ejit_ret(struct ejit_func *s) { emit_insn_o(s, END); } void ejit_retr(struct ejit_func *s, struct ejit_gpr r0) { emit_insn_oxr(s, RETR, r0); } void ejit_retr_f(struct ejit_func *s, struct ejit_fpr f0) { emit_insn_oxf(s, RETR_F, f0); } void ejit_retr_d(struct ejit_func *s, struct ejit_fpr f0) { emit_insn_oxf(s, RETR_D, f0); } void ejit_reti(struct ejit_func *s, int64_t i) { emit_insn_oi(s, RETI, i); } void ejit_reti_f(struct ejit_func *s, float f) { emit_insn_oF(s, RETI_F, f); } void ejit_reti_d(struct ejit_func *s, double f) { emit_insn_oD(s, RETI_D, f); } void ejit_extr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, EXTR8, r0, r1); } void ejit_extr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, EXTR16, r0, r1); } void ejit_extr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, EXTR32, r0, r1); } void ejit_extr_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, EXTRU8, r0, r1); } void ejit_extr_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, EXTRU16, r0, r1); } void ejit_extr_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, EXTRU32, r0, r1); } void ejit_extr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1) { emit_insn_ofr(s, EXTRF, f0, r1); } void ejit_extr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1) { emit_insn_ofr(s, EXTRD, f0, r1); } void ejit_addr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, ADDR, r0, r1, r2); } void ejit_addr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, ADDR_F, f0, f1, f2); } void ejit_addr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, ADDR_D, f0, f1, f2); } void ejit_addi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, ADDI, r0, r1, o); } void ejit_absr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { emit_insn_off(s, ABSR_F, f0, f1); } void ejit_absr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { emit_insn_off(s, ABSR_D, f0, f1); } void ejit_subr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, SUBR, r0, r1, r2); } void ejit_subr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, SUBR_F, f0, f1, f2); } void ejit_subr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, SUBR_D, f0, f1, f2); } void ejit_subi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, long o) { emit_insn_orri(s, SUBI, r0, r1, o); } void ejit_mulr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, MULR, r0, r1, r2); } void ejit_mulr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, MULR_F, f0, f1, f2); } void ejit_mulr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, MULR_D, f0, f1, f2); } void ejit_divr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, DIVR, r0, r1, r2); } void ejit_divr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, DIVR_U, r0, r1, r2); } void ejit_divr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, DIVR_F, f0, f1, f2); } void ejit_divr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_offf(s, DIVR_D, f0, f1, f2); } void ejit_remr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, REMR, r0, r1, r2); } void ejit_remr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, REMR_U, r0, r1, r2); } void ejit_lshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, LSHI, r0, r1, o); } void ejit_lshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, LSHR, r0, r1, r2); } void ejit_rshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, RSHI, r0, r1, o); } void ejit_rshi_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, RSHI_U, r0, r1, o); } void ejit_rshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, RSHR, r0, r1, r2); } void ejit_rshr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, RSHR_U, r0, r1, r2); } void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, ANDR, r0, r1, r2); } void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, ANDI, r0, r1, o); } void ejit_orr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, ORR, r0, r1, r2); } void ejit_ori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, ORI, r0, r1, o); } void ejit_xorr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, XORR, r0, r1, r2); } void ejit_xori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { emit_insn_orri(s, XORI, r0, r1, o); } void ejit_comr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, COMR, r0, r1); } void ejit_negr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_orr(s, NEGR, r0, r1); } void ejit_negr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { emit_insn_off(s, NEGR_F, f0, f1); } void ejit_negr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { emit_insn_off(s, NEGR_D, f0, f1); } void ejit_movi(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { emit_insn_ori(s, MOVI, r0, o); } void ejit_movi_f(struct ejit_func *s, struct ejit_fpr f0, float o) { emit_insn_ofF(s, MOVI_F, f0, o); } void ejit_movi_d(struct ejit_func *s, struct ejit_fpr f0, double o) { emit_insn_ofD(s, MOVI_D, f0, o); } void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { if (r0.r == r1.r) return; emit_insn_orr(s, MOVR, r0, r1); } void ejit_movr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { if (f0.f == f1.f) return; emit_insn_off(s, MOVR_F, f0, f1); } void ejit_movr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { if (f0.f == f1.f) return; emit_insn_off(s, MOVR_D, f0, f1); } void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, EQR, r0, r1, r2); } void ejit_eqr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, EQR_F, r0, f1, f2); } void ejit_eqr_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, EQR_D, r0, f1, f2); } void ejit_ner(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, NER, r0, r1, r2); } void ejit_ner_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, NER_F, r0, f1, f2); } void ejit_ner_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, NER_D, r0, f1, f2); } void ejit_gtr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GTR, r0, r1, r2); } void ejit_gtr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GTR_U, r0, r1, r2); } void ejit_gtr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GTR_F, r0, f1, f2); } void ejit_gtr_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GTR_D, r0, f1, f2); } void ejit_ltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GTR, r0, r2, r1); } void ejit_ltr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GTR_U, r0, r2, r1); } void ejit_ltr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GTR_F, r0, f2, f1); } void ejit_ltr_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GTR_D, r0, f2, f1); } void ejit_ger(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GER, r0, r1, r2); } void ejit_ger_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GER_U, r0, r1, r2); } void ejit_ger_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GER_F, r0, f1, f2); } void ejit_ger_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GER_D, r0, f1, f2); } void ejit_ler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GER, r0, r2, r1); } void ejit_ler_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_orrr(s, GER_U, r0, r2, r1); } void ejit_ler_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GER_F, r0, f2, f1); } void ejit_ler_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1, struct ejit_fpr f2) { emit_insn_orff(s, GER_D, r0, f2, f1); } void ejit_truncr_d_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1) { emit_insn_orf(s, TRUNCR_D_32, r0, f1); } void ejit_truncr_d_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1) { s->use_64 = true; emit_insn_orf(s, TRUNCR_D_64, r0, f1); } void ejit_truncr_f_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1) { emit_insn_orf(s, TRUNCR_F_32, r0, f1); } void ejit_truncr_f_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr f1) { s->use_64 = true; emit_insn_orf(s, TRUNCR_F_64, r0, f1); } struct ejit_reloc ejit_bner(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BNER, r0, r1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bnei(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BNEI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bner_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BNER_F, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bner_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BNER_D, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_beqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BEQR, r0, r1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_beqi(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BEQI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_beqr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BEQR_F, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_beqr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BEQR_D, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bger(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGER, r0, r1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bger_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGER_U, r0, r1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bger_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGER_F, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bger_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGER_D, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgei(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BGEI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgei_u(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BGEI_U, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGER, r1, r0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bler_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGER_U, r1, r0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bler_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGER_F, f1, f0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bler_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGER_D, f1, f0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_blei(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BLEI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_blei_u(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BLEI_U, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgti(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BGTI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgti_u(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BGTI_U, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgtr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGTR, r0, r1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgtr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGTR_U, r0, r1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgtr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGTR_F, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bgtr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGTR_D, f0, f1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGTR, r1, r0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bltr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BGTR_U, r1, r0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bltr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGTR_F, f1, f0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bltr_d(struct ejit_func *s, struct ejit_fpr f0, struct ejit_fpr f1) { size_t addr = insns_len(&s->insns); emit_insn_oxff(s, BGTR_D, f1, f0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_blti(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BLTI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_blti_u(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BLTI_U, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_jmp(struct ejit_func *s) { size_t addr = insns_len(&s->insns); emit_insn_o(s, JMP); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_jmpr(struct ejit_func *s, struct ejit_gpr r0) { size_t addr = insns_len(&s->insns); emit_insn_oxr(s, JMPR, r0); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bmci(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BMCI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bmcr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BMCR, r0, r1); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bmsi(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = insns_len(&s->insns); emit_insn_oxri(s, BMSI, r0, o); return (struct ejit_reloc){.insn = addr}; } struct ejit_reloc ejit_bmsr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { size_t addr = insns_len(&s->insns); emit_insn_oxrr(s, BMSR, r0, r1); return (struct ejit_reloc){.insn = addr}; } static struct interp_state create_interp_state() { struct interp_state state; state.gprs = gprs_create(); state.fprs = fprs_create(); state.args = args_create(); return state; } static void destroy_interp_state(struct interp_state state) { gprs_destroy(&state.gprs); fprs_destroy(&state.fprs); args_destroy(&state.args); } int64_t ejit_run_interp(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], struct interp_state *state, bool run, void ***labels_wb) { if (run) { assert(f->size && "trying to run a function that hasn't been compiled"); assert(f->rtype == EJIT_VOID || ejit_int_type(f->rtype)); if (f->arena) return ((ejit_escape_t)f->arena)(argc, args); } int64_t retval = 0; double retval_f = 0.0; #include "interp.inc" return retval; } double ejit_run_interp_f(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], struct interp_state *state, bool run, void ***labels_wb) { if (run) { assert(f->size && "trying to run a function that hasn't been compiled"); /* void functions should use ejit_run_interp */ assert(ejit_float_type(f->rtype)); if (f->arena) return ((ejit_escape_f_t)f->arena)(argc, args); } int64_t retval = 0; double retval_f = 0.0; #include "interp.inc" return retval_f; } int64_t ejit_run_func(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) { assert(f->size && "trying to run a function that hasn't been compiled"); assert(f->rtype == EJIT_VOID || ejit_int_type(f->rtype)); if (f->arena) return (int64_t)((ejit_escape_t)f->arena)(argc, args); struct interp_state state = create_interp_state(); long r = ejit_run_interp(f, argc, args, &state, true, NULL); destroy_interp_state(state); return r; } double ejit_run_func_f(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) { assert(f->size && "trying to run a function that hasn't been compiled"); assert(ejit_float_type(f->rtype)); if (f->arena) return ((ejit_escape_f_t)f->arena)(argc, args); struct interp_state state = create_interp_state(); double r = ejit_run_interp_f(f, argc, args, &state, true, NULL); destroy_interp_state(state); return r; } size_t ejit_get_prio(struct ejit_func *s) { return s->prio; } void ejit_set_prio(struct ejit_func *s, size_t prio) { s->prio = prio; } void ejit_inc_prio(struct ejit_func *s, size_t prio) { s->prio += prio; } void ejit_dec_prio(struct ejit_func *s, size_t prio) { s->prio -= prio; }