diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-04-24 20:37:36 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-04-24 20:37:36 +0300 |
commit | 15310fc90dc6ab2ba52603027eebe8aa5a606a27 (patch) | |
tree | ad7606ede5d486a841d2b70498c1393134716380 | |
parent | d9e7718b03596c9af89411a8991f5a1da7b4ad5f (diff) | |
download | ejit-master.tar.gz ejit-master.zip |
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/ejit/ejit.h | 4 | ||||
-rw-r--r-- | src/ejit.c | 2 | ||||
-rw-r--r-- | tests/bger_d.c | 31 | ||||
-rw-r--r-- | tests/bger_f.c | 31 | ||||
-rw-r--r-- | tests/blti_u.c | 4 | ||||
-rw-r--r-- | tests/ger_d.c | 27 | ||||
-rw-r--r-- | tests/ger_f.c | 27 | ||||
-rw-r--r-- | tests/ldxr_i16.c | 35 | ||||
-rw-r--r-- | tests/ldxr_u64.c | 29 | ||||
-rw-r--r-- | tests/ler64_u.c | 37 | ||||
-rw-r--r-- | tests/ltr_u.c | 35 |
12 files changed, 260 insertions, 4 deletions
@@ -16,7 +16,7 @@ check: all coverage: $(MAKE) clean $(MAKE) CFLAGS='--coverage' check - mkdir coverage + mkdir -p coverage lcov --capture --directory . --out coverage/ejit.info genhtml coverage/ejit.info --out coverage diff --git a/include/ejit/ejit.h b/include/ejit/ejit.h index ab06d8f..d3bc6c3 100644 --- a/include/ejit/ejit.h +++ b/include/ejit/ejit.h @@ -864,6 +864,8 @@ void ejit_ger_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, void ejit_ler(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2); +void ejit_ler_u(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); void ejit_ler_d(struct ejit_func *s, struct ejit_gpr r0, struct ejit_fpr r1, @@ -912,6 +914,8 @@ struct ejit_reloc ejit_bger_u(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1); struct ejit_reloc ejit_bger_f(struct ejit_func *s, struct ejit_fpr r0, struct ejit_fpr r1); +struct ejit_reloc ejit_bger_d(struct ejit_func *s, struct ejit_fpr r0, + struct ejit_fpr r1); struct ejit_reloc ejit_bgei(struct ejit_func *s, struct ejit_gpr r0, int64_t o); struct ejit_reloc ejit_bgei_u(struct ejit_func *s, struct ejit_gpr r0, @@ -954,7 +954,7 @@ void ejit_ldxr_u32(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, void ejit_ldxr_u64(struct ejit_func *s, struct ejit_gpr r0, struct ejit_gpr r1, struct ejit_gpr r2) { - emit_insn_orrr(s, EJIT_OP_LDXIU64, r0, r1, r2); + emit_insn_orrr(s, EJIT_OP_LDXRU64, r0, r1, r2); } void ejit_ldxr_f(struct ejit_func *s, struct ejit_fpr f0, struct ejit_gpr r1, diff --git a/tests/bger_d.c b/tests/bger_d.c new file mode 100644 index 0000000..97b6141 --- /dev/null +++ b/tests/bger_d.c @@ -0,0 +1,31 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + struct ejit_reloc r = ejit_bger_d(f, EJIT_FPR(0), EJIT_FPR(1)); + ejit_reti(f, 0); + + struct ejit_label l = ejit_label(f); + ejit_patch(f, r, l); + ejit_reti(f, 1); + + ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit, true); + + assert(erfi2(f, EJIT_ARG( 0, double), EJIT_ARG( 0, double)) == 1); + assert(erfi2(f, EJIT_ARG( 0, double), EJIT_ARG( 1, double)) == 0); + assert(erfi2(f, EJIT_ARG( 1, double), EJIT_ARG( 0, double)) == 1); + assert(erfi2(f, EJIT_ARG(-1, double), EJIT_ARG( 0, double)) == 0); + assert(erfi2(f, EJIT_ARG( 0, double), EJIT_ARG(-1, double)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/bger_f.c b/tests/bger_f.c new file mode 100644 index 0000000..9e863cb --- /dev/null +++ b/tests/bger_f.c @@ -0,0 +1,31 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(float)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(float)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + struct ejit_reloc r = ejit_bger_f(f, EJIT_FPR(0), EJIT_FPR(1)); + ejit_reti(f, 0); + + struct ejit_label l = ejit_label(f); + ejit_patch(f, r, l); + ejit_reti(f, 1); + + ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit, true); + + assert(erfi2(f, EJIT_ARG( 0, float), EJIT_ARG( 0, float)) == 1); + assert(erfi2(f, EJIT_ARG( 0, float), EJIT_ARG( 1, float)) == 0); + assert(erfi2(f, EJIT_ARG( 1, float), EJIT_ARG( 0, float)) == 1); + assert(erfi2(f, EJIT_ARG(-1, float), EJIT_ARG( 0, float)) == 0); + assert(erfi2(f, EJIT_ARG( 0, float), EJIT_ARG(-1, float)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/blti_u.c b/tests/blti_u.c index 3e4ed27..52d3b2c 100644 --- a/tests/blti_u.c +++ b/tests/blti_u.c @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) }; struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands); - struct ejit_reloc r = ejit_blti_u(f, EJIT_GPR(0), 0); + struct ejit_reloc r = ejit_blti_u(f, EJIT_GPR(0), 1); ejit_reti(f, 0); struct ejit_label l = ejit_label(f); @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit, true); - assert(erfi1(f, EJIT_ARG( 0, long)) == 0); + assert(erfi1(f, EJIT_ARG( 0, long)) == 1); assert(erfi1(f, EJIT_ARG( 1, long)) == 0); assert(erfi1(f, EJIT_ARG(-1, long)) == 0); diff --git a/tests/ger_d.c b/tests/ger_d.c new file mode 100644 index 0000000..74835b8 --- /dev/null +++ b/tests/ger_d.c @@ -0,0 +1,27 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + + ejit_ger_d(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, true); + + assert(erfi2(f, EJIT_ARG(1, double), EJIT_ARG(1, double)) == 1); + assert(erfi2(f, EJIT_ARG(1, double), EJIT_ARG(0, double)) == 1); + assert(erfi2(f, EJIT_ARG(-1, double), EJIT_ARG(0, double)) == 0); + assert(erfi2(f, EJIT_ARG(-1, double), EJIT_ARG(-1, double)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/ger_f.c b/tests/ger_f.c new file mode 100644 index 0000000..d1be5ab --- /dev/null +++ b/tests/ger_f.c @@ -0,0 +1,27 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(float)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(float)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + + ejit_ger_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, true); + + assert(erfi2(f, EJIT_ARG(1, float), EJIT_ARG(1, float)) == 1); + assert(erfi2(f, EJIT_ARG(1, float), EJIT_ARG(0, float)) == 1); + assert(erfi2(f, EJIT_ARG(-1, float), EJIT_ARG(0, float)) == 0); + assert(erfi2(f, EJIT_ARG(-1, float), EJIT_ARG(-1, float)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/ldxr_i16.c b/tests/ldxr_i16.c new file mode 100644 index 0000000..c423bce --- /dev/null +++ b/tests/ldxr_i16.c @@ -0,0 +1,35 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint16_t data[] = { 0xffff, 0x0000, 0x4242 }; + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + 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_i16(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, true); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int16_t) * 0, unsigned) + ) == -1); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int16_t) * 1, unsigned) + ) == 0); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int16_t) * 2, unsigned) + ) == 0x4242); + + ejit_destroy_func(f); +} diff --git a/tests/ldxr_u64.c b/tests/ldxr_u64.c new file mode 100644 index 0000000..3ad3c28 --- /dev/null +++ b/tests/ldxr_u64.c @@ -0,0 +1,29 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 }; + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + 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(int64_t), 2, operands); + ejit_ldxr_u64(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, true); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(0, unsigned)) == (int64_t)0xffffffffffffffff); + assert(erfi2(f, EJIT_ARG(data, void *), EJIT_ARG(8, unsigned)) == 0); + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(16, unsigned)) == 0x4242424212345678); + + ejit_destroy_func(f); +} diff --git a/tests/ler64_u.c b/tests/ler64_u.c new file mode 100644 index 0000000..6c3f473 --- /dev/null +++ b/tests/ler64_u.c @@ -0,0 +1,37 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_ler_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(int64_t), do_jit, true); + + assert(erfl2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(1, int64_t)) == 1); + + assert(erfl2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(0, int64_t)) == 0); + + assert(erfl2(f, + EJIT_ARG(0x0fffffffffffffff, int64_t), + EJIT_ARG(0x0ffffffffffffff0, int64_t)) == 0); + + assert(erfl2(f, + EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x6fffffffffffffff, int64_t)) == 0); + ejit_destroy_func(f); +} diff --git a/tests/ltr_u.c b/tests/ltr_u.c new file mode 100644 index 0000000..07bd745 --- /dev/null +++ b/tests/ltr_u.c @@ -0,0 +1,35 @@ +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + 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_ltr_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, true); + + assert(erfi2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 0); + assert(erfi2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 0); + + assert(erfi2(f, EJIT_ARG(-1, long), EJIT_ARG(1, long)) == 0); + assert(erfi2(f, EJIT_ARG(-1, long), EJIT_ARG(0, long)) == 0); + + assert(erfi2(f, + EJIT_ARG(0x0fffffffffffffff, long), + EJIT_ARG(0x0ffffffffffffff0, long)) == 0); + + assert(erfi2(f, + EJIT_ARG(0x7fffffffffffffff, long), + EJIT_ARG(0x6fffffffffffffff, long)) == 0); + ejit_destroy_func(f); +} |