guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 64/86: Add flag-checking test-and-branch tests


From: Andy Wingo
Subject: [Guile-commits] 64/86: Add flag-checking test-and-branch tests
Date: Wed, 3 Apr 2019 11:39:01 -0400 (EDT)

wingo pushed a commit to branch lightening
in repository guile.

commit 0d0c6b1a4b182e1f12af7cb2b5ed4f931a913352
Author: Andy Wingo <address@hidden>
Date:   Tue Mar 26 15:25:57 2019 +0100

    Add flag-checking test-and-branch tests
---
 tests/bmci.c | 32 ++++++++++++++++++++++++++++++++
 tests/bmcr.c | 37 +++++++++++++++++++++++++++++++++++++
 tests/bmsi.c | 32 ++++++++++++++++++++++++++++++++
 tests/bmsr.c | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 138 insertions(+)

diff --git a/tests/bmci.c b/tests/bmci.c
new file mode 100644
index 0000000..0ffe415
--- /dev/null
+++ b/tests/bmci.c
@@ -0,0 +1,32 @@
+#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_INTMAX };
+  jit_arg_t args[1];
+  const jit_anyreg_t regs[] = { { .gpr=JIT_R0 } };
+
+  jit_receive(j, 1, abi, args);
+  jit_load_args(j, 1, abi, args, regs);
+
+  jit_reloc_t r = jit_bmci(j, JIT_R0, 1);
+  jit_reti(j, 0);
+  jit_patch_here(j, r);
+  jit_reti(j, 1);
+
+  intmax_t (*f)(intmax_t) = jit_end(j, NULL);
+
+  ASSERT(f(0) == 1);
+  ASSERT(f(1) == 0);
+  ASSERT(f(-1) == 0);
+  ASSERT(f(2) == 1);
+}
+
+int
+main (int argc, char *argv[])
+{
+  return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bmcr.c b/tests/bmcr.c
new file mode 100644
index 0000000..03591fc
--- /dev/null
+++ b/tests/bmcr.c
@@ -0,0 +1,37 @@
+#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_INTMAX, JIT_ARG_ABI_INTMAX };
+  jit_arg_t args[2];
+  const jit_anyreg_t regs[] = { { .gpr=JIT_R0 }, { .gpr=JIT_R1 } };
+
+  jit_receive(j, 2, abi, args);
+  jit_load_args(j, 2, abi, args, regs);
+
+  jit_reloc_t r = jit_bmcr(j, JIT_R0, JIT_R1);
+  jit_reti(j, 0);
+  jit_patch_here(j, r);
+  jit_reti(j, 1);
+
+  intmax_t (*f)(intmax_t, intmax_t) = jit_end(j, NULL);
+
+  ASSERT(f(0, 0) == 1);
+  ASSERT(f(0, 1) == 1);
+  ASSERT(f(1, 0) == 1);
+  ASSERT(f(-1, 0) == 1);
+  ASSERT(f(0, -1) == 1);
+  ASSERT(f(1, 1) == 0);
+  ASSERT(f(1, -1) == 0);
+  ASSERT(f(-1, 1) == 0);
+  ASSERT(f(-1, -1) == 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+  return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bmsi.c b/tests/bmsi.c
new file mode 100644
index 0000000..21f986f
--- /dev/null
+++ b/tests/bmsi.c
@@ -0,0 +1,32 @@
+#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_INTMAX };
+  jit_arg_t args[1];
+  const jit_anyreg_t regs[] = { { .gpr=JIT_R0 } };
+
+  jit_receive(j, 1, abi, args);
+  jit_load_args(j, 1, abi, args, regs);
+
+  jit_reloc_t r = jit_bmsi(j, JIT_R0, 1);
+  jit_reti(j, 0);
+  jit_patch_here(j, r);
+  jit_reti(j, 1);
+
+  intmax_t (*f)(intmax_t) = jit_end(j, NULL);
+
+  ASSERT(f(0) == 0);
+  ASSERT(f(1) == 1);
+  ASSERT(f(-1) == 1);
+  ASSERT(f(2) == 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+  return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bmsr.c b/tests/bmsr.c
new file mode 100644
index 0000000..cd58951
--- /dev/null
+++ b/tests/bmsr.c
@@ -0,0 +1,37 @@
+#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_INTMAX, JIT_ARG_ABI_INTMAX };
+  jit_arg_t args[2];
+  const jit_anyreg_t regs[] = { { .gpr=JIT_R0 }, { .gpr=JIT_R1 } };
+
+  jit_receive(j, 2, abi, args);
+  jit_load_args(j, 2, abi, args, regs);
+
+  jit_reloc_t r = jit_bmsr(j, JIT_R0, JIT_R1);
+  jit_reti(j, 0);
+  jit_patch_here(j, r);
+  jit_reti(j, 1);
+
+  intmax_t (*f)(intmax_t, intmax_t) = jit_end(j, NULL);
+
+  ASSERT(f(0, 0) == 0);
+  ASSERT(f(0, 1) == 0);
+  ASSERT(f(1, 0) == 0);
+  ASSERT(f(-1, 0) == 0);
+  ASSERT(f(0, -1) == 0);
+  ASSERT(f(1, 1) == 1);
+  ASSERT(f(1, -1) == 1);
+  ASSERT(f(-1, 1) == 1);
+  ASSERT(f(-1, -1) == 1);
+}
+
+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]