(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c/
scan-3.c
       1  /* { dg-require-effective-target size32plus } */
       2  
       3  extern void abort (void);
       4  float r = 1.0f, a[1024], b[1024];
       5  
       6  __attribute__((noipa)) void
       7  foo (float *a, float *b)
       8  {
       9    #pragma omp for reduction (inscan, *:r)
      10    for (int i = 0; i < 1024; i++)
      11      {
      12        r *= a[i];
      13        #pragma omp scan inclusive(r)
      14        b[i] = r;
      15      }
      16  }
      17  
      18  __attribute__((noipa)) float
      19  bar (void)
      20  {
      21    float s = -__builtin_inff ();
      22    #pragma omp parallel for reduction (inscan, max:s)
      23    for (int i = 0; i < 1024; i++)
      24      {
      25        s = s > a[i] ? s : a[i];
      26        #pragma omp scan inclusive(s)
      27        b[i] = s;
      28      }
      29    return s;
      30  }
      31  
      32  int
      33  main ()
      34  {
      35    float s = 1.0f;
      36    for (int i = 0; i < 1024; ++i)
      37      {
      38        if (i < 80)
      39  	a[i] = (i & 1) ? 0.25f : 0.5f;
      40        else if (i < 200)
      41  	a[i] = (i % 3) == 0 ? 2.0f : (i % 3) == 1 ? 4.0f : 1.0f;
      42        else if (i < 280)
      43  	a[i] = (i & 1) ? 0.25f : 0.5f;
      44        else if (i < 380)
      45  	a[i] = (i % 3) == 0 ? 2.0f : (i % 3) == 1 ? 4.0f : 1.0f;
      46        else
      47  	switch (i % 6)
      48  	  {
      49  	  case 0: a[i] = 0.25f; break;
      50  	  case 1: a[i] = 2.0f; break;
      51  	  case 2: a[i] = -1.0f; break;
      52  	  case 3: a[i] = -4.0f; break;
      53  	  case 4: a[i] = 0.5f; break;
      54  	  case 5: a[i] = 1.0f; break;
      55  	  default: a[i] = 0.0f; break;
      56  	  }
      57        b[i] = -19.0f;
      58        asm ("" : "+g" (i));
      59      }
      60    #pragma omp parallel
      61    foo (a, b);
      62    if (r * 16384.0f != 0.125f)
      63      abort ();
      64    float m = -175.25f;
      65    for (int i = 0; i < 1024; ++i)
      66      {
      67        s *= a[i];
      68        if (b[i] != s)
      69  	abort ();
      70        else
      71  	{
      72  	  a[i] = m - ((i % 3) == 1 ? 2.0f : (i % 3) == 2 ? 4.0f : 0.0f);
      73  	  b[i] = -231.75f;
      74  	  m += 0.75f;
      75  	}
      76      }
      77    if (bar () != 592.0f)
      78      abort ();
      79    s = -__builtin_inff ();
      80    for (int i = 0; i < 1024; ++i)
      81      {
      82        if (s < a[i])
      83  	s = a[i];
      84        if (b[i] != s)
      85  	abort ();
      86      }
      87    return 0;
      88  }