[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 66/86: Add sub-and-branch-on-overflow tests
From: |
Andy Wingo |
Subject: |
[Guile-commits] 66/86: Add sub-and-branch-on-overflow tests |
Date: |
Wed, 3 Apr 2019 11:39:02 -0400 (EDT) |
wingo pushed a commit to branch lightening
in repository guile.
commit 8a8273c45c975ec218d0f36c934b7a47a04e1bbc
Author: Andy Wingo <address@hidden>
Date: Tue Mar 26 16:09:07 2019 +0100
Add sub-and-branch-on-overflow tests
---
tests/bosubi.c | 43 +++++++++++++++++++++++++++++++++++++++++++
tests/bosubi_u.c | 39 +++++++++++++++++++++++++++++++++++++++
tests/bosubr.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/bosubr_u.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
tests/bxsubi.c | 42 ++++++++++++++++++++++++++++++++++++++++++
tests/bxsubi_u.c | 38 ++++++++++++++++++++++++++++++++++++++
tests/bxsubr.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
tests/bxsubr_u.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 354 insertions(+)
diff --git a/tests/bosubi.c b/tests/bosubi.c
new file mode 100644
index 0000000..b645140
--- /dev/null
+++ b/tests/bosubi.c
@@ -0,0 +1,43 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bosubi(j, JIT_R0, 1);
+ jit_retr(j, JIT_R0);
+ jit_patch_here(j, r);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(-1) == -2);
+ ASSERT(f(0) == -1);
+ ASSERT(f(1) == 0);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0x7fffffff) == 0x7ffffffe);
+ ASSERT(f(0x80000000) == overflowed);
+ ASSERT(f(0x80000001) == 0x80000000);
+#else
+ ASSERT(f(0x7fffffffffffffff) == 0x7ffffffffffffffe);
+ ASSERT(f(0x8000000000000000) == overflowed);
+ ASSERT(f(0x8000000000000001) == 0x8000000000000000);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bosubi_u.c b/tests/bosubi_u.c
new file mode 100644
index 0000000..76a7d67
--- /dev/null
+++ b/tests/bosubi_u.c
@@ -0,0 +1,39 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bosubi_u(j, JIT_R0, 1);
+ jit_retr(j, JIT_R0);
+ jit_patch_here(j, r);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(-1) == -2);
+ ASSERT(f(0) == overflowed);
+ ASSERT(f(1) == 0);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0x80000000) == 0x7fffffff);
+#else
+ ASSERT(f(0x8000000000000000) == 0x7fffffffffffffff);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bosubr.c b/tests/bosubr.c
new file mode 100644
index 0000000..e79c10b
--- /dev/null
+++ b/tests/bosubr.c
@@ -0,0 +1,49 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bosubr(j, JIT_R0, JIT_R1);
+ jit_retr(j, JIT_R0);
+ jit_patch_here(j, r);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t, intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(0, 0) == 0);
+ ASSERT(f(0, 1) == -1);
+ ASSERT(f(1, 1) == 0);
+ ASSERT(f(1, -1) == 2);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0xffffffff, 0xffffffff) == 0);
+ ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
+ ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
+ ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
+ ASSERT(f(0x80000000, 0x7fffffff) == overflowed);
+ ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
+ ASSERT(f(0x80000000, 0x80000000) == 0);
+#else
+ ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
+ ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == overflowed);
+ ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bosubr_u.c b/tests/bosubr_u.c
new file mode 100644
index 0000000..ad55af3
--- /dev/null
+++ b/tests/bosubr_u.c
@@ -0,0 +1,48 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bosubr_u(j, JIT_R0, JIT_R1);
+ jit_retr(j, JIT_R0);
+ jit_patch_here(j, r);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t, intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(0, 0) == 0);
+ ASSERT(f(1, 1) == 0);
+ ASSERT(f(0, 1) == overflowed);
+ ASSERT(f(1, 0) == 1);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0xffffffff, 0xffffffff) == 0);
+ ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
+ ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
+ ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
+ ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
+ ASSERT(f(0x80000000, 0x80000000) == 0);
+#else
+ ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
+ ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bxsubi.c b/tests/bxsubi.c
new file mode 100644
index 0000000..83669ac
--- /dev/null
+++ b/tests/bxsubi.c
@@ -0,0 +1,42 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bxsubi(j, JIT_R0, 1);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_patch_here(j, r);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(-1) == -2);
+ ASSERT(f(0) == -1);
+ ASSERT(f(1) == 0);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0x7fffffff) == 0x7ffffffe);
+ ASSERT(f(0x80000000) == overflowed);
+ ASSERT(f(0x80000001) == 0x80000000);
+#else
+ ASSERT(f(0x7fffffffffffffff) == 0x7ffffffffffffffe);
+ ASSERT(f(0x8000000000000000) == overflowed);
+ ASSERT(f(0x8000000000000001) == 0x8000000000000000);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bxsubi_u.c b/tests/bxsubi_u.c
new file mode 100644
index 0000000..5d09727
--- /dev/null
+++ b/tests/bxsubi_u.c
@@ -0,0 +1,38 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bxsubi_u(j, JIT_R0, 1);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_patch_here(j, r);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(-1) == -2);
+ ASSERT(f(0) == overflowed);
+ ASSERT(f(1) == 0);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0x80000000) == 0x7fffffff);
+#else
+ ASSERT(f(0x8000000000000000) == 0x7fffffffffffffff);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bxsubr.c b/tests/bxsubr.c
new file mode 100644
index 0000000..aa99db9
--- /dev/null
+++ b/tests/bxsubr.c
@@ -0,0 +1,48 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bxsubr(j, JIT_R0, JIT_R1);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_patch_here(j, r);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t, intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(0, 0) == 0);
+ ASSERT(f(0, 1) == -1);
+ ASSERT(f(1, 1) == 0);
+ ASSERT(f(1, -1) == 2);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0xffffffff, 0xffffffff) == 0);
+ ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
+ ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
+ ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
+ ASSERT(f(0x80000000, 0x7fffffff) == overflowed);
+ ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
+ ASSERT(f(0x80000000, 0x80000000) == 0);
+#else
+ ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
+ ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == overflowed);
+ ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/bxsubr_u.c b/tests/bxsubr_u.c
new file mode 100644
index 0000000..f476c24
--- /dev/null
+++ b/tests/bxsubr_u.c
@@ -0,0 +1,47 @@
+#include "test.h"
+
+static const intmax_t overflowed = 0xcabba9e5;
+
+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_bxsubr_u(j, JIT_R0, JIT_R1);
+ jit_movi(j, JIT_R0, overflowed);
+ jit_patch_here(j, r);
+ jit_retr(j, JIT_R0);
+
+ intmax_t (*f)(intmax_t, intmax_t) = jit_end(j, NULL);
+
+ ASSERT(f(0, 0) == 0);
+ ASSERT(f(1, 1) == 0);
+ ASSERT(f(0, 1) == overflowed);
+ ASSERT(f(1, 0) == 1);
+
+#if __WORDSIZE == 32
+ ASSERT(f(0xffffffff, 0xffffffff) == 0);
+ ASSERT(f(0x7fffffff, 0) == 0x7fffffff);
+ ASSERT(f(0x7fffffff, 1) == 0x7ffffffe);
+ ASSERT(f(0x7fffffff, 0x7fffffff) == 0);
+ ASSERT(f(0x7fffffff, 0x80000000) == overflowed);
+ ASSERT(f(0x80000000, 0x80000000) == 0);
+#else
+ ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == overflowed);
+ ASSERT(f(0x8000000000000000, 0x8000000000000000) == 0);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
- [Guile-commits] 48/86: Add ldi tests, (continued)
- [Guile-commits] 48/86: Add ldi tests, Andy Wingo, 2019/04/03
- [Guile-commits] 57/86: Fix stxi_d bug, Andy Wingo, 2019/04/03
- [Guile-commits] 49/86: Add ldxr tests, Andy Wingo, 2019/04/03
- [Guile-commits] 61/86: Add int/int reg/imm compare-and-branch tests, Andy Wingo, 2019/04/03
- [Guile-commits] 63/86: Add unordered float compare-and-branch tests, Andy Wingo, 2019/04/03
- [Guile-commits] 53/86: Add stxr tests, Andy Wingo, 2019/04/03
- [Guile-commits] 56/86: Tweak test build to run faster, and adapt CI, Andy Wingo, 2019/04/03
- [Guile-commits] 40/86: Add bitops tests, Andy Wingo, 2019/04/03
- [Guile-commits] 78/86: Clean up stack after calls, Andy Wingo, 2019/04/03
- [Guile-commits] 75/86: get_temp_{gpr, xpr} returns a jit_{gpr, fpr}_t, Andy Wingo, 2019/04/03
- [Guile-commits] 66/86: Add sub-and-branch-on-overflow tests,
Andy Wingo <=
- [Guile-commits] 73/86: Add movi_[df] tests, Andy Wingo, 2019/04/03
- [Guile-commits] 64/86: Add flag-checking test-and-branch tests, Andy Wingo, 2019/04/03
- [Guile-commits] 69/86: Add abs/sqrt tests, Andy Wingo, 2019/04/03
- [Guile-commits] 67/86: Add some nop and jmp tests, and fix a hazard with jmpi/calli, Andy Wingo, 2019/04/03
- [Guile-commits] 62/86: Add anti-float comparison tests, Andy Wingo, 2019/04/03
- [Guile-commits] 51/86: Add str tests, Andy Wingo, 2019/04/03
- [Guile-commits] 58/86: Add bltr test, Andy Wingo, 2019/04/03
- [Guile-commits] 65/86: Add add-and-branch-on-overflow tests, Andy Wingo, 2019/04/03
- [Guile-commits] 59/86: Add more integer reg/reg branch-and-compare tests, Andy Wingo, 2019/04/03
- [Guile-commits] 80/86: Add subdir-objects option to libguile makefile., Andy Wingo, 2019/04/03