diff options
Diffstat (limited to 'src/ejit.c')
-rw-r--r-- | src/ejit.c | 79 |
1 files changed, 19 insertions, 60 deletions
@@ -339,6 +339,7 @@ struct ejit_func *ejit_create_func(enum ejit_type rtype, size_t argc, f->size = 0; f->prio = 1; f->use_64 = false; + f->max_args = 0; for (size_t i = 0; i < argc; ++i) { types_append(&f->sign, args[i].type); @@ -403,7 +404,7 @@ void ejit_select_compile_func(struct ejit_func *f, size_t gpr, size_t fpr, void **labels; /* just get labels, don't actually run anything yet */ - ejit_run(f, 0, NULL, NULL, false, &labels); + ejit_run(f, 0, NULL, false, &labels); foreach_vec(ii, f->insns) { struct ejit_insn i = *insns_at(&f->insns, ii); @@ -448,6 +449,7 @@ void ejit_patch(struct ejit_func *f, struct ejit_reloc r, struct ejit_label l) void ejit_calli_i(struct ejit_func *s, struct ejit_func *f, size_t argc, const struct ejit_operand args[argc]) { + f->max_args = argc > f->max_args ? argc : f->max_args; check_operands(f, argc, args); for (size_t i = 0; i < argc; ++i) { @@ -467,6 +469,7 @@ void ejit_calli_l(struct ejit_func *s, struct ejit_func *f, size_t argc, const struct ejit_operand args[argc]) { s->use_64 = true; + f->max_args = argc > f->max_args ? argc : f->max_args; check_operands(f, argc, args); for (size_t i = 0; i < argc; ++i) { @@ -485,6 +488,7 @@ void ejit_calli_l(struct ejit_func *s, struct ejit_func *f, size_t argc, void ejit_calli_f(struct ejit_func *s, struct ejit_func *f, size_t argc, const struct ejit_operand args[argc]) { + s->max_args = argc > s->max_args ? argc : s->max_args; check_operands(f, argc, args); for (size_t i = 0; i < argc; ++i) { @@ -503,6 +507,7 @@ void ejit_calli_f(struct ejit_func *s, struct ejit_func *f, size_t argc, void ejit_calli_d(struct ejit_func *s, struct ejit_func *f, size_t argc, const struct ejit_operand args[argc]) { + s->max_args = argc > s->max_args ? argc : s->max_args; check_operands(f, argc, args); for (size_t i = 0; i < argc; ++i) { @@ -521,6 +526,7 @@ void ejit_calli_d(struct ejit_func *s, struct ejit_func *f, size_t argc, void ejit_escapei_i(struct ejit_func *s, ejit_escape_i_t f, size_t argc, const struct ejit_operand args[argc]) { + s->max_args = argc > s->max_args ? argc : s->max_args; 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; @@ -538,6 +544,7 @@ void ejit_escapei_l(struct ejit_func *s, ejit_escape_l_t f, size_t argc, const struct ejit_operand args[argc]) { s->use_64 = true; + s->max_args = argc > s->max_args ? argc : s->max_args; 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; @@ -554,6 +561,7 @@ void ejit_escapei_l(struct ejit_func *s, ejit_escape_l_t f, size_t argc, void ejit_escapei_f(struct ejit_func *s, ejit_escape_f_t f, size_t argc, const struct ejit_operand args[argc]) { + s->max_args = argc > s->max_args ? argc : s->max_args; 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; @@ -570,6 +578,7 @@ void ejit_escapei_f(struct ejit_func *s, ejit_escape_f_t f, size_t argc, void ejit_escapei_d(struct ejit_func *s, ejit_escape_d_t f, size_t argc, const struct ejit_operand args[argc]) { + s->max_args = argc > s->max_args ? argc : s->max_args; 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; @@ -1647,23 +1656,8 @@ struct ejit_reloc ejit_bmsr(struct ejit_func *s, struct ejit_gpr r0, 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); -} - -long ejit_run_func_ctx_i(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], struct interp_state *ctx) +long ejit_run_func_i(struct ejit_func *f, size_t argc, + struct ejit_arg args[argc]) { check_args(f, argc, args); assert((f->rtype == EJIT_VOID || ejit_int_type(f->rtype)) @@ -1672,64 +1666,29 @@ long ejit_run_func_ctx_i(struct ejit_func *f, size_t argc, struct ejit_arg args[ #endif ); - return ejit_run(f, argc, args, ctx, true, NULL).i; + return ejit_run(f, argc, args, true, NULL).i; } -long ejit_run_func_i(struct ejit_func *f, size_t argc, +int64_t ejit_run_func_l(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) { - struct interp_state state = create_interp_state(); - long r = ejit_run_func_ctx_i(f, argc, args, &state); - destroy_interp_state(state); - return r; -} - -int64_t ejit_run_func_ctx_l(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], struct interp_state *ctx) -{ check_args(f, argc, args); assert(f->rtype == EJIT_INT64 || f->rtype == EJIT_UINT64); - return ejit_run(f, argc, args, ctx, true, NULL).i; -} - -int64_t ejit_run_func_l(struct ejit_func *f, size_t argc, - struct ejit_arg args[argc]) -{ - struct interp_state state = create_interp_state(); - int64_t r = ejit_run_func_ctx_l(f, argc, args, &state); - destroy_interp_state(state); - return r; + return ejit_run(f, argc, args, true, NULL).i; } -float ejit_run_func_ctx_f(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], struct interp_state *ctx) +float ejit_run_func_f(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) { check_args(f, argc, args); assert(f->rtype == EJIT_FLOAT); - return ejit_run(f, argc, args, ctx, true, NULL).f; + return ejit_run(f, argc, args, true, NULL).f; } -float ejit_run_func_f(struct ejit_func *f, size_t argc, - struct ejit_arg args[argc]) -{ - struct interp_state state = create_interp_state(); - float r = ejit_run_func_ctx_f(f, argc, args, &state); - destroy_interp_state(state); - return r; -} - -double ejit_run_func_ctx_d(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], struct interp_state *ctx) +double ejit_run_func_d(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) { check_args(f, argc, args); assert(f->rtype == EJIT_DOUBLE); - return ejit_run(f, argc, args, ctx, true, NULL).f; -} - -double ejit_run_func_d(struct ejit_func *f, size_t argc, - struct ejit_arg args[argc]) -{ - struct interp_state state = create_interp_state(); - double r = ejit_run_func_ctx_d(f, argc, args, &state); - destroy_interp_state(state); - return r; + return ejit_run(f, argc, args, true, NULL).f; } struct ejit_arg ejit_run_func(struct ejit_func *f, size_t argc, struct ejit_arg args[argc]) |