aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/extasm.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2015-04-21 10:21:06 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2015-04-21 10:21:06 +0200
commit426881cde464691b61c5c49cf5038d21aace75fe (patch)
tree0817d5fe4d5d51abd793e471f73f0ad9de3f2228 /test/regression/extasm.c
parent1b5db339bb05f773a6a132be4c0b8cea54d50461 (diff)
downloadcompcert-kvx-426881cde464691b61c5c49cf5038d21aace75fe.tar.gz
compcert-kvx-426881cde464691b61c5c49cf5038d21aace75fe.zip
Support for GCC-style extended asm, continued:
- support "r", "m" and "i" constraints - support "%Q" and "%R" modifiers for register pairs - support register clobbers - split off analysis and transformation of asm statements in cparser/ExtendedAsm.ml
Diffstat (limited to 'test/regression/extasm.c')
-rw-r--r--test/regression/extasm.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/regression/extasm.c b/test/regression/extasm.c
new file mode 100644
index 00000000..a69b3e79
--- /dev/null
+++ b/test/regression/extasm.c
@@ -0,0 +1,70 @@
+/* Testing extended asm.
+ To run the test, compile with -S and grep "TEST" in the generated .s */
+
+int clobbers(int x)
+{
+ int y;
+ asm("TEST0 out:%0 in:%1" : "=r"(y) : "r"(x) : "cc"
+#if defined(__i386__)
+ , "eax", "edx", "ecx"
+#elif defined(__arm__)
+ , "r0", "r1", "r2"
+#elif defined(__PPC__)
+ , "r3", "r4", "r5"
+#endif
+);
+ return y;
+}
+
+int main()
+{
+ int x;
+ void * y;
+ long long z;
+ double f;
+ char c[16];
+
+ /* No inputs, no outputs */
+ asm("TEST1 %%");
+ /* r inputs */
+ asm("TEST2 in:%0" : : "r" (x));
+ asm("TEST3 in:%0,%1" : : "r" (x), "r" (f));
+ /* r output */
+ asm("TEST4 out:%0" : "=r" (x));
+ /* r inputs and outputs */
+ asm("TEST5 out:%0 in:%1" : "=r" (f) : "r" (y));
+ /* m inputs */
+ asm("TEST6 in:%0" : : "m" (c[2]));
+ asm("TEST7 out:%0 in:%1,%2" : "=r"(x) : "m" (c[0]), "r" (y));
+ /* m output */
+ asm("TEST8 out:%0 in:%1" : "=m" (c[4]) : "r" (f));
+ /* i input */
+ asm("TEST9 in:%0,%1,%2" : : "r"(x), "i"(sizeof(x) + 2), "r"(y));
+#ifdef FAILURES
+ asm("FAIL1 in:%0" : : "i"(x));
+#endif
+ /* 64-bit output */
+ asm("TEST10 out: high %R0,lo %Q0" : "=r" (z));
+ /* 64-bit input */
+ asm("TEST11 out:%0 in:%1,high %R2,lo %Q2,%3"
+ : "=r"(x) : "r"(y), "r"(z), "r"(f));
+#ifdef FAILURES
+ asm("FAIL2 out:%0" : "=r"(z));
+ asm("FAIL3 in:%0" : : "r"(z));
+#endif
+ /* Named arguments */
+ asm("TEST12 a:%[a] b:%[b] c:%[c]" : : [a]"i"(12), [b]"i"(34), [c]"i"(56));
+ asm("TEST13 a:%[a] x:%[x]" : [x]"=r"(x) : [a]"i"(78));
+ asm("TEST14 a:%[a] in2:%1 c:%[c]" : : [a]"i"(12), "i"(34), [c]"i"(56));
+#ifdef FAILURES
+ asm("FAIL4 a:%[a]" : "=r"(x) : [z]"i"(0));
+#endif
+ /* Various failures */
+#ifdef FAILURES
+ asm("FAIL5 out:%0,%1" : "=r"(x), "=r"(y));
+ asm("FAIL6 in:%0" : : "g"(x));
+ asm("FAIL7 out:%0" : "=r" (x+1));
+#endif
+ return 0;
+}
+