1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-02 18:26:20 +02:00

Add more div tests

This commit is contained in:
Andy Wingo 2019-03-26 09:10:19 +01:00
parent b371e913ff
commit 8e0102564a
5 changed files with 200 additions and 0 deletions

4
.gitignore vendored
View file

@ -17,3 +17,7 @@
/tests/test-qmulr_u
/tests/test-divr
/tests/test-divr_u
/tests/test-divr_d
/tests/test-divr_f
/tests/test-qdivr
/tests/test-qdivr_u

30
tests/test-divr_d.c Normal file
View file

@ -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_ABI_DOUBLE };
jit_arg_t args[2];
const jit_anyreg_t regs[] = { { .gpr=JIT_F0 }, { .gpr=JIT_F1 }};
jit_receive(j, 2, abi, args);
jit_load_args(j, 2, abi, args, regs);
jit_divr_d(j, JIT_F0, JIT_F0, JIT_F1);
jit_retr_d(j, JIT_F0);
size_t size = 0;
void* ret = jit_end(j, &size);
double (*f)(double, double) = ret;
ASSERT(f(-0.5f, 0.5f) == -1.0f);
ASSERT(f(1.25f, 0.5f) == 2.5f);
}
int
main (int argc, char *argv[])
{
return main_helper(argc, argv, run_test);
}

30
tests/test-divr_f.c Normal file
View file

@ -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_ABI_FLOAT };
jit_arg_t args[2];
const jit_anyreg_t regs[] = { { .gpr=JIT_F0 }, { .gpr=JIT_F1 }};
jit_receive(j, 2, abi, args);
jit_load_args(j, 2, abi, args, regs);
jit_divr_f(j, JIT_F0, JIT_F0, JIT_F1);
jit_retr_f(j, JIT_F0);
size_t size = 0;
void* ret = jit_end(j, &size);
float (*f)(float, float) = ret;
ASSERT(f(-0.5f, 0.5f) == -1.0f);
ASSERT(f(1.25f, 0.5f) == 2.5f);
}
int
main (int argc, char *argv[])
{
return main_helper(argc, argv, run_test);
}

69
tests/test-qdivr.c Normal file
View file

@ -0,0 +1,69 @@
#include "test.h"
static void
maybe_save(jit_state_t *j, jit_gpr_t reg)
{
if (jit_class(reg) & jit_class_sav)
jit_pushr(j, reg);
}
static void
maybe_restore(jit_state_t *j, jit_gpr_t reg)
{
if (jit_class(reg) & jit_class_sav)
jit_popr(j, reg);
}
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_POINTER, JIT_ARG_ABI_POINTER,
JIT_ARG_ABI_INTMAX, JIT_ARG_ABI_INTMAX
};
jit_arg_t args[4];
const jit_anyreg_t regs[] = {
{ .gpr=JIT_R0 }, { .gpr=JIT_R1 },
{ .gpr=JIT_R2 }, { .gpr=JIT_V0 }
};
maybe_save(j, JIT_V0);
maybe_save(j, JIT_V1);
maybe_save(j, JIT_V2);
jit_receive(j, 4, abi, args);
jit_load_args(j, 4, abi, args, regs);
jit_qdivr(j, JIT_V1, JIT_V2, JIT_R2, JIT_V0);
jit_str(j, JIT_R0, JIT_V1);
jit_str(j, JIT_R1, JIT_V2);
maybe_restore(j, JIT_V2);
maybe_restore(j, JIT_V1);
maybe_restore(j, JIT_V0);
jit_ret(j);
size_t size = 0;
void* ret = jit_end(j, &size);
void (*f)(intmax_t*, intmax_t*, intmax_t, intmax_t) = ret;
#define QDIV(a, b, c, d) \
do { \
intmax_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); ASSERT(D == d); \
} while (0)
QDIV(10, 3, 3, 1);
QDIV(-33, 9, -3, -6);
QDIV(-41, -7, 5, -6);
QDIV(65536, 4096, 16, 0);
}
int
main (int argc, char *argv[])
{
return main_helper(argc, argv, run_test);
}

67
tests/test-qdivr_u.c Normal file
View file

@ -0,0 +1,67 @@
#include "test.h"
static void
maybe_save(jit_state_t *j, jit_gpr_t reg)
{
if (jit_class(reg) & jit_class_sav)
jit_pushr(j, reg);
}
static void
maybe_restore(jit_state_t *j, jit_gpr_t reg)
{
if (jit_class(reg) & jit_class_sav)
jit_popr(j, reg);
}
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_POINTER, JIT_ARG_ABI_POINTER,
JIT_ARG_ABI_INTMAX, JIT_ARG_ABI_INTMAX
};
jit_arg_t args[4];
const jit_anyreg_t regs[] = {
{ .gpr=JIT_R0 }, { .gpr=JIT_R1 },
{ .gpr=JIT_R2 }, { .gpr=JIT_V0 }
};
maybe_save(j, JIT_V0);
maybe_save(j, JIT_V1);
maybe_save(j, JIT_V2);
jit_receive(j, 4, abi, args);
jit_load_args(j, 4, abi, args, regs);
jit_qdivr_u(j, JIT_V1, JIT_V2, JIT_R2, JIT_V0);
jit_str(j, JIT_R0, JIT_V1);
jit_str(j, JIT_R1, JIT_V2);
maybe_restore(j, JIT_V2);
maybe_restore(j, JIT_V1);
maybe_restore(j, JIT_V0);
jit_ret(j);
size_t size = 0;
void* ret = jit_end(j, &size);
void (*f)(intmax_t*, intmax_t*, intmax_t, intmax_t) = ret;
#define QDIV(a, b, c, d) \
do { \
intmax_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); ASSERT(D == d); \
} while (0)
QDIV(-1, -2, 1, 1);
QDIV(-2, -5, 1, 3);
}
int
main (int argc, char *argv[])
{
return main_helper(argc, argv, run_test);
}