scan-7.c 1.7 KB

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