Imported Upstream version 4.7.3
[platform/upstream/gcc48.git] / gcc / testsuite / gcc.dg / vect / fast-math-bb-slp-call-3.c
1 #include <stdlib.h>
2 #include <math.h>
3
4 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
5 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
6
7 typedef struct {
8     int initialHeight, initialWidth;
9     int rotatedHeight, rotatedWidth;
10     int autoCropHeight, autoCropWidth;
11 } ufraw_data;
12
13 void __attribute__((noinline,noclone))
14 ufraw_test(ufraw_data *uf)
15 {
16   int iWidth = uf->initialWidth;
17   int iHeight = uf->initialHeight;
18   double aspectRatio = ((double)iWidth) / iHeight;
19   double midX = iWidth / 2.0 - 0.5;
20   double midY = iHeight / 2.0 - 0.5;
21   double maxX = 0, maxY = 0;
22   double minX = 999999, minY = 999999;
23   double lastX = 0, lastY = 0, area = 0;
24   double scale;
25   int i;
26   for (i = 0; i < iWidth + iHeight - 1; i++)
27     {
28       int x, y;
29       if (i < iWidth) { // Trace the left border of the image
30           x = i;
31           y = 0;
32       } else { // Trace the bottom border of the image
33           x = iWidth - 1;
34           y = i - iWidth + 1;
35       }
36       double srcX = x - midX;
37       double srcY = y - midY;
38       // A digital planimeter:
39       area += srcY * lastX - srcX * lastY;
40       lastX = srcX;
41       lastY = srcY;
42       maxX = MAX(maxX, fabs(srcX));
43       maxY = MAX(maxY, fabs(srcY));
44       if (fabs(srcX / srcY) > aspectRatio)
45         minX = MIN(minX, fabs(srcX));
46       else
47         minY = MIN(minY, fabs(srcY));
48     }
49   scale = sqrt((iWidth - 1) * (iHeight - 1) / area);
50   uf->rotatedWidth = MIN(ceil(2 * maxX + 1.0) * scale, 2 * iWidth);
51   uf->rotatedHeight = MIN(ceil(2 * maxY + 1.0) * scale, 2 * iHeight);
52   uf->autoCropWidth = MIN(floor(2 * minX) * scale, 2 * iWidth);
53   uf->autoCropHeight = MIN(floor(2 * minY) * scale, 2 * iHeight);
54   if (uf->autoCropWidth != 3)
55     abort ();
56 }
57
58 int main()
59 {
60   ufraw_data uf_data;
61   ufraw_data *uf = &uf_data;
62   uf->initialWidth = 4;
63   uf->initialHeight = 5;
64   ufraw_test(uf);
65   return 0;
66 }
67
68 /* { dg-final { cleanup-tree-dump "slp" } } */