summaryrefslogtreecommitdiff
path: root/test/regression/compar.c
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-10-06 15:46:47 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-10-06 15:46:47 +0000
commitf7693b3d897b90fd3bc2533be002dc0bdcd9f6c2 (patch)
tree93ea9491693324d2d690c4236a2c88c3b461e225 /test/regression/compar.c
parent261ef24f7fd2ef443f73c468b9b1fa496371f3bf (diff)
Merge of branch seq-and-or. See Changelog for details.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2059 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/regression/compar.c')
-rw-r--r--test/regression/compar.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/regression/compar.c b/test/regression/compar.c
new file mode 100644
index 0000000..14ce34b
--- /dev/null
+++ b/test/regression/compar.c
@@ -0,0 +1,80 @@
+/* Code generation for comparisons */
+
+#include <stdio.h>
+
+unsigned int f(int x, unsigned int y, char * z)
+{
+ unsigned int r = 0;
+
+ /* Without explicit comparison */
+ if (x) r |= 1;
+ if (y) r |= 2;
+ if (z) r |= 4;
+
+ /* Negated comparisons */
+ if (!x) r |= 8;
+ if (!y) r |= 0x10;
+ if (!z) r |= 0x20;
+
+ /* Explicit comparisons against 0 */
+ if (x == 0) r |= 0x40;
+ if (y == 0) r |= 0x80;
+ if (z == 0) r |= 0x100;
+
+ if (x != 0) r |= 0x200;
+ if (y != 0) r |= 0x400;
+ if (z != 0) r |= 0x800;
+
+ /* With masks */
+ if (x & 1) r |= 0x1000;
+ if (!(x & 2)) r |= 0x2000;
+ if ((x & 4) == 0) r |= 0x4000;
+ if ((x & 8) != 0) r |= 0x8000;
+
+ return r;
+}
+
+/* Same, but we compute the boolean value of the tests */
+
+unsigned int g(int x, unsigned int y, char * z)
+{
+ unsigned int r = 0;
+
+#define MERGE(tst) r = (r << 1) | (tst)
+
+ /* Without explicit comparison */
+ MERGE((_Bool) x);
+ MERGE((_Bool) y);
+ MERGE((_Bool) z);
+
+ /* Negated comparisons */
+ MERGE((_Bool) !x);
+ MERGE((_Bool) !y);
+ MERGE((_Bool) !z);
+
+ /* Explicit comparisons against 0 */
+ MERGE(x == 0);
+ MERGE(y == 0);
+ MERGE(z == 0);
+
+ MERGE(x != 0);
+ MERGE(y != 0);
+ MERGE(z != 0);
+
+ /* With masks */
+ MERGE((_Bool) (x & 1));
+ MERGE(! (x & 2));
+ MERGE((x & 4) == 0);
+ MERGE((x & 8) != 0);
+
+ return r;
+}
+
+int main(void)
+{
+ printf("f(0, 0, 0) = 0x%x\n", f(0, 0, 0));
+ printf("g(0, 0, 0) = 0x%x\n", g(0, 0, 0));
+ printf("f(12, 1, \"x\") = 0x%x\n", f(12, 1, "x"));
+ printf("g(12, 1, \"x\") = 0x%x\n", g(12, 1, "x"));
+ return 0;
+}