aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ejit/ejit.h82
-rw-r--r--src/common.h6
-rw-r--r--src/ejit.c112
-rw-r--r--src/interp.c124
-rw-r--r--tests/addx.c79
-rw-r--r--tests/bltgtr_f.c41
-rw-r--r--tests/boaddi.c41
-rw-r--r--tests/boaddi_u.c41
-rw-r--r--tests/boaddr.c51
-rw-r--r--tests/boaddr_u.c51
-rw-r--r--tests/bordr_f.c36
-rw-r--r--tests/bosubi.c41
-rw-r--r--tests/bosubi_u.c37
-rw-r--r--tests/bosubr.c48
-rw-r--r--tests/bosubr_u.c47
-rw-r--r--tests/bswapr_ui.c28
-rw-r--r--tests/bswapr_ul.c27
-rw-r--r--tests/bswapr_us.c24
-rw-r--r--tests/buneqr_f.c35
-rw-r--r--tests/bunger_f.c34
-rw-r--r--tests/bungtr_f.c34
-rw-r--r--tests/bunler_f.c34
-rw-r--r--tests/bunltr_f.c34
-rw-r--r--tests/bunordr_f.c36
-rw-r--r--tests/bxaddi.c39
-rw-r--r--tests/bxaddi_u.c39
-rw-r--r--tests/bxaddr.c49
-rw-r--r--tests/bxaddr_u.c49
-rw-r--r--tests/bxsubi.c39
-rw-r--r--tests/bxsubi_u.c35
-rw-r--r--tests/bxsubr.c46
-rw-r--r--tests/bxsubr_u.c45
-rw-r--r--tests/call_10.c64
-rw-r--r--tests/call_double.c38
-rw-r--r--tests/call_float.c38
-rw-r--r--tests/callee_9.c102
-rw-r--r--tests/cas_atomic.c33
-rw-r--r--tests/comr.c94
-rw-r--r--tests/divr.c204
-rw-r--r--tests/divr_f.c40
-rw-r--r--tests/divr_u.c134
-rw-r--r--tests/do_jit.h8
-rw-r--r--tests/eqr.c2
-rw-r--r--tests/eqr_f.c16
-rw-r--r--tests/escapei_10.c81
-rw-r--r--tests/escapei_double.c43
-rw-r--r--tests/escapei_float.c43
-rw-r--r--tests/qdivr.c45
-rw-r--r--tests/qdivr_u.c43
-rw-r--r--tests/qmulr.c59
-rw-r--r--tests/qmulr_u.c47
-rw-r--r--tests/sqrtr_f.c25
-rw-r--r--tests/subx.c63
53 files changed, 859 insertions, 1827 deletions
diff --git a/include/ejit/ejit.h b/include/ejit/ejit.h
index a910366..03137ab 100644
--- a/include/ejit/ejit.h
+++ b/include/ejit/ejit.h
@@ -226,19 +226,20 @@ void ejit_destroy_func(struct ejit_func *s);
.r = (double)(x), \
.type = (t)})
+/* maybe slight hack, but increase width to interpeter register width */
static inline struct ejit_arg ejit_i8(int8_t a)
{
- return (struct ejit_arg){.i8 = a, .type = EJIT_INT8};
+ return (struct ejit_arg){.i64 = a, .type = EJIT_INT8};
}
static inline struct ejit_arg ejit_i16(int16_t a)
{
- return (struct ejit_arg){.i16 = a, .type = EJIT_INT16};
+ return (struct ejit_arg){.i64 = a, .type = EJIT_INT16};
}
static inline struct ejit_arg ejit_i32(int32_t a)
{
- return (struct ejit_arg){.i32 = a, .type = EJIT_INT32};
+ return (struct ejit_arg){.i64 = a, .type = EJIT_INT32};
}
static inline struct ejit_arg ejit_i64(int64_t a)
@@ -253,7 +254,7 @@ static inline struct ejit_arg ejit_pointer(void *p)
static inline struct ejit_arg ejit_float(float a)
{
- return (struct ejit_arg){.f = a, .type = EJIT_FLOAT};
+ return (struct ejit_arg){.d = a, .type = EJIT_FLOAT};
}
static inline struct ejit_arg ejit_double(double a)
@@ -335,17 +336,17 @@ void ejit_ldi_f(struct ejit_func *s, struct ejit_fpr r0, void *p);
void ejit_ldi_d(struct ejit_func *s, struct ejit_fpr r0, void *p);
/* from r1 + o to r0 */
-void ejit_ldxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
- int64_t o);
-
-void ejit_ldxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+void ejit_ldxi_i8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
int64_t o);
-void ejit_ldxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
- int64_t o);
+void ejit_ldxi_i16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o);
-void ejit_ldxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
- int64_t o);
+void ejit_ldxi_i32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o);
+
+void ejit_ldxi_i64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o);
void ejit_ldxi_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
int64_t o);
@@ -365,6 +366,30 @@ void ejit_ldxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
void ejit_ldxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
int64_t o);
+static inline void ejit_ldxi_ptr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, int64_t o)
+{
+ if (sizeof(void *) == sizeof(int64_t))
+ ejit_ldxi_u64(s, r0, r1, o);
+ else if (sizeof(void *) == sizeof(int32_t))
+ ejit_ldxi_u32(s, r0, r1, o);
+ else
+ abort();
+}
+
+#define EJIT_LDXI(f, t, r0, r1, o) \
+ _Generic((t)(0), \
+ int8_t: ejit_ldxi_i8, \
+ uint8_t: ejit_ldxi_u8, \
+ int16_t: ejit_ldxi_i16, \
+ uint16_t: ejit_ldxi_u16, \
+ int32_t: ejit_ldxi_i32, \
+ uint32_t: ejit_ldxi_u32, \
+ int64_t: ejit_ldxi_i64, \
+ uint64_t: ejit_ldxi_u64, \
+ float: ejit_ldxi_f, \
+ double: ejit_ldxi_d, \
+ default: ejit_ldxi_ptr)((f), (r0), (r1), (o))
+
void ejit_sti_8(struct ejit_func *s, struct ejit_gpr r0, void *p);
void ejit_sti_16(struct ejit_func *s, struct ejit_gpr r0, void *p);
void ejit_sti_32(struct ejit_func *s, struct ejit_gpr r0, void *p);
@@ -397,6 +422,31 @@ void ejit_stxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
int64_t o);
+static inline void ejit_stxi_ptr(struct ejit_func *s, struct ejit_gpr r0,
+ struct ejit_gpr r1, int64_t o)
+{
+ if (sizeof(void *) == sizeof(int64_t))
+ ejit_stxi_64(s, r0, r1, o);
+ else if (sizeof(void *) == sizeof(int32_t))
+ ejit_stxi_32(s, r0, r1, o);
+ else
+ abort();
+}
+
+#define EJIT_STXI(f, t, r0, r1, o) \
+ _Generic((t)(0), \
+ int8_t: ejit_stxi_8, \
+ uint8_t: ejit_stxi_8, \
+ int16_t: ejit_stxi_16, \
+ uint16_t: ejit_stxi_16, \
+ int32_t: ejit_stxi_32, \
+ uint32_t: ejit_stxi_32, \
+ int64_t: ejit_stxi_64, \
+ uint64_t: ejit_stxi_64, \
+ float: ejit_stxi_f, \
+ double: ejit_stxi_d, \
+ default: ejit_stxi_ptr)((f), (r0), (r1), (o))
+
void ejit_addr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2);
@@ -424,6 +474,8 @@ void ejit_mulr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
void ejit_divr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2);
+void ejit_divr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
struct ejit_fpr r2);
@@ -432,10 +484,14 @@ void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
int64_t o);
+void ejit_comr(struct ejit_func *f, struct ejit_gpr r0, struct ejit_gpr r1);
void ejit_negr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2);
+void ejit_eqr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
+
void ejit_ltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2);
@@ -445,7 +501,7 @@ struct ejit_reloc ejit_bner(struct ejit_func *s, struct ejit_gpr r0,
struct ejit_gpr r1);
struct ejit_reloc ejit_bnei(struct ejit_func *s, struct ejit_gpr r0, int64_t o);
struct ejit_reloc ejit_bner_f(struct ejit_func *s, struct ejit_fpr r0,
- struct ejit_fpr r1);
+ struct ejit_fpr r1);
struct ejit_reloc ejit_beqr(struct ejit_func *s, struct ejit_gpr r0,
struct ejit_gpr r1);
diff --git a/src/common.h b/src/common.h
index 1f21c74..218b589 100644
--- a/src/common.h
+++ b/src/common.h
@@ -64,8 +64,14 @@ enum ejit_opcode {
SUBI,
MULR,
+ MULR_F,
+
DIVR,
+ DIVR_U,
+ DIVR_F,
+
NEGR,
+ COMR,
ANDR,
ANDI,
diff --git a/src/ejit.c b/src/ejit.c
index adba1cc..c4e82b1 100644
--- a/src/ejit.c
+++ b/src/ejit.c
@@ -192,18 +192,107 @@ void ejit_retval(struct ejit_func *s, struct ejit_gpr r0)
emit_insn_i(s, RETVAL, r0.r, 0, 0);
}
+void ejit_retval_f(struct ejit_func *s, struct ejit_fpr r0)
+{
+ emit_insn_i(s, RETVAL_F, r0.f, 0, 0);
+}
+
+void ejit_stxi_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, STXI8, r0.r, r1.r, o);
+}
+
+void ejit_stxi_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, STXI16, r0.r, r1.r, o);
+}
+
+void ejit_stxi_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, STXI32, r0.r, r1.r, o);
+}
+
void ejit_stxi_64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
int64_t o)
{
emit_insn_i(s, STXI64, r0.r, r1.r, o);
}
+void ejit_stxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, STXIF, r0.f, r1.r, o);
+}
+
+void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, STXID, r0.f, r1.r, o);
+}
+
+void ejit_ldxi_i8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXI8, r0.r, r1.r, o);
+}
+
+void ejit_ldxi_i16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXI16, r0.r, r1.r, o);
+}
+
+void ejit_ldxi_i32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXI32, r0.r, r1.r, o);
+}
+
+void ejit_ldxi_i64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXI64, r0.r, r1.r, o);
+}
+
+void ejit_ldxi_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXIU8, r0.r, r1.r, o);
+}
+
+void ejit_ldxi_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXIU16, r0.r, r1.r, o);
+}
+
+void ejit_ldxi_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXIU32, r0.r, r1.r, o);
+}
+
void ejit_ldxi_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
int64_t o)
{
emit_insn_i(s, LDXIU64, r0.r, r1.r, o);
}
+void ejit_ldxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXIF, r0.f, r1.r, o);
+}
+
+void ejit_ldxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LDXID, r0.f, r1.r, o);
+}
+
void ejit_retr(struct ejit_func *s, struct ejit_gpr r0)
{
emit_insn_r(s, RETR, r0.r, 0, 0);
@@ -277,6 +366,18 @@ 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_divr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, DIVR_U, r0.r, r1.r, r2.r);
+}
+
+void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2)
+{
+ emit_insn_r(s, DIVR_F, r0.f, r1.f, r2.f);
+}
+
void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2)
{
@@ -289,6 +390,11 @@ void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
emit_insn_i(s, ANDI, r0.r, r1.r, o);
}
+void ejit_comr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1)
+{
+ emit_insn_i(s, COMR, r0.r, r1.r, 0);
+}
+
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);
@@ -313,6 +419,12 @@ void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
emit_insn_r(s, EQR, r0.r, r1.r, r2.r);
}
+void ejit_eqr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2)
+{
+ emit_insn_r(s, EQR_F, r0.r, r1.f, r2.f);
+}
+
void ejit_ltr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2)
{
diff --git a/src/interp.c b/src/interp.c
index fe61c36..383599e 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -24,11 +24,17 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[SUBI] = &&SUBI,
[MULR] = &&MULR,
+
[DIVR] = &&DIVR,
+ [DIVR_U] = &&DIVR_U,
+ [DIVR_F] = &&DIVR_F,
[ANDR] = &&ANDR,
[ANDI] = &&ANDI,
+ [COMR] = &&COMR,
+ [NEGR] = &&NEGR,
+
[EQR] = &&EQR,
[EQR_F] = &&EQR_F,
@@ -43,8 +49,23 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[GER_U] = &&GER_U,
[GER_F] = &&GER_F,
+ [STXI8] = &&STXI8,
+ [STXI16] = &&STXI16,
+ [STXI32] = &&STXI32,
[STXI64] = &&STXI64,
+ [STXIF] = &&STXIF,
+ [STXID] = &&STXID,
+
+ [LDXI8] = &&LDXI8,
+ [LDXI16] = &&LDXI16,
+ [LDXI32] = &&LDXI32,
+ [LDXI64] = &&LDXI64,
+ [LDXIU8] = &&LDXIU8,
+ [LDXIU16] = &&LDXIU16,
+ [LDXIU32] = &&LDXIU32,
[LDXIU64] = &&LDXIU64,
+ [LDXIF] = &&LDXIF,
+ [LDXID] = &&LDXID,
[BNER] = &&BNER,
[BNEI] = &&BNEI,
@@ -87,6 +108,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[RETI_F] = &&RETI_F,
[RETVAL] = &&RETVAL,
+ [RETVAL_F] = &&RETVAL_F,
[ARG] = &&ARG,
[ARG_I] = &&ARG_I,
@@ -99,6 +121,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[CALLI] = &&CALLI,
[CALLI_F] = &&CALLI_F,
[ESCAPEI] = &&ESCAPEI,
+ [ESCAPEI_F] = &&ESCAPEI_F,
[START] = &&START,
[END] = &&END,
@@ -188,6 +211,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = gpr[i.r1] / gpr[i.r2];
DISPATCH();
+ DO(DIVR_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();
+
DO(ANDR);
gpr[i.r0] = gpr[i.r1] & gpr[i.r2];
DISPATCH();
@@ -196,6 +227,14 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = gpr[i.r1] & i.o;
DISPATCH();
+ DO(COMR);
+ gpr[i.r0] = ~gpr[i.r1];
+ DISPATCH();
+
+ DO(NEGR);
+ gpr[i.r0] = -gpr[i.r1];
+ DISPATCH();
+
DO(EQR);
gpr[i.r0] = gpr[i.r1] == gpr[i.r2];
DISPATCH();
@@ -236,16 +275,86 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = fpr[i.r1] >= fpr[i.r2];
DISPATCH();
+ DO(STXI8);
+ int8_t *addr = (int8_t *)(gpr[i.r1] + i.o);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STXI16);
+ int16_t *addr = (int16_t *)(gpr[i.r1] + i.o);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
+ DO(STXI32);
+ int32_t *addr = (int32_t *)(gpr[i.r1] + i.o);
+ *addr = gpr[i.r0];
+ DISPATCH();
+
DO(STXI64);
int64_t *addr = (int64_t *)(gpr[i.r1] + i.o);
*addr = gpr[i.r0];
DISPATCH();
+ DO(STXIF);
+ float *addr = (float *)(gpr[i.r1] + i.o);
+ *addr = fpr[i.r0];
+ DISPATCH();
+
+ DO(STXID);
+ double *addr = (double *)(gpr[i.r1] + i.o);
+ *addr = fpr[i.r0];
+ DISPATCH();
+
+ DO(LDXI8);
+ int8_t *addr = (int8_t *)(gpr[i.r1] + i.o);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXI16);
+ int16_t *addr = (int16_t *)(gpr[i.r1] + i.o);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXI32);
+ int32_t *addr = (int32_t *)(gpr[i.r1] + i.o);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXI64);
+ int64_t *addr = (int64_t *)(gpr[i.r1] + i.o);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXIU8);
+ uint8_t *addr = (uint8_t *)(gpr[i.r1] + i.o);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXIU16);
+ uint16_t *addr = (uint16_t *)(gpr[i.r1] + i.o);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXIU32);
+ uint32_t *addr = (uint32_t *)(gpr[i.r1] + i.o);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
DO(LDXIU64);
uint64_t *addr = (uint64_t *)(gpr[i.r1] + i.o);
gpr[i.r0] = *addr;
DISPATCH();
+ DO(LDXIF);
+ float *addr = (float *)(gpr[i.r1] + i.o);
+ fpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXID);
+ double *addr = (double *)(gpr[i.r1] + i.o);
+ fpr[i.r0] = *addr;
+ DISPATCH();
+
DO(BNER);
if (gpr[i.r1] != gpr[i.r2])
JUMP(i.r0);
@@ -410,6 +519,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
gpr[i.r0] = retval;
DISPATCH();
+ DO(RETVAL_F);
+ fpr[i.r0] = retval_f;
+ DISPATCH();
+
DO(PARAM);
gpr[i.r2] = args[i.r0].u64;
DISPATCH();
@@ -465,6 +578,17 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
vec_shrink(&state->args, prev_argc);
DISPATCH();
+ DO(ESCAPEI_F);
+ ejit_escape_f_t f = i.p;
+ size_t argc = vec_len(&state->args) - prev_argc;
+ struct ejit_arg *args = ((struct ejit_arg *)state->args.buf) +
+ prev_argc;
+
+ retval_f = f(argc, args);
+
+ vec_shrink(&state->args, prev_argc);
+ DISPATCH();
+
/* dispatch is technically unnecessary for returns, but keep it for
* symmetry */
DO(RETR);
diff --git a/tests/addx.c b/tests/addx.c
deleted file mode 100644
index eed95ba..0000000
--- a/tests/addx.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* still not entirely sure about semantics, should 32bit systems report carry on
- * 32bit or 64bit internal register sizes? */
-#warning "carry operations unimplemented but TODO"
-int main(){
-}
-
-/* would look something like this */
-#if 0
-#include <ejit/ejit.h>
-#include <assert.h>
-#include "do_jit.h"
-
-int main()
-{
- struct ejit_operand operands[2] = {
- EJIT_OPERAND_GPR(0, EJIT_TYPE(long)),
- EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
- };
- struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
-
- ejit_movi(j, EJIT_GPR(2), EJIT_GPR(0));
- ejit_addcr(j, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
- ejit_addxi(j, EJIT_GPR(2), EJIT_GPR(2), 0);
- ejit_retr(j, EJIT_GPR(2));
-
- ejit_select_compile_func(f, 3, 0, EJIT_USE64(long), do_jit);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = ret;
-
- assert(ejit_run_func_2(f, EJIT_ARG(0, long), EJIT_ARG(0, long)) == 0);
-
-#if EJIT_WORDSIZE == 32
- /* carry */
- assert(ejit_run_func_2(f,
- EJIT_ARG(0xffffffff, long),
- EJIT_ARG(0xffffffff, long)) == 1);
- /* overflow */
- assert(ejit_run_func_2(f,
- EJIT_ARG(0x7fffffff long),
- EJIT_ARG(1, long)) == 0);
-
- /* overflow */
- assert(ejit_run_func_2(f,
- EJIT_ARG(0x7fffffff, long),
- EJIT_ARG(0x7fffffff, long)) == 0);
-
- /* carry */
- assert(ejit_run_func_2(f,
- EJIT_ARG(0x7fffffff, long),
- EJIT_ARG(0x80000000, long)) == 0);
-
- /* carry+overflow */
- assert(ejit_run_func_2(f,
- EJIT_ARG(0x80000000, long),
- EJIT_ARG(0x80000000, long)) == 1);
-#else
- /* nothing */
- assert(f(0xffffffff, 0xffffffff) == 0);
- /* nothing */
- assert(f(0x7fffffff, 1) == 0);
- /* nothing */
- assert(f(0x7fffffff, 0x7fffffff) == 0);
- /* nothing */
- assert(f(0x7fffffff, 0x80000000) == 0);
- /* nothing */
- assert(f(0x80000000, 0x80000000) == 0);
- /* carry */
- assert(f(0xffffffffffffffff, 0xffffffffffffffff) == 1);
- /* overflow */
- assert(f(0x7fffffffffffffff, 1) == 0);
- /* overflow */
- assert(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
- /* overflow */
- assert(f(0x7fffffffffffffff, 0x8000000000000000) == 0);
- /* carry+overflow */
- assert(f(0x8000000000000000, 0x8000000000000000) == 1);
-#endif
-}
-#endif
diff --git a/tests/bltgtr_f.c b/tests/bltgtr_f.c
deleted file mode 100644
index 32b2a96..0000000
--- a/tests/bltgtr_f.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <ejit/ejit.h>
-#include <assert.h>
-#include "do_jit.h"
-
-int main()
-{
- struct ejit_operand operands[2] = {
- EJIT_OPERAND_FPR(0, EJIT_TYPE(double)),
- EJIT_OPERAND_FPR(1, EJIT_TYPE(double)),
- };
-
- struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
- struct ejit_reloc r = ejit_bltgtr_f(f, EJIT_FPR(0), EJIT_FPR(1));
- ejit_reti(f, 0);
-
- struct ejit_label l = ejit_label(f);
- ejit_patch(f, r, l);
- ejit_reti(f, 1);
-
- ejit_select_compile_func(f, 0, 2, EJIT_USE64(double), do_jit);
-
- assert(ejit_run_func_2(f, EJIT_ARG(0, double),
- EJIT_ARG(0, double)) == 0);
- assert(ejit_run_func_2(f, EJIT_ARG(0, double),
- EJIT_ARG(1, double)) == 1);
- assert(ejit_run_func_2(f, EJIT_ARG(1, double),
- EJIT_ARG(0, double)) == 1);
- assert(ejit_run_func_2(f, EJIT_ARG(0, double),
- EJIT_ARG(-1, double)) == 1);
- assert(ejit_run_func_2(f, EJIT_ARG(-1, double),
- EJIT_ARG(0, double)) == 1);
- assert(ejit_run_func_2(f, EJIT_ARG(1, double),
- EJIT_ARG(1, double)) == 0);
-
- assert(ejit_run_func_2(f, EJIT_ARG(0, double),
- EJIT_ARG(0.0/0.0, double)) == 0);
- assert(ejit_run_func_2(f, EJIT_ARG(0.0/0.0, double),
- EJIT_ARG(0, double)) == 0);
- assert(ejit_run_func_2(f, EJIT_ARG(0.0/0.0, double),
- EJIT_ARG(0.0/0.0, double)) == 0);
-}
diff --git a/tests/boaddi.c b/tests/boaddi.c
deleted file mode 100644
index e0fed81..0000000
--- a/tests/boaddi.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_boaddi(j, JIT_R0, 1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == 0);
- ASSERT(f(0) == 1);
- ASSERT(f(1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x7fffffff) == overflowed);
- ASSERT(f(0x80000000) == 0x80000001);
- ASSERT(f(0xffffffff) == 0);
-#else
- ASSERT(f(0x7fffffffffffffff) == overflowed);
- ASSERT(f(0x8000000000000000) == 0x8000000000000001);
- ASSERT(f(0xffffffffffffffff) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/boaddi_u.c b/tests/boaddi_u.c
deleted file mode 100644
index b6ffa89..0000000
--- a/tests/boaddi_u.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_boaddi_u(j, JIT_R0, 1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == overflowed);
- ASSERT(f(0) == 1);
- ASSERT(f(1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x7fffffff) == 0x80000000);
- ASSERT(f(0x80000000) == 0x80000001);
- ASSERT(f(0xffffffff) == overflowed);
-#else
- ASSERT(f(0x7fffffffffffffff) == 0x8000000000000000);
- ASSERT(f(0x8000000000000000) == 0x8000000000000001);
- ASSERT(f(0xffffffffffffffff) == overflowed);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/boaddr.c b/tests/boaddr.c
deleted file mode 100644
index 69668f7..0000000
--- a/tests/boaddr.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_boaddr(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(1, 1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == -2);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == overflowed);
- ASSERT(f(0x7fffffff, 0x7fffffff) == overflowed);
- ASSERT(f(0x7fffffff, 0x80000000) == -1);
- ASSERT(f(0x80000000, 0x80000000) == overflowed);
-#else
- ASSERT(f(0xffffffff, 0xffffffff) == 0xffffffffull + 0xffffffffull);
- ASSERT(f(0x7fffffff, 1) == 0x80000000);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0x7fffffffull + 0x7fffffffull);
- ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff);
- ASSERT(f(0x80000000, 0x80000000) == 0x100000000);
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == -2);
- ASSERT(f(0x7fffffffffffffff, 1) == overflowed);
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == overflowed);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == -1);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == overflowed);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/boaddr_u.c b/tests/boaddr_u.c
deleted file mode 100644
index 1483471..0000000
--- a/tests/boaddr_u.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_boaddr_u(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(1, 1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == overflowed);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == 0x80000000);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0x7fffffffu + 0x7fffffffu);
- ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff);
- ASSERT(f(0x80000000, 0x80000000) == overflowed);
-#else
- ASSERT(f(0xffffffff, 0xffffffff) == 0xffffffffull + 0xffffffffull);
- ASSERT(f(0x7fffffff, 1) == 0x80000000);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0x7fffffffull + 0x7fffffffull);
- ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff);
- ASSERT(f(0x80000000, 0x80000000) == 0x100000000);
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == overflowed);
- ASSERT(f(0x7fffffffffffffff, 1) == 0x8000000000000000);
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == -2);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == -1);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == overflowed);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bordr_f.c b/tests/bordr_f.c
deleted file mode 100644
index a3db62e..0000000
--- a/tests/bordr_f.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
-
- jit_reloc_t r = jit_bordr_f(j, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 0);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 1);
-
- jit_word_t (*f)(float, float) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 1);
- ASSERT(f(0, 1) == 1);
- ASSERT(f(1, 0) == 1);
- ASSERT(f(-1, 0) == 1);
- ASSERT(f(0, -1) == 1);
- ASSERT(f(1, 1) == 1);
-
- ASSERT(f(0, 0.0/0.0) == 0);
- ASSERT(f(0.0/0.0, 0) == 0);
- ASSERT(f(0.0/0.0, 0.0/0.0) == 0);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bosubi.c b/tests/bosubi.c
deleted file mode 100644
index b1bbc77..0000000
--- a/tests/bosubi.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_bosubi(j, JIT_R0, 1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == -2);
- ASSERT(f(0) == -1);
- ASSERT(f(1) == 0);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x7fffffff) == 0x7ffffffe);
- ASSERT(f(0x80000000) == overflowed);
- ASSERT(f(0x80000001) == 0x80000000);
-#else
- ASSERT(f(0x7fffffffffffffff) == 0x7ffffffffffffffe);
- ASSERT(f(0x8000000000000000) == overflowed);
- ASSERT(f(0x8000000000000001) == 0x8000000000000000);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bosubi_u.c b/tests/bosubi_u.c
deleted file mode 100644
index c04b971..0000000
--- a/tests/bosubi_u.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_bosubi_u(j, JIT_R0, 1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == -2);
- ASSERT(f(0) == overflowed);
- ASSERT(f(1) == 0);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x80000000) == 0x7fffffff);
-#else
- ASSERT(f(0x8000000000000000) == 0x7fffffffffffffff);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bosubr.c b/tests/bosubr.c
deleted file mode 100644
index 01ea9fe..0000000
--- a/tests/bosubr.c
+++ /dev/null
@@ -1,48 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_bosubr(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(0, 1) == -1);
- ASSERT(f(1, 1) == 0);
- ASSERT(f(1, -1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == 0);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
- ASSERT(f(0x80000000, 0x7fffffff) == overflowed);
- ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
- ASSERT(f(0x80000000, 0x80000000) == 0);
-#else
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
- ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == overflowed);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bosubr_u.c b/tests/bosubr_u.c
deleted file mode 100644
index 0f6d5b7..0000000
--- a/tests/bosubr_u.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_bosubr_u(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_patch_here(j, r);
- jit_movi(j, JIT_R0, overflowed);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(1, 1) == 0);
- ASSERT(f(0, 1) == overflowed);
- ASSERT(f(1, 0) == 1);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == 0);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
- ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
- ASSERT(f(0x80000000, 0x80000000) == 0);
-#else
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bswapr_ui.c b/tests/bswapr_ui.c
deleted file mode 100644
index 9c4b42b..0000000
--- a/tests/bswapr_ui.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_bswapr_ui(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(0) == 0);
- ASSERT(f(0x12345678) == 0x78563412);
-#if EJIT_WORDSIZE > 32
- ASSERT(f(0xff12345678) == 0x78563412);
- ASSERT(f(0xff00000000) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bswapr_ul.c b/tests/bswapr_ul.c
deleted file mode 100644
index 03136d8..0000000
--- a/tests/bswapr_ul.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
-#if EJIT_WORDSIZE > 32
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_bswapr_ul(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(0) == 0);
- ASSERT(f(0x12345678) == 0x7856341200000000);
- ASSERT(f(0xff12345678) == 0x78563412ff000000);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bswapr_us.c b/tests/bswapr_us.c
deleted file mode 100644
index a2c223b..0000000
--- a/tests/bswapr_us.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_bswapr_us(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(0) == 0);
- ASSERT(f(0x12345678) == 0x7856);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/buneqr_f.c b/tests/buneqr_f.c
deleted file mode 100644
index 4277f86..0000000
--- a/tests/buneqr_f.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
-
- jit_reloc_t r = jit_buneqr_f(j, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 0);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 1);
-
- jit_word_t (*f)(float, float) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 1);
- ASSERT(f(0, 1) == 0);
- ASSERT(f(1, 0) == 0);
- ASSERT(f(-1, 0) == 0);
- ASSERT(f(0, -1) == 0);
- ASSERT(f(1, 1) == 1);
-
- ASSERT(f(0, 0.0/0.0) == 1);
- ASSERT(f(0.0/0.0, 0) == 1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bunger_f.c b/tests/bunger_f.c
deleted file mode 100644
index 0fa542b..0000000
--- a/tests/bunger_f.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
-
- jit_reloc_t r = jit_bunger_f(j, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 0);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 1);
-
- jit_word_t (*f)(float, float) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 1);
- ASSERT(f(0, 1) == 0);
- ASSERT(f(1, 0) == 1);
- ASSERT(f(-1, 0) == 0);
- ASSERT(f(0, -1) == 1);
-
- ASSERT(f(0, 0.0/0.0) == 1);
- ASSERT(f(0.0/0.0, 0) == 1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bungtr_f.c b/tests/bungtr_f.c
deleted file mode 100644
index 94a9170..0000000
--- a/tests/bungtr_f.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
-
- jit_reloc_t r = jit_bungtr_f(j, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 0);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 1);
-
- jit_word_t (*f)(float, float) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(0, 1) == 0);
- ASSERT(f(1, 0) == 1);
- ASSERT(f(-1, 0) == 0);
- ASSERT(f(0, -1) == 1);
-
- ASSERT(f(0, 0.0/0.0) == 1);
- ASSERT(f(0.0/0.0, 0) == 1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bunler_f.c b/tests/bunler_f.c
deleted file mode 100644
index 3b40f95..0000000
--- a/tests/bunler_f.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
-
- jit_reloc_t r = jit_bunler_f(j, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 0);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 1);
-
- jit_word_t (*f)(float, float) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 1);
- ASSERT(f(0, 1) == 1);
- ASSERT(f(1, 0) == 0);
- ASSERT(f(-1, 0) == 1);
- ASSERT(f(0, -1) == 0);
-
- ASSERT(f(0, 0.0/0.0) == 1);
- ASSERT(f(0.0/0.0, 0) == 1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bunltr_f.c b/tests/bunltr_f.c
deleted file mode 100644
index d86ce1a..0000000
--- a/tests/bunltr_f.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
-
- jit_reloc_t r = jit_bunltr_f(j, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 0);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 1);
-
- jit_word_t (*f)(float, float) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(0, 1) == 1);
- ASSERT(f(1, 0) == 0);
- ASSERT(f(-1, 0) == 1);
- ASSERT(f(0, -1) == 0);
-
- ASSERT(f(0, 0.0/0.0) == 1);
- ASSERT(f(0.0/0.0, 0) == 1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bunordr_f.c b/tests/bunordr_f.c
deleted file mode 100644
index 663d988..0000000
--- a/tests/bunordr_f.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
-
- jit_reloc_t r = jit_bunordr_f(j, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 0);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_reti(j, 1);
-
- jit_word_t (*f)(float, float) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(0, 1) == 0);
- ASSERT(f(1, 0) == 0);
- ASSERT(f(-1, 0) == 0);
- ASSERT(f(0, -1) == 0);
- ASSERT(f(1, 1) == 0);
-
- ASSERT(f(0, 0.0/0.0) == 1);
- ASSERT(f(0.0/0.0, 0) == 1);
- ASSERT(f(0.0/0.0, 0.0/0.0) == 1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxaddi.c b/tests/bxaddi.c
deleted file mode 100644
index 282b1f1..0000000
--- a/tests/bxaddi.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_bxaddi(j, JIT_R0, 1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == 0);
- ASSERT(f(0) == 1);
- ASSERT(f(1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x7fffffff) == overflowed);
- ASSERT(f(0x80000000) == 0x80000001);
- ASSERT(f(0xffffffff) == 0);
-#else
- ASSERT(f(0x7fffffffffffffff) == overflowed);
- ASSERT(f(0x8000000000000000) == 0x8000000000000001);
- ASSERT(f(0xffffffffffffffff) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxaddi_u.c b/tests/bxaddi_u.c
deleted file mode 100644
index dc3140e..0000000
--- a/tests/bxaddi_u.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_bxaddi_u(j, JIT_R0, 1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == overflowed);
- ASSERT(f(0) == 1);
- ASSERT(f(1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x7fffffff) == 0x80000000);
- ASSERT(f(0x80000000) == 0x80000001);
- ASSERT(f(0xffffffff) == overflowed);
-#else
- ASSERT(f(0x7fffffffffffffff) == 0x8000000000000000);
- ASSERT(f(0x8000000000000000) == 0x8000000000000001);
- ASSERT(f(0xffffffffffffffff) == overflowed);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxaddr.c b/tests/bxaddr.c
deleted file mode 100644
index 472906d..0000000
--- a/tests/bxaddr.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_bxaddr(j, JIT_R0, JIT_R1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(1, 1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == -2);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == overflowed);
- ASSERT(f(0x7fffffff, 0x7fffffff) == overflowed);
- ASSERT(f(0x7fffffff, 0x80000000) == -1);
- ASSERT(f(0x80000000, 0x80000000) == overflowed);
-#else
- ASSERT(f(0xffffffff, 0xffffffff) == 0xffffffffull + 0xffffffffull);
- ASSERT(f(0x7fffffff, 1) == 0x80000000);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0x7fffffffull + 0x7fffffffull);
- ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff);
- ASSERT(f(0x80000000, 0x80000000) == 0x100000000);
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == -2);
- ASSERT(f(0x7fffffffffffffff, 1) == overflowed);
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == overflowed);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == -1);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == overflowed);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxaddr_u.c b/tests/bxaddr_u.c
deleted file mode 100644
index d40e0ff..0000000
--- a/tests/bxaddr_u.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_bxaddr_u(j, JIT_R0, JIT_R1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(1, 1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == overflowed);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == 0x80000000);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0x7fffffffu + 0x7fffffffu);
- ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff);
- ASSERT(f(0x80000000, 0x80000000) == overflowed);
-#else
- ASSERT(f(0xffffffff, 0xffffffff) == 0xffffffffull + 0xffffffffull);
- ASSERT(f(0x7fffffff, 1) == 0x80000000);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0x7fffffffull + 0x7fffffffull);
- ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff);
- ASSERT(f(0x80000000, 0x80000000) == 0x100000000);
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == overflowed);
- ASSERT(f(0x7fffffffffffffff, 1) == 0x8000000000000000);
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == -2);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == -1);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == overflowed);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxsubi.c b/tests/bxsubi.c
deleted file mode 100644
index e6224bf..0000000
--- a/tests/bxsubi.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_bxsubi(j, JIT_R0, 1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == -2);
- ASSERT(f(0) == -1);
- ASSERT(f(1) == 0);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x7fffffff) == 0x7ffffffe);
- ASSERT(f(0x80000000) == overflowed);
- ASSERT(f(0x80000001) == 0x80000000);
-#else
- ASSERT(f(0x7fffffffffffffff) == 0x7ffffffffffffffe);
- ASSERT(f(0x8000000000000000) == overflowed);
- ASSERT(f(0x8000000000000001) == 0x8000000000000000);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxsubi_u.c b/tests/bxsubi_u.c
deleted file mode 100644
index 6c1d1f3..0000000
--- a/tests/bxsubi_u.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_reloc_t r = jit_bxsubi_u(j, JIT_R0, 1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(-1) == -2);
- ASSERT(f(0) == overflowed);
- ASSERT(f(1) == 0);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x80000000) == 0x7fffffff);
-#else
- ASSERT(f(0x8000000000000000) == 0x7fffffffffffffff);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxsubr.c b/tests/bxsubr.c
deleted file mode 100644
index 50f5dbb..0000000
--- a/tests/bxsubr.c
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_bxsubr(j, JIT_R0, JIT_R1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(0, 1) == -1);
- ASSERT(f(1, 1) == 0);
- ASSERT(f(1, -1) == 2);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == 0);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
- ASSERT(f(0x80000000, 0x7fffffff) == overflowed);
- ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
- ASSERT(f(0x80000000, 0x80000000) == 0);
-#else
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
- ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == overflowed);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/bxsubr_u.c b/tests/bxsubr_u.c
deleted file mode 100644
index 771ea3c..0000000
--- a/tests/bxsubr_u.c
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "test.h"
-
-static const jit_word_t overflowed = 0xcabba9e5;
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_reloc_t r = jit_bxsubr_u(j, JIT_R0, JIT_R1);
- jit_movi(j, JIT_R0, overflowed);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0, 0) == 0);
- ASSERT(f(1, 1) == 0);
- ASSERT(f(0, 1) == overflowed);
- ASSERT(f(1, 0) == 1);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 0xffffffff) == 0);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
- ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
- ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
- ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
- ASSERT(f(0x80000000, 0x80000000) == 0);
-#else
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
- ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/call_10.c b/tests/call_10.c
deleted file mode 100644
index 533acda..0000000
--- a/tests/call_10.c
+++ /dev/null
@@ -1,64 +0,0 @@
-#include "test.h"
-
-static int32_t f(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e,
- int32_t f, int32_t g, int32_t h, int32_t i, int32_t j) {
- ASSERT(a == 0);
- ASSERT(b == 1);
- ASSERT(c == 2);
- ASSERT(d == 3);
- ASSERT(e == 4);
- ASSERT(f == 5);
- ASSERT(g == 6);
- ASSERT(h == 7);
- ASSERT(i == 8);
- ASSERT(j == 9);
- return 42;
-}
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0));
-
- jit_operand_t args[10] = {
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 0 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 1 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 2 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 3 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 4 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 5 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 6 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 7 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 8 * sizeof(int32_t)),
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0,
- 9 * sizeof(int32_t))
- };
- jit_calli(j, f, 10, args);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_ret(j);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- int32_t (*f)(int32_t*) = ret;
-
- int32_t iargs[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- ASSERT(f(iargs) == 42);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/call_double.c b/tests/call_double.c
deleted file mode 100644
index 1138655..0000000
--- a/tests/call_double.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "test.h"
-
-static double f(int32_t a, double b) {
- return b + a;
-}
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R1));
-
- jit_operand_t args[2] = {
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0, 0),
- jit_operand_mem(JIT_OPERAND_ABI_DOUBLE, JIT_R1, 0)
- };
- jit_calli(j, f, 2, args);
- jit_retval_d(j, JIT_F0);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_d(j, JIT_F0);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- double (*f)(int32_t*, double*) = ret;
-
- double d = 22.0f;
- int32_t i = 20;
- ASSERT(f(&i, &d) == 42.0f);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/call_float.c b/tests/call_float.c
deleted file mode 100644
index 9534e4b..0000000
--- a/tests/call_float.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "test.h"
-
-static float f(int32_t a, float b) {
- return b + a;
-}
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R1));
-
- jit_operand_t args[2] = {
- jit_operand_mem(JIT_OPERAND_ABI_INT32, JIT_R0, 0),
- jit_operand_mem(JIT_OPERAND_ABI_FLOAT, JIT_R1, 0)
- };
- jit_calli(j, f, 2, args);
- jit_retval_f(j, JIT_F0);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- float (*f)(int32_t*, float*) = ret;
-
- float d = 22.0f;
- int32_t i = 20;
- ASSERT(f(&i, &d) == 42.0f);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/callee_9.c b/tests/callee_9.c
index 9d4e217..7dd131f 100644
--- a/tests/callee_9.c
+++ b/tests/callee_9.c
@@ -1,68 +1,78 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
struct args
{
int8_t a;
int16_t b;
int32_t c;
- jit_word_t d;
+ long d;
uint16_t e;
float f;
double g;
float h;
};
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
+int main()
{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 3, 0, 0);
-
- jit_operand_t args[9] = {
- jit_operand_gpr(JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr(JIT_OPERAND_ABI_INT8, JIT_R1),
- jit_operand_gpr(JIT_OPERAND_ABI_INT16, JIT_R2),
- jit_operand_gpr(JIT_OPERAND_ABI_INT32, JIT_V0),
- jit_operand_gpr(JIT_OPERAND_ABI_WORD, JIT_V1),
- jit_operand_gpr(JIT_OPERAND_ABI_UINT16, JIT_V2),
- jit_operand_fpr(JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr(JIT_OPERAND_ABI_DOUBLE, JIT_F1),
- jit_operand_fpr(JIT_OPERAND_ABI_FLOAT, JIT_F2),
+ struct ejit_operand operands[9] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_INT8),
+ EJIT_OPERAND_GPR(2, EJIT_INT16),
+ EJIT_OPERAND_GPR(3, EJIT_INT32),
+ EJIT_OPERAND_GPR(4, EJIT_TYPE(long)),
+ EJIT_OPERAND_GPR(5, EJIT_UINT16),
+ EJIT_OPERAND_FPR(0, EJIT_FLOAT),
+ EJIT_OPERAND_FPR(1, EJIT_DOUBLE),
+ EJIT_OPERAND_FPR(2, EJIT_FLOAT)
};
- jit_load_args(j, 9, args);
- jit_stxi_c(j, offsetof(struct args, a), JIT_R0, JIT_R1); // a
- jit_stxi_s(j, offsetof(struct args, b), JIT_R0, JIT_R2); // b
- jit_stxi_i(j, offsetof(struct args, c), JIT_R0, JIT_V0); // c
- jit_stxi(j, offsetof(struct args, d), JIT_R0, JIT_V1);// d
- jit_stxi_s(j, offsetof(struct args, e), JIT_R0, JIT_V2); // e
- jit_stxi_f(j, offsetof(struct args, f), JIT_R0, JIT_F0); // f
- jit_stxi_d(j, offsetof(struct args, g), JIT_R0, JIT_F1); // g
- jit_stxi_f(j, offsetof(struct args, h), JIT_R0, JIT_F2); // h
- jit_leave_jit_abi(j, 3, 0, align);
- jit_retr(j, JIT_R0);
+ struct ejit_func *f = ejit_create_func(EJIT_POINTER, 9, operands);
+ EJIT_STXI(f, int8_t, EJIT_GPR(1), EJIT_GPR(0),
+ offsetof(struct args, a)); // a
+ EJIT_STXI(f, int16_t, EJIT_GPR(2), EJIT_GPR(0),
+ offsetof(struct args, b)); // b
+ EJIT_STXI(f, int32_t, EJIT_GPR(3), EJIT_GPR(0),
+ offsetof(struct args, c)); // c
+ EJIT_STXI(f, long, EJIT_GPR(4), EJIT_GPR(0),
+ offsetof(struct args, d)); // d
+ EJIT_STXI(f, uint16_t, EJIT_GPR(5), EJIT_GPR(0),
+ offsetof(struct args, e)); // e
+ EJIT_STXI(f, float, EJIT_FPR(0), EJIT_GPR(0),
+ offsetof(struct args, f)); // f
+ EJIT_STXI(f, double, EJIT_FPR(1), EJIT_GPR(0),
+ offsetof(struct args, g)); // g
+ EJIT_STXI(f, float, EJIT_FPR(2), EJIT_GPR(0),
+ offsetof(struct args, h)); // h
- size_t size = 0;
- void* ret = jit_end(j, &size);
+ ejit_retr(f, EJIT_GPR(0));
- struct args* (*f)(struct args*, int8_t, int16_t, int32_t, jit_word_t,
- uint16_t, float, double, float) = ret;
+ ejit_select_compile_func(f, 6, 3, EJIT_USE64(long), do_jit);
struct args in = { 0, 1, 2, 3, 4, 5, 6, 7 };
struct args out;
- ASSERT(f(&out, in.a, in.b, in.c, in.d, in.e, in.f, in.g, in.h) == &out);
- ASSERT(in.a == out.a);
- ASSERT(in.b == out.b);
- ASSERT(in.c == out.c);
- ASSERT(in.d == out.d);
- ASSERT(in.e == out.e);
- ASSERT(in.f == out.f);
- ASSERT(in.g == out.g);
- ASSERT(in.h == out.h);
-}
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ struct ejit_arg args[9] = {
+ EJIT_ARG(&out, void *),
+ EJIT_ARG(in.a, int8_t),
+ EJIT_ARG(in.b, int16_t),
+ EJIT_ARG(in.c, int32_t),
+ EJIT_ARG(in.d, long),
+ EJIT_ARG(in.e, uint16_t),
+ EJIT_ARG(in.f, float),
+ EJIT_ARG(in.g, double),
+ EJIT_ARG(in.h, float)
+ };
+ assert((void *)ejit_run_func(f, 8, args) == &out);
+ assert(in.a == out.a);
+ assert(in.b == out.b);
+ assert(in.c == out.c);
+ assert(in.d == out.d);
+ assert(in.e == out.e);
+ assert(in.f == out.f);
+ assert(in.g == out.g);
+ assert(in.h == out.h);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/cas_atomic.c b/tests/cas_atomic.c
deleted file mode 100644
index a382eae..0000000
--- a/tests/cas_atomic.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "test.h"
-
-static long data[] = { 0x12121212, 0x00000000, 0x34343434 };
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_3(j, jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R1),
- jit_operand_gpr (JIT_OPERAND_ABI_INT32, JIT_R2));
-
- jit_cas_atomic(j, JIT_R0, JIT_R0, JIT_R1, JIT_R2);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_ret(j);
-
- void (*f)(void*, int32_t, int32_t) = jit_end(j, NULL);
-
- ASSERT(data[0] == 0x12121212);
- ASSERT(data[1] == 0x00);
- ASSERT(data[2] == 0x34343434);
- f(&data[1], 0, 0x0f0f0f0f);
- ASSERT(data[0] == 0x12121212);
- ASSERT(data[1] == 0x0f0f0f0f);
- ASSERT(data[2] == 0x34343434);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/comr.c b/tests/comr.c
index 3cfacac..a6b6dc3 100644
--- a/tests/comr.c
+++ b/tests/comr.c
@@ -1,41 +1,61 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
+int main()
{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_comr(j, JIT_R0, JIT_R0);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
-
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0) == 0xffffffff);
- ASSERT(f(1) == 0xfffffffe);
- ASSERT(f(0xffffffff) == 0);
- ASSERT(f(0x80000000) == 0x7fffffff);
- ASSERT(f(0x7fffffff) == 0x80000000);
- ASSERT(f(0x80000001) == 0x7ffffffe);
-#else
- ASSERT(f(0) == 0xffffffffffffffff);
- ASSERT(f(1) == 0xfffffffffffffffe);
- ASSERT(f(0xffffffff) == 0xffffffff00000000);
- ASSERT(f(0x80000000) == 0xffffffff7fffffff);
- ASSERT(f(0x7fffffff) == 0xffffffff80000000);
- ASSERT(f(0x80000001) == 0xffffffff7ffffffe);
- ASSERT(f(0xffffffffffffffff) == 0);
- ASSERT(f(0x8000000000000000) == 0x7fffffffffffffff);
- ASSERT(f(0x7fffffffffffffff) == 0x8000000000000000);
- ASSERT(f(0x8000000000000001) == 0x7ffffffffffffffe);
-#endif
-}
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+
+ ejit_comr(f, EJIT_GPR(0), EJIT_GPR(0));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
+
+ assert((int32_t)ejit_run_func_1(f, EJIT_ARG(0, long))
+ == (int32_t)0xffffffff);
+
+ assert((int32_t)ejit_run_func_1(f, EJIT_ARG(1, long))
+ == (int32_t)0xfffffffe);
+
+ assert((int32_t)ejit_run_func_1(f, EJIT_ARG(0xffffffff, long)) == 0);
+ assert((int32_t)ejit_run_func_1(f, EJIT_ARG(0x80000000, long))
+ == 0x7fffffff);
+
+ assert((int32_t)ejit_run_func_1(f, EJIT_ARG(0x7fffffff, long))
+ == (int32_t)0x80000000);
+
+ assert((int32_t)ejit_run_func_1(f, EJIT_ARG(0x80000001, long))
+ == (int32_t)0x7ffffffe);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0, long))
+ == (int64_t)0xffffffffffffffff);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(1, long))
+ == (int64_t)0xfffffffffffffffe);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0xffffffff, long))
+ == (int64_t)0xffffffff00000000);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0x80000000, long))
+ == (int64_t)0xffffffff7fffffff);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0x7fffffff, long))
+ == (int64_t)0xffffffff80000000);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0x80000001, long))
+ == (int64_t)0xffffffff7ffffffe);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0xffffffffffffffff, long)) == 0);
+ assert(ejit_run_func_1(f, EJIT_ARG(0x8000000000000000, long))
+ == (int64_t)0x7fffffffffffffff);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0x7fffffffffffffff, long))
+ == (int64_t)0x8000000000000000);
+
+ assert(ejit_run_func_1(f, EJIT_ARG(0x8000000000000001, long))
+ == (int64_t)0x7ffffffffffffffe);
}
diff --git a/tests/divr.c b/tests/divr.c
index c68fcaa..e16a8bf 100644
--- a/tests/divr.c
+++ b/tests/divr.c
@@ -1,60 +1,152 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
+int main()
{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_divr(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = ret;
-
- ASSERT(f(0x7fffffff, 1) == 0x7fffffff);
- ASSERT(f(1, 0x7fffffff) == 0);
- ASSERT(f(0x80000000, 1) == 0x80000000);
- ASSERT(f(1, 0x80000000) == 0);
- ASSERT(f(0x7fffffff, 2) == 0x3fffffff);
- ASSERT(f(2, 0x7fffffff) == 0);
- ASSERT(f(2, 0x80000000) == 0);
- ASSERT(f(0x7fffffff, 0x80000000) == 0);
- ASSERT(f(0, 0x7fffffff) == 0);
- ASSERT(f(0xffffffff, 0xffffffff) == 1);
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0x80000000, 2) == 0xc0000000);
- ASSERT(f(0x80000000, 0x7fffffff) == 0xffffffff);
- ASSERT(f(0x7fffffff, 0xffffffff) == 0x80000001);
- ASSERT(f(0xffffffff, 0x7fffffff) == 0);
-#else
- ASSERT(f(0x80000000, 2) == 0x40000000);
- ASSERT(f(0x80000000, 0x7fffffff) == 1);
- ASSERT(f(0x7fffffff, 0xffffffff) == 0);
- ASSERT(f(0xffffffff, 0x7fffffff) == 2);
- ASSERT(f(0x7fffffffffffffff, 1) == 0x7fffffffffffffff);
- ASSERT(f(1, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x8000000000000000, 1) == 0x8000000000000000);
- ASSERT(f(1, 0x8000000000000000) == 0);
- ASSERT(f(0x7fffffffffffffff, 2) == 0x3fffffffffffffff);
- ASSERT(f(2, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x8000000000000000, 2) == 0xc000000000000000);
- ASSERT(f(2, 0x8000000000000000) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0);
- ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0xffffffffffffffff);
- ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0x8000000000000001);
- ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 0);
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 1);
-#endif
-}
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long)),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ ejit_divr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(1, long)) == 0x7fffffff);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(1, long),
+ EJIT_ARG(0x7fffffff, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x80000000, long),
+ EJIT_ARG(1, long)) == 0x80000000);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(1, long),
+ EJIT_ARG(0x80000000, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(2, long)) == 0x3fffffff);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(2, long),
+ EJIT_ARG(0x7fffffff, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(2, long),
+ EJIT_ARG(0x80000000, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(0x80000000, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0, long),
+ EJIT_ARG(0x7fffffff, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0xffffffff, long),
+ EJIT_ARG(0xffffffff, long)) == 1);
+
+#warning "Some 32bit handling still unclear"
+ /* 32bit specific stuff, unsure how this should be handled on 64bit
+ * systems
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x80000000, long),
+ EJIT_ARG(2, long)) == 0xc0000000);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x80000000, long),
+ EJIT_ARG(0x7fffffff, long)) == 0xffffffff);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(0xffffffff, long)) == 0x80000001);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0xffffffff, long),
+ EJIT_ARG(0x7fffffff, long)) == 0);
+ */
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x80000000, long),
+ EJIT_ARG(2, long)) == 0x40000000);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x80000000, long),
+ EJIT_ARG(0x7fffffff, long)) == 1);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(0xffffffff, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0xffffffff, long),
+ EJIT_ARG(0x7fffffff, long)) == 2);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(1, long)) == 0x7fffffffffffffff);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(1, long),
+ EJIT_ARG(0x7fffffffffffffff, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x8000000000000000, long),
+ EJIT_ARG(1, long))
+ == (int64_t)0x8000000000000000);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(1, long),
+ EJIT_ARG(0x8000000000000000, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(2, long))
+ == (int64_t)0x3fffffffffffffff);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(2, long),
+ EJIT_ARG(0x7fffffffffffffff, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x8000000000000000, long),
+ EJIT_ARG(2, long))
+ == (int64_t)0xc000000000000000);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(2, long),
+ EJIT_ARG(0x8000000000000000, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(0x8000000000000000, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x8000000000000000, long),
+ EJIT_ARG(0x7fffffffffffffff, long))
+ == (int32_t)0xffffffffffffffff);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(0xffffffffffffffff, long))
+ == (int32_t)0x8000000000000001);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0xffffffffffffffff, long),
+ EJIT_ARG(0x7fffffffffffffff, long)) == 0);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0xffffffffffffffff, long),
+ EJIT_ARG(0xffffffffffffffff, long)) == 1);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/divr_f.c b/tests/divr_f.c
index 085ecff..081c63d 100644
--- a/tests/divr_f.c
+++ b/tests/divr_f.c
@@ -1,27 +1,27 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
+int main()
{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0),
- jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F1));
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_FPR(0, EJIT_TYPE(double)),
+ EJIT_OPERAND_FPR(1, EJIT_TYPE(double))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 2, operands);
- jit_divr_f(j, JIT_F0, JIT_F0, JIT_F1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
+ ejit_divr_f(f, EJIT_FPR(0), EJIT_FPR(0), EJIT_FPR(1));
+ ejit_retr_f(f, EJIT_FPR(0));
- size_t size = 0;
- void* ret = jit_end(j, &size);
+ ejit_select_compile_func(f, 0, 2, EJIT_USE64(double), do_jit);
- float (*f)(float, float) = ret;
- ASSERT(f(-0.5f, 0.5f) == -1.0f);
- ASSERT(f(1.25f, 0.5f) == 2.5f);
-}
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(-0.5f, double),
+ EJIT_ARG(0.5f, double)) == -1.0f);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(1.25f, double),
+ EJIT_ARG(0.5f, double)) == 2.5f);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/divr_u.c b/tests/divr_u.c
index 65d0ae2..1af4874 100644
--- a/tests/divr_u.c
+++ b/tests/divr_u.c
@@ -1,55 +1,87 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
+int main()
{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_divr_u(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = ret;
-
- ASSERT(f(0x7fffffff, 1) == 0x7fffffff);
- ASSERT(f(1, 0x7fffffff) == 0);
- ASSERT(f(0x80000000, 1) == 0x80000000);
- ASSERT(f(1, 0x80000000) == 0);
- ASSERT(f(0x7fffffff, 2) == 0x3fffffff);
- ASSERT(f(2, 0x7fffffff) == 0);
- ASSERT(f(0x80000000, 2) == 0x40000000);
- ASSERT(f(2, 0x80000000) == 0);
- ASSERT(f(0x7fffffff, 0x80000000) == 0);
- ASSERT(f(0x80000000, 0x7fffffff) == 1);
- ASSERT(f(0, 0x7fffffff) == 0);
- ASSERT(f(0x7fffffff, 0xffffffff) == 0);
- ASSERT(f(0xffffffff, 0x7fffffff) == 2);
- ASSERT(f(0xffffffff, 0xffffffff) == 1);
-#if EJIT_WORDSIZE != 32
- ASSERT(f(0x7fffffffffffffff, 1) == 0x7fffffffffffffff);
- ASSERT(f(1, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x8000000000000000, 1) == 0x8000000000000000);
- ASSERT(f(1, 0x8000000000000000) == 0);
- ASSERT(f(0x7fffffffffffffff, 2) == 0x3fffffffffffffff);
- ASSERT(f(2, 0x7fffffffffffffff) == 0);
- ASSERT(f(0x8000000000000000, 2) == 0x4000000000000000);
- ASSERT(f(2, 0x8000000000000000) == 0);
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0);
- ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 1);
- ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0);
- ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 2);
- ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 1);
-#endif
-}
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long)),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ ejit_divr_u(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit);
+
+ assert(erf2(f, EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(1, long)) == 0x7fffffff);
+ assert(erf2(f, EJIT_ARG(0x80000000, long),
+ EJIT_ARG(1, long)) == 0x80000000);
+ assert(erf2(f, EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(2, long)) == 0x3fffffff);
+ assert(erf2(f, EJIT_ARG(0x80000000, long),
+ EJIT_ARG(2, long)) == 0x40000000);
+ assert(erf2(f, EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(0x80000000, long)) == 0);
+ assert(erf2(f, EJIT_ARG(0x80000000, long),
+ EJIT_ARG(0x7fffffff, long)) == 1);
+ assert(erf2(f, EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(0xffffffff, long)) == 0);
+ assert(erf2(f, EJIT_ARG(0xffffffff, long),
+ EJIT_ARG(0x7fffffff, long)) == 2);
+ assert(erf2(f, EJIT_ARG(0xffffffff, long),
+ EJIT_ARG(0xffffffff, long)) == 1);
+ assert(erf2(f, EJIT_ARG(1, long), EJIT_ARG(0x7fffffff, long)) == 0);
+ assert(erf2(f, EJIT_ARG(1, long), EJIT_ARG(0x80000000, long)) == 0);
+ assert(erf2(f, EJIT_ARG(2, long), EJIT_ARG(0x7fffffff, long)) == 0);
+ assert(erf2(f, EJIT_ARG(2, long), EJIT_ARG(0x80000000, long)) == 0);
+ assert(erf2(f, EJIT_ARG(0, long), EJIT_ARG(0x7fffffff, long)) == 0);
+ /* wordsize != 64 */
+ assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, long), EJIT_ARG(1, long))
+ == 0x7fffffffffffffff);
+
+ assert(erf2(f, EJIT_ARG(0x8000000000000000, long), EJIT_ARG(1, long))
+ == (int64_t)0x8000000000000000);
+
+ assert(erf2(f, EJIT_ARG(0x7fffffffffffffff, long), EJIT_ARG(2, long))
+ == 0x3fffffffffffffff);
+
+ assert(erf2(f, EJIT_ARG(0x8000000000000000, long), EJIT_ARG(2, long))
+ == 0x4000000000000000);
+
+ assert(erf2(f, EJIT_ARG(1, long),
+ EJIT_ARG(0x7fffffffffffffff, long)) == 0);
+
+ assert(erf2(f, EJIT_ARG(1, long),
+ EJIT_ARG(0x8000000000000000, long)) == 0);
+
+ assert(erf2(f, EJIT_ARG(2, long),
+ EJIT_ARG(0x7fffffffffffffff, long)) == 0);
+
+ assert(erf2(f, EJIT_ARG(2, long),
+ EJIT_ARG(0x8000000000000000, long)) == 0);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(0x8000000000000000, long)) == 0);
+
+ assert(erf2(f,
+ EJIT_ARG(0x8000000000000000, long),
+ EJIT_ARG(0x7fffffffffffffff, long)) == 1);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(0xffffffffffffffff, long)) == 0);
+
+ assert(erf2(f,
+ EJIT_ARG(0xffffffffffffffff, long),
+ EJIT_ARG(0x7fffffffffffffff, long)) == 2);
+
+ assert(erf2(f,
+ EJIT_ARG(0xffffffffffffffff, long),
+ EJIT_ARG(0xffffffffffffffff, long)) == 1);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/do_jit.h b/tests/do_jit.h
index d0d4921..637ed7d 100644
--- a/tests/do_jit.h
+++ b/tests/do_jit.h
@@ -7,4 +7,12 @@ static bool do_jit = false;
static bool do_jit = true;
#endif
+#define erf3 ejit_run_func_3
+#define erf2 ejit_run_func_2
+#define erf1 ejit_run_func_1
+
+#define erff3 ejit_run_func_f_3
+#define erff2 ejit_run_func_f_2
+#define erff1 ejit_run_func_f_1
+
#endif /* DOJIT_H */
diff --git a/tests/eqr.c b/tests/eqr.c
index 7f33b19..7b8067e 100644
--- a/tests/eqr.c
+++ b/tests/eqr.c
@@ -5,7 +5,7 @@
int main()
{
struct ejit_operand operands[2] = {
- EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long)),
EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
};
diff --git a/tests/eqr_f.c b/tests/eqr_f.c
index 7afe002..e11397b 100644
--- a/tests/eqr_f.c
+++ b/tests/eqr_f.c
@@ -5,7 +5,7 @@
int main()
{
struct ejit_operand operands[2] = {
- EJIT_OPERAND_FPR(0, EJIT_TYPE(double))
+ EJIT_OPERAND_FPR(0, EJIT_TYPE(double)),
EJIT_OPERAND_FPR(1, EJIT_TYPE(double))
};
@@ -16,17 +16,17 @@ int main()
ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit);
- assert(ejit_run_func_2(f, EJIT_ARG(1, double),
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(1, double),
EJIT_ARG(1, double)) == 1);
- assert(ejit_run_func_2(f, EJIT_ARG(1, double),
- EJIT_ARG(0, double)) == 0);
assert(ejit_run_func_2(f,
- EJIT_ARG(0x7fffffffffffffff, double),
- EJIT_ARG(0x7ffffffffffffff0, double)) == 0);
+ EJIT_ARG(1, double),
+ EJIT_ARG(0, double)) == 0);
assert(ejit_run_func_2(f,
- EJIT_ARG(0x6fffffffffffffff, double),
- EJIT_ARG(0x7fffffffffffffff, double)) == 0);
+ EJIT_ARG(0.0/0.0, double),
+ EJIT_ARG(0.0/0.0, double)) == 0);
+
ejit_destroy_func(f);
}
diff --git a/tests/escapei_10.c b/tests/escapei_10.c
new file mode 100644
index 0000000..2ca1ea2
--- /dev/null
+++ b/tests/escapei_10.c
@@ -0,0 +1,81 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static int32_t func(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e,
+ int32_t f, int32_t g, int32_t h, int32_t i, int32_t j)
+{
+ assert(a == 0);
+ assert(b == 1);
+ assert(c == 2);
+ assert(d == 3);
+ assert(e == 4);
+ assert(f == 5);
+ assert(g == 6);
+ assert(h == 7);
+ assert(i == 8);
+ assert(j == 9);
+ return 42;
+}
+
+static long escape_func(size_t argc, const struct ejit_arg args[argc])
+{
+ assert(argc == 10);
+ assert(args[0].type == EJIT_INT32);
+ assert(args[1].type == EJIT_INT32);
+ assert(args[3].type == EJIT_INT32);
+ assert(args[4].type == EJIT_INT32);
+ assert(args[5].type == EJIT_INT32);
+ assert(args[6].type == EJIT_INT32);
+ assert(args[7].type == EJIT_INT32);
+ assert(args[8].type == EJIT_INT32);
+ assert(args[9].type == EJIT_INT32);
+
+ int32_t a = args[0].i32;
+ int32_t b = args[1].i32;
+ int32_t c = args[2].i32;
+ int32_t d = args[3].i32;
+ int32_t e = args[4].i32;
+ int32_t f = args[5].i32;
+ int32_t g = args[6].i32;
+ int32_t h = args[7].i32;
+ int32_t i = args[8].i32;
+ int32_t j = args[9].i32;
+ return func(a, b, c, d, e, f, g, h, i, j);
+}
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER)
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_INT32, 1, operands);
+ /* move from argument array to registers */
+ for (size_t i = 0; i < 10; ++i) {
+ ejit_ldxi_i32(f, EJIT_GPR(i + 1), EJIT_GPR(0),
+ i * sizeof(int32_t));
+ }
+
+ struct ejit_operand args[10] = {
+ EJIT_OPERAND_GPR( 1, EJIT_INT32),
+ EJIT_OPERAND_GPR( 2, EJIT_INT32),
+ EJIT_OPERAND_GPR( 3, EJIT_INT32),
+ EJIT_OPERAND_GPR( 4, EJIT_INT32),
+ EJIT_OPERAND_GPR( 5, EJIT_INT32),
+ EJIT_OPERAND_GPR( 6, EJIT_INT32),
+ EJIT_OPERAND_GPR( 7, EJIT_INT32),
+ EJIT_OPERAND_GPR( 8, EJIT_INT32),
+ EJIT_OPERAND_GPR( 9, EJIT_INT32),
+ EJIT_OPERAND_GPR(10, EJIT_INT32),
+ };
+ ejit_escapei(f, escape_func, 10, args);
+ ejit_retval(f, EJIT_GPR(0));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 11, 0, false, do_jit);
+
+ int32_t iargs[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ assert(ejit_run_func_1(f, EJIT_ARG(iargs, void *)) == 42);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/escapei_double.c b/tests/escapei_double.c
new file mode 100644
index 0000000..3165ece
--- /dev/null
+++ b/tests/escapei_double.c
@@ -0,0 +1,43 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static double func(int32_t a, double b) {
+ return b + a;
+}
+
+static double escape_func(size_t argc, const struct ejit_arg args[argc])
+{
+ assert(argc == 2);
+ assert(args[0].type == EJIT_INT32);
+ assert(args[1].type == EJIT_DOUBLE);
+ int32_t a = args[0].i32;
+ double b = args[1].d;
+ return func(a, b);
+}
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_POINTER)
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_DOUBLE, 2, operands);
+ EJIT_LDXI(f, int32_t, EJIT_GPR(0), EJIT_GPR(0), 0);
+ EJIT_LDXI(f, double, EJIT_FPR(0), EJIT_GPR(1), 0);
+
+ struct ejit_operand args[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_INT32),
+ EJIT_OPERAND_FPR(0, EJIT_DOUBLE)
+ };
+ ejit_escapei_f(f, escape_func, 2, args);
+ ejit_retval_f(f, EJIT_FPR(0));
+ ejit_retr_f(f, EJIT_FPR(0));
+
+ ejit_select_compile_func(f, 2, 1, false, do_jit);
+
+ double d = 22.0f;
+ int32_t i = 20;
+ assert(erff2(f, EJIT_ARG(&i, void *), EJIT_ARG(&d, void *)) == 42.0f);
+}
diff --git a/tests/escapei_float.c b/tests/escapei_float.c
new file mode 100644
index 0000000..a947f24
--- /dev/null
+++ b/tests/escapei_float.c
@@ -0,0 +1,43 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static float func(int32_t a, float b) {
+ return b + a;
+}
+
+static double escape_func(size_t argc, const struct ejit_arg args[argc])
+{
+ assert(argc == 2);
+ assert(args[0].type == EJIT_INT32);
+ assert(args[1].type == EJIT_FLOAT);
+ int32_t a = args[0].i32;
+ float b = args[1].f;
+ return func(a, b);
+}
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_POINTER)
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_FLOAT, 2, operands);
+ EJIT_LDXI(f, int32_t, EJIT_GPR(0), EJIT_GPR(0), 0);
+ EJIT_LDXI(f, float, EJIT_FPR(0), EJIT_GPR(1), 0);
+
+ struct ejit_operand args[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_INT32),
+ EJIT_OPERAND_FPR(0, EJIT_FLOAT)
+ };
+ ejit_escapei_f(f, escape_func, 2, args);
+ ejit_retval_f(f, EJIT_FPR(0));
+ ejit_retr_f(f, EJIT_FPR(0));
+
+ ejit_select_compile_func(f, 2, 1, false, do_jit);
+
+ float d = 22.0f;
+ int32_t i = 20;
+ assert(erff2(f, EJIT_ARG(&i, void *), EJIT_ARG(&d, void *)) == 42.0f);
+}
diff --git a/tests/qdivr.c b/tests/qdivr.c
deleted file mode 100644
index c559802..0000000
--- a/tests/qdivr.c
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 3, 0, 0);
-
- jit_operand_t args[] =
- { jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R1),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_V0) };
- jit_load_args(j, 4, args);
-
- jit_qdivr(j, JIT_V1, JIT_V2, JIT_R2, JIT_V0);
- jit_str(j, JIT_R0, JIT_V1);
- jit_str(j, JIT_R1, JIT_V2);
-
- jit_leave_jit_abi(j, 3, 0, align);
-
- jit_ret(j);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- void (*f)(jit_word_t*, jit_word_t*, jit_word_t, jit_word_t) = ret;
-
-#define QDIV(a, b, c, d) \
- do { \
- jit_word_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); \
- ASSERT(D == d); \
- } while (0)
-
- QDIV(10, 3, 3, 1);
- QDIV(-33, 9, -3, -6);
- QDIV(-41, -7, 5, -6);
- QDIV(65536, 4096, 16, 0);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/qdivr_u.c b/tests/qdivr_u.c
deleted file mode 100644
index df215ec..0000000
--- a/tests/qdivr_u.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
-
- size_t align = jit_enter_jit_abi(j, 3, 0, 0);
-
- jit_operand_t args[] =
- { jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R1),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_V0) };
- jit_load_args(j, 4, args);
-
- jit_qdivr_u(j, JIT_V1, JIT_V2, JIT_R2, JIT_V0);
- jit_str(j, JIT_R0, JIT_V1);
- jit_str(j, JIT_R1, JIT_V2);
-
- jit_leave_jit_abi(j, 3, 0, align);
-
- jit_ret(j);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- void (*f)(jit_word_t*, jit_word_t*, jit_word_t, jit_word_t) = ret;
-#define QDIV(a, b, c, d) \
- do { \
- jit_word_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); \
- ASSERT(D == d); \
- } while (0)
-
- QDIV(-1, -2, 1, 1);
- QDIV(-2, -5, 1, 3);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/qmulr.c b/tests/qmulr.c
deleted file mode 100644
index b7aa5e8..0000000
--- a/tests/qmulr.c
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
-
- size_t align = jit_enter_jit_abi(j, 3, 0, 0);
-
- jit_operand_t args[] =
- { jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R1),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_V0) };
- jit_load_args(j, 4, args);
-
- jit_qmulr(j, JIT_V1, JIT_V2, JIT_R2, JIT_V0);
- jit_str(j, JIT_R0, JIT_V1);
- jit_str(j, JIT_R1, JIT_V2);
-
- jit_leave_jit_abi(j, 3, 0, align);
-
- jit_ret(j);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- void (*f)(jit_word_t*, jit_word_t*, jit_word_t, jit_word_t) = ret;
-
-#define QMUL(a, b, c, d) \
- do { \
- jit_word_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); \
- ASSERT(D == d); \
- } while (0)
-
- QMUL(-2, -1, 2, 0);
- QMUL(0, -1, 0, 0);
- QMUL(-1, 0, 0, 0);
- QMUL(1, -1, -1, -1);
-#if EJIT_WORDSIZE == 32
- QMUL(0x7ffff, 0x7ffff, 0xfff00001, 0x3f);
- QMUL(0x80000000, -2, 0, 1);
- QMUL(0x80000000, 2, 0, -1);
- QMUL(0x80000001, 3, 0x80000003, -2);
- QMUL(0x80000001, -3, 0x7ffffffd, 1);
-#else
- QMUL(0x7ffffffff, 0x7ffffffff, 0xfffffff000000001, 0x3f);
- QMUL(0x8000000000000000, -2, 0, 1);
- QMUL(0x8000000000000000, 2, 0, -1);
- QMUL(0x8000000000000001, 3, 0x8000000000000003, -2);
- QMUL(0x8000000000000001, -3, 0x7ffffffffffffffd, 1);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/qmulr_u.c b/tests/qmulr_u.c
deleted file mode 100644
index 3840c92..0000000
--- a/tests/qmulr_u.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
-
- size_t align = jit_enter_jit_abi(j, 3, 0, 0);
-
- jit_operand_t args[] =
- { jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_POINTER, JIT_R1),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R2),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_V0) };
- jit_load_args(j, 4, args);
-
- jit_qmulr_u(j, JIT_V1, JIT_V2, JIT_R2, JIT_V0);
- jit_str(j, JIT_R0, JIT_V1);
- jit_str(j, JIT_R1, JIT_V2);
-
- jit_leave_jit_abi(j, 3, 0, align);
-
- jit_ret(j);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- void (*f)(jit_word_t*, jit_word_t*, jit_word_t, jit_word_t) = ret;
-
-#define UQMUL(a, b, c, d) \
- do { \
- jit_word_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); \
- ASSERT(D == d); \
- } while (0)
-
-#if EJIT_WORDSIZE == 32
- UQMUL(0xffffff, 0xffffff, 0xfe000001, 0xffff);
-#else
- UQMUL(0xffffffffff, 0xffffffffff, 0xfffffe0000000001, 0xffff);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/sqrtr_f.c b/tests/sqrtr_f.c
deleted file mode 100644
index 7735f68..0000000
--- a/tests/sqrtr_f.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_1(j, jit_operand_fpr (JIT_OPERAND_ABI_FLOAT, JIT_F0));
-
- jit_sqrtr_f(j, JIT_F0, JIT_F0);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
-
- float (*f)(float) = jit_end(j, NULL);
-
- ASSERT(f(0.0) == 0.0);
- ASSERT(f(4.0) == 2.0);
- ASSERT(f(-4.0) != f(-4.0)); // nan
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/subx.c b/tests/subx.c
deleted file mode 100644
index b2bb3c2..0000000
--- a/tests/subx.c
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "test.h"
-
-static void
-run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
-{
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
- jit_load_args_2(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
-
- jit_movi(j, JIT_R2, 0);
- jit_subcr(j, JIT_R0, JIT_R0, JIT_R1);
- jit_subxi(j, JIT_R2, JIT_R2, 0);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R2);
-
- size_t size = 0;
- void* ret = jit_end(j, &size);
-
- jit_word_t (*f)(jit_word_t, jit_word_t) = ret;
-
- ASSERT(f(0, 0) == 0);
-
-#if EJIT_WORDSIZE == 32
- /* carry */
- ASSERT(f(0x7fffffff, 0xffffffff) == 0xffffffff);
- /* overflow */
- ASSERT(f(0x80000000, 1) == 0);
- /* carry */
- ASSERT(f(0x7fffffff, 0x80000000) == 0xffffffff);
- /* overflow */
- ASSERT(f(0x80000000, 0x7fffffff) == 0);
- /* carry+overflow */
- ASSERT(f(1, 0x80000000) == 0xffffffff);
-#else
- /* carry */
- ASSERT(f(0x7fffffff, 0xffffffff) == -1);
- /* nothing */
- ASSERT(f(0x80000000, 1) == 0);
- /* carry */
- ASSERT(f(0x7fffffff, 0x80000000) == -1);
- /* nothing */
- ASSERT(f(0x80000000, 0x7fffffff) == 0);
- /* carry */
- ASSERT(f(1, 0x80000000) == -1);
- /* carry */
- ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == -1);
- /* overflow */
- ASSERT(f(0x8000000000000000, 1) == 0);
- /* carry */
- ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == -1);
- /* overflow */
- ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0);
- /* carry+overflow */
- ASSERT(f(1, 0x8000000000000000) == -1);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}