guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 38/86: Add more div tests


From: Andy Wingo
Subject: [Guile-commits] 38/86: Add more div tests
Date: Wed, 3 Apr 2019 11:38:55 -0400 (EDT)

wingo pushed a commit to branch lightening
in repository guile.

commit 8e0102564a0c444989add5f6aa16f92a9487d501
Author: Andy Wingo <address@hidden>
Date:   Tue Mar 26 09:10:19 2019 +0100

    Add more div tests
---
 .gitignore           |  4 +++
 tests/test-divr_d.c  | 30 +++++++++++++++++++++++
 tests/test-divr_f.c  | 30 +++++++++++++++++++++++
 tests/test-qdivr.c   | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/test-qdivr_u.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 200 insertions(+)

diff --git a/.gitignore b/.gitignore
index 5c0fa51..0b8c0ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/tests/test-divr_d.c b/tests/test-divr_d.c
new file mode 100644
index 0000000..978e4a4
--- /dev/null
+++ b/tests/test-divr_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_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);
+}
diff --git a/tests/test-divr_f.c b/tests/test-divr_f.c
new file mode 100644
index 0000000..681df0a
--- /dev/null
+++ b/tests/test-divr_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_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);
+}
diff --git a/tests/test-qdivr.c b/tests/test-qdivr.c
new file mode 100644
index 0000000..f3862ff
--- /dev/null
+++ b/tests/test-qdivr.c
@@ -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);
+}
diff --git a/tests/test-qdivr_u.c b/tests/test-qdivr_u.c
new file mode 100644
index 0000000..29589c8
--- /dev/null
+++ b/tests/test-qdivr_u.c
@@ -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);
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]