diff options
Diffstat (limited to 'tests')
87 files changed, 1041 insertions, 1374 deletions
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); -} |