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/andr.c | |
parent | d4c1d32e0aa21677e72c54ed220fdc70cea732c8 (diff) | |
download | ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.tar.gz ejit-322c7fba3d2f4c9b5b0d78b44feefd38ae44d017.zip |
continue working through bytecode ops
Diffstat (limited to 'tests/andr.c')
-rw-r--r-- | tests/andr.c | 140 |
1 files changed, 96 insertions, 44 deletions
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); } |