summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/fixed-point/noassoc.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/fixed-point/noassoc.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/fixed-point/noassoc.c')
-rw-r--r--gcc/testsuite/gcc.dg/fixed-point/noassoc.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/fixed-point/noassoc.c b/gcc/testsuite/gcc.dg/fixed-point/noassoc.c
new file mode 100644
index 000000000..5d134e158
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fixed-point/noassoc.c
@@ -0,0 +1,53 @@
+/* { dg-do run } */
+/* { dg-options "-std=gnu99 -O0" } */
+
+extern void abort (void);
+
+/* Make sure GCC knows there is no associativity for saturating types. */
+
+/* Don't transform to (temp + (0.5r + 0.8r)) */
+_Sat _Fract add_test (_Sat _Fract temp)
+{
+ return temp + 0.5r + 0.8r;
+}
+
+/* Don't transform to (temp * ((-0.5r - 0.5r) * (-0.5r - 0.5r))) */
+_Sat _Fract mul_test (_Sat _Fract temp)
+{
+ return temp * (-0.5r - 0.5r) * (-0.5r - 0.5r);
+}
+
+/* Don't transform to ((temp1 + temp2) * 0.5r) */
+_Sat _Fract mul_add_test (_Sat _Fract temp1, _Sat _Fract temp2)
+{
+ return temp1 * 0.5r + temp2 * 0.5r;
+}
+
+/* Don't transform to ((temp1 - temp2) * 0.5r) */
+_Sat _Fract mul_sub_test (_Sat _Fract temp1, _Sat _Fract temp2)
+{
+ return temp1 * 0.5r - temp2 * 0.5r;
+}
+
+int main ()
+{
+ _Sat _Fract a;
+
+ a = add_test (-0.5r);
+ if (a != 0.8r)
+ abort ();
+
+ a = mul_test (0.1r);
+ if (a != 0.1r)
+ abort ();
+
+ a = mul_add_test (0.75r, 0.5r);
+ if (a != 0.625r)
+ abort ();
+
+ a = mul_sub_test (0.75r, -0.5r);
+ if (a != 0.625r)
+ abort ();
+
+ return 0;
+}