From 9fe8ccf4ae09018fdde01a9d83f9db10ad354221 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 29 Jun 2024 20:11:34 +0300 Subject: work through branching instructions --- src/interp.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 202 insertions(+), 6 deletions(-) (limited to 'src/interp.c') diff --git a/src/interp.c b/src/interp.c index 059b1d3..fe61c36 100644 --- a/src/interp.c +++ b/src/interp.c @@ -30,19 +30,57 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, [ANDI] = &&ANDI, [EQR] = &&EQR, - [LTR] = &<R, + [EQR_F] = &&EQR_F, + + [NER] = &&NER, + [NER_F] = &&NER_F, + + [GTR] = &>R, + [GTR_U] = &>R_U, + [GTR_F] = &>R_F, + + [GER] = &&GER, + [GER_U] = &&GER_U, + [GER_F] = &&GER_F, [STXI64] = &&STXI64, [LDXIU64] = &&LDXIU64, - [BLTR] = &&BLTR, + [BNER] = &&BNER, [BNEI] = &&BNEI, + [BNER_F] = &&BNER_F, + [BEQR] = &&BEQR, [BEQI] = &&BEQI, + [BEQR_F] = &&BEQR_F, + + [BGER] = &&BGER, + [BGER_U] = &&BGER_U, + [BGEI] = &&BGEI, + [BGEI_U] = &&BGEI_U, + [BGER_F] = &&BGER_F, + + [BLEI] = &&BLEI, + [BLEI_U] = &&BLEI_U, + + [BGTR] = &&BGTR, + [BGTR_U] = &&BGTR_U, [BGTI] = &&BGTI, + [BGTI_U] = &&BGTI_U, + [BGTR_F] = &&BGTR_F, + + [BLTI] = &&BLTI, + [BLTI_U] = &&BLTI_U, + + [BLTGTR_F] = &&BLTGTR_F, [JMP] = &&JMP, + [BMCI] = &&BMCI, + [BMCR] = &&BMCR, + [BMSI] = &&BMSI, + [BMSR] = &&BMSR, + [RETR] = &&RETR, [RETI] = &&RETI, [RETR_F] = &&RETR_F, @@ -162,8 +200,40 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = gpr[i.r1] == gpr[i.r2]; DISPATCH(); - DO(LTR); - gpr[i.r0] = gpr[i.r1] < gpr[i.r2]; + DO(EQR_F); + gpr[i.r0] = fpr[i.r1] == fpr[i.r2]; + DISPATCH(); + + DO(NER); + gpr[i.r0] = gpr[i.r1] != gpr[i.r2]; + DISPATCH(); + + DO(NER_F); + gpr[i.r0] = fpr[i.r1] != fpr[i.r2]; + DISPATCH(); + + DO(GTR); + gpr[i.r0] = gpr[i.r1] > gpr[i.r2]; + DISPATCH(); + + DO(GTR_U); + gpr[i.r0] = (uint64_t)gpr[i.r1] > (uint64_t)gpr[i.r2]; + DISPATCH(); + + DO(GTR_F); + gpr[i.r0] = fpr[i.r1] > fpr[i.r2]; + DISPATCH(); + + DO(GER); + gpr[i.r0] = gpr[i.r1] >= gpr[i.r2]; + DISPATCH(); + + DO(GER_U); + gpr[i.r0] = (uint64_t)gpr[i.r1] >= (uint64_t)gpr[i.r2]; + DISPATCH(); + + DO(GER_F); + gpr[i.r0] = fpr[i.r1] >= fpr[i.r2]; DISPATCH(); DO(STXI64); @@ -176,8 +246,8 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, gpr[i.r0] = *addr; DISPATCH(); - DO(BLTR); - if (gpr[i.r1] < gpr[i.r2]) + DO(BNER); + if (gpr[i.r1] != gpr[i.r2]) JUMP(i.r0); DISPATCH(); @@ -188,6 +258,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, DISPATCH(); + DO(BNER_F); + if (fpr[i.r1] != fpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + DO(BEQR); if (gpr[i.r1] == gpr[i.r2]) JUMP(i.r0); @@ -200,16 +276,136 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc, DISPATCH(); + DO(BEQR_F); + if (fpr[i.r1] == fpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + + DO(BGTR); + if (gpr[i.r1] > gpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + + DO(BGTR_U); + if ((uint64_t)gpr[i.r1] > (uint64_t)gpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + DO(BGTI); if (gpr[i.r1] > i.o) JUMP(i.r0); DISPATCH(); + DO(BGTI_U); + if ((uint64_t)gpr[i.r1] > (uint64_t)i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BGTR_F); + if (fpr[i.r1] > fpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + + DO(BLTI); + if (gpr[i.r1] < i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BLTI_U); + if ((uint64_t)gpr[i.r1] < (uint64_t)i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BGER); + if (gpr[i.r1] >= gpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + + DO(BGER_U); + if ((uint64_t)gpr[i.r1] >= (uint64_t)gpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + + DO(BGEI); + if (gpr[i.r1] >= i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BGEI_U); + if ((uint64_t)gpr[i.r1] >= (uint64_t)i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BGER_F); + if (fpr[i.r1] >= fpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + + DO(BLEI); + if (gpr[i.r1] <= i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BLEI_U); + if ((uint64_t)gpr[i.r1] <= (uint64_t)i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BLTGTR_F); + double f0 = fpr[i.r1]; + double f1 = fpr[i.r2]; + + if (isnan(f0) || isnan(f1)) + JUMP(++pc); + + if (!(f0 >= f1) || !(f0 <= f1)) + JUMP(i.r0); + + DISPATCH(); + DO(JMP); JUMP(i.r0); DISPATCH(); + DO(BMSR); + if (gpr[i.r1] & gpr[i.r2]) + JUMP(i.r0); + + DISPATCH(); + + DO(BMSI); + if (gpr[i.r1] & i.o) + JUMP(i.r0); + + DISPATCH(); + + DO(BMCR); + if (!(gpr[i.r1] & gpr[i.r2])) + JUMP(i.r0); + + DISPATCH(); + + DO(BMCI); + if (!(gpr[i.r1] & i.o)) + JUMP(i.r0); + + DISPATCH(); + DO(RETVAL); gpr[i.r0] = retval; DISPATCH(); -- cgit v1.2.3