diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-29 18:00:51 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-29 18:00:51 +0300 |
commit | 322c7fba3d2f4c9b5b0d78b44feefd38ae44d017 (patch) | |
tree | de20ed83ee9231e853cefb46bb8ba60cf65e09dd /src | |
parent | d4c1d32e0aa21677e72c54ed220fdc70cea732c8 (diff) | |
download | ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.tar.gz ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.zip |
continue working through bytecode ops
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 8 | ||||
-rw-r--r-- | src/ejit.c | 39 | ||||
-rw-r--r-- | src/interp.c | 18 |
3 files changed, 53 insertions, 12 deletions
diff --git a/src/common.h b/src/common.h index 1e21e89..37332aa 100644 --- a/src/common.h +++ b/src/common.h @@ -67,11 +67,15 @@ enum ejit_opcode { DIVR, NEGR, + ANDR, + ANDI, + EQR, LTR, BLTR, BNEI, + BEQR, BEQI, BGTI, JMP, @@ -115,7 +119,7 @@ struct ejit_insn { union { size_t r2; void *p; - long o; + int64_t o; double d; }; }; @@ -150,7 +154,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, void ***labels_wb); int64_t ejit_run_interp(struct ejit_func *f, size_t argc, - struct ejit_arg args[argc], struct interp_state *state); + struct ejit_arg args[argc], struct interp_state *state); bool ejit_compile(struct ejit_func *f, bool use_64); @@ -6,7 +6,7 @@ #include "common.h" static void emit_insn_i(struct ejit_func *f, enum ejit_opcode op, size_t r0, - size_t r1, long o) + size_t r1, int64_t o) { struct ejit_insn i = {.op = op, .r0 = r0, .r1 = r1, .o = o}; vec_append(&f->insns, &i); @@ -183,13 +183,13 @@ void ejit_retval(struct ejit_func *s, struct ejit_gpr r0) } void ejit_stxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o) + int64_t o) { emit_insn_i(s, STXI64, r0.r, r1.r, o); } void ejit_ldxi_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o) + int64_t o) { emit_insn_i(s, LDXIU64, r0.r, r1.r, o); } @@ -204,7 +204,7 @@ void ejit_retr_f(struct ejit_func *s, struct ejit_fpr r0) emit_insn_r(s, RETR_F, r0.f, 0, 0); } -void ejit_reti(struct ejit_func *s, long i) +void ejit_reti(struct ejit_func *s, int64_t i) { emit_insn_i(s, RETI, 0, 0, i); } @@ -227,7 +227,7 @@ void ejit_addr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1, } void ejit_addi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, - long o) + int64_t o) { emit_insn_i(s, ADDI, r0.r, r1.r, o); } @@ -267,12 +267,24 @@ void ejit_divr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, emit_insn_r(s, DIVR, 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) +{ + emit_insn_r(s, ANDR, r0.r, r1.r, r2.r); +} + +void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, + int64_t o) +{ + emit_insn_i(s, ANDI, r0.r, r1.r, o); +} + 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_movi(struct ejit_func *s, struct ejit_gpr r0, long o) +void ejit_movi(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { emit_insn_i(s, MOVI, r0.r, 0, o); } @@ -305,21 +317,28 @@ struct ejit_reloc ejit_bltr(struct ejit_func *s, struct ejit_gpr r0, return (struct ejit_reloc){.insn = addr}; } -struct ejit_reloc ejit_bnei(struct ejit_func *s, struct ejit_gpr r0, long o) +struct ejit_reloc ejit_bnei(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = vec_len(&s->insns); emit_insn_i(s, BNEI, 0, r0.r, o); return (struct ejit_reloc){.insn = addr}; } -struct ejit_reloc ejit_beqi(struct ejit_func *s, struct ejit_gpr r0, long o) +struct ejit_reloc ejit_beqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1) +{ + size_t addr = vec_len(&s->insns); + emit_insn_r(s, BEQR, 0, r0.r, r1.r); + 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 = vec_len(&s->insns); emit_insn_i(s, BEQI, 0, r0.r, o); return (struct ejit_reloc){.insn = addr}; } -struct ejit_reloc ejit_bgti(struct ejit_func *s, struct ejit_gpr r0, long o) +struct ejit_reloc ejit_bgti(struct ejit_func *s, struct ejit_gpr r0, int64_t o) { size_t addr = vec_len(&s->insns); emit_insn_i(s, BGTI, 0, r0.r, o); @@ -336,7 +355,7 @@ struct ejit_reloc ejit_jmp(struct ejit_func *s) static struct interp_state create_interp_state() { struct interp_state state; - state.gprs = vec_create(sizeof(long)); + state.gprs = vec_create(sizeof(int64_t)); state.fprs = vec_create(sizeof(double)); state.args = vec_create(sizeof(struct ejit_arg)); return state; diff --git a/src/interp.c b/src/interp.c index 3395537..059b1d3 100644 --- a/src/interp.c +++ b/src/interp.c @@ -26,6 +26,9 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, [MULR] = &&MULR, [DIVR] = &&DIVR, + [ANDR] = &&ANDR, + [ANDI] = &&ANDI, + [EQR] = &&EQR, [LTR] = &<R, @@ -34,6 +37,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, [BLTR] = &&BLTR, [BNEI] = &&BNEI, + [BEQR] = &&BEQR, [BEQI] = &&BEQI, [BGTI] = &&BGTI, @@ -146,6 +150,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = gpr[i.r1] / gpr[i.r2]; DISPATCH(); + DO(ANDR); + gpr[i.r0] = gpr[i.r1] & gpr[i.r2]; + DISPATCH(); + + DO(ANDI); + gpr[i.r0] = gpr[i.r1] & i.o; + DISPATCH(); + DO(EQR); gpr[i.r0] = gpr[i.r1] == gpr[i.r2]; DISPATCH(); @@ -176,6 +188,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, DISPATCH(); + DO(BEQR); + if (gpr[i.r1] == gpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + DO(BEQI); if (gpr[i.r1] == i.o) JUMP(i.r0); |