aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-06-30 16:39:24 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-06-30 16:40:12 +0300
commite618924df98d4ee5037db86c768a8c8014e49c4c (patch)
treeabf7e2457f49c52d3ea6c6c5fb79577e5a4ad011
parent451797936119d8236843c4e9aee4a47dc5cddd56 (diff)
downloadejit-e618924df98d4ee5037db86c768a8c8014e49c4c.tar.gz
ejit-e618924df98d4ee5037db86c768a8c8014e49c4c.zip
work through loads and stores
-rw-r--r--include/ejit/ejit.h130
-rw-r--r--src/common.h24
-rw-r--r--src/ejit.c247
-rw-r--r--src/interp.c179
-rw-r--r--tests/extr_16.c24
-rw-r--r--tests/extr_32.c25
-rw-r--r--tests/extr_8.c24
-rw-r--r--tests/extr_c.c27
-rw-r--r--tests/extr_d_f.c26
-rw-r--r--tests/extr_f.c25
-rw-r--r--tests/extr_i.c30
-rw-r--r--tests/extr_s.c28
-rw-r--r--tests/extr_u16.c24
-rw-r--r--tests/extr_u32.c24
-rw-r--r--tests/extr_u8.c24
-rw-r--r--tests/extr_uc.c27
-rw-r--r--tests/extr_ui.c29
-rw-r--r--tests/extr_us.c27
-rw-r--r--tests/ger.c10
-rw-r--r--tests/ger_u.c33
-rw-r--r--tests/gtr.c8
-rw-r--r--tests/gtr_f.c10
-rw-r--r--tests/gtr_u.c32
-rw-r--r--tests/jmp0.c35
-rw-r--r--tests/jmp_table.c80
-rw-r--r--tests/jmpi_local.c36
-rw-r--r--tests/ldi_c.c24
-rw-r--r--tests/ldi_d.c26
-rw-r--r--tests/ldi_f.c28
-rw-r--r--tests/ldi_i.c24
-rw-r--r--tests/ldi_i16.c20
-rw-r--r--tests/ldi_i32.c19
-rw-r--r--tests/ldi_i64.c20
-rw-r--r--tests/ldi_i8.c19
-rw-r--r--tests/ldi_l.c26
-rw-r--r--tests/ldi_s.c24
-rw-r--r--tests/ldi_u16.c20
-rw-r--r--tests/ldi_u64.c19
-rw-r--r--tests/ldi_u8.c19
-rw-r--r--tests/ldi_uc.c24
-rw-r--r--tests/ldi_ui.c26
-rw-r--r--tests/ldi_us.c24
-rw-r--r--tests/ldr_atomic.c28
-rw-r--r--tests/ldr_c.c27
-rw-r--r--tests/ldr_d.c27
-rw-r--r--tests/ldr_f.c27
-rw-r--r--tests/ldr_i.c27
-rw-r--r--tests/ldr_l.c29
-rw-r--r--tests/ldr_s.c27
-rw-r--r--tests/ldr_uc.c27
-rw-r--r--tests/ldr_ui.c29
-rw-r--r--tests/ldr_us.c27
-rw-r--r--tests/ldxi_c.c27
-rw-r--r--tests/ldxi_d.c34
-rw-r--r--tests/ldxi_f.c34
-rw-r--r--tests/ldxi_i.c27
-rw-r--r--tests/ldxi_i16.c24
-rw-r--r--tests/ldxi_i32.c24
-rw-r--r--tests/ldxi_i64.c25
-rw-r--r--tests/ldxi_i8.c24
-rw-r--r--tests/ldxi_l.c29
-rw-r--r--tests/ldxi_s.c27
-rw-r--r--tests/ldxi_u16.c24
-rw-r--r--tests/ldxi_u32.c24
-rw-r--r--tests/ldxi_u64.c26
-rw-r--r--tests/ldxi_u8.c24
-rw-r--r--tests/ldxi_uc.c27
-rw-r--r--tests/ldxi_ui.c29
-rw-r--r--tests/ldxi_us.c27
-rw-r--r--tests/ldxr_c.c28
-rw-r--r--tests/ldxr_d.c41
-rw-r--r--tests/ldxr_f.c43
-rw-r--r--tests/ldxr_i.c28
-rw-r--r--tests/ldxr_i32.c26
-rw-r--r--tests/ldxr_i64.c26
-rw-r--r--tests/ldxr_i8.c25
-rw-r--r--tests/ldxr_l.c30
-rw-r--r--tests/ldxr_s.c28
-rw-r--r--tests/ldxr_u16.c27
-rw-r--r--tests/ldxr_u32.c27
-rw-r--r--tests/ldxr_u8.c25
-rw-r--r--tests/ldxr_uc.c28
-rw-r--r--tests/ldxr_ui.c30
-rw-r--r--tests/ldxr_us.c28
-rw-r--r--tests/ler.c2
-rw-r--r--tests/ler_f.c4
-rw-r--r--tests/lshi.c34
-rw-r--r--tests/lshr.c205
-rw-r--r--tests/ltr.c2
-rw-r--r--tests/ltr_f.c2
-rw-r--r--tests/mov_addr.c25
91 files changed, 1606 insertions, 1389 deletions
diff --git a/include/ejit/ejit.h b/include/ejit/ejit.h
index 03137ab..eeac089 100644
--- a/include/ejit/ejit.h
+++ b/include/ejit/ejit.h
@@ -322,10 +322,10 @@ void ejit_movi(struct ejit_func *s, struct ejit_gpr r0, int64_t i);
void ejit_movr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
void ejit_movr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1);
-void ejit_ldi_8(struct ejit_func *s, struct ejit_gpr r0, void *p);
-void ejit_ldi_16(struct ejit_func *s, struct ejit_gpr r0, void *p);
-void ejit_ldi_32(struct ejit_func *s, struct ejit_gpr r0, void *p);
-void ejit_ldi_64(struct ejit_func *s, struct ejit_gpr r0, void *p);
+void ejit_ldi_i8(struct ejit_func *s, struct ejit_gpr r0, void *p);
+void ejit_ldi_i16(struct ejit_func *s, struct ejit_gpr r0, void *p);
+void ejit_ldi_i32(struct ejit_func *s, struct ejit_gpr r0, void *p);
+void ejit_ldi_i64(struct ejit_func *s, struct ejit_gpr r0, void *p);
void ejit_ldi_u8(struct ejit_func *s, struct ejit_gpr r0, void *p);
void ejit_ldi_u16(struct ejit_func *s, struct ejit_gpr r0, void *p);
@@ -366,7 +366,8 @@ 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)
+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);
@@ -376,8 +377,15 @@ static inline void ejit_ldxi_ptr(struct ejit_func *s, struct ejit_gpr r0, struct
abort();
}
-#define EJIT_LDXI(f, t, r0, r1, o) \
- _Generic((t)(0), \
+static inline void ejit_ldxi_label(struct ejit_func *s, struct ejit_gpr r0,
+ struct ejit_gpr r1, int64_t o)
+{
+ /** @todo implement properly */
+ ejit_ldxi_ptr(s, r0, r1, o);
+}
+
+#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, \
@@ -386,10 +394,72 @@ static inline void ejit_ldxi_ptr(struct ejit_func *s, struct ejit_gpr r0, struct
uint32_t: ejit_ldxi_u32, \
int64_t: ejit_ldxi_i64, \
uint64_t: ejit_ldxi_u64, \
- float: ejit_ldxi_f, \
- double: ejit_ldxi_d, \
+ float: ejit_ldxi_f, \
+ double: ejit_ldxi_d, \
default: ejit_ldxi_ptr)((f), (r0), (r1), (o))
+void ejit_ldxr_i8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_i16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_i32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_i64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+void ejit_ldxr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
+static inline void ejit_ldxr_ptr(struct ejit_func *s, struct ejit_gpr r0,
+ struct ejit_gpr r1, struct ejit_gpr r2)
+{
+ if (sizeof(void *) == sizeof(int64_t))
+ ejit_ldxr_u64(s, r0, r1, r2);
+ else if (sizeof(void *) == sizeof(int32_t))
+ ejit_ldxr_u32(s, r0, r1, r2);
+ else
+ abort();
+}
+
+static inline void ejit_ldxr_label(struct ejit_func *s, struct ejit_gpr r0,
+ struct ejit_gpr r1, struct ejit_gpr r2)
+{
+ /** @todo implement properly */
+ ejit_ldxr_ptr(s, r0, r1, r2);
+}
+
+#define EJIT_LDXR(f, t, r0, r1, r2) \
+ _Generic((t)(0), \
+ int8_t: ejit_ldxr_i8, \
+ uint8_t: ejit_ldxr_u8, \
+ int16_t: ejit_ldxr_i16, \
+ uint16_t: ejit_ldxr_u16, \
+ int32_t: ejit_ldxr_i32, \
+ uint32_t: ejit_ldxr_u32, \
+ int64_t: ejit_ldxr_i64, \
+ uint64_t: ejit_ldxr_u64, \
+ float: ejit_ldxr_f, \
+ double: ejit_ldxr_d, \
+ default: ejit_ldxr_ptr)((f), (r0), (r1), (r2))
+
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);
@@ -447,6 +517,13 @@ static inline void ejit_stxi_ptr(struct ejit_func *s, struct ejit_gpr r0,
double: ejit_stxi_d, \
default: ejit_stxi_ptr)((f), (r0), (r1), (o))
+void ejit_extr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
+void ejit_extr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
+void ejit_extr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
+void ejit_extr_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
+void ejit_extr_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
+void ejit_extr_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1);
+
void ejit_addr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2);
@@ -479,6 +556,15 @@ void ejit_divr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
struct ejit_fpr r2);
+void ejit_lshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o);
+void ejit_lshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_rshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o);
+void ejit_rshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+
void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2);
void ejit_andi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
@@ -490,10 +576,33 @@ 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);
+ struct ejit_fpr r2);
+
+void ejit_gtr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_gtr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_gtr_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);
+void ejit_ltr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_ltr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
+
+void ejit_ger(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_ger_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_ger_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
+
+void ejit_ler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2);
+void ejit_ler_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2);
struct ejit_reloc ejit_bltr(struct ejit_func *s, struct ejit_gpr r0,
struct ejit_gpr r1);
@@ -557,6 +666,7 @@ struct ejit_reloc ejit_bltgtr_f(struct ejit_func *s, struct ejit_fpr r0,
struct ejit_fpr r1);
struct ejit_reloc ejit_jmp(struct ejit_func *s);
+struct ejit_reloc ejit_jmpr(struct ejit_func *s, struct ejit_gpr r0);
struct ejit_reloc ejit_bmci(struct ejit_func *s, struct ejit_gpr r0, int64_t o);
struct ejit_reloc ejit_bmcr(struct ejit_func *s, struct ejit_gpr r0,
diff --git a/src/common.h b/src/common.h
index 218b589..e9f0b69 100644
--- a/src/common.h
+++ b/src/common.h
@@ -31,6 +31,17 @@ enum ejit_opcode {
LDXIF,
LDXID,
+ LDXR8,
+ LDXR16,
+ LDXR32,
+ LDXR64,
+ LDXRU8,
+ LDXRU16,
+ LDXRU32,
+ LDXRU64,
+ LDXRF,
+ LDXRD,
+
STI8,
STI16,
STI32,
@@ -53,6 +64,13 @@ enum ejit_opcode {
STXIF,
STXID,
+ EXTR8,
+ EXTR16,
+ EXTR32,
+ EXTRU8,
+ EXTRU16,
+ EXTRU32,
+
ADDR,
ADDR_F,
ADDI,
@@ -73,6 +91,11 @@ enum ejit_opcode {
NEGR,
COMR,
+ LSHI,
+ LSHR,
+ RSHI,
+ RSHR,
+
ANDR,
ANDI,
@@ -117,6 +140,7 @@ enum ejit_opcode {
BLTGTR_F,
JMP,
+ JMPR,
BMCI,
BMCR,
diff --git a/src/ejit.c b/src/ejit.c
index c4e82b1..4f407aa 100644
--- a/src/ejit.c
+++ b/src/ejit.c
@@ -233,8 +233,58 @@ void ejit_stxi_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
emit_insn_i(s, STXID, r0.f, r1.r, o);
}
+void ejit_ldi_i8(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDI8, r0.r, 0, p);
+}
+
+void ejit_ldi_i16(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDI16, r0.r, 0, p);
+}
+
+void ejit_ldi_i32(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDI32, r0.r, 0, p);
+}
+
+void ejit_ldi_i64(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDI64, r0.r, 0, p);
+}
+
+void ejit_ldi_u8(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDIU8, r0.r, 0, p);
+}
+
+void ejit_ldi_u16(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDIU16, r0.r, 0, p);
+}
+
+void ejit_ldi_u32(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDIU32, r0.r, 0, p);
+}
+
+void ejit_ldi_u64(struct ejit_func *s, struct ejit_gpr r0, void *p)
+{
+ emit_insn_p(s, LDIU64, r0.r, 0, p);
+}
+
+void ejit_ldi_f(struct ejit_func *s, struct ejit_fpr r0, void *p)
+{
+ emit_insn_p(s, LDIF, r0.f, 0, p);
+}
+
+void ejit_ldi_d(struct ejit_func *s, struct ejit_fpr r0, void *p)
+{
+ emit_insn_p(s, LDID, r0.f, 0, p);
+}
+
void ejit_ldxi_i8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
- int64_t o)
+ int64_t o)
{
emit_insn_i(s, LDXI8, r0.r, r1.r, o);
}
@@ -258,7 +308,7 @@ void ejit_ldxi_i64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
}
void ejit_ldxi_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
- int64_t o)
+ int64_t o)
{
emit_insn_i(s, LDXIU8, r0.r, r1.r, o);
}
@@ -282,17 +332,77 @@ void ejit_ldxi_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
}
void ejit_ldxi_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
- int64_t o)
+ 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)
+ int64_t o)
{
emit_insn_i(s, LDXID, r0.f, r1.r, o);
}
+void ejit_ldxr_i8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXR8, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_i16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXR16, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_i32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXR32, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_i64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXR64, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXRU8, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXRU16, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXRU32, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXIU64, r0.r, r1.r, r2.r);
+}
+
+void ejit_ldxr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXRF, r0.f, r1.r, r2.r);
+}
+
+void ejit_ldxr_d(struct ejit_func *s, struct ejit_fpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LDXRD, r0.f, r1.r, r2.r);
+}
+
void ejit_retr(struct ejit_func *s, struct ejit_gpr r0)
{
emit_insn_r(s, RETR, r0.r, 0, 0);
@@ -313,6 +423,36 @@ void ejit_reti_f(struct ejit_func *s, double f)
emit_insn_f(s, RETI_F, 0, 0, f);
}
+void ejit_extr_8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1)
+{
+ emit_insn_i(s, EXTR8, r0.r, r1.r, 0);
+}
+
+void ejit_extr_16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1)
+{
+ emit_insn_i(s, EXTR16, r0.r, r1.r, 0);
+}
+
+void ejit_extr_32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1)
+{
+ emit_insn_i(s, EXTR32, r0.r, r1.r, 0);
+}
+
+void ejit_extr_u8(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1)
+{
+ emit_insn_i(s, EXTRU8, r0.r, r1.r, 0);
+}
+
+void ejit_extr_u16(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1)
+{
+ emit_insn_i(s, EXTRU16, r0.r, r1.r, 0);
+}
+
+void ejit_extr_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1)
+{
+ emit_insn_i(s, EXTRU32, r0.r, r1.r, 0);
+}
+
void ejit_addr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2)
{
@@ -378,6 +518,30 @@ void ejit_divr_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1,
emit_insn_r(s, DIVR_F, r0.f, r1.f, r2.f);
}
+void ejit_lshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, LSHI, r0.r, r1.r, o);
+}
+
+void ejit_lshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, LSHR, r0.r, r1.r, r2.r);
+}
+
+void ejit_rshi(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ int64_t o)
+{
+ emit_insn_i(s, RSHI, r0.r, r1.r, o);
+}
+
+void ejit_rshr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, RSHR, r0.r, r1.r, r2.r);
+}
+
void ejit_andr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
struct ejit_gpr r2)
{
@@ -420,17 +584,83 @@ void ejit_eqr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
}
void ejit_eqr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
- struct ejit_fpr r2)
+ struct ejit_fpr r2)
{
emit_insn_r(s, EQR_F, r0.r, r1.f, r2.f);
}
+void ejit_gtr(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, GTR, r0.r, r1.r, r2.r);
+}
+
+void ejit_gtr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, GTR_U, r0.r, r1.r, r2.r);
+}
+
+void ejit_gtr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2)
+{
+ emit_insn_r(s, GTR_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)
{
emit_insn_r(s, GER, r0.r, r2.r, r1.r);
}
+void ejit_ltr_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, GER_U, r0.r, r2.r, r1.r);
+}
+
+void ejit_ltr_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2)
+{
+ emit_insn_r(s, GER_F, r0.r, r2.f, r1.f);
+}
+
+void ejit_ger(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, GER, r0.r, r1.r, r2.r);
+}
+
+void ejit_ger_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, GER_U, r0.r, r1.r, r2.r);
+}
+
+void ejit_ger_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2)
+{
+ emit_insn_r(s, GER_F, r0.r, r1.f, r2.f);
+}
+
+void ejit_ler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, GTR, r0.r, r2.r, r1.r);
+}
+
+void ejit_ler_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1,
+ struct ejit_gpr r2)
+{
+ emit_insn_r(s, GTR_U, r0.r, r2.r, r1.r);
+}
+
+void ejit_ler_f(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1,
+ struct ejit_fpr r2)
+{
+ emit_insn_r(s, GTR_F, r0.r, r2.f, r1.f);
+}
+
struct ejit_reloc ejit_bner(struct ejit_func *s, struct ejit_gpr r0,
struct ejit_gpr r1)
{
@@ -648,6 +878,13 @@ struct ejit_reloc ejit_jmp(struct ejit_func *s)
return (struct ejit_reloc){.insn = addr};
}
+struct ejit_reloc ejit_jmpr(struct ejit_func *s, struct ejit_gpr r0)
+{
+ size_t addr = vec_len(&s->insns);
+ emit_insn_i(s, JMPR, 0, r0.r, 0);
+ return (struct ejit_reloc){.insn = addr};
+}
+
struct ejit_reloc ejit_bmci(struct ejit_func *s, struct ejit_gpr r0, int64_t o)
{
size_t addr = vec_len(&s->insns);
diff --git a/src/interp.c b/src/interp.c
index 383599e..30a7672 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -13,6 +13,13 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[MOVR] = &&MOVR,
[MOVR_F] = &&MOVR_F,
+ [EXTR8] = &&EXTR8,
+ [EXTR16] = &&EXTR16,
+ [EXTR32] = &&EXTR32,
+ [EXTRU8] = &&EXTRU8,
+ [EXTRU16] = &&EXTRU16,
+ [EXTRU32] = &&EXTRU32,
+
[ADDR] = &&ADDR,
[ADDR_F] = &&ADDR_F,
[ADDI] = &&ADDI,
@@ -29,6 +36,11 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[DIVR_U] = &&DIVR_U,
[DIVR_F] = &&DIVR_F,
+ [LSHI] = &&LSHI,
+ [LSHR] = &&LSHR,
+ [RSHI] = &&RSHI,
+ [RSHR] = &&RSHR,
+
[ANDR] = &&ANDR,
[ANDI] = &&ANDI,
@@ -56,6 +68,17 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[STXIF] = &&STXIF,
[STXID] = &&STXID,
+ [LDI8] = &&LDI8,
+ [LDI16] = &&LDI16,
+ [LDI32] = &&LDI32,
+ [LDI64] = &&LDI64,
+ [LDIU8] = &&LDIU8,
+ [LDIU16] = &&LDIU16,
+ [LDIU32] = &&LDIU32,
+ [LDIU64] = &&LDIU64,
+ [LDIF] = &&LDIF,
+ [LDID] = &&LDID,
+
[LDXI8] = &&LDXI8,
[LDXI16] = &&LDXI16,
[LDXI32] = &&LDXI32,
@@ -67,6 +90,17 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[LDXIF] = &&LDXIF,
[LDXID] = &&LDXID,
+ [LDXR8] = &&LDXR8,
+ [LDXR16] = &&LDXR16,
+ [LDXR32] = &&LDXR32,
+ [LDXR64] = &&LDXR64,
+ [LDXRU8] = &&LDXRU8,
+ [LDXRU16] = &&LDXRU16,
+ [LDXRU32] = &&LDXRU32,
+ [LDXRU64] = &&LDXRU64,
+ [LDXRF] = &&LDXRF,
+ [LDXRD] = &&LDXRD,
+
[BNER] = &&BNER,
[BNEI] = &&BNEI,
[BNER_F] = &&BNER_F,
@@ -96,6 +130,7 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
[BLTGTR_F] = &&BLTGTR_F,
[JMP] = &&JMP,
+ [JMPR] = &&JMPR,
[BMCI] = &&BMCI,
[BMCR] = &&BMCR,
@@ -175,6 +210,30 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
fpr[i.r0] = fpr[i.r1];
DISPATCH();
+ DO(EXTR8);
+ gpr[i.r0] = (int8_t)gpr[i.r1];
+ DISPATCH();
+
+ DO(EXTR16);
+ gpr[i.r0] = (int16_t)gpr[i.r1];
+ DISPATCH();
+
+ DO(EXTR32);
+ gpr[i.r0] = (int32_t)gpr[i.r1];
+ DISPATCH();
+
+ DO(EXTRU8);
+ gpr[i.r0] = (uint8_t)gpr[i.r1];
+ DISPATCH();
+
+ DO(EXTRU16);
+ gpr[i.r0] = (uint16_t)gpr[i.r1];
+ DISPATCH();
+
+ DO(EXTRU32);
+ gpr[i.r0] = (uint32_t)gpr[i.r1];
+ DISPATCH();
+
DO(ADDR);
gpr[i.r0] = gpr[i.r1] + gpr[i.r2];
DISPATCH();
@@ -219,6 +278,22 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
fpr[i.r0] = fpr[i.r1] / fpr[i.r2];
DISPATCH();
+ DO(LSHI);
+ gpr[i.r0] = gpr[i.r1] << i.o;
+ DISPATCH();
+
+ DO(LSHR);
+ gpr[i.r0] = gpr[i.r1] << gpr[i.r2];
+ DISPATCH();
+
+ DO(RSHI);
+ gpr[i.r0] = gpr[i.r1] >> i.o;
+ DISPATCH();
+
+ DO(RSHR);
+ gpr[i.r0] = gpr[i.r1] >> gpr[i.r2];
+ DISPATCH();
+
DO(ANDR);
gpr[i.r0] = gpr[i.r1] & gpr[i.r2];
DISPATCH();
@@ -305,6 +380,56 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
*addr = fpr[i.r0];
DISPATCH();
+ DO(LDI8);
+ int8_t *addr = (int8_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDI16);
+ int16_t *addr = (int16_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDI32);
+ int32_t *addr = (int32_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDI64);
+ int64_t *addr = (int64_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDIU8);
+ uint8_t *addr = (uint8_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDIU16);
+ uint16_t *addr = (uint16_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDIU32);
+ uint32_t *addr = (uint32_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDIU64);
+ uint64_t *addr = (uint64_t *)i.p;
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDIF);
+ float *addr = (float *)i.p;
+ fpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDID);
+ double *addr = (double *)i.p;
+ fpr[i.r0] = *addr;
+ DISPATCH();
+
DO(LDXI8);
int8_t *addr = (int8_t *)(gpr[i.r1] + i.o);
gpr[i.r0] = *addr;
@@ -355,6 +480,56 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
fpr[i.r0] = *addr;
DISPATCH();
+ DO(LDXR8);
+ int8_t *addr = (int8_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXR16);
+ int16_t *addr = (int16_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXR32);
+ int32_t *addr = (int32_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXR64);
+ int64_t *addr = (int64_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXRU8);
+ uint8_t *addr = (uint8_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXRU16);
+ uint16_t *addr = (uint16_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXRU32);
+ uint32_t *addr = (uint32_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXRU64);
+ uint64_t *addr = (uint64_t *)(gpr[i.r1] + gpr[i.r2]);
+ gpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXRF);
+ float *addr = (float *)(gpr[i.r1] + gpr[i.r2]);
+ fpr[i.r0] = *addr;
+ DISPATCH();
+
+ DO(LDXRD);
+ double *addr = (double *)(gpr[i.r1] + gpr[i.r2]);
+ fpr[i.r0] = *addr;
+ DISPATCH();
+
DO(BNER);
if (gpr[i.r1] != gpr[i.r2])
JUMP(i.r0);
@@ -491,6 +666,10 @@ union interp_ret ejit_interp(struct ejit_func *f, size_t argc,
JUMP(i.r0);
DISPATCH();
+ DO(JMPR);
+ JUMP(gpr[i.r1]);
+ DISPATCH();
+
DO(BMSR);
if (gpr[i.r1] & gpr[i.r2])
JUMP(i.r0);
diff --git a/tests/extr_16.c b/tests/extr_16.c
new file mode 100644
index 0000000..5c825a3
--- /dev/null
+++ b/tests/extr_16.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_extr_16(f, 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(erf1(f, EJIT_ARG(0, long)) == 0);
+ assert(erf1(f, EJIT_ARG(1, long)) == 1);
+ assert(erf1(f, EJIT_ARG(0xfff, long)) == 0xfff);
+ assert(erf1(f, EJIT_ARG(0xffff, long)) == -1);
+ assert(erf1(f, EJIT_ARG(0xfffff, long)) == -1);
+ assert(erf1(f, EJIT_ARG(0xf0000, long)) == 0);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/extr_32.c b/tests/extr_32.c
new file mode 100644
index 0000000..8b65f53
--- /dev/null
+++ b/tests/extr_32.c
@@ -0,0 +1,25 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_extr_32(f, 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(erf1(f, EJIT_ARG(0, long)) == 0);
+ assert(erf1(f, EJIT_ARG(1, long)) == 1);
+ assert(erf1(f, EJIT_ARG(0xfffffff, long)) == 0xfffffff);
+ assert(erf1(f, EJIT_ARG(0xffffffff, long)) == -1);
+ assert(erf1(f, EJIT_ARG(0xfffffffff, long)) == -1);
+ assert(erf1(f, EJIT_ARG(0xf00000000, long)) == 0);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/extr_8.c b/tests/extr_8.c
new file mode 100644
index 0000000..12fe287
--- /dev/null
+++ b/tests/extr_8.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 1,
+ operands);
+ ejit_extr_8(f, EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, EJIT_USE64(unsigned long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(0, unsigned long)) == 0);
+ assert(erf1(f, EJIT_ARG(1, unsigned long)) == 1);
+ assert(erf1(f, EJIT_ARG(0xf, unsigned long)) == 0xf);
+ assert(erf1(f, EJIT_ARG(0xff, unsigned long)) == -1);
+ assert(erf1(f, EJIT_ARG(0xfff, unsigned long)) == -1);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/extr_c.c b/tests/extr_c.c
deleted file mode 100644
index ff652a7..0000000
--- a/tests/extr_c.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)
-{
- 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_extr_c(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(1) == 1);
- ASSERT(f(0xf) == 0xf);
- ASSERT(f(0xff) == -1);
- ASSERT(f(0xfff) == -1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/extr_d_f.c b/tests/extr_d_f.c
deleted file mode 100644
index 87ad4a8..0000000
--- a/tests/extr_d_f.c
+++ /dev/null
@@ -1,26 +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_DOUBLE, JIT_F0));
-
- jit_extr_d_f(j, JIT_F0, JIT_F0);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
-
- float (*f)(double) = jit_end(j, NULL);
-
- ASSERT(f(0.0) == 0.0f);
- ASSERT(f(0.5) == 0.5f);
- ASSERT(f(1.0 / 0.0) == 1.0f / 0.0f);
- ASSERT(f(1.25) == 1.25f);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/extr_f.c b/tests/extr_f.c
deleted file mode 100644
index 7721127..0000000
--- a/tests/extr_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_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
-
- jit_extr_f(j, JIT_F0, JIT_R0);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
-
- float (*f)(jit_word_t) = jit_end(j, NULL);
-
- ASSERT(f(0) == 0.0f);
- ASSERT(f(1) == 1.0f);
- ASSERT(f(-100) == -100.0f);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/extr_i.c b/tests/extr_i.c
deleted file mode 100644
index cf3a2e1..0000000
--- a/tests/extr_i.c
+++ /dev/null
@@ -1,30 +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_extr_i(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(1) == 1);
- ASSERT(f(0xfffffff) == 0xfffffff);
- ASSERT(f(0xffffffff) == -1);
- ASSERT(f(0xfffffffff) == -1);
- ASSERT(f(0xf00000000) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/extr_s.c b/tests/extr_s.c
deleted file mode 100644
index 08ea42e..0000000
--- a/tests/extr_s.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_extr_s(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(1) == 1);
- ASSERT(f(0xfff) == 0xfff);
- ASSERT(f(0xffff) == -1);
- ASSERT(f(0xfffff) == -1);
- ASSERT(f(0xf0000) == 0);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/extr_u16.c b/tests/extr_u16.c
new file mode 100644
index 0000000..3063e33
--- /dev/null
+++ b/tests/extr_u16.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_extr_u16(f, 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(erf1(f, EJIT_ARG(0, long)) == 0);
+ assert(erf1(f, EJIT_ARG(1, long)) == 1);
+ assert(erf1(f, EJIT_ARG(0xffff, long)) == 0xffff);
+ assert(erf1(f, EJIT_ARG(0xfffff, long)) == 0xffff);
+ assert(erf1(f, EJIT_ARG(0xf0000, long)) == 0);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/extr_u32.c b/tests/extr_u32.c
new file mode 100644
index 0000000..5897d2f
--- /dev/null
+++ b/tests/extr_u32.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(long))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_extr_u32(f, 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(erf1(f, EJIT_ARG(0, long)) == 0);
+ assert(erf1(f, EJIT_ARG(1, long)) == 1);
+ assert(erf1(f, EJIT_ARG(0xffffffff, long)) == 0xffffffff);
+ assert(erf1(f, EJIT_ARG(0xfffffffff, long)) == 0xffffffff);
+ assert(erf1(f, EJIT_ARG(0xf00000000, long)) == 0);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/extr_u8.c b/tests/extr_u8.c
new file mode 100644
index 0000000..ee677a9
--- /dev/null
+++ b/tests/extr_u8.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 1,
+ operands);
+ ejit_extr_u8(f, EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, EJIT_USE64(unsigned long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(0, unsigned long)) == 0);
+ assert(erf1(f, EJIT_ARG(1, unsigned long)) == 1);
+ assert(erf1(f, EJIT_ARG(0xff, unsigned long)) == 0xff);
+ assert(erf1(f, EJIT_ARG(0xfff, unsigned long)) == 0xff);
+ assert(erf1(f, EJIT_ARG(0xf00, unsigned long)) == 0);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/extr_uc.c b/tests/extr_uc.c
deleted file mode 100644
index 063962b..0000000
--- a/tests/extr_uc.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)
-{
- 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_extr_uc(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(1) == 1);
- ASSERT(f(0xff) == 0xff);
- ASSERT(f(0xfff) == 0xff);
- ASSERT(f(0xf00) == 0);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/extr_ui.c b/tests/extr_ui.c
deleted file mode 100644
index 457e8f8..0000000
--- a/tests/extr_ui.c
+++ /dev/null
@@ -1,29 +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_extr_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(1) == 1);
- ASSERT(f(0xffffffff) == 0xffffffff);
- ASSERT(f(0xfffffffff) == 0xffffffff);
- ASSERT(f(0xf00000000) == 0);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/extr_us.c b/tests/extr_us.c
deleted file mode 100644
index 61374cc..0000000
--- a/tests/extr_us.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)
-{
- 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_extr_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(1) == 1);
- ASSERT(f(0xffff) == 0xffff);
- ASSERT(f(0xfffff) == 0xffff);
- ASSERT(f(0xf0000) == 0);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ger.c b/tests/ger.c
index 195d4c1..5192aac 100644
--- a/tests/ger.c
+++ b/tests/ger.c
@@ -5,26 +5,26 @@
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))
};
struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
- ejit_gtr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_ger(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(1, long), EJIT_ARG(1, long)) == 1);
- assert(ejit_run_func_2(f, EJIT_ARG(0, long), EJIT_ARG(1, long)) == 1);
+ assert(ejit_run_func_2(f, EJIT_ARG(0, long), EJIT_ARG(1, long)) == 0);
assert(ejit_run_func_2(f,
EJIT_ARG(0x0fffffffffffffff, long),
- EJIT_ARG(0x0ffffffffffffff0, long)) == 0);
+ EJIT_ARG(0x0ffffffffffffff0, long)) == 1);
assert(ejit_run_func_2(f,
EJIT_ARG(0x7fffffffffffffff, long),
- EJIT_ARG(0x6fffffffffffffff, long)) == 1);
+ EJIT_ARG(0x6ffffffffffffff0, long)) == 1);
ejit_destroy_func(f);
}
diff --git a/tests/ger_u.c b/tests/ger_u.c
new file mode 100644
index 0000000..96d2ddd
--- /dev/null
+++ b/tests/ger_u.c
@@ -0,0 +1,33 @@
+#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_ger_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(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 1);
+ assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 1);
+
+ assert(ejit_run_func_2(f, EJIT_ARG(-1, long), EJIT_ARG(1, long)) == 1);
+ assert(ejit_run_func_2(f, EJIT_ARG(-1, long), EJIT_ARG(0, long)) == 1);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x0fffffffffffffff, long),
+ EJIT_ARG(0x0ffffffffffffff0, long)) == 1);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(0x6fffffffffffffff, long)) == 1);
+ ejit_destroy_func(f);
+}
diff --git a/tests/gtr.c b/tests/gtr.c
index 34dfd39..967d944 100644
--- a/tests/gtr.c
+++ b/tests/gtr.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))
};
@@ -17,14 +17,14 @@ int main()
ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit);
assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 0);
- assert(ejit_run_func_2(f, EJIT_ARG(0, long), EJIT_ARG(1, long)) == 1);
+ assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 1);
assert(ejit_run_func_2(f,
EJIT_ARG(0x0fffffffffffffff, long),
- EJIT_ARG(0x0ffffffffffffff0, long)) == 0);
+ EJIT_ARG(0x0ffffffffffffff0, long)) == 1);
assert(ejit_run_func_2(f,
EJIT_ARG(0x7fffffffffffffff, long),
- EJIT_ARG(0x6fffffffffffffff, long)) == 1);
+ EJIT_ARG(0x6ffffffffffffff0, long)) == 1);
ejit_destroy_func(f);
}
diff --git a/tests/gtr_f.c b/tests/gtr_f.c
index 4c07bfe..2fb2834 100644
--- a/tests/gtr_f.c
+++ b/tests/gtr_f.c
@@ -5,21 +5,19 @@
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))
};
struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
- ejit_gtr(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1));
+ ejit_gtr_f(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1));
ejit_retr(f, EJIT_GPR(0));
ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit);
- 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(1, double)) == 1);
+ assert(erf2(f, EJIT_ARG(1, double), EJIT_ARG(1, double)) == 0);
+ assert(erf2(f, EJIT_ARG(1, double), EJIT_ARG(0, double)) == 1);
ejit_destroy_func(f);
}
diff --git a/tests/gtr_u.c b/tests/gtr_u.c
new file mode 100644
index 0000000..6c4f5b3
--- /dev/null
+++ b/tests/gtr_u.c
@@ -0,0 +1,32 @@
+#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_gtr_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(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 0);
+ assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 1);
+ assert(ejit_run_func_2(f, EJIT_ARG(-1, long), EJIT_ARG(1, long)) == 1);
+ assert(ejit_run_func_2(f, EJIT_ARG(-1, long), EJIT_ARG(0, long)) == 1);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x0fffffffffffffff, long),
+ EJIT_ARG(0x0ffffffffffffff0, long)) == 1);
+
+ assert(ejit_run_func_2(f,
+ EJIT_ARG(0x7fffffffffffffff, long),
+ EJIT_ARG(0x6ffffffffffffff0, long)) == 1);
+ ejit_destroy_func(f);
+}
diff --git a/tests/jmp0.c b/tests/jmp0.c
index 0f86fe6..c5fda98 100644
--- a/tests/jmp0.c
+++ b/tests/jmp0.c
@@ -1,24 +1,23 @@
-#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));
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
- jit_reloc_t r = jit_jmp(j);
- jit_patch_here(j, r);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ struct ejit_reloc r = ejit_jmp(f);
+ struct ejit_label l = ejit_label(f);
+ ejit_patch(f, r, l);
+ ejit_retr(f, EJIT_GPR(0));
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
- ASSERT(f(42) == 42);
- ASSERT(f(-1) == -1);
-}
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ assert(erf1(f, EJIT_ARG(42, long)) == 42);
+ assert(erf1(f, EJIT_ARG(-1, long)) == -1);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/jmp_table.c b/tests/jmp_table.c
index 2ea14cd..10f9226 100644
--- a/tests/jmp_table.c
+++ b/tests/jmp_table.c
@@ -1,61 +1,57 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
-#define NTARGETS ((size_t) 4)
+#define NTARGETS 4
+struct ejit_label targets[NTARGETS];
-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_POINTER, JIT_R0));
-
- jit_reloc_t default_target = jit_bgei_u(j, JIT_R0, NTARGETS);
-
- // FIXME: need ldxr with word stride, then can eliminate lshi.
- jit_lshi(j, JIT_R0, JIT_R0, sizeof(intptr_t) == 4 ? 2 : 3);
- jit_reloc_t table = jit_mov_addr(j, JIT_R1);
- jit_ldxr(j, JIT_R1, JIT_R1, JIT_R0);
- jit_jmpr(j, JIT_R1);
-
- jit_begin_data (j, (NTARGETS + 1) * sizeof(intptr_t));
- jit_align(j, sizeof(intptr_t));
- jit_patch_here(j, table);
- jit_reloc_t targets[NTARGETS];
- jit_reloc_t tails[NTARGETS];
- for (size_t i = 0; i < NTARGETS; i++) {
- targets[i] = jit_emit_addr(j);
- }
- jit_end_data (j);
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER)
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ struct ejit_reloc default_target = ejit_bgei_u(f, EJIT_GPR(0),
+ NTARGETS);
+
+ ejit_lshi(f, EJIT_GPR(0), EJIT_GPR(0),
+ sizeof(struct ejit_label) == 4 ? 2 : 3);
+
+#warning \
+ "Label rewriting is not currently working so this will fail the jit test"
+ ejit_ldxi_label(f, EJIT_GPR(1), EJIT_GPR(0), (int64_t)targets);
+ ejit_jmpr(f, EJIT_GPR(1));
+ struct ejit_reloc tails[NTARGETS];
for (size_t i = 0; i < NTARGETS; i++) {
- jit_patch_here(j, targets[i]);
- jit_movi(j, JIT_R0, i * i);
- tails[i] = jit_jmp(j);
+ targets[i] = ejit_label(f);
+ ejit_movi(f, EJIT_GPR(0), i * i);
+ tails[i] = ejit_jmp(f);
}
- jit_patch_here(j, default_target);
- jit_movi(j, JIT_R0, 42);
+ struct ejit_label default_label = ejit_label(f);
+ ejit_patch(f, default_target, default_label);
+ ejit_movi(f, EJIT_GPR(0), 42);
+
+ struct ejit_label dst = ejit_label(f);
for (int i = 0; i < NTARGETS; i++) {
- jit_patch_here(j, tails[i]);
+ ejit_patch(f, tails[i], dst);
}
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit);
for (int i = -2; i < ((int) NTARGETS) + 2; i++) {
if (i < 0) {
- ASSERT(f(i) == 42);
+ assert(erf1(f, EJIT_ARG(i, long)) == 42);
} else if (i < NTARGETS) {
- ASSERT(f(i) == i * i);
+ assert(erf1(f, EJIT_ARG(i, long)) == i * i);
} else {
- ASSERT(f(i) == 42);
+ assert(erf1(f, EJIT_ARG(i, long)) == 42);
}
}
-}
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ ejit_destroy_func(f);
}
diff --git a/tests/jmpi_local.c b/tests/jmpi_local.c
index 1131997..76cba7c 100644
--- a/tests/jmpi_local.c
+++ b/tests/jmpi_local.c
@@ -1,25 +1,25 @@
-#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);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(int), 0, NULL);
+ struct ejit_reloc r = ejit_jmp(f);
+ ejit_reti(f, 0);
- jit_reloc_t r = jit_jmp (j);
- jit_reti (j, 0);
- jit_pointer_t addr = jit_address (j);
- jit_reti (j, 1);
- jit_patch_here (j, r);
- jit_jmpi (j, addr);
- jit_reti (j, 2);
+ struct ejit_label l = ejit_label(f);
+ ejit_reti(f, 1);
- int (*f)(void) = jit_end(j, NULL);
+ ejit_patch(f, r, l);
- ASSERT(f() == 1);
-}
+ struct ejit_reloc j = ejit_jmp(f);
+ ejit_patch(f, j, l);
+ ejit_reti(f, 2);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ ejit_select_compile_func(f, 0, 0, EJIT_USE64(long), do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == 1);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/ldi_c.c b/tests/ldi_c.c
deleted file mode 100644
index c6539c0..0000000
--- a/tests/ldi_c.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_ldi_c(j, JIT_R0, &data[0]);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == -1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldi_d.c b/tests/ldi_d.c
index c7574dc..7c9b36c 100644
--- a/tests/ldi_d.c
+++ b/tests/ldi_d.c
@@ -1,24 +1,18 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
static double data = -1.5;
-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);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 0, NULL);
+ ejit_ldi_d(f, EJIT_FPR(0), &data);
+ ejit_retr_f(f, EJIT_FPR(0));
- jit_ldi_d(j, JIT_F0, &data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_d(j, JIT_F0);
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(double), do_jit);
- double (*f)(void) = jit_end(j, NULL);
+ assert(ejit_run_func_f(f, 0, NULL) == data);
- ASSERT(f() == data);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ ejit_destroy_func(f);
}
diff --git a/tests/ldi_f.c b/tests/ldi_f.c
index d5cd095..48974d2 100644
--- a/tests/ldi_f.c
+++ b/tests/ldi_f.c
@@ -1,24 +1,18 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
-static float data = -1.5f;
+static float data = -1.5;
-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);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(float), 0, NULL);
+ ejit_ldi_f(f, EJIT_FPR(0), &data);
+ ejit_retr_f(f, EJIT_FPR(0));
- jit_ldi_f(j, JIT_F0, &data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(float), do_jit);
- float (*f)(void) = jit_end(j, NULL);
+ assert(ejit_run_func_f(f, 0, NULL) == data);
- ASSERT(f() == data);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ ejit_destroy_func(f);
}
diff --git a/tests/ldi_i.c b/tests/ldi_i.c
deleted file mode 100644
index 72035d4..0000000
--- a/tests/ldi_i.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "test.h"
-
-static uint32_t data = 0xffffffff;
-
-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_ldi_i(j, JIT_R0, &data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == -1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldi_i16.c b/tests/ldi_i16.c
new file mode 100644
index 0000000..32c8b33
--- /dev/null
+++ b/tests/ldi_i16.c
@@ -0,0 +1,20 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint16_t data = 0xffff;
+
+int main()
+{
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 0,
+ NULL);
+
+ ejit_ldi_i16(f, EJIT_GPR(0), &data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, false, do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == -1);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldi_i32.c b/tests/ldi_i32.c
new file mode 100644
index 0000000..60eee1a
--- /dev/null
+++ b/tests/ldi_i32.c
@@ -0,0 +1,19 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 0,
+ NULL);
+ ejit_ldi_u32(f, EJIT_GPR(0), data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, false, do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == data[0]);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldi_i64.c b/tests/ldi_i64.c
new file mode 100644
index 0000000..a7a8c98
--- /dev/null
+++ b/tests/ldi_i64.c
@@ -0,0 +1,20 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ static uint64_t data[] = { 0xffffffffffffffff, 0x00000000,
+ 0x42424242 };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 0,
+ NULL);
+ ejit_ldi_i64(f, EJIT_GPR(0), data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, true, do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == -1);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldi_i8.c b/tests/ldi_i8.c
new file mode 100644
index 0000000..2d3c55a
--- /dev/null
+++ b/tests/ldi_i8.c
@@ -0,0 +1,19 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint8_t data[] = { 0xff, 0x00, 0x42 };
+
+int main()
+{
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 0,
+ NULL);
+ ejit_ldi_i8(f, EJIT_GPR(0), &data[0]);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(unsigned long), do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == -1);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldi_l.c b/tests/ldi_l.c
deleted file mode 100644
index 58a8099..0000000
--- a/tests/ldi_l.c
+++ /dev/null
@@ -1,26 +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
- static uint64_t data = 0xffffffffffffffff;
-
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
-
- jit_ldi_l(j, JIT_R0, &data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == -1);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldi_s.c b/tests/ldi_s.c
deleted file mode 100644
index 7d10106..0000000
--- a/tests/ldi_s.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "test.h"
-
-static uint16_t data = 0xffff;
-
-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_ldi_s(j, JIT_R0, &data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == -1);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldi_u16.c b/tests/ldi_u16.c
new file mode 100644
index 0000000..b73c1da
--- /dev/null
+++ b/tests/ldi_u16.c
@@ -0,0 +1,20 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
+
+int main()
+{
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 0,
+ NULL);
+
+ ejit_ldi_u16(f, EJIT_GPR(0), data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(unsigned long), do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == data[0]);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldi_u64.c b/tests/ldi_u64.c
new file mode 100644
index 0000000..633f5dc
--- /dev/null
+++ b/tests/ldi_u64.c
@@ -0,0 +1,19 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+int main()
+{
+ static uint64_t data[] = { 0x12345678ffffffff, 0x00000000, 0x42424242 };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 0,
+ NULL);
+ ejit_ldi_u64(f, EJIT_GPR(0), data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, true, do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == (int64_t)data[0]);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldi_u8.c b/tests/ldi_u8.c
new file mode 100644
index 0000000..19aa555
--- /dev/null
+++ b/tests/ldi_u8.c
@@ -0,0 +1,19 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint8_t data[] = { 0xff, 0x00, 0x42 };
+
+int main()
+{
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(unsigned long), 0,
+ NULL);
+ ejit_ldi_u8(f, EJIT_GPR(0), &data[0]);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(unsigned long), do_jit);
+
+ assert(ejit_run_func(f, 0, NULL) == 0xff);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldi_uc.c b/tests/ldi_uc.c
deleted file mode 100644
index d5c80ac..0000000
--- a/tests/ldi_uc.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_ldi_uc(j, JIT_R0, data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == 0xff);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldi_ui.c b/tests/ldi_ui.c
deleted file mode 100644
index bfccc30..0000000
--- a/tests/ldi_ui.c
+++ /dev/null
@@ -1,26 +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
- static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
-
- jit_begin(j, arena_base, arena_size);
- size_t align = jit_enter_jit_abi(j, 0, 0, 0);
-
- jit_ldi_ui(j, JIT_R0, data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == data[0]);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldi_us.c b/tests/ldi_us.c
deleted file mode 100644
index 970db9c..0000000
--- a/tests/ldi_us.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "test.h"
-
-static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
-
-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_ldi_us(j, JIT_R0, data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == data[0]);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_atomic.c b/tests/ldr_atomic.c
deleted file mode 100644
index 339ba56..0000000
--- a/tests/ldr_atomic.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "test.h"
-
-static long data[] = { 0x0f0f0f0f, 0x00000000, 0x42424242 };
-
-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_R1));
-
- /* atm does not test for actual atomicity, just that no segfaults etc happen */
- jit_ldr_atomic(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == 0x0f0f0f0f);
- ASSERT(f(&data[1]) == 0);
- ASSERT(f(&data[2]) == 0x42424242);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_c.c b/tests/ldr_c.c
deleted file mode 100644
index a630123..0000000
--- a/tests/ldr_c.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_R1));
-
- jit_ldr_c(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == -1);
- ASSERT(f(&data[1]) == 0);
- ASSERT(f(&data[2]) == 0x42);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_d.c b/tests/ldr_d.c
deleted file mode 100644
index 6a4c1bd..0000000
--- a/tests/ldr_d.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static double data[] = { -1.0, 0.0, 0.5 };
-
-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_R1));
-
- jit_ldr_d(j, JIT_F0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_d(j, JIT_F0);
-
- double (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == data[0]);
- ASSERT(f(&data[1]) == data[1]);
- ASSERT(f(&data[2]) == data[2]);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_f.c b/tests/ldr_f.c
deleted file mode 100644
index 4ea978d..0000000
--- a/tests/ldr_f.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static float data[] = { -1.0, 0.0, 0.5 };
-
-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_R1));
-
- jit_ldr_f(j, JIT_F0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
-
- float (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == data[0]);
- ASSERT(f(&data[1]) == data[1]);
- ASSERT(f(&data[2]) == data[2]);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_i.c b/tests/ldr_i.c
deleted file mode 100644
index a7a4cd0..0000000
--- a/tests/ldr_i.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
-
-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_R1));
-
- jit_ldr_i(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == -1);
- ASSERT(f(&data[1]) == 0);
- ASSERT(f(&data[2]) == 0x42424242);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_l.c b/tests/ldr_l.c
deleted file mode 100644
index d689d47..0000000
--- a/tests/ldr_l.c
+++ /dev/null
@@ -1,29 +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
- static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 };
-
- 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_R1));
-
- jit_ldr_l(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == -1);
- ASSERT(f(&data[1]) == 0);
- ASSERT(f(&data[2]) == data[2]);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_s.c b/tests/ldr_s.c
deleted file mode 100644
index cbb72ab..0000000
--- a/tests/ldr_s.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
-
-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_R1));
-
- jit_ldr_s(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == -1);
- ASSERT(f(&data[1]) == 0);
- ASSERT(f(&data[2]) == 0x4242);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_uc.c b/tests/ldr_uc.c
deleted file mode 100644
index 65d56cf..0000000
--- a/tests/ldr_uc.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_R1));
-
- jit_ldr_uc(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == 0xff);
- ASSERT(f(&data[1]) == 0);
- ASSERT(f(&data[2]) == 0x42);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_ui.c b/tests/ldr_ui.c
deleted file mode 100644
index 92ace34..0000000
--- a/tests/ldr_ui.c
+++ /dev/null
@@ -1,29 +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
- static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
-
- 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_R1));
-
- jit_ldr_ui(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == data[0]);
- ASSERT(f(&data[1]) == data[1]);
- ASSERT(f(&data[2]) == data[2]);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldr_us.c b/tests/ldr_us.c
deleted file mode 100644
index 5d1a67d..0000000
--- a/tests/ldr_us.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
-
-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_R1));
-
- jit_ldr_us(j, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*) = jit_end(j, NULL);
-
- ASSERT(f(&data[0]) == data[0]);
- ASSERT(f(&data[1]) == data[1]);
- ASSERT(f(&data[2]) == data[2]);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxi_c.c b/tests/ldxi_c.c
deleted file mode 100644
index cc40ddb..0000000
--- a/tests/ldxi_c.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_ldxi_c(j, JIT_R0, JIT_R0, (uintptr_t)&data);
- 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) == -1);
- ASSERT(f(1) == 0);
- ASSERT(f(2) == 0x42);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxi_d.c b/tests/ldxi_d.c
index a93e582..da3ed0a 100644
--- a/tests/ldxi_d.c
+++ b/tests/ldxi_d.c
@@ -1,27 +1,25 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
static double data[] = { -1.0, 0.0, 0.5 };
-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));
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
- jit_ldxi_d(j, JIT_F0, JIT_R0, (uintptr_t)data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_d(j, JIT_F0);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 1, operands);
- double (*f)(jit_uword_t) = jit_end(j, NULL);
+ ejit_ldxi_d(f, EJIT_FPR(0), EJIT_GPR(0), (uintptr_t)data);
+ ejit_retr_f(f, EJIT_FPR(0));
- ASSERT(f(0) == data[0]);
- ASSERT(f(8) == data[1]);
- ASSERT(f(16) == data[2]);
-}
+ ejit_select_compile_func(f, 1, 1, EJIT_USE64(long), do_jit);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ assert(erff1(f, EJIT_ARG(sizeof(double) * 0, long)) == data[0]);
+ assert(erff1(f, EJIT_ARG(sizeof(double) * 1, long)) == data[1]);
+ assert(erff1(f, EJIT_ARG(sizeof(double) * 2, long)) == data[2]);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/ldxi_f.c b/tests/ldxi_f.c
index 015d816..eb2ad58 100644
--- a/tests/ldxi_f.c
+++ b/tests/ldxi_f.c
@@ -1,27 +1,25 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
static float data[] = { -1.0, 0.0, 0.5 };
-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));
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
- jit_ldxi_f(j, JIT_F0, JIT_R0, (uintptr_t)data);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(float), 1, operands);
- float (*f)(jit_uword_t) = jit_end(j, NULL);
+ ejit_ldxi_d(f, EJIT_FPR(0), EJIT_GPR(0), (uintptr_t)data);
+ ejit_retr_f(f, EJIT_FPR(0));
- ASSERT(f(0) == data[0]);
- ASSERT(f(4) == data[1]);
- ASSERT(f(8) == data[2]);
-}
+ ejit_select_compile_func(f, 1, 1, EJIT_USE64(long), do_jit);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ assert(erff1(f, EJIT_ARG(sizeof(float) * 0, long)) == data[0]);
+ assert(erff1(f, EJIT_ARG(sizeof(float) * 1, long)) == data[1]);
+ assert(erff1(f, EJIT_ARG(sizeof(float) * 2, long)) == data[2]);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/ldxi_i.c b/tests/ldxi_i.c
deleted file mode 100644
index 7e53001..0000000
--- a/tests/ldxi_i.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
-
-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_ldxi_i(j, JIT_R0, JIT_R0, (uintptr_t)data);
- 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) == -1);
- ASSERT(f(4) == 0);
- ASSERT(f(8) == 0x42424242);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxi_i16.c b/tests/ldxi_i16.c
new file mode 100644
index 0000000..e2af936
--- /dev/null
+++ b/tests/ldxi_i16.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+
+ ejit_ldxi_i16(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)&data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(0, long)) == -1);
+ assert(erf1(f, EJIT_ARG(1, long)) == 0);
+ assert(erf1(f, EJIT_ARG(2, long)) == 0x4242);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_i32.c b/tests/ldxi_i32.c
new file mode 100644
index 0000000..dac93ae
--- /dev/null
+++ b/tests/ldxi_i32.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_ldxi_i32(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 0, long)) == -1);
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 1, long)) == 0);
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 2, long)) == 0x42424242);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_i64.c b/tests/ldxi_i64.c
new file mode 100644
index 0000000..72112dd
--- /dev/null
+++ b/tests/ldxi_i64.c
@@ -0,0 +1,25 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_ldxi_i64(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, true, do_jit);
+
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 0, long)) == -1);
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 1, long)) == 0);
+ assert((uint64_t)erf1(f,
+ EJIT_ARG(sizeof(int32_t) * 2, long)) == data[2]);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_i8.c b/tests/ldxi_i8.c
new file mode 100644
index 0000000..a7d0629
--- /dev/null
+++ b/tests/ldxi_i8.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint8_t data[] = { 0xff, 0x00, 0x42 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+
+ ejit_ldxi_i8(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)&data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(0, long)) == -1);
+ assert(erf1(f, EJIT_ARG(1, long)) == 0);
+ assert(erf1(f, EJIT_ARG(2, long)) == 0x42);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_l.c b/tests/ldxi_l.c
deleted file mode 100644
index 3a4454f..0000000
--- a/tests/ldxi_l.c
+++ /dev/null
@@ -1,29 +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
- static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 };
-
- 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_ldxi_l(j, JIT_R0, JIT_R0, (uintptr_t)data);
- 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) == -1);
- ASSERT(f(8) == 0);
- ASSERT(f(16) == data[2]);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxi_s.c b/tests/ldxi_s.c
deleted file mode 100644
index 05125da..0000000
--- a/tests/ldxi_s.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
-
-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_ldxi_s(j, JIT_R0, JIT_R0, (uintptr_t)data);
- 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) == -1);
- ASSERT(f(2) == 0);
- ASSERT(f(4) == 0x4242);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxi_u16.c b/tests/ldxi_u16.c
new file mode 100644
index 0000000..a5d8fca
--- /dev/null
+++ b/tests/ldxi_u16.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+
+ ejit_ldxi_i16(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)&data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(0, long)) == 0xffff);
+ assert(erf1(f, EJIT_ARG(1, long)) == 0);
+ assert(erf1(f, EJIT_ARG(2, long)) == 0x4242);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_u32.c b/tests/ldxi_u32.c
new file mode 100644
index 0000000..04b8df8
--- /dev/null
+++ b/tests/ldxi_u32.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_ldxi_u32(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 0, long)) == 0xffffffff);
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 1, long)) == 0);
+ assert(erf1(f, EJIT_ARG(sizeof(int32_t) * 2, long)) == 0x42424242);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_u64.c b/tests/ldxi_u64.c
new file mode 100644
index 0000000..193fcf3
--- /dev/null
+++ b/tests/ldxi_u64.c
@@ -0,0 +1,26 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+ ejit_ldxi_u64(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, true, do_jit);
+
+ assert((uint64_t)erf1(f,
+ EJIT_ARG(sizeof(int32_t) * 0, long)) == data[0]);
+ assert((uint64_t)erf1(f, EJIT_ARG(sizeof(int32_t) * 1, long)) == 0);
+ assert((uint64_t)erf1(f,
+ EJIT_ARG(sizeof(int32_t) * 2, long)) == data[2]);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_u8.c b/tests/ldxi_u8.c
new file mode 100644
index 0000000..1942441
--- /dev/null
+++ b/tests/ldxi_u8.c
@@ -0,0 +1,24 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint8_t data[] = { 0xff, 0x00, 0x42 };
+
+int main()
+{
+ struct ejit_operand operands[1] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
+
+ ejit_ldxi_u8(f, EJIT_GPR(0), EJIT_GPR(0), (uintptr_t)&data);
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit);
+
+ assert(erf1(f, EJIT_ARG(0, long)) == 0xff);
+ assert(erf1(f, EJIT_ARG(1, long)) == 0);
+ assert(erf1(f, EJIT_ARG(2, long)) == 0x42);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxi_uc.c b/tests/ldxi_uc.c
deleted file mode 100644
index dc82aa2..0000000
--- a/tests/ldxi_uc.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_ldxi_uc(j, JIT_R0, JIT_R0, (uintptr_t)data);
- 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) == 0xff);
- ASSERT(f(1) == 0);
- ASSERT(f(2) == 0x42);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxi_ui.c b/tests/ldxi_ui.c
deleted file mode 100644
index 4500507..0000000
--- a/tests/ldxi_ui.c
+++ /dev/null
@@ -1,29 +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
- static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
-
- 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_ldxi_ui(j, JIT_R0, JIT_R0, (uintptr_t)data);
- 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) == data[0]);
- ASSERT(f(4) == data[1]);
- ASSERT(f(8) == data[2]);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxi_us.c b/tests/ldxi_us.c
deleted file mode 100644
index db2d8c8..0000000
--- a/tests/ldxi_us.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "test.h"
-
-static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
-
-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_ldxi_us(j, JIT_R0, JIT_R0, (uintptr_t)data);
- 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) == data[0]);
- ASSERT(f(2) == data[1]);
- ASSERT(f(4) == data[2]);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxr_c.c b/tests/ldxr_c.c
deleted file mode 100644
index b691b58..0000000
--- a/tests/ldxr_c.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_WORD, JIT_R1));
-
- jit_ldxr_c(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*, jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(data, 0) == -1);
- ASSERT(f(data, 1) == 0);
- ASSERT(f(data, 2) == 0x42);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxr_d.c b/tests/ldxr_d.c
index e8bb45e..3a9edc0 100644
--- a/tests/ldxr_d.c
+++ b/tests/ldxr_d.c
@@ -1,28 +1,31 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
static double data[] = { -1.0, 0.0, 0.5 };
-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_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 2, operands);
- jit_ldxr_d(j, JIT_F0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_d(j, JIT_F0);
+ ejit_ldxr_d(f, EJIT_FPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr_f(f, EJIT_FPR(0));
- double (*f)(void*, jit_uword_t) = jit_end(j, NULL);
+ ejit_select_compile_func(f, 2, 1, false, do_jit);
- ASSERT(f(data, 0) == data[0]);
- ASSERT(f(data, 8) == data[1]);
- ASSERT(f(data, 16) == data[2]);
-}
+ assert(erff2(f,
+ EJIT_ARG(data, void *),
+ EJIT_ARG(0 * sizeof(double), unsigned)) == data[0]);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ assert(erff2(f,
+ EJIT_ARG(data, void *),
+ EJIT_ARG(1 * sizeof(double), unsigned)) == data[1]);
+
+ assert(erff2(f,
+ EJIT_ARG(data, void *),
+ EJIT_ARG(2 * sizeof(double), unsigned)) == data[2]);
}
diff --git a/tests/ldxr_f.c b/tests/ldxr_f.c
index c6dacba..202a4a1 100644
--- a/tests/ldxr_f.c
+++ b/tests/ldxr_f.c
@@ -1,28 +1,33 @@
-#include "test.h"
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
static float data[] = { -1.0, 0.0, 0.5 };
-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_POINTER, JIT_R0),
- jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R1));
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(float), 2, operands);
- jit_ldxr_f(j, JIT_F0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr_f(j, JIT_F0);
+ ejit_ldxr_f(f, EJIT_FPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr_f(f, EJIT_FPR(0));
- float (*f)(void*, jit_uword_t) = jit_end(j, NULL);
+ ejit_select_compile_func(f, 2, 1, false, do_jit);
- ASSERT(f(data, 0) == data[0]);
- ASSERT(f(data, 4) == data[1]);
- ASSERT(f(data, 8) == data[2]);
-}
+ assert(erff2(f,
+ EJIT_ARG(data, void *),
+ EJIT_ARG(0 * sizeof(float), unsigned)) == data[0]);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ assert(erff2(f,
+ EJIT_ARG(data, void *),
+ EJIT_ARG(1 * sizeof(float), unsigned)) == data[1]);
+
+ assert(erff2(f,
+ EJIT_ARG(data, void *),
+ EJIT_ARG(2 * sizeof(float), unsigned)) == data[2]);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/ldxr_i.c b/tests/ldxr_i.c
deleted file mode 100644
index e035438..0000000
--- a/tests/ldxr_i.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "test.h"
-
-static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
-
-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_WORD, JIT_R1));
-
- jit_ldxr_i(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*, jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(data, 0) == -1);
- ASSERT(f(data, 4) == 0);
- ASSERT(f(data, 8) == 0x42424242);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxr_i32.c b/tests/ldxr_i32.c
new file mode 100644
index 0000000..719280a
--- /dev/null
+++ b/tests/ldxr_i32.c
@@ -0,0 +1,26 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
+ ejit_ldxr_i32(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, false, do_jit);
+
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(0, unsigned)) == -1);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(4, unsigned)) == 0);
+ assert(erf2(f, EJIT_ARG(data, void *),
+ EJIT_ARG(8, unsigned)) == 0x42424242);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxr_i64.c b/tests/ldxr_i64.c
new file mode 100644
index 0000000..96333d9
--- /dev/null
+++ b/tests/ldxr_i64.c
@@ -0,0 +1,26 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 };
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
+ ejit_ldxr_i64(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, true, do_jit);
+
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(0, unsigned)) == -1);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(8, unsigned)) == 0);
+ assert(erf2(f, EJIT_ARG(data, void *),
+ EJIT_ARG(16, unsigned)) == (int64_t)data[2]);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxr_i8.c b/tests/ldxr_i8.c
new file mode 100644
index 0000000..c5de17e
--- /dev/null
+++ b/tests/ldxr_i8.c
@@ -0,0 +1,25 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint8_t data[] = { 0xff, 0x00, 0x42 };
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
+ ejit_ldxr_i8(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, false, do_jit);
+
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(0, unsigned)) == -1);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(4, unsigned)) == 0);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(8, unsigned)) == 0x42);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxr_l.c b/tests/ldxr_l.c
deleted file mode 100644
index 6dcb5c7..0000000
--- a/tests/ldxr_l.c
+++ /dev/null
@@ -1,30 +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
- static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 };
-
- 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_WORD, JIT_R1));
-
- jit_ldxr_l(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*, jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(data, 0) == -1);
- ASSERT(f(data, 8) == 0);
- ASSERT(f(data, 16) == data[2]);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxr_s.c b/tests/ldxr_s.c
deleted file mode 100644
index cea155f..0000000
--- a/tests/ldxr_s.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "test.h"
-
-static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
-
-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_WORD, JIT_R1));
-
- jit_ldxr_s(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*, jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(data, 0) == -1);
- ASSERT(f(data, 2) == 0);
- ASSERT(f(data, 4) == 0x4242);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxr_u16.c b/tests/ldxr_u16.c
new file mode 100644
index 0000000..38b6492
--- /dev/null
+++ b/tests/ldxr_u16.c
@@ -0,0 +1,27 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
+ ejit_ldxr_u16(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, false, do_jit);
+
+ assert(erf2(f, EJIT_ARG(data, void *),
+ EJIT_ARG(0, unsigned)) == 0xffff);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(2, unsigned)) == 0);
+ assert(erf2(f, EJIT_ARG(data, void *),
+ EJIT_ARG(4, unsigned)) == 0x4242);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxr_u32.c b/tests/ldxr_u32.c
new file mode 100644
index 0000000..212ae75
--- /dev/null
+++ b/tests/ldxr_u32.c
@@ -0,0 +1,27 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
+ ejit_ldxr_u32(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, false, do_jit);
+
+ assert(erf2(f, EJIT_ARG(data, void *),
+ EJIT_ARG(0, unsigned)) == 0xffffffff);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(4, unsigned)) == 0);
+ assert(erf2(f, EJIT_ARG(data, void *),
+ EJIT_ARG(8, unsigned)) == 0x42424242);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxr_u8.c b/tests/ldxr_u8.c
new file mode 100644
index 0000000..d1f5023
--- /dev/null
+++ b/tests/ldxr_u8.c
@@ -0,0 +1,25 @@
+#include <ejit/ejit.h>
+#include <assert.h>
+#include "do_jit.h"
+
+static uint8_t data[] = { 0xff, 0x00, 0x42 };
+
+int main()
+{
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_POINTER),
+ EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned))
+ };
+
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands);
+ ejit_ldxr_u8(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1));
+ ejit_retr(f, EJIT_GPR(0));
+
+ ejit_select_compile_func(f, 2, 0, false, do_jit);
+
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(0, unsigned)) == 0xff);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(4, unsigned)) == 0);
+ assert(erf2(f, EJIT_ARG(data, void *), EJIT_ARG(8, unsigned)) == 0x42);
+
+ ejit_destroy_func(f);
+}
diff --git a/tests/ldxr_uc.c b/tests/ldxr_uc.c
deleted file mode 100644
index 3b6ab3e..0000000
--- a/tests/ldxr_uc.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "test.h"
-
-static uint8_t data[] = { 0xff, 0x00, 0x42 };
-
-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_WORD, JIT_R1));
-
- jit_ldxr_uc(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*, jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(data, 0) == 0xff);
- ASSERT(f(data, 1) == 0);
- ASSERT(f(data, 2) == 0x42);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxr_ui.c b/tests/ldxr_ui.c
deleted file mode 100644
index eddb56b..0000000
--- a/tests/ldxr_ui.c
+++ /dev/null
@@ -1,30 +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
- static uint32_t data[] = { 0xffffffff, 0x00000000, 0x42424242 };
-
- 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_WORD, JIT_R1));
-
- jit_ldxr_ui(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*, jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(data, 0) == data[0]);
- ASSERT(f(data, 4) == data[1]);
- ASSERT(f(data, 8) == data[2]);
-#endif
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ldxr_us.c b/tests/ldxr_us.c
deleted file mode 100644
index d18c133..0000000
--- a/tests/ldxr_us.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "test.h"
-
-static uint16_t data[] = { 0xffff, 0x0000, 0x4242 };
-
-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_WORD, JIT_R1));
-
- jit_ldxr_us(j, JIT_R0, JIT_R0, JIT_R1);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- jit_uword_t (*f)(void*, jit_uword_t) = jit_end(j, NULL);
-
- ASSERT(f(data, 0) == data[0]);
- ASSERT(f(data, 2) == data[1]);
- ASSERT(f(data, 4) == data[2]);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}
diff --git a/tests/ler.c b/tests/ler.c
index 0bd6e26..90c4c4c 100644
--- a/tests/ler.c
+++ b/tests/ler.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/ler_f.c b/tests/ler_f.c
index 00fe9ef..ecb4b3f 100644
--- a/tests/ler_f.c
+++ b/tests/ler_f.c
@@ -5,13 +5,13 @@
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))
};
struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 2, operands);
- ejit_ler(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1));
+ ejit_ler_f(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1));
ejit_retr(f, EJIT_GPR(0));
ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit);
diff --git a/tests/lshi.c b/tests/lshi.c
index 772c0ed..92550a5 100644
--- a/tests/lshi.c
+++ b/tests/lshi.c
@@ -1,27 +1,21 @@
-#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));
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long))
+ };
- jit_lshi(j, JIT_R0, JIT_R0, 31);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
+ struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands);
- jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
+ ejit_lshi(f, EJIT_GPR(0), EJIT_GPR(0), 31);
+ ejit_retr(f, EJIT_GPR(0));
-#if EJIT_WORDSIZE == 32
- ASSERT(f(-0x7f) == 0x80000000);
-#else
- ASSERT(f(-0x7f) == 0xffffffc080000000);
-#endif
-}
+ ejit_select_compile_func(f, 1, 0, false, do_jit);
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
+ assert(erf1(f, EJIT_ARG(-0x7f, long)) == (int64_t)0xffffffc080000000);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/lshr.c b/tests/lshr.c
index 89b9084..4bfef86 100644
--- a/tests/lshr.c
+++ b/tests/lshr.c
@@ -1,69 +1,144 @@
-#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_lshr(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(0x7f, 1) == 0xfe);
- ASSERT(f(0x7fff, 2) == 0x1fffc);
- ASSERT(f(0x81, 16) == 0x810000);
- ASSERT(f(0xff, 15) == 0x7f8000);
- ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
-#if EJIT_WORDSIZE == 32
- ASSERT(f(0xffffffff, 8) == 0xffffff00);
- ASSERT(f(0x7fffffff, 3) == 0xfffffff8);
- ASSERT(f(-0x7f, 31) == 0x80000000);
- ASSERT(f(-0x7fff, 30) == 0x40000000);
- ASSERT(f(-0x7fffffff, 29) == 0x20000000);
- ASSERT(f(0x80000001, 28) == 0x10000000);
- ASSERT(f(0x8001, 17) == 0x20000);
- ASSERT(f(0x80000001, 18) == 0x40000);
- ASSERT(f(-0xffff, 24) == 0x1000000);
-#else
- ASSERT(f(0xffffffff, 8) == 0xffffffff00);
- ASSERT(f(0x7fffffff, 3) == 0x3fffffff8);
- ASSERT(f(-0x7f, 31) == 0xffffffc080000000);
- ASSERT(f(-0x7fff, 30) == 0xffffe00040000000);
- ASSERT(f(-0x7fffffff, 29) == 0xf000000020000000);
- ASSERT(f(0x80000001, 28) == 0x800000010000000);
- ASSERT(f(0x8001, 17) == 0x100020000);
- ASSERT(f(0x80000001, 18) == 0x2000000040000);
- ASSERT(f(-0xffff, 24) == 0xffffff0001000000);
- ASSERT(f(0x7f, 33) == 0xfe00000000);
- ASSERT(f(0x7ffff, 34) == 0x1ffffc00000000);
- ASSERT(f(0x7fffffff, 35) == 0xfffffff800000000);
- ASSERT(f(-0x7f, 63) == 0x8000000000000000);
- ASSERT(f(-0x7fff, 62) == 0x4000000000000000);
- ASSERT(f(-0x7fffffff, 61) == 0x2000000000000000);
- ASSERT(f(0x80000001, 60) == 0x1000000000000000);
- ASSERT(f(0x81, 48) == 0x81000000000000);
- ASSERT(f(0x8001, 49) == 0x2000000000000);
- ASSERT(f(0x80000001, 40) == 0x10000000000);
- ASSERT(f(0xff, 47) == 0x7f800000000000);
- ASSERT(f(0xffff0001, 56) == 0x100000000000000);
- ASSERT(f(0xffffffff, 40) == 0xffffff0000000000);
- ASSERT(f(0x7fffffffff, 33) == 0xfffffffe00000000);
- ASSERT(f(-0x7fffffffff, 63) == 0x8000000000000000);
- ASSERT(f(0x8000000001, 48) == 0x1000000000000);
- ASSERT(f(0xffffffffff, 47) == 0xffff800000000000);
-#endif
-}
+ struct ejit_operand operands[2] = {
+ EJIT_OPERAND_GPR(0, EJIT_TYPE(long)),
+ EJIT_OPERAND_GPR(1, 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), 2, operands);
+
+ ejit_lshr(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(0x7f, long),
+ EJIT_ARG(1, long)) == 0xfe);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7fff, long),
+ EJIT_ARG(2, long)) == 0x1fffc);
+
+ assert(erf2(f,
+ EJIT_ARG(0x81, long),
+ EJIT_ARG(16, long)) == 0x810000);
+
+ assert(erf2(f,
+ EJIT_ARG(0xff, long),
+ EJIT_ARG(15, long)) == 0x7f8000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(0, long)) == 0x7fffffff);
+
+ assert(erf2(f,
+ EJIT_ARG(0xffffffff, long),
+ EJIT_ARG(8, long)) == 0xffffffff00);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(3, long)) == 0x3fffffff8);
+
+ assert(erf2(f,
+ EJIT_ARG(-0x7f, long),
+ EJIT_ARG(31, long)) == (int64_t)0xffffffc080000000);
+
+ assert(erf2(f,
+ EJIT_ARG(-0x7fff, long),
+ EJIT_ARG(30, long)) == (int64_t)0xffffe00040000000);
+
+ assert(erf2(f,
+ EJIT_ARG(-0x7fffffff, long),
+ EJIT_ARG(29, long)) == (int64_t)0xf000000020000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x80000001, long),
+ EJIT_ARG(28, long)) == (int64_t)0x800000010000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x8001, long),
+ EJIT_ARG(17, long)) == 0x100020000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x80000001, long),
+ EJIT_ARG(18, long)) == (int64_t)0x2000000040000);
+
+ assert(erf2(f,
+ EJIT_ARG(-0xffff, long),
+ EJIT_ARG(24, long)) == (int64_t)0xffffff0001000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7f, long),
+ EJIT_ARG(33, long)) == 0xfe00000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7ffff, long),
+ EJIT_ARG(34, long)) == 0x1ffffc00000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7fffffff, long),
+ EJIT_ARG(35, long)) == (int64_t)0xfffffff800000000);
+
+ assert(erf2(f,
+ EJIT_ARG(-0x7f, long),
+ EJIT_ARG(63, long)) == (int64_t)0x8000000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(-0x7fff, long),
+ EJIT_ARG(62, long)) == 0x4000000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(-0x7fffffff, long),
+ EJIT_ARG(61, long)) == 0x2000000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x80000001, long),
+ EJIT_ARG(60, long)) == 0x1000000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x81, long),
+ EJIT_ARG(48, long)) == 0x81000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x8001, long),
+ EJIT_ARG(49, long)) == 0x2000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x80000001, long),
+ EJIT_ARG(40, long)) == 0x10000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0xff, long),
+ EJIT_ARG(47, long)) == 0x7f800000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0xffff0001, long),
+ EJIT_ARG(56, long)) == 0x100000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0xffffffff, long),
+ EJIT_ARG(40, long)) == (int64_t)0xffffff0000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x7fffffffff, long),
+ EJIT_ARG(33, long)) == (int64_t)0xfffffffe00000000);
+
+ assert(erf2(f,
+ EJIT_ARG(-0x7fffffffff, long),
+ EJIT_ARG(63, long)) == (int64_t)0x8000000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0x8000000001, long),
+ EJIT_ARG(48, long)) == 0x1000000000000);
+
+ assert(erf2(f,
+ EJIT_ARG(0xffffffffff, long),
+ EJIT_ARG(47, long)) == (int64_t)0xffff800000000000);
+
+ ejit_destroy_func(f);
}
diff --git a/tests/ltr.c b/tests/ltr.c
index 2deb6ae..85f7af0 100644
--- a/tests/ltr.c
+++ b/tests/ltr.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/ltr_f.c b/tests/ltr_f.c
index 5e5a98b..f925c4f 100644
--- a/tests/ltr_f.c
+++ b/tests/ltr_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))
};
diff --git a/tests/mov_addr.c b/tests/mov_addr.c
deleted file mode 100644
index 01a0e7e..0000000
--- a/tests/mov_addr.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "test.h"
-
-static uint64_t thing = 0x123456789abcdef0;
-
-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_patch_there(j, jit_mov_addr(j, JIT_R0), &thing);
- jit_leave_jit_abi(j, 0, 0, align);
- jit_retr(j, JIT_R0);
-
- void* (*f)(void) = jit_end(j, NULL);
-
- ASSERT(f() == &thing);
- ASSERT(*(uint64_t*)f() == thing);
-}
-
-int
-main (int argc, char *argv[])
-{
- return main_helper(argc, argv, run_test);
-}