diff options
Diffstat (limited to 'src/ejit.c')
-rw-r--r-- | src/ejit.c | 184 |
1 files changed, 176 insertions, 8 deletions
@@ -197,6 +197,36 @@ void ejit_retval_f(struct ejit_func *s, struct ejit_fpr r0) emit_insn_i(s, RETVAL_F, r0.f, 0, 0); } +void ejit_sti_8(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI8, r0.r, 0, p); +} + +void ejit_sti_16(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI16, r0.r, 0, p); +} + +void ejit_sti_32(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI32, r0.r, 0, p); +} + +void ejit_sti_64(struct ejit_func *s, struct ejit_gpr r0, void *p) +{ + emit_insn_p(s, STI64, r0.r, 0, p); +} + +void ejit_sti_f(struct ejit_func *s, struct ejit_fpr r0, void *p) +{ + emit_insn_p(s, STIF, r0.f, 0, p); +} + +void ejit_sti_d(struct ejit_func *s, struct ejit_fpr r0, void *p) +{ + emit_insn_p(s, STID, r0.f, 0, p); +} + void ejit_stxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { @@ -233,6 +263,42 @@ void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, emit_insn_i(s, STXID, r0.f, r1.r, o); } +void ejit_stxr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR8, r0.r, r1.r, r2.r); +} + +void ejit_stxr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR16, r0.r, r1.r, r2.r); +} + +void ejit_stxr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR32, r0.r, r1.r, r2.r); +} + +void ejit_stxr_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXR64, r0.r, r1.r, r2.r); +} + +void ejit_stxr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXRF, r0.f, r1.r, r2.r); +} + +void ejit_stxr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, STXRD, r0.f, r1.r, r2.r); +} + void ejit_ldi_i8(struct ejit_func *s, struct ejit_gpr r0, void *p) { emit_insn_p(s, LDI8, r0.r, 0, p); @@ -403,6 +469,11 @@ void ejit_ldxr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1, emit_insn_r(s, LDXRD, r0.f, r1.r, r2.r); } +void ejit_ret(struct ejit_func *s) +{ + emit_insn_i(s, END, 0, 0, 0); +} + void ejit_retr(struct ejit_func *s, struct ejit_gpr r0) { emit_insn_r(s, RETR, r0.r, 0, 0); @@ -500,6 +571,12 @@ void ejit_mulr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, emit_insn_r(s, MULR, r0.r, r1.r, r2.r); } +void ejit_mulr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, + struct ejit_fpr r2) +{ + emit_insn_r(s, MULR_F, r0.f, r1.f, r2.f); +} + void ejit_divr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -518,6 +595,18 @@ void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, emit_insn_r(s, DIVR_F, r0.f, r1.f, r2.f); } +void ejit_remr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, REMR, r0.r, r1.r, r2.r); +} + +void ejit_remr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, REMR_U, r0.r, r1.r, r2.r); +} + void ejit_lshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o) { @@ -536,12 +625,24 @@ void ejit_rshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, emit_insn_i(s, RSHI, r0.r, r1.r, o); } +void ejit_rshi_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o) +{ + emit_insn_i(s, RSHI_U, r0.r, r1.r, o); +} + void ejit_rshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { emit_insn_r(s, RSHR, r0.r, r1.r, r2.r); } +void ejit_rshr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, RSHR_U, r0.r, r1.r, r2.r); +} + void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -554,6 +655,30 @@ void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, emit_insn_i(s, ANDI, r0.r, r1.r, o); } +void ejit_orr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, ORR, r0.r, r1.r, r2.r); +} + +void ejit_ori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o) +{ + emit_insn_i(s, ORI, r0.r, r1.r, o); +} + +void ejit_xorr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, XORR, r0.r, r1.r, r2.r); +} + +void ejit_xori(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o) +{ + emit_insn_i(s, XORI, r0.r, r1.r, o); +} + void ejit_comr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { emit_insn_i(s, COMR, r0.r, r1.r, 0); @@ -564,11 +689,21 @@ void ejit_negr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) emit_insn_i(s, NEGR, r0.r, r1.r, 0); } +void ejit_negr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1) +{ + emit_insn_i(s, NEGR_F, r0.f, r1.f, 0); +} + void ejit_movi(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { emit_insn_i(s, MOVI, r0.r, 0, o); } +void ejit_movi_f(struct ejit_func *s, struct ejit_fpr r0, double o) +{ + emit_insn_f(s, MOVI_F, r0.f, 0, o); +} + void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) { if (r0.r == r1.r) @@ -577,6 +712,14 @@ void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) emit_insn_i(s, MOVR, r0.r, r1.r, 0); } +void ejit_movr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1) +{ + if (r0.f == r1.f) + return; + + emit_insn_i(s, MOVR_F, r0.f, r1.f, 0); +} + void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -589,6 +732,18 @@ void ejit_eqr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, emit_insn_r(s, EQR_F, r0.r, r1.f, r2.f); } +void ejit_ner(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + struct ejit_gpr r2) +{ + emit_insn_r(s, NER, r0.r, r1.r, r2.r); +} + +void ejit_ner_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, + struct ejit_fpr r2) +{ + emit_insn_r(s, NER_F, r0.r, r1.f, r2.f); +} + void ejit_gtr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { @@ -610,19 +765,19 @@ void ejit_gtr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, void ejit_ltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GER, r0.r, r2.r, r1.r); + emit_insn_r(s, GTR, r0.r, r2.r, r1.r); } void ejit_ltr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GER_U, r0.r, r2.r, r1.r); + emit_insn_r(s, GTR_U, r0.r, r2.r, r1.r); } void ejit_ltr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, struct ejit_fpr r2) { - emit_insn_r(s, GER_F, r0.r, r2.f, r1.f); + emit_insn_r(s, GTR_F, r0.r, r2.f, r1.f); } void ejit_ger(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, @@ -646,19 +801,31 @@ void ejit_ger_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, void ejit_ler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GTR, r0.r, r2.r, r1.r); + emit_insn_r(s, GER, r0.r, r2.r, r1.r); } void ejit_ler_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_r(s, GTR_U, r0.r, r2.r, r1.r); + emit_insn_r(s, GER_U, r0.r, r2.r, r1.r); } void ejit_ler_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, struct ejit_fpr r2) { - emit_insn_r(s, GTR_F, r0.r, r2.f, r1.f); + emit_insn_r(s, GER_F, r0.r, r2.f, r1.f); +} + +void ejit_truncr_d_32(struct ejit_func *s, struct ejit_gpr r0, + struct ejit_fpr r1) +{ + emit_insn_i(s, TRUNCR_D_32, r0.r, r1.f, 0); +} + +void ejit_truncr_d_64(struct ejit_func *s, struct ejit_gpr r0, + struct ejit_fpr r1) +{ + emit_insn_i(s, TRUNCR_D_64, r0.r, r1.f, 0); } struct ejit_reloc ejit_bner(struct ejit_func *s, struct ejit_gpr r0, @@ -942,12 +1109,13 @@ long ejit_run_interp(struct ejit_func *f, size_t argc, return ejit_interp(f, argc, args, state, true, NULL).r; } -long ejit_run_func(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) +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 ((ejit_escape_t)f->arena)(argc, args); + return (int64_t)((ejit_escape_t)f->arena)(argc, args); struct interp_state state = create_interp_state(); long r = ejit_interp(f, argc, args, &state, true, NULL).r; |