diff options
Diffstat (limited to 'tests/jmp_table.c')
-rw-r--r-- | tests/jmp_table.c | 80 |
1 files changed, 38 insertions, 42 deletions
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); } |