diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-26 22:36:59 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-26 22:36:59 +0300 |
commit | 892d0f16b2e69bc527b576ee896c39484216338f (patch) | |
tree | 473a4553d0dff32055ff1c22f9a7d44f4e984c02 | |
parent | 827dec28e4c0b1c4972f1419e0ac23e4dbd9d916 (diff) | |
download | ejit-892d0f16b2e69bc527b576ee896c39484216338f.tar.gz ejit-892d0f16b2e69bc527b576ee896c39484216338f.zip |
move labels out of the bytecode
+ Speeds up interpreter a little bit since we don't have to execute
what's effectively a no-op
-rw-r--r-- | src/common.h | 2 | ||||
-rw-r--r-- | src/compile/compile.c | 10 | ||||
-rw-r--r-- | src/ejit.c | 4 | ||||
-rw-r--r-- | src/interp.c | 4 |
4 files changed, 13 insertions, 7 deletions
diff --git a/src/common.h b/src/common.h index 921fca2..8f42985 100644 --- a/src/common.h +++ b/src/common.h @@ -93,7 +93,6 @@ enum ejit_opcode { START, END, - LABEL, OPCODE_COUNT, }; @@ -116,6 +115,7 @@ struct ejit_insn { struct ejit_func { struct vec insns; + struct vec labels; enum ejit_type rtype; size_t gpr; diff --git a/src/compile/compile.c b/src/compile/compile.c index d716ca3..91a8ea8 100644 --- a/src/compile/compile.c +++ b/src/compile/compile.c @@ -287,7 +287,16 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena, struct vec labels = vec_create(sizeof(jit_addr_t)); vec_reserve(&labels, vec_len(&f->insns)); + size_t label = 0; foreach_vec(ii, f->insns) { + /* if we've hit a label, add it to our vector of label addresses */ + if (label < vec_len(&f->labels)) { + if (vect_at(size_t, f->labels, label) == ii) { + compile_label(j, ii, &labels); + label++; + } + } + struct ejit_insn i = vect_at(struct ejit_insn, f->insns, ii); switch (i.op) { case MOVR: compile_movr(f, j, i); break; @@ -349,7 +358,6 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena, break; } - case LABEL: compile_label(j, ii, &labels); break; case RET: { jit_gpr_t r = getloc(f, j, i.r0, 0); /* R0 won't get overwritten by jit_leave_jit_abi */ @@ -37,6 +37,7 @@ struct ejit_func *ejit_create_func(enum ejit_type rtype, size_t argc, const stru f->rtype = rtype; f->insns = vec_create(sizeof(struct ejit_insn)); + f->labels = vec_create(sizeof(size_t)); f->arena = NULL; f->size = 0; @@ -84,13 +85,14 @@ void ejit_destroy_func(struct ejit_func *f) munmap(f->arena, f->size); vec_destroy(&f->insns); + vec_destroy(&f->labels); free(f); } struct ejit_label ejit_label(struct ejit_func *f) { size_t addr = vec_len(&f->insns); - emit_insn_r(f, LABEL, 0, 0, 0); + vec_append(&f->labels, &addr); return (struct ejit_label){.addr = addr}; } diff --git a/src/interp.c b/src/interp.c index f15adc5..4f034f7 100644 --- a/src/interp.c +++ b/src/interp.c @@ -46,7 +46,6 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, struct ejit_arg a [CALLI_F] = &&CALLI_F, [ESCAPEI] = &&ESCAPEI, - [LABEL] = &&LABEL, [START] = &&START, [END] = &&END, }; @@ -79,9 +78,6 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, struct ejit_arg a DO(START); DISPATCH(); - DO(LABEL); - DISPATCH(); - DO(END); goto out_int; DISPATCH(); |