aboutsummaryrefslogtreecommitdiff
path: root/src/interp.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-22 17:40:09 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-22 17:43:44 +0300
commit7f7b22674ed8e9633cd0e47662508c3641e9f967 (patch)
tree6e692c9ec8f6cb0672f626d5be54601ec23aef63 /src/interp.c
parent60a53db87421667a268f60b58c5a02eebb289d6b (diff)
downloadejit-7f7b22674ed8e9633cd0e47662508c3641e9f967.tar.gz
ejit-7f7b22674ed8e9633cd0e47662508c3641e9f967.zip
use type-specific vectors instead of generic ones
+ An attempt at speeding up function calls in the interpreted mode
Diffstat (limited to 'src/interp.c')
-rw-r--r--src/interp.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/interp.c b/src/interp.c
index 5618564..01121e5 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -219,12 +219,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
return (union interp_ret){.r = 0};
}
- size_t prev_gprs = vec_len(&state->gprs);
- size_t prev_fprs = vec_len(&state->fprs);
- size_t prev_argc = vec_len(&state->args);
+ size_t prev_gprs = gprs_len(&state->gprs);
+ size_t prev_fprs = fprs_len(&state->fprs);
+ size_t prev_argc = args_len(&state->args);
- vec_reserve(&state->gprs, prev_gprs + f->gpr);
- vec_reserve(&state->fprs, prev_fprs + f->fpr);
+ gprs_reserve(&state->gprs, prev_gprs + f->gpr);
+ fprs_reserve(&state->fprs, prev_fprs + f->fpr);
union fpr {
double d;
@@ -964,12 +964,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(ARG);
struct ejit_arg a = ejit_build_arg(i.r1, gpr[i.r2]);
- vec_append(&state->args, &a);
+ args_append(&state->args, a);
DISPATCH();
DO(ARG_I);
struct ejit_arg a = ejit_build_arg(i.r1, i.o);
- vec_append(&state->args, &a);
+ args_append(&state->args, a);
DISPATCH();
DO(ARG_F);
@@ -979,7 +979,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
else
a = ejit_build_arg_f(i.r1, fpr[i.r2].f);
- vec_append(&state->args, &a);
+ args_append(&state->args, a);
DISPATCH();
DO(ARG_FI);
@@ -989,12 +989,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
else
a = ejit_build_arg_f(i.r1, i.f);
- vec_append(&state->args, &a);
+ args_append(&state->args, a);
DISPATCH();
DO(CALLI);
struct ejit_func *f = i.p;
- size_t argc = vec_len(&state->args) - prev_argc;
+ size_t argc = args_len(&state->args) - prev_argc;
struct ejit_arg *args = ((struct ejit_arg *)state->args.buf) +
prev_argc;
@@ -1002,32 +1002,42 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr = ((long *)state->gprs.buf) + prev_gprs;
fpr = ((union fpr *)state->fprs.buf) + prev_fprs;
- vec_shrink(&state->args, prev_argc);
+ args_shrink(&state->args, prev_argc);
DISPATCH();
DO(CALLI_F);
+ struct ejit_func *f = i.p;
+ size_t argc = args_len(&state->args) - prev_argc;
+ struct ejit_arg *args = ((struct ejit_arg *)state->args.buf) +
+ prev_argc;
+
+ retval_f = ejit_run_interp_f(f, argc, args, state);
+
+ gpr = ((long *)state->gprs.buf) + prev_gprs;
+ fpr = ((union fpr *)state->fprs.buf) + prev_fprs;
+ args_shrink(&state->args, prev_argc);
DISPATCH();
DO(ESCAPEI);
ejit_escape_t f = i.p;
- size_t argc = vec_len(&state->args) - prev_argc;
+ size_t argc = args_len(&state->args) - prev_argc;
struct ejit_arg *args = ((struct ejit_arg *)state->args.buf) +
prev_argc;
retval = f(argc, args);
- vec_shrink(&state->args, prev_argc);
+ args_shrink(&state->args, prev_argc);
DISPATCH();
DO(ESCAPEI_F);
ejit_escape_f_t f = i.p;
- size_t argc = vec_len(&state->args) - prev_argc;
+ size_t argc = args_len(&state->args) - prev_argc;
struct ejit_arg *args = ((struct ejit_arg *)state->args.buf) +
prev_argc;
retval_f = f(argc, args);
- vec_shrink(&state->args, prev_argc);
+ args_shrink(&state->args, prev_argc);
DISPATCH();
/* dispatch is technically unnecessary for returns, but keep it for
@@ -1067,12 +1077,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
#undef DO
out_int:
- vec_shrink(&state->gprs, prev_gprs);
- vec_shrink(&state->fprs, prev_fprs);
+ gprs_shrink(&state->gprs, prev_gprs);
+ fprs_shrink(&state->fprs, prev_fprs);
return (union interp_ret){.r = retval};
out_float:
- vec_shrink(&state->gprs, prev_gprs);
- vec_shrink(&state->fprs, prev_fprs);
+ gprs_shrink(&state->gprs, prev_gprs);
+ fprs_shrink(&state->fprs, prev_fprs);
return (union interp_ret){.d = retval_f};
}