aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.dg/pr63762.c
blob: df110676eca6eb7418a9a24ec0a6ad72c8f8d88e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* PR middle-end/63762 */
/* { dg-do assemble } */
/* { dg-options "-O2" } */

#include <stdlib.h>

void *astFree ();
void *astMalloc ();
void astNegate (void *);
int astGetNegated (void *);
void astGetRegionBounds (void *, double *, double *);
int astResampleF (void *, ...);

extern int astOK;

int
MaskF (int inside, int ndim, const int lbnd[], const int ubnd[],
       float in[], float val)
{

  void *used_region;
  float *c, *d, *out, *tmp_out;
  double *lbndgd, *ubndgd;
  int *lbndg, *ubndg, idim, ipix, nax, nin, nout, npix, npixg, result = 0;
  if (!astOK) return result;
  lbndg = astMalloc (sizeof (int)*(size_t) ndim);
  ubndg = astMalloc (sizeof (int)*(size_t) ndim);
  lbndgd = astMalloc (sizeof (double)*(size_t) ndim);
  ubndgd = astMalloc (sizeof (double)*(size_t) ndim);
  if (astOK)
    {
      astGetRegionBounds (used_region, lbndgd, ubndgd);
      npix = 1;
      npixg = 1;
      for (idim = 0; idim < ndim; idim++)
        {
          lbndg[ idim ] = lbnd[ idim ];
          ubndg[ idim ] = ubnd[ idim ];
          npix *= (ubnd[ idim ] - lbnd[ idim ] + 1);
          if (npixg >= 0) npixg *= (ubndg[ idim ] - lbndg[ idim ] + 1);
        }
      if (npixg <= 0 && astOK)
        {
          if ((inside != 0) == (astGetNegated( used_region ) != 0))
            {
              c = in;
              for (ipix = 0; ipix < npix; ipix++) *(c++) = val;
              result = npix;
            }
        }
      else if (npixg > 0 && astOK)
        {
          if ((inside != 0) == (astGetNegated (used_region) != 0))
            {
              tmp_out = astMalloc (sizeof (float)*(size_t) npix);
              if (tmp_out)
                {
                  c = tmp_out;
                  for (ipix = 0; ipix < npix; ipix++) *(c++) = val;
                  result = npix - npixg;
                }
              out = tmp_out;
            }
          else
            {
              tmp_out = NULL;
              out = in;
            }
          if (inside) astNegate (used_region);
          result += astResampleF (used_region, ndim, lbnd, ubnd, in, NULL,
                                  NULL, NULL, 0, 0.0, 100, val, ndim,
                                  lbnd, ubnd, lbndg, ubndg, out, NULL);
          if (inside) astNegate (used_region);
        }
    }
  return result;
}