| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O2 -mjsr" } */ |
| 3 |
|
| 4 |
void *malloc (__SIZE_TYPE__); |
| 5 |
void *realloc (void *, __SIZE_TYPE__); |
| 6 |
|
| 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]; }; |
| 11 |
|
| 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); |
| 15 |
|
| 16 |
static void |
| 17 |
bar (struct D *svp, int *n_points_max, |
| 18 |
struct A p, int *seg_map, int *active_segs, int i) |
| 19 |
{ |
| 20 |
int asi, n_points; |
| 21 |
struct C *seg; |
| 22 |
|
| 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++; |
| 31 |
} |
| 32 |
|
| 33 |
struct D * |
| 34 |
test (struct D *vp) |
| 35 |
{ |
| 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; |
| 42 |
|
| 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; |
| 47 |
|
| 48 |
if (vp->n_segs == 0) |
| 49 |
return new_vp; |
| 50 |
|
| 51 |
active_segs = ((int *) malloc ((vp->n_segs) * sizeof (int))); |
| 52 |
cursor = ((int *) malloc ((vp->n_segs) * sizeof (int))); |
| 53 |
|
| 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 *))); |
| 58 |
|
| 59 |
n_points_max = ((int *) malloc ((n_segs_max) * sizeof (int))); |
| 60 |
|
| 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) |
| 65 |
{ |
| 66 |
for (i = 0; i < n_active_segs; i++) |
| 67 |
{ |
| 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--; |
| 72 |
} |
| 73 |
|
| 74 |
while (seg_idx < vp->n_segs && y == vp->segs[seg_idx].points[0].y) |
| 75 |
{ |
| 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++) |
| 86 |
{ |
| 87 |
tmp2 = active_segs[j]; |
| 88 |
active_segs[j] = tmp1; |
| 89 |
tmp1 = tmp2; |
| 90 |
} |
| 91 |
active_segs[n_active_segs] = tmp1; |
| 92 |
n_active_segs++; |
| 93 |
seg_idx++; |
| 94 |
} |
| 95 |
first_share = -1; |
| 96 |
share_x = 0; |
| 97 |
|
| 98 |
for (i = 0; i < n_active_segs; i++) |
| 99 |
{ |
| 100 |
asi = active_segs[i]; |
| 101 |
p_curs = ips[asi][1]; |
| 102 |
if (p_curs.y == y) |
| 103 |
{ |
| 104 |
bar (new_vp, n_points_max, |
| 105 |
p_curs, seg_map, active_segs, i); |
| 106 |
|
| 107 |
n_ips[asi]--; |
| 108 |
for (j = 0; j < n_ips[asi]; j++) |
| 109 |
ips[asi][j] = ips[asi][j + 1]; |
| 110 |
|
| 111 |
if (first_share < 0 || p_curs.x != share_x) |
| 112 |
{ |
| 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; |
| 119 |
} |
| 120 |
} |
| 121 |
else |
| 122 |
{ |
| 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; |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
return new_vp; |
| 132 |
} |
| 133 |
|
| 134 |
/* { dg-final { scan-assembler-not "bsr" } } */ |