[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 37/86: Tests for some div operations
From: |
Andy Wingo |
Subject: |
[Guile-commits] 37/86: Tests for some div operations |
Date: |
Wed, 3 Apr 2019 11:38:55 -0400 (EDT) |
wingo pushed a commit to branch lightening
in repository guile.
commit b371e913ffd5c3198ff77312051c900dac54e0cd
Author: Andy Wingo <address@hidden>
Date: Mon Mar 25 21:11:44 2019 +0100
Tests for some div operations
---
.gitignore | 2 ++
tests/test-divr.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test-divr_u.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+)
diff --git a/.gitignore b/.gitignore
index 24586fc..5c0fa51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,5 @@
/tests/test-subx
/tests/test-qmulr
/tests/test-qmulr_u
+/tests/test-divr
+/tests/test-divr_u
diff --git a/tests/test-divr.c b/tests/test-divr.c
new file mode 100644
index 0000000..389a69d
--- /dev/null
+++ b/tests/test-divr.c
@@ -0,0 +1,63 @@
+#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_divr(j, JIT_R0, JIT_R0, JIT_R1);
+ jit_retr(j, JIT_R0);
+
+ size_t size = 0;
+ void* ret = jit_end(j, &size);
+
+ intmax_t (*f)(intmax_t, intmax_t) = ret;
+
+ ASSERT(f(0x7fffffff, 1) == 0x7fffffff);
+ ASSERT(f(1, 0x7fffffff) == 0);
+ ASSERT(f(0x80000000, 1) == 0x80000000);
+ ASSERT(f(1, 0x80000000) == 0);
+ ASSERT(f(0x7fffffff, 2) == 0x3fffffff);
+ ASSERT(f(2, 0x7fffffff) == 0);
+ ASSERT(f(2, 0x80000000) == 0);
+ ASSERT(f(0x7fffffff, 0x80000000) == 0);
+ ASSERT(f(0, 0x7fffffff) == 0);
+ ASSERT(f(0xffffffff, 0xffffffff) == 1);
+#if __WORDSIZE == 32
+ ASSERT(f(0x80000000, 2) == 0xc0000000);
+ ASSERT(f(0x80000000, 0x7fffffff) == 0xffffffff);
+ ASSERT(f(0x7fffffff, 0xffffffff) == 0x80000001);
+ ASSERT(f(0xffffffff, 0x7fffffff) == 0);
+#else
+ ASSERT(f(0x80000000, 2) == 0x40000000);
+ ASSERT(f(0x80000000, 0x7fffffff) == 1);
+ ASSERT(f(0x7fffffff, 0xffffffff) == 0);
+ ASSERT(f(0xffffffff, 0x7fffffff) == 2);
+ ASSERT(f(0x7fffffffffffffff, 1) == 0x7fffffffffffffff);
+ ASSERT(f(1, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x8000000000000000, 1) == 0x8000000000000000);
+ ASSERT(f(1, 0x8000000000000000) == 0);
+ ASSERT(f(0x7fffffffffffffff, 2) == 0x3fffffffffffffff);
+ ASSERT(f(2, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x8000000000000000, 2) == 0xc000000000000000);
+ ASSERT(f(2, 0x8000000000000000) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0);
+ ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 0xffffffffffffffff);
+ ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0x8000000000000001);
+ ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 1);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/test-divr_u.c b/tests/test-divr_u.c
new file mode 100644
index 0000000..177c609
--- /dev/null
+++ b/tests/test-divr_u.c
@@ -0,0 +1,58 @@
+#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_divr_u(j, JIT_R0, JIT_R0, JIT_R1);
+ jit_retr(j, JIT_R0);
+
+ size_t size = 0;
+ void* ret = jit_end(j, &size);
+
+ intmax_t (*f)(intmax_t, intmax_t) = ret;
+
+ ASSERT(f(0x7fffffff, 1) == 0x7fffffff);
+ ASSERT(f(1, 0x7fffffff) == 0);
+ ASSERT(f(0x80000000, 1) == 0x80000000);
+ ASSERT(f(1, 0x80000000) == 0);
+ ASSERT(f(0x7fffffff, 2) == 0x3fffffff);
+ ASSERT(f(2, 0x7fffffff) == 0);
+ ASSERT(f(0x80000000, 2) == 0x40000000);
+ ASSERT(f(2, 0x80000000) == 0);
+ ASSERT(f(0x7fffffff, 0x80000000) == 0);
+ ASSERT(f(0x80000000, 0x7fffffff) == 1);
+ ASSERT(f(0, 0x7fffffff) == 0);
+ ASSERT(f(0x7fffffff, 0xffffffff) == 0);
+ ASSERT(f(0xffffffff, 0x7fffffff) == 2);
+ ASSERT(f(0xffffffff, 0xffffffff) == 1);
+#if __WORDSIZE != 32
+ ASSERT(f(0x7fffffffffffffff, 1) == 0x7fffffffffffffff);
+ ASSERT(f(1, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x8000000000000000, 1) == 0x8000000000000000);
+ ASSERT(f(1, 0x8000000000000000) == 0);
+ ASSERT(f(0x7fffffffffffffff, 2) == 0x3fffffffffffffff);
+ ASSERT(f(2, 0x7fffffffffffffff) == 0);
+ ASSERT(f(0x8000000000000000, 2) == 0x4000000000000000);
+ ASSERT(f(2, 0x8000000000000000) == 0);
+ ASSERT(f(0x7fffffffffffffff, 0x8000000000000000) == 0);
+ ASSERT(f(0x8000000000000000, 0x7fffffffffffffff) == 1);
+ ASSERT(f(0x7fffffffffffffff, 0xffffffffffffffff) == 0);
+ ASSERT(f(0xffffffffffffffff, 0x7fffffffffffffff) == 2);
+ ASSERT(f(0xffffffffffffffff, 0xffffffffffffffff) == 1);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
- [Guile-commits] 33/86: Flesh out README, (continued)
- [Guile-commits] 33/86: Flesh out README, Andy Wingo, 2019/04/03
- [Guile-commits] 36/86: Add more tests, Andy Wingo, 2019/04/03
- [Guile-commits] 18/86: Add endian.h, Andy Wingo, 2019/04/03
- [Guile-commits] 30/86: Add "addi" test, Andy Wingo, 2019/04/03
- [Guile-commits] 31/86: Better loading of args to registers; add tests, Andy Wingo, 2019/04/03
- [Guile-commits] 26/86: Inline private.h into jit.c, Andy Wingo, 2019/04/03
- [Guile-commits] 32/86: Convert tests to jit_load_args, Andy Wingo, 2019/04/03
- [Guile-commits] 34/86: Add note about current status, Andy Wingo, 2019/04/03
- [Guile-commits] 14/86: Simplify file names, Andy Wingo, 2019/04/03
- [Guile-commits] 39/86: Add remr tests, Andy Wingo, 2019/04/03
- [Guile-commits] 37/86: Tests for some div operations,
Andy Wingo <=
- [Guile-commits] 35/86: Add new tests, Andy Wingo, 2019/04/03
- [Guile-commits] 28/86: Beginnings of port of x86 to new design, Andy Wingo, 2019/04/03
- [Guile-commits] 44/86: Add mov_addr test, Andy Wingo, 2019/04/03
- [Guile-commits] 38/86: Add more div tests, Andy Wingo, 2019/04/03
- [Guile-commits] 52/86: Add sti tests, Andy Wingo, 2019/04/03
- [Guile-commits] 47/86: Add ldr tests, Andy Wingo, 2019/04/03
- [Guile-commits] 46/86: Add bswap tests, and fix missing breaks in jit_load_args, Andy Wingo, 2019/04/03
- [Guile-commits] 50/86: Add ldxi tests, Andy Wingo, 2019/04/03
- [Guile-commits] 41/86: Add lsh/rsh tests, Andy Wingo, 2019/04/03
- [Guile-commits] 15/86: Remove unneeded bits of lightning, Andy Wingo, 2019/04/03