RISC-V: Add testcase for testing li pseudo instruction
authorKito Cheng <kito.cheng@sifive.com>
Mon, 26 Aug 2019 02:15:47 +0000 (02:15 +0000)
committerKito Cheng <kito@gcc.gnu.org>
Mon, 26 Aug 2019 02:15:47 +0000 (02:15 +0000)
gcc/testsuite/ChangeLog:

gcc.target/riscv/li.c: New test.

From-SVN: r274920

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/riscv/li.c [new file with mode: 0644]

index 08e48c3e5504e40d1b9a7116240765996753d272..dd4d9b7b631b3b5c48a0f380b79f8c9697892ed1 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-26  Kito Cheng  <kito.cheng@sifive.com>
+
+       * gcc.target/riscv/li.c: New test.
+
 2019-08-24  Nathan Sidwell  <nathan@acm.org>
 
        * g++.dg/inherit/virtual14.C: New.
diff --git a/gcc/testsuite/gcc.target/riscv/li.c b/gcc/testsuite/gcc.target/riscv/li.c
new file mode 100644 (file)
index 0000000..fa5c02c
--- /dev/null
@@ -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;
+}