aboutsummaryrefslogtreecommitdiff
path: root/src/interp.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-13 20:56:26 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-13 20:56:26 +0300
commitae9e103995c1d809be7b8717905593e7dbbf9d17 (patch)
tree0ceaf6ee66e1d67bb8d0b9dd6f37b5687e4c2f09 /src/interp.c
parente618924df98d4ee5037db86c768a8c8014e49c4c (diff)
downloadejit-ae9e103995c1d809be7b8717905593e7dbbf9d17.tar.gz
ejit-ae9e103995c1d809be7b8717905593e7dbbf9d17.zip
bytecode tests pass
Diffstat (limited to 'src/interp.c')
-rw-r--r--src/interp.c143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/interp.c b/src/interp.c
index 30a7672..a86b754 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -10,6 +10,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
{
static void *labels[OPCODE_COUNT] = {
[MOVI] = &&MOVI,
+ [MOVI_F] = &&MOVI_F,
[MOVR] = &&MOVR,
[MOVR_F] = &&MOVR_F,
@@ -31,21 +32,34 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[SUBI] = &&SUBI,
[MULR] = &&MULR,
+ [MULR_F] = &&MULR_F,
[DIVR] = &&DIVR,
[DIVR_U] = &&DIVR_U,
[DIVR_F] = &&DIVR_F,
+ [REMR] = &&REMR,
+ [REMR_U] = &&REMR_U,
+
[LSHI] = &&LSHI,
[LSHR] = &&LSHR,
[RSHI] = &&RSHI,
[RSHR] = &&RSHR,
+ [RSHI_U] = &&RSHI_U,
+ [RSHR_U] = &&RSHR_U,
[ANDR] = &&ANDR,
[ANDI] = &&ANDI,
+ [ORR] = &&ORR,
+ [ORI] = &&ORI,
+
+ [XORR] = &&XORR,
+ [XORI] = &&XORI,
+
[COMR] = &&COMR,
[NEGR] = &&NEGR,
+ [NEGR_F] = &&NEGR_F,
[EQR] = &&EQR,
[EQR_F] = &&EQR_F,
@@ -61,6 +75,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[GER_U] = &&GER_U,
[GER_F] = &&GER_F,
+ [STI8] = &&STI8,
+ [STI16] = &&STI16,
+ [STI32] = &&STI32,
+ [STI64] = &&STI64,
+ [STIF] = &&STIF,
+ [STID] = &&STID,
+
[STXI8] = &&STXI8,
[STXI16] = &&STXI16,
[STXI32] = &&STXI32,
@@ -68,6 +89,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[STXIF] = &&STXIF,
[STXID] = &&STXID,
+ [STXR8] = &&STXR8,
+ [STXR16] = &&STXR16,
+ [STXR32] = &&STXR32,
+ [STXR64] = &&STXR64,
+ [STXRF] = &&STXRF,
+ [STXRD] = &&STXRD,
+
[LDI8] = &&LDI8,
[LDI16] = &&LDI16,
[LDI32] = &&LDI32,
@@ -101,6 +129,9 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[LDXRF] = &&LDXRF,
[LDXRD] = &&LDXRD,
+ [TRUNCR_D_32] = &&TRUNCR_D_32,
+ [TRUNCR_D_64] = &&TRUNCR_D_64,
+
[BNER] = &&BNER,
[BNEI] = &&BNEI,
[BNER_F] = &&BNER_F,
@@ -202,6 +233,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = i.o;
DISPATCH();
+ DO(MOVI_F);
+ fpr[i.r0] = i.d;
+ DISPATCH();
+
DO(MOVR);
gpr[i.r0] = gpr[i.r1];
DISPATCH();
@@ -266,6 +301,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = gpr[i.r1] * gpr[i.r2];
DISPATCH();
+ DO(MULR_F);
+ fpr[i.r0] = fpr[i.r1] * fpr[i.r2];
+ DISPATCH();
+
DO(DIVR);
gpr[i.r0] = gpr[i.r1] / gpr[i.r2];
DISPATCH();
@@ -274,6 +313,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = (uint64_t)gpr[i.r1] / (uint64_t)gpr[i.r2];
DISPATCH();
+ DO(REMR);
+ gpr[i.r0] = gpr[i.r1] % gpr[i.r2];
+ DISPATCH();
+
+ DO(REMR_U);
+ gpr[i.r0] = (uint64_t)gpr[i.r1] % (uint64_t)gpr[i.r2];
+ DISPATCH();
+
DO(DIVR_F);
fpr[i.r0] = fpr[i.r1] / fpr[i.r2];
DISPATCH();
@@ -294,6 +341,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = gpr[i.r1] >> gpr[i.r2];
DISPATCH();
+ DO(RSHI_U);
+ gpr[i.r0] = (uint64_t)gpr[i.r1] >> i.o;
+ DISPATCH();
+
+ DO(RSHR_U);
+ gpr[i.r0] = (uint64_t)gpr[i.r1] >> gpr[i.r2];
+ DISPATCH();
+
DO(ANDR);
gpr[i.r0] = gpr[i.r1] & gpr[i.r2];
DISPATCH();
@@ -302,6 +357,22 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = gpr[i.r1] & i.o;
DISPATCH();
+ DO(ORR);
+ gpr[i.r0] = gpr[i.r1] | gpr[i.r2];
+ DISPATCH();
+
+ DO(ORI);
+ gpr[i.r0] = gpr[i.r1] | i.o;
+ DISPATCH();
+
+ DO(XORR);
+ gpr[i.r0] = gpr[i.r1] ^ gpr[i.r2];
+ DISPATCH();
+
+ DO(XORI);
+ gpr[i.r0] = gpr[i.r1] ^ i.o;
+ DISPATCH();
+
DO(COMR);
gpr[i.r0] = ~gpr[i.r1];
DISPATCH();
@@ -310,6 +381,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = -gpr[i.r1];
DISPATCH();
+ DO(NEGR_F);
+ fpr[i.r0] = -fpr[i.r1];
+ DISPATCH();
+
DO(EQR);
gpr[i.r0] = gpr[i.r1] == gpr[i.r2];
DISPATCH();
@@ -350,6 +425,36 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = fpr[i.r1] >= fpr[i.r2];
DISPATCH();
+ DO(STI8);
+ int8_t *addr = (int8_t *)(i.p);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STI16);
+ int16_t *addr = (int16_t *)(i.p);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STI32);
+ int32_t *addr = (int32_t *)(i.p);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STI64);
+ int64_t *addr = (int64_t *)(i.p);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STIF);
+ float *addr = (float *)(i.p);
+ *addr = fpr[i.r0];
+ DISPATCH();
+
+ DO(STID);
+ double *addr = (double *)(i.p);
+ *addr = fpr[i.r0];
+ DISPATCH();
+
DO(STXI8);
int8_t *addr = (int8_t *)(gpr[i.r1] + i.o);
*addr = gpr[i.r0];
@@ -380,6 +485,36 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
*addr = fpr[i.r0];
DISPATCH();
+ DO(STXR8);
+ int8_t *addr = (int8_t *)(gpr[i.r1] + gpr[i.r2]);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STXR16);
+ int16_t *addr = (int16_t *)(gpr[i.r1] + gpr[i.r2]);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STXR32);
+ int32_t *addr = (int32_t *)(gpr[i.r1] + gpr[i.r2]);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STXR64);
+ int64_t *addr = (int64_t *)(gpr[i.r1] + gpr[i.r2]);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STXRF);
+ float *addr = (float *)(gpr[i.r1] + gpr[i.r2]);
+ *addr = fpr[i.r0];
+ DISPATCH();
+
+ DO(STXRD);
+ double *addr = (double *)(gpr[i.r1] + gpr[i.r2]);
+ *addr = fpr[i.r0];
+ DISPATCH();
+
DO(LDI8);
int8_t *addr = (int8_t *)i.p;
gpr[i.r0] = *addr;
@@ -530,6 +665,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
fpr[i.r0] = *addr;
DISPATCH();
+ DO(TRUNCR_D_32);
+ gpr[i.r0] = (int32_t)fpr[i.r1];
+ DISPATCH();
+
+ DO(TRUNCR_D_64);
+ gpr[i.r0] = (int64_t)fpr[i.r1];
+ DISPATCH();
+
DO(BNER);
if (gpr[i.r1] != gpr[i.r2])
JUMP(i.r0);