aboutsummaryrefslogtreecommitdiff
path: root/src/interp.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-14 14:46:40 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-14 14:46:40 +0300
commitdcca95ebeef7ad047b437c7e65bcd2d33784cae4 (patch)
tree39a3f9834df0dc7c27d080efef15c22889730dc5 /src/interp.c
parent215ac4569f897b10215248c4caa3191919a555df (diff)
downloadejit-dcca95ebeef7ad047b437c7e65bcd2d33784cae4.tar.gz
ejit-dcca95ebeef7ad047b437c7e65bcd2d33784cae4.zip
add float + double instead of just double
Diffstat (limited to 'src/interp.c')
-rw-r--r--src/interp.c220
1 files changed, 168 insertions, 52 deletions
diff --git a/src/interp.c b/src/interp.c
index 8462112..293da46 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -11,8 +11,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
static void *labels[OPCODE_COUNT] = {
[MOVI] = &&MOVI,
[MOVI_F] = &&MOVI_F,
+ [MOVI_D] = &&MOVI_D,
[MOVR] = &&MOVR,
[MOVR_F] = &&MOVR_F,
+ [MOVR_D] = &&MOVR_D,
[EXTR8] = &&EXTR8,
[EXTR16] = &&EXTR16,
@@ -23,20 +25,25 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[ADDR] = &&ADDR,
[ADDR_F] = &&ADDR_F,
+ [ADDR_D] = &&ADDR_D,
[ADDI] = &&ADDI,
[ABSR_F] = &&ABSR_F,
+ [ABSR_D] = &&ABSR_D,
[SUBR] = &&SUBR,
[SUBR_F] = &&SUBR_F,
+ [SUBR_D] = &&SUBR_D,
[SUBI] = &&SUBI,
[MULR] = &&MULR,
[MULR_F] = &&MULR_F,
+ [MULR_D] = &&MULR_D,
[DIVR] = &&DIVR,
[DIVR_U] = &&DIVR_U,
[DIVR_F] = &&DIVR_F,
+ [DIVR_D] = &&DIVR_D,
[REMR] = &&REMR,
[REMR_U] = &&REMR_U,
@@ -60,20 +67,25 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[COMR] = &&COMR,
[NEGR] = &&NEGR,
[NEGR_F] = &&NEGR_F,
+ [NEGR_D] = &&NEGR_D,
[EQR] = &&EQR,
[EQR_F] = &&EQR_F,
+ [EQR_D] = &&EQR_D,
[NER] = &&NER,
[NER_F] = &&NER_F,
+ [NER_D] = &&NER_D,
[GTR] = &&GTR,
[GTR_U] = &&GTR_U,
[GTR_F] = &&GTR_F,
+ [GTR_D] = &&GTR_D,
[GER] = &&GER,
[GER_U] = &&GER_U,
[GER_F] = &&GER_F,
+ [GER_D] = &&GER_D,
[STI8] = &&STI8,
[STI16] = &&STI16,
@@ -131,20 +143,25 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[TRUNCR_D_32] = &&TRUNCR_D_32,
[TRUNCR_D_64] = &&TRUNCR_D_64,
+ [TRUNCR_F_32] = &&TRUNCR_F_32,
+ [TRUNCR_F_64] = &&TRUNCR_F_64,
[BNER] = &&BNER,
[BNEI] = &&BNEI,
[BNER_F] = &&BNER_F,
+ [BNER_D] = &&BNER_D,
[BEQR] = &&BEQR,
[BEQI] = &&BEQI,
[BEQR_F] = &&BEQR_F,
+ [BEQR_D] = &&BEQR_D,
[BGER] = &&BGER,
[BGER_U] = &&BGER_U,
[BGEI] = &&BGEI,
[BGEI_U] = &&BGEI_U,
[BGER_F] = &&BGER_F,
+ [BGER_D] = &&BGER_D,
[BLEI] = &&BLEI,
[BLEI_U] = &&BLEI_U,
@@ -154,12 +171,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[BGTI] = &&BGTI,
[BGTI_U] = &&BGTI_U,
[BGTR_F] = &&BGTR_F,
+ [BGTR_D] = &&BGTR_D,
[BLTI] = &&BLTI,
[BLTI_U] = &&BLTI_U,
- [BLTGTR_F] = &&BLTGTR_F,
-
[JMP] = &&JMP,
[JMPR] = &&JMPR,
@@ -172,9 +188,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[RETI] = &&RETI,
[RETR_F] = &&RETR_F,
[RETI_F] = &&RETI_F,
+ [RETR_D] = &&RETR_D,
+ [RETI_D] = &&RETI_D,
[RETVAL] = &&RETVAL,
[RETVAL_F] = &&RETVAL_F,
+ [RETVAL_D] = &&RETVAL_D,
[ARG] = &&ARG,
[ARG_I] = &&ARG_I,
@@ -205,8 +224,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
vec_reserve(&state->gprs, prev_gprs + f->gpr);
vec_reserve(&state->fprs, prev_fprs + f->fpr);
+ union fpr {
+ double d;
+ float f;
+ };
long *gpr = ((long *)state->gprs.buf) + prev_gprs;
- double *fpr = ((double *)state->fprs.buf) + prev_fprs;
+ union fpr *fpr = ((union fpr *)state->fprs.buf) + prev_fprs;
struct ejit_insn *insns = f->insns.buf;
@@ -234,7 +257,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(MOVI_F);
- fpr[i.r0] = i.d;
+ fpr[i.r0].f = i.f;
+ DISPATCH();
+
+ DO(MOVI_D);
+ fpr[i.r0].d = i.d;
DISPATCH();
DO(MOVR);
@@ -242,7 +269,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(MOVR_F);
- fpr[i.r0] = fpr[i.r1];
+ fpr[i.r0].f = fpr[i.r1].f;
+ DISPATCH();
+
+ DO(MOVR_D);
+ fpr[i.r0].d = fpr[i.r1].d;
DISPATCH();
DO(EXTR8);
@@ -274,7 +305,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(ADDR_F);
- fpr[i.r0] = fpr[i.r1] + fpr[i.r2];
+ fpr[i.r0].f = fpr[i.r1].f + fpr[i.r2].f;
+ DISPATCH();
+
+ DO(ADDR_D);
+ fpr[i.r0].d = fpr[i.r1].d + fpr[i.r2].d;
DISPATCH();
DO(ADDI);
@@ -282,7 +317,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(ABSR_F);
- fpr[i.r0] = fabs(fpr[i.r1]);
+ fpr[i.r0].f = fabs(fpr[i.r1].f);
+ DISPATCH();
+
+ DO(ABSR_D);
+ fpr[i.r0].d = fabs(fpr[i.r1].d);
DISPATCH();
DO(SUBR);
@@ -290,7 +329,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(SUBR_F);
- fpr[i.r0] = fpr[i.r1] - fpr[i.r2];
+ fpr[i.r0].f = fpr[i.r1].f - fpr[i.r2].f;
+ DISPATCH();
+
+ DO(SUBR_D);
+ fpr[i.r0].d = fpr[i.r1].d - fpr[i.r2].d;
DISPATCH();
DO(SUBI);
@@ -302,7 +345,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(MULR_F);
- fpr[i.r0] = fpr[i.r1] * fpr[i.r2];
+ fpr[i.r0].f = fpr[i.r1].f * fpr[i.r2].f;
+ DISPATCH();
+
+ DO(MULR_D);
+ fpr[i.r0].d = fpr[i.r1].d * fpr[i.r2].d;
DISPATCH();
DO(DIVR);
@@ -322,7 +369,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(DIVR_F);
- fpr[i.r0] = fpr[i.r1] / fpr[i.r2];
+ fpr[i.r0].f = fpr[i.r1].f / fpr[i.r2].f;
+ DISPATCH();
+
+ DO(DIVR_D);
+ fpr[i.r0].d = fpr[i.r1].d / fpr[i.r2].d;
DISPATCH();
DO(LSHI);
@@ -382,7 +433,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(NEGR_F);
- fpr[i.r0] = -fpr[i.r1];
+ fpr[i.r0].f = -fpr[i.r1].f;
+ DISPATCH();
+
+ DO(NEGR_D);
+ fpr[i.r0].d = -fpr[i.r1].d;
DISPATCH();
DO(EQR);
@@ -390,7 +445,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(EQR_F);
- gpr[i.r0] = fpr[i.r1] == fpr[i.r2];
+ gpr[i.r0] = fpr[i.r1].f == fpr[i.r2].f;
+ DISPATCH();
+
+ DO(EQR_D);
+ gpr[i.r0] = fpr[i.r1].d == fpr[i.r2].d;
DISPATCH();
DO(NER);
@@ -398,7 +457,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(NER_F);
- gpr[i.r0] = fpr[i.r1] != fpr[i.r2];
+ gpr[i.r0] = fpr[i.r1].f != fpr[i.r2].f;
+ DISPATCH();
+
+ DO(NER_D);
+ gpr[i.r0] = fpr[i.r1].d != fpr[i.r2].d;
DISPATCH();
DO(GTR);
@@ -410,7 +473,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(GTR_F);
- gpr[i.r0] = fpr[i.r1] > fpr[i.r2];
+ gpr[i.r0] = fpr[i.r1].f > fpr[i.r2].f;
+ DISPATCH();
+
+ DO(GTR_D);
+ gpr[i.r0] = fpr[i.r1].d > fpr[i.r2].d;
DISPATCH();
DO(GER);
@@ -422,7 +489,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(GER_F);
- gpr[i.r0] = fpr[i.r1] >= fpr[i.r2];
+ gpr[i.r0] = fpr[i.r1].f >= fpr[i.r2].f;
+ DISPATCH();
+
+ DO(GER_D);
+ gpr[i.r0] = fpr[i.r1].d >= fpr[i.r2].d;
DISPATCH();
DO(STI8);
@@ -447,12 +518,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(STIF);
float *addr = (float *)(i.p);
- *addr = fpr[i.r0];
+ *addr = fpr[i.r0].f;
DISPATCH();
DO(STID);
double *addr = (double *)(i.p);
- *addr = fpr[i.r0];
+ *addr = fpr[i.r0].d;
DISPATCH();
DO(STXI8);
@@ -477,12 +548,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(STXIF);
float *addr = (float *)(gpr[i.r1] + i.o);
- *addr = fpr[i.r0];
+ *addr = fpr[i.r0].f;
DISPATCH();
DO(STXID);
double *addr = (double *)(gpr[i.r1] + i.o);
- *addr = fpr[i.r0];
+ *addr = fpr[i.r0].d;
DISPATCH();
DO(STXR8);
@@ -507,12 +578,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(STXRF);
float *addr = (float *)(gpr[i.r1] + gpr[i.r2]);
- *addr = fpr[i.r0];
+ *addr = fpr[i.r0].f;
DISPATCH();
DO(STXRD);
double *addr = (double *)(gpr[i.r1] + gpr[i.r2]);
- *addr = fpr[i.r0];
+ *addr = fpr[i.r0].d;
DISPATCH();
DO(LDI8);
@@ -557,12 +628,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(LDIF);
float *addr = (float *)i.p;
- fpr[i.r0] = *addr;
+ fpr[i.r0].f = *addr;
DISPATCH();
DO(LDID);
double *addr = (double *)i.p;
- fpr[i.r0] = *addr;
+ fpr[i.r0].d = *addr;
DISPATCH();
DO(LDXI8);
@@ -607,12 +678,12 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(LDXIF);
float *addr = (float *)(gpr[i.r1] + i.o);
- fpr[i.r0] = *addr;
+ fpr[i.r0].f = *addr;
DISPATCH();
DO(LDXID);
double *addr = (double *)(gpr[i.r1] + i.o);
- fpr[i.r0] = *addr;
+ fpr[i.r0].d = *addr;
DISPATCH();
DO(LDXR8);
@@ -657,20 +728,28 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(LDXRF);
float *addr = (float *)(gpr[i.r1] + gpr[i.r2]);
- fpr[i.r0] = *addr;
+ fpr[i.r0].f = *addr;
DISPATCH();
DO(LDXRD);
double *addr = (double *)(gpr[i.r1] + gpr[i.r2]);
- fpr[i.r0] = *addr;
+ fpr[i.r0].d = *addr;
DISPATCH();
DO(TRUNCR_D_32);
- gpr[i.r0] = (int32_t)fpr[i.r1];
+ gpr[i.r0] = (int32_t)fpr[i.r1].d;
DISPATCH();
DO(TRUNCR_D_64);
- gpr[i.r0] = (int64_t)fpr[i.r1];
+ gpr[i.r0] = (int64_t)fpr[i.r1].d;
+ DISPATCH();
+
+ DO(TRUNCR_F_32);
+ gpr[i.r0] = (int32_t)fpr[i.r1].f;
+ DISPATCH();
+
+ DO(TRUNCR_F_64);
+ gpr[i.r0] = (int64_t)fpr[i.r1].f;
DISPATCH();
DO(BNER);
@@ -686,7 +765,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(BNER_F);
- if (fpr[i.r1] != fpr[i.r2])
+ if (fpr[i.r1].f != fpr[i.r2].f)
+ JUMP(i.r0);
+
+ DISPATCH();
+
+ DO(BNER_D);
+ if (fpr[i.r1].d != fpr[i.r2].d)
JUMP(i.r0);
DISPATCH();
@@ -704,7 +789,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(BEQR_F);
- if (fpr[i.r1] == fpr[i.r2])
+ if (fpr[i.r1].f == fpr[i.r2].f)
+ JUMP(i.r0);
+
+ DISPATCH();
+
+ DO(BEQR_D);
+ if (fpr[i.r1].d == fpr[i.r2].d)
JUMP(i.r0);
DISPATCH();
@@ -734,7 +825,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(BGTR_F);
- if (fpr[i.r1] > fpr[i.r2])
+ if (fpr[i.r1].f > fpr[i.r2].f)
+ JUMP(i.r0);
+
+ DISPATCH();
+
+ DO(BGTR_D);
+ if (fpr[i.r1].d > fpr[i.r2].d)
JUMP(i.r0);
DISPATCH();
@@ -776,31 +873,25 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(BGER_F);
- if (fpr[i.r1] >= fpr[i.r2])
+ if (fpr[i.r1].f >= fpr[i.r2].f)
JUMP(i.r0);
DISPATCH();
- DO(BLEI);
- if (gpr[i.r1] <= i.o)
+ DO(BGER_D);
+ if (fpr[i.r1].d >= fpr[i.r2].d)
JUMP(i.r0);
DISPATCH();
- DO(BLEI_U);
- if ((uint64_t)gpr[i.r1] <= (uint64_t)i.o)
+ DO(BLEI);
+ if (gpr[i.r1] <= 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))
+ DO(BLEI_U);
+ if ((uint64_t)gpr[i.r1] <= (uint64_t)i.o)
JUMP(i.r0);
DISPATCH();
@@ -842,7 +933,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(RETVAL_F);
- fpr[i.r0] = retval_f;
+ fpr[i.r0].f = retval_f;
+ DISPATCH();
+
+ DO(RETVAL_D);
+ fpr[i.r0].d = retval_f;
DISPATCH();
DO(PARAM);
@@ -851,9 +946,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DO(PARAM_F);
if (i.r1 == EJIT_FLOAT)
- fpr[i.r2] = args[i.r0].f;
+ fpr[i.r2].f = args[i.r0].f;
else
- fpr[i.r2] = args[i.r0].d;
+ fpr[i.r2].d = args[i.r0].d;
+
DISPATCH();
DO(ARG);
@@ -867,12 +963,22 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(ARG_F);
- struct ejit_arg a = ejit_build_arg_f(i.r1, fpr[i.r2]);
+ struct ejit_arg a;
+ if (i.r1 == EJIT_DOUBLE)
+ a = ejit_build_arg_f(i.r1, fpr[i.r2].d);
+ else
+ a = ejit_build_arg_f(i.r1, fpr[i.r2].f);
+
vec_append(&state->args, &a);
DISPATCH();
DO(ARG_FI);
- struct ejit_arg a = ejit_build_arg_f(i.r1, i.d);
+ struct ejit_arg a;
+ if (i.r1 == EJIT_DOUBLE)
+ a = ejit_build_arg_f(i.r1, i.d);
+ else
+ a = ejit_build_arg_f(i.r1, i.f);
+
vec_append(&state->args, &a);
DISPATCH();
@@ -885,7 +991,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
retval = ejit_run_interp(f, argc, args, state);
gpr = ((long *)state->gprs.buf) + prev_gprs;
- fpr = ((double *)state->fprs.buf) + prev_fprs;
+ fpr = ((union fpr *)state->fprs.buf) + prev_fprs;
vec_shrink(&state->args, prev_argc);
DISPATCH();
@@ -927,11 +1033,21 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
DISPATCH();
DO(RETR_F);
- retval_f = fpr[i.r0];
+ retval_f = fpr[i.r0].f;
+ goto out_float;
+ DISPATCH();
+
+ DO(RETR_D);
+ retval_f = fpr[i.r0].d;
goto out_float;
DISPATCH();
DO(RETI_F);
+ retval_f = i.f;
+ goto out_float;
+ DISPATCH();
+
+ DO(RETI_D);
retval_f = i.d;
goto out_float;
DISPATCH();