diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-29 18:00:51 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-06-29 18:00:51 +0300 |
commit | 322c7fba3d2f4c9b5b0d78b44feefd38ae44d017 (patch) | |
tree | de20ed83ee9231e853cefb46bb8ba60cf65e09dd /tests | |
parent | d4c1d32e0aa21677e72c54ed220fdc70cea732c8 (diff) | |
download | ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.tar.gz ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.zip |
continue working through bytecode ops
Diffstat (limited to 'tests')
-rw-r--r-- | tests/addr.c | 7 | ||||
-rw-r--r-- | tests/addr_f.c | 37 | ||||
-rw-r--r-- | tests/addx.c | 88 | ||||
-rw-r--r-- | tests/andi.c | 40 | ||||
-rw-r--r-- | tests/andr.c | 140 | ||||
-rw-r--r-- | tests/beqi.c | 41 | ||||
-rw-r--r-- | tests/beqr.c | 49 |
7 files changed, 229 insertions, 173 deletions
diff --git a/tests/addr.c b/tests/addr.c index 472030f..b67eb29 100644 --- a/tests/addr.c +++ b/tests/addr.c @@ -2,8 +2,7 @@ #include <assert.h> #include "do_jit.h" -int -main (int argc, char *argv[]) +int main() { struct ejit_operand operands[2] = { EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), @@ -17,6 +16,8 @@ main (int argc, char *argv[]) ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit); - assert(ejit_run_func_2(f, EJIT_ARG(42, long), EJIT_ARG(69, long)) == 111); + assert(ejit_run_func_2(f, + EJIT_ARG(42, long), + EJIT_ARG(69, long)) == 111); ejit_destroy_func(f); } diff --git a/tests/addr_f.c b/tests/addr_f.c index 2aa9002..6562134 100644 --- a/tests/addr_f.c +++ b/tests/addr_f.c @@ -1,27 +1,24 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_2(j, jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F0), - jit_operand_fpr (JIT_OPERAND_ABI_DOUBLE, JIT_F1)); + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; - jit_addr_d(j, JIT_F0, JIT_F0, JIT_F1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr_d(j, JIT_F0); + struct ejit_func *f = ejit_create_func(EJIT_TYPE(double), 2, operands); - size_t size = 0; - void* ret = jit_end(j, &size); + ejit_addr_f(f, EJIT_FPR(0), EJIT_FPR(0), EJIT_FPR(1)); + ejit_retr_f(f, EJIT_FPR(0)); - double (*f)(double, double) = ret; - ASSERT(f(42., 69.) == 111.); - ASSERT(f(42.5, 69.5) == 112.); -} + ejit_select_compile_func(f, 0, 2, EJIT_USE64(double), do_jit); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + assert(ejit_run_func_f_2(f, EJIT_ARG(42., double), + EJIT_ARG(69., double)) == 111.); + assert(ejit_run_func_f_2(f, EJIT_ARG(42.5, double), + EJIT_ARG(69.5, double)) == 112.); + ejit_destroy_func(f); } diff --git a/tests/addx.c b/tests/addx.c index 94b2f19..eed95ba 100644 --- a/tests/addx.c +++ b/tests/addx.c @@ -1,63 +1,79 @@ -#include "test.h" +/* still not entirely sure about semantics, should 32bit systems report carry on + * 32bit or 64bit internal register sizes? */ +#warning "carry operations unimplemented but TODO" +int main(){ +} + +/* would look something like this */ +#if 0 +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -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)); + 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); - jit_movi(j, JIT_R2, 0); - jit_addcr(j, JIT_R0, JIT_R0, JIT_R1); - jit_addxi(j, JIT_R2, JIT_R2, 0); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R2); + ejit_movi(j, EJIT_GPR(2), EJIT_GPR(0)); + ejit_addcr(j, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_addxi(j, EJIT_GPR(2), EJIT_GPR(2), 0); + ejit_retr(j, EJIT_GPR(2)); - size_t size = 0; - void* ret = jit_end(j, &size); + ejit_select_compile_func(f, 3, 0, EJIT_USE64(long), do_jit); jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - ASSERT(f(0, 0) == 0); + assert(ejit_run_func_2(f, EJIT_ARG(0, long), EJIT_ARG(0, long)) == 0); #if EJIT_WORDSIZE == 32 /* carry */ - ASSERT(f(0xffffffff, 0xffffffff) == 1); + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffff, long), + EJIT_ARG(0xffffffff, long)) == 1); /* overflow */ - ASSERT(f(0x7fffffff, 1) == 0); + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff long), + EJIT_ARG(1, long)) == 0); + /* overflow */ - ASSERT(f(0x7fffffff, 0x7fffffff) == 0); + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, long), + EJIT_ARG(0x7fffffff, long)) == 0); + /* carry */ - ASSERT(f(0x7fffffff, 0x80000000) == 0); + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, long), + EJIT_ARG(0x80000000, long)) == 0); + /* carry+overflow */ - ASSERT(f(0x80000000, 0x80000000) == 1); + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, long), + EJIT_ARG(0x80000000, long)) == 1); #else /* nothing */ - ASSERT(f(0xffffffff, 0xffffffff) == 0); + assert(f(0xffffffff, 0xffffffff) == 0); /* nothing */ - ASSERT(f(0x7fffffff, 1) == 0); + assert(f(0x7fffffff, 1) == 0); /* nothing */ - ASSERT(f(0x7fffffff, 0x7fffffff) == 0); + assert(f(0x7fffffff, 0x7fffffff) == 0); /* nothing */ - ASSERT(f(0x7fffffff, 0x80000000) == 0); + assert(f(0x7fffffff, 0x80000000) == 0); /* nothing */ - ASSERT(f(0x80000000, 0x80000000) == 0); + assert(f(0x80000000, 0x80000000) == 0); /* carry */ - ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 1); + assert(f(0xffffffffffffffff, 0xffffffffffffffff) == 1); /* overflow */ - ASSERT(f(0x7fffffffffffffff, 1) == 0); + assert(f(0x7fffffffffffffff, 1) == 0); /* overflow */ - ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0); + assert(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0); /* overflow */ - ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0); + assert(f(0x7fffffffffffffff, 0x8000000000000000) == 0); /* carry+overflow */ - ASSERT(f(0x8000000000000000, 0x8000000000000000) == 1); + assert(f(0x8000000000000000, 0x8000000000000000) == 1); #endif } - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); -} +#endif diff --git a/tests/andi.c b/tests/andi.c index fa3551b..e41a424 100644 --- a/tests/andi.c +++ b/tests/andi.c @@ -1,31 +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_andi(j, JIT_R0, JIT_R0, 1); - 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); - size_t size = 0; - void* ret = jit_end(j, &size); + ejit_andi(f, EJIT_GPR(0), EJIT_GPR(0), 1); + ejit_retr(f, EJIT_GPR(0)); - jit_word_t (*f)(jit_word_t) = ret; + ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit); - ASSERT(f(0x7fffffff) == 1); - ASSERT(f(0x80000000) == 0); -#if EJIT_WORDSIZE == 64 - ASSERT(f(0x7fffffffffffffff) == 1); - ASSERT(f(0x8000000000000000) == 0); -#endif -} - -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + assert(ejit_run_func_1(f, EJIT_ARG(0x7fffffff, long)) == 1); + assert(ejit_run_func_1(f, EJIT_ARG(0x80000000, long)) == 0); + assert(ejit_run_func_1(f, EJIT_ARG(0x7fffffffffffffff, long)) == 1); + assert(ejit_run_func_1(f, EJIT_ARG(0x8000000000000000, long)) == 0); + ejit_destroy_func(f); } diff --git a/tests/andr.c b/tests/andr.c index c4aaeaf..e714794 100644 --- a/tests/andr.c +++ b/tests/andr.c @@ -1,48 +1,100 @@ -#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_andr(j, JIT_R0, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_retr(j, JIT_R0); - - size_t size = 0; - void* ret = jit_end(j, &size); - - jit_word_t (*f)(jit_word_t, jit_word_t) = ret; - - ASSERT(f(0x7fffffff, 1) == 1); - ASSERT(f(1, 0x7fffffff) == 1); - ASSERT(f(0x80000000, 1) == 0); - ASSERT(f(1, 0x80000000) == 0); - ASSERT(f(0x7fffffff, 0x80000000) == 0); - ASSERT(f(0x80000000, 0x7fffffff) == 0); - ASSERT(f(0x7fffffff, 0xffffffff) == 0x7fffffff); - ASSERT(f(0xffffffff, 0x7fffffff) == 0x7fffffff); - ASSERT(f(0xffffffff, 0xffffffff) == 0xffffffff); - ASSERT(f(0x7fffffff, 0) == 0); - ASSERT(f(0, 0x7fffffff) == 0); -#if EJIT_WORDSIZE == 64 - ASSERT(f(0x7fffffffffffffff, 1) == 1); - ASSERT(f(1, 0x7fffffffffffffff) == 1); - ASSERT(f(0x8000000000000000, 1) == 0); - ASSERT(f(1, 0x8000000000000000) == 0); - ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0); - ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0); - ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0x7fffffffffffffff); - ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 0x7fffffffffffffff); - ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0xffffffffffffffff); -#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_andr(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, long), + EJIT_ARG(1, long)) == 1); + + assert(ejit_run_func_2(f, + EJIT_ARG(1, long), + EJIT_ARG(0x7fffffff, long)) == 1); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, long), + EJIT_ARG(1, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(1, long), + EJIT_ARG(0x80000000, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, long), + EJIT_ARG(0x80000000, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x80000000, long), + EJIT_ARG(0x7fffffff, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, long), + EJIT_ARG(0xffffffff, long)) == 0x7fffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffff, long), + EJIT_ARG(0x7fffffff, long)) == 0x7fffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffff, long), + EJIT_ARG(0xffffffff, long)) == 0xffffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffff, long), + EJIT_ARG(0, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0, long), + EJIT_ARG(0x7fffffff, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, long), + EJIT_ARG(1, long)) == 1); + assert(ejit_run_func_2(f, + EJIT_ARG(1, long), + EJIT_ARG(0x7fffffffffffffff, long)) == 1); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x8000000000000000, long), + EJIT_ARG(1, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(1, long), + EJIT_ARG(0x8000000000000000, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, long), + EJIT_ARG(0x8000000000000000, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x8000000000000000, long), + EJIT_ARG(0x7fffffffffffffff, long)) == 0); + + assert(ejit_run_func_2(f, + EJIT_ARG(0x7fffffffffffffff, long), + EJIT_ARG(0xffffffffffffffff, long)) + == 0x7fffffffffffffff); + + assert(ejit_run_func_2(f, + EJIT_ARG(0xffffffffffffffff, long), + EJIT_ARG(0x7fffffffffffffff, long)) + == 0x7fffffffffffffff); + + assert((uint64_t)ejit_run_func_2(f, + EJIT_ARG(0xffffffffffffffff, long), + EJIT_ARG(0xffffffffffffffff, long)) + == 0xffffffffffffffff); } diff --git a/tests/beqi.c b/tests/beqi.c index b366a8e..147cd50 100644 --- a/tests/beqi.c +++ b/tests/beqi.c @@ -1,28 +1,27 @@ -#include "test.h" +#include <ejit/ejit.h> +#include <assert.h> +#include "do_jit.h" -static void -run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +int main() { - jit_begin(j, arena_base, arena_size); - size_t align = jit_enter_jit_abi(j, 0, 0, 0); - jit_load_args_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_beqi(j, JIT_R0, 0); - jit_leave_jit_abi(j, 0, 0, align); - jit_reti(j, 0); - jit_patch_here(j, r); - jit_leave_jit_abi(j, 0, 0, align); - jit_reti(j, 1); + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands); - jit_word_t (*f)(jit_word_t) = jit_end(j, NULL); + struct ejit_reloc r = ejit_beqi(f, EJIT_GPR(0), 0); + ejit_reti(f, 0); - ASSERT(f(0) == 1); - ASSERT(f(1) == 0); - ASSERT(f(-1) == 0); -} + struct ejit_label l = ejit_label(f); + ejit_patch(f, r, l); + ejit_reti(f, 1); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit); + + assert(ejit_run_func_1(f, EJIT_ARG(0, long)) == 1); + assert(ejit_run_func_1(f, EJIT_ARG(1, long)) == 0); + assert(ejit_run_func_1(f, EJIT_ARG(-1, long)) == 0); + + ejit_destroy_func(f); } diff --git a/tests/beqr.c b/tests/beqr.c index 0cc4476..109b48c 100644 --- a/tests/beqr.c +++ b/tests/beqr.c @@ -1,32 +1,31 @@ -#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)); + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(long)) + }; - jit_reloc_t r = jit_beqr(j, JIT_R0, JIT_R1); - jit_leave_jit_abi(j, 0, 0, align); - jit_reti(j, 0); - jit_patch_here(j, r); - jit_leave_jit_abi(j, 0, 0, align); - jit_reti(j, 1); + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); - jit_word_t (*f)(jit_word_t, jit_word_t) = jit_end(j, NULL); + struct ejit_reloc r = ejit_beqr(f, EJIT_GPR(0), EJIT_GPR(1)); + ejit_reti(f, 0); - ASSERT(f(0, 0) == 1); - ASSERT(f(0, 1) == 0); - ASSERT(f(1, 0) == 0); - ASSERT(f(-1, 0) == 0); - ASSERT(f(0, -1) == 0); - ASSERT(f(1, 1) == 1); -} + struct ejit_label l = ejit_label(f); + ejit_patch(f, r, l); + ejit_reti(f, 1); -int -main (int argc, char *argv[]) -{ - return main_helper(argc, argv, run_test); + ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit); + + assert(ejit_run_func_2(f, EJIT_ARG(0, long), EJIT_ARG(0, 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(1, long), EJIT_ARG(0, long)) == 0); + assert(ejit_run_func_2(f, EJIT_ARG(-1, long), EJIT_ARG(0, long)) == 0); + assert(ejit_run_func_2(f, EJIT_ARG(0, long), EJIT_ARG(-1, long)) == 0); + assert(ejit_run_func_2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 1); + + ejit_destroy_func(f); } |