2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / gcc.target / rx / mjsr.c
blobc73a01bb5200aba79d8324c756d6d84732525d6e
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -mjsr" } */
4 void *malloc (__SIZE_TYPE__);
5 void *realloc (void *, __SIZE_TYPE__);
7 struct A { double x, y; };
8 struct B { double x0, y0, x1, y1; };
9 struct C { int n_points; int dir; struct B bbox; struct A *points; };
10 struct D { int n_segs; struct C segs[1]; };
12 void foo (int, int, int *, int, int *, struct A **, int *, int *,
13 struct D *, int *, struct D **, int *, int **);
14 int baz (struct A, struct A, struct A, struct A);
16 static void
17 bar (struct D *svp, int *n_points_max,
18 struct A p, int *seg_map, int *active_segs, int i)
20 int asi, n_points;
21 struct C *seg;
23 asi = seg_map[active_segs[i]];
24 seg = &svp->segs[asi];
25 n_points = seg->n_points;
26 seg->points = ((struct A *)
27 realloc (seg->points, (n_points_max[asi] <<= 1) * sizeof (struct A)));
28 seg->points[n_points] = p;
29 seg->bbox.y1 = p.y;
30 seg->n_points++;
33 struct D *
34 test (struct D *vp)
36 int *active_segs, n_active_segs, *cursor, seg_idx;
37 double y, share_x;
38 int tmp1, tmp2, asi, i, j, *n_ips, *n_ips_max, n_segs_max;
39 struct A **ips, p_curs, *pts;
40 struct D *new_vp;
41 int *n_points_max, *seg_map, first_share;
43 n_segs_max = 16;
44 new_vp = (struct D *) malloc (sizeof (struct D) +
45 (n_segs_max - 1) * sizeof (struct C));
46 new_vp->n_segs = 0;
48 if (vp->n_segs == 0)
49 return new_vp;
51 active_segs = ((int *) malloc ((vp->n_segs) * sizeof (int)));
52 cursor = ((int *) malloc ((vp->n_segs) * sizeof (int)));
54 seg_map = ((int *) malloc ((vp->n_segs) * sizeof (int)));
55 n_ips = ((int *) malloc ((vp->n_segs) * sizeof (int)));
56 n_ips_max = ((int *) malloc ((vp->n_segs) * sizeof (int)));
57 ips = ((struct A * *) malloc ((vp->n_segs) * sizeof (struct A *)));
59 n_points_max = ((int *) malloc ((n_segs_max) * sizeof (int)));
61 n_active_segs = 0;
62 seg_idx = 0;
63 y = vp->segs[0].points[0].y;
64 while (seg_idx < vp->n_segs || n_active_segs > 0)
66 for (i = 0; i < n_active_segs; i++)
68 asi = active_segs[i];
69 if (vp->segs[asi].n_points - 1 == cursor[asi] &&
70 vp->segs[asi].points[cursor[asi]].y == y)
71 i--;
74 while (seg_idx < vp->n_segs && y == vp->segs[seg_idx].points[0].y)
76 cursor[seg_idx] = 0;
77 n_ips[seg_idx] = 1;
78 n_ips_max[seg_idx] = 2;
79 ips[seg_idx] =
80 ((struct A *) malloc ((n_ips_max[seg_idx]) * sizeof (struct A)));
81 ips[seg_idx][0] = vp->segs[seg_idx].points[0];
82 pts = ((struct A *) malloc ((16) * sizeof (struct A)));
83 pts[0] = vp->segs[seg_idx].points[0];
84 tmp1 = seg_idx;
85 for (j = i; j < n_active_segs; j++)
87 tmp2 = active_segs[j];
88 active_segs[j] = tmp1;
89 tmp1 = tmp2;
91 active_segs[n_active_segs] = tmp1;
92 n_active_segs++;
93 seg_idx++;
95 first_share = -1;
96 share_x = 0;
98 for (i = 0; i < n_active_segs; i++)
100 asi = active_segs[i];
101 p_curs = ips[asi][1];
102 if (p_curs.y == y)
104 bar (new_vp, n_points_max,
105 p_curs, seg_map, active_segs, i);
107 n_ips[asi]--;
108 for (j = 0; j < n_ips[asi]; j++)
109 ips[asi][j] = ips[asi][j + 1];
111 if (first_share < 0 || p_curs.x != share_x)
113 foo (first_share, i,
114 active_segs, n_active_segs,
115 cursor, ips, n_ips, n_ips_max, vp, seg_map,
116 &new_vp, &n_segs_max, &n_points_max);
117 first_share = i;
118 share_x = p_curs.x;
121 else
123 foo (first_share, i,
124 active_segs, n_active_segs,
125 cursor, ips, n_ips, n_ips_max, vp, seg_map,
126 &new_vp, &n_segs_max, &n_points_max);
127 first_share = -1;
131 return new_vp;
134 /* { dg-final { scan-assembler-not "bsr" } } */