This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] RISC-V: Add testcase for testing li pseudo instruction
- From: Kito Cheng <kito dot cheng at sifive dot com>
- To: gcc-patches at gcc dot gnu dot org, kito dot cheng at gmail dot com, jimw at sifive dot com
- Cc: Kito Cheng <kito dot cheng at sifive dot com>
- Date: Fri, 23 Aug 2019 15:13:02 +0800
- Subject: [PATCH] RISC-V: Add testcase for testing li pseudo instruction
gcc/testsuite/ChangeLog:
gcc.target/riscv/li.c: New test.
---
gcc/testsuite/gcc.target/riscv/li.c | 36 +++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/riscv/li.c
diff --git a/gcc/testsuite/gcc.target/riscv/li.c b/gcc/testsuite/gcc.target/riscv/li.c
new file mode 100644
index 00000000000..fa5c02caee8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/li.c
@@ -0,0 +1,36 @@
+/* { dg-do run } */
+/* { dg-options "-O1" } */
+#include <stdlib.h>
+#define LOAD_IMM(var, val) \
+ asm ("li %0, %1\n": "=r"(var): "i" (val))
+
+#define CHECK_LI(type, val) \
+ { \
+ type var; \
+ LOAD_IMM(var, val); \
+ if (var != val) \
+ abort(); \
+ }
+
+#define CHECK_LI32(val) CHECK_LI(int, val)
+#define CHECK_LI64(val) CHECK_LI(long long, val)
+
+int main()
+{
+ CHECK_LI32(0x8001);
+ CHECK_LI32(0x1f01);
+ CHECK_LI32(0x12345001);
+ CHECK_LI32(0xf2345001);
+#if __riscv_xlen == 64
+ CHECK_LI64(0x8001ll);
+ CHECK_LI64(0x1f01ll);
+ CHECK_LI64(0x12345001ll);
+ CHECK_LI64(0xf2345001ll);
+ CHECK_LI64(0xf12345001ll);
+ CHECK_LI64(0xff00ff00ff001f01ll);
+ CHECK_LI64(0x7ffffffff2345001ll);
+ CHECK_LI64(0x7f0f243ff2345001ll);
+ CHECK_LI64(0x1234567887654321ll);
+#endif
+ return 0;
+}
--
2.17.1