From ece71ef64c96717b1f50bcac2933a97075e9198c Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 26 Mar 2019 22:29:48 +0100 Subject: [PATCH] Add float/double cast inst tests --- tests/extr_d_f.c | 30 ++++++++++++++++++++++++++++++ tests/extr_f_d.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/extr_d_f.c create mode 100644 tests/extr_f_d.c diff --git a/tests/extr_d_f.c b/tests/extr_d_f.c new file mode 100644 index 000000000..570bae814 --- /dev/null +++ b/tests/extr_d_f.c @@ -0,0 +1,30 @@ +#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); + + const jit_arg_abi_t abi[] = { JIT_ARG_ABI_DOUBLE }; + jit_arg_t args[1]; + const jit_anyreg_t regs[] = { { .fpr=JIT_F0 } }; + + jit_receive(j, 1, abi, args); + jit_load_args(j, 1, abi, args, regs); + + jit_extr_d_f(j, JIT_F0, JIT_F0); + 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_d.c b/tests/extr_f_d.c new file mode 100644 index 000000000..5e90be41b --- /dev/null +++ b/tests/extr_f_d.c @@ -0,0 +1,30 @@ +#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); + + const jit_arg_abi_t abi[] = { JIT_ARG_ABI_FLOAT }; + jit_arg_t args[1]; + const jit_anyreg_t regs[] = { { .fpr=JIT_F0 } }; + + jit_receive(j, 1, abi, args); + jit_load_args(j, 1, abi, args, regs); + + jit_extr_f_d(j, JIT_F0, JIT_F0); + jit_retr_d(j, JIT_F0); + + double (*f)(float) = jit_end(j, NULL); + + ASSERT(f(0.0f) == 0.0); + ASSERT(f(0.5f) == 0.5); + ASSERT(f(1.0f / 0.0f) == 1.0 / 0.0); + ASSERT(f(1.25f) == 1.25); +} + +int +main (int argc, char *argv[]) +{ + return main_helper(argc, argv, run_test); +}