[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 36/86: Add more tests
From: |
Andy Wingo |
Subject: |
[Guile-commits] 36/86: Add more tests |
Date: |
Wed, 3 Apr 2019 11:38:55 -0400 (EDT) |
wingo pushed a commit to branch lightening
in repository guile.
commit 56d8f8d6f0a50676dcdd5adfbb3d9b85e7e4c313
Author: Andy Wingo <address@hidden>
Date: Mon Mar 25 21:02:24 2019 +0100
Add more tests
---
.gitignore | 2 ++
jit.h | 48 +++++++++++++++---------------
tests/test-qmulr.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test-qmulr_u.c | 70 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 178 insertions(+), 24 deletions(-)
diff --git a/.gitignore b/.gitignore
index 6e242f3..24586fc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,5 @@
/tests/test-subr_d
/tests/test-subr_f
/tests/test-subx
+/tests/test-qmulr
+/tests/test-qmulr_u
diff --git a/jit.h b/jit.h
index 3b14591..4d89d5f 100644
--- a/jit.h
+++ b/jit.h
@@ -483,31 +483,31 @@ FOR_EACH_INSTRUCTION(DECLARE_INSTRUCTION)
#undef DECLARE_INSTRUCTION
#if __WORDSIZE == 32
-# define jit_ldr(u,v) jit_ldr_i(u,v)
-# define jit_ldi(u,v) jit_ldi_i(u,v)
-# define jit_ldxr(u,v,w) jit_ldxr_i(u,v,w)
-# define jit_ldxi(u,v,w) jit_ldxi_i(u,v,w)
-# define jit_str(u,v) jit_str_i(u,v)
-# define jit_sti(u,v) jit_sti_i(u,v)
-# define jit_stxr(u,v,w) jit_stxr_i(u,v,w)
-# define jit_stxi(u,v,w) jit_stxi_i(u,v,w)
-# define jit_retval(u) jit_retval_i(u)
-# define jit_bswapr(u,v) jit_bswapr_ui(u,v)
-# define jit_truncr_d(u,v) jit_truncr_d_i(u,v)
-# define jit_truncr_f(u,v) jit_truncr_f_i(u,v)
+# define jit_ldr(j,u,v) jit_ldr_i(j,u,v)
+# define jit_ldi(j,u,v) jit_ldi_i(j,u,v)
+# define jit_ldxr(j,u,v,w) jit_ldxr_i(j,u,v,w)
+# define jit_ldxi(j,u,v,w) jit_ldxi_i(j,u,v,w)
+# define jit_str(j,u,v) jit_str_i(j,u,v)
+# define jit_sti(j,u,v) jit_sti_i(j,u,v)
+# define jit_stxr(j,u,v,w) jit_stxr_i(j,u,v,w)
+# define jit_stxi(j,u,v,w) jit_stxi_i(j,u,v,w)
+# define jit_retval(j,u) jit_retval_i(j,u)
+# define jit_bswapr(j,u,v) jit_bswapr_ui(j,u,v)
+# define jit_truncr_d(j,u,v) jit_truncr_d_i(j,u,v)
+# define jit_truncr_f(j,u,v) jit_truncr_f_i(j,u,v)
#else
-# define jit_ldr(u,v) jit_ldr_l(u,v)
-# define jit_ldi(u,v) jit_ldi_l(u,v)
-# define jit_ldxr(u,v,w) jit_ldxr_l(u,v,w)
-# define jit_ldxi(u,v,w) jit_ldxi_l(u,v,w)
-# define jit_str(u,v) jit_str_l(u,v)
-# define jit_sti(u,v) jit_sti_l(u,v)
-# define jit_stxr(u,v,w) jit_stxr_l(u,v,w)
-# define jit_stxi(u,v,w) jit_stxi_l(u,v,w)
-# define jit_retval(u) jit_retval_l(u)
-# define jit_bswapr(u,v) jit_bswapr_ul(u,v)
-# define jit_truncr_d(u,v) jit_truncr_d_l(u,v)
-# define jit_truncr_f(u,v) jit_truncr_f_l(u,v)
+# define jit_ldr(j,u,v) jit_ldr_l(j,u,v)
+# define jit_ldi(j,u,v) jit_ldi_l(j,u,v)
+# define jit_ldxr(j,u,v,w) jit_ldxr_l(j,u,v,w)
+# define jit_ldxi(j,u,v,w) jit_ldxi_l(j,u,v,w)
+# define jit_str(j,u,v) jit_str_l(j,u,v)
+# define jit_sti(j,u,v) jit_sti_l(j,u,v)
+# define jit_stxr(j,u,v,w) jit_stxr_l(j,u,v,w)
+# define jit_stxi(j,u,v,w) jit_stxi_l(j,u,v,w)
+# define jit_retval(j,u) jit_retval_l(j,u)
+# define jit_bswapr(j,u,v) jit_bswapr_ul(j,u,v)
+# define jit_truncr_d(j,u,v) jit_truncr_d_l(j,u,v)
+# define jit_truncr_f(j,u,v) jit_truncr_f_l(j,u,v)
#endif
#endif /* _jit_h */
diff --git a/tests/test-qmulr.c b/tests/test-qmulr.c
new file mode 100644
index 0000000..279045c
--- /dev/null
+++ b/tests/test-qmulr.c
@@ -0,0 +1,82 @@
+#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_qmulr(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 QMUL(a, b, c, d) \
+ do { \
+ intmax_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); ASSERT(D == d); \
+ } while (0)
+
+ QMUL(-2, -1, 2, 0);
+ QMUL(0, -1, 0, 0);
+ QMUL(-1, 0, 0, 0);
+ QMUL(1, -1, -1, -1);
+#if __WORDSIZE == 32
+ QMUL(0x7ffff, 0x7ffff, 0xfff00001, 0x3f);
+ QMUL(0x80000000, -2, 0, 1);
+ QMUL(0x80000000, 2, 0, -1);
+ QMUL(0x80000001, 3, 0x80000003, -2);
+ QMUL(0x80000001, -3, 0x7ffffffd, 1);
+#else
+ QMUL(0x7ffffffff, 0x7ffffffff, 0xfffffff000000001, 0x3f);
+ QMUL(0x8000000000000000, -2, 0, 1);
+ QMUL(0x8000000000000000, 2, 0, -1);
+ QMUL(0x8000000000000001, 3, 0x8000000000000003, -2);
+ QMUL(0x8000000000000001, -3, 0x7ffffffffffffffd, 1);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
diff --git a/tests/test-qmulr_u.c b/tests/test-qmulr_u.c
new file mode 100644
index 0000000..6b8121c
--- /dev/null
+++ b/tests/test-qmulr_u.c
@@ -0,0 +1,70 @@
+#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_qmulr_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 UQMUL(a, b, c, d) \
+ do { \
+ intmax_t C = 0, D = 0; f(&C, &D, a, b); ASSERT(C == c); ASSERT(D == d); \
+ } while (0)
+
+#if __WORDSIZE == 32
+ UQMUL(0xffffff, 0xffffff, 0xfe000001, 0xffff);
+#else
+ UQMUL(0xffffffffff, 0xffffffffff, 0xfffffe0000000001, 0xffff);
+#endif
+}
+
+int
+main (int argc, char *argv[])
+{
+ return main_helper(argc, argv, run_test);
+}
- [Guile-commits] 04/86: Remove example .c files from documentation, (continued)
- [Guile-commits] 04/86: Remove example .c files from documentation, Andy Wingo, 2019/04/03
- [Guile-commits] 23/86: Update gitignore, Andy Wingo, 2019/04/03
- [Guile-commits] 03/86: Strip "get-jit-size" feature from lightning., Andy Wingo, 2019/04/03
- [Guile-commits] 25/86: Remove needless PUBLIC/HIDDEN definitions, Andy Wingo, 2019/04/03
- [Guile-commits] 19/86: Update call/receive machinery, Andy Wingo, 2019/04/03
- [Guile-commits] 10/86: Remove autotools, Andy Wingo, 2019/04/03
- [Guile-commits] 21/86: "extern"-related cleanup, and further implementation, Andy Wingo, 2019/04/03
- [Guile-commits] 27/86: Make _rvs array static-const, Andy Wingo, 2019/04/03
- [Guile-commits] 11/86: Rename include to jit.h, move all files to jit/, Andy Wingo, 2019/04/03
- [Guile-commits] 33/86: Flesh out README, Andy Wingo, 2019/04/03
- [Guile-commits] 36/86: Add more tests,
Andy Wingo <=
- [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, 2019/04/03
- [Guile-commits] 35/86: Add new tests, Andy Wingo, 2019/04/03