simd-6.C 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // { dg-do run }
  2. // { dg-additional-options "-msse2" { target sse2_runtime } }
  3. // { dg-additional-options "-mavx" { target avx_runtime } }
  4. extern "C" void abort ();
  5. int a[1024] __attribute__((aligned (32))) = { 1 };
  6. struct S
  7. {
  8. int s;
  9. S () : s (0) {}
  10. S (int x) : s (x) {}
  11. ~S () {}
  12. };
  13. #pragma omp declare reduction (+:S:omp_out.s += omp_in.s) \
  14. initializer (omp_priv (0))
  15. #pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) \
  16. initializer (omp_priv (0))
  17. #pragma omp declare reduction (foo:int:omp_out += omp_in) \
  18. initializer (omp_priv = 0)
  19. __attribute__((noinline, noclone)) S
  20. foo (S s)
  21. {
  22. int i, v = 0, &u = v;
  23. S t;
  24. #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u)
  25. for (i = 0; i < 1024; i++)
  26. {
  27. int x = a[i];
  28. s.s += x;
  29. t.s += x;
  30. u += x;
  31. }
  32. if (t.s != s.s || u != s.s)
  33. abort ();
  34. return t;
  35. }
  36. __attribute__((noinline, noclone)) int
  37. bar (S &s, S &t)
  38. {
  39. int i, v = 0, &u = v;
  40. #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u)
  41. for (i = 0; i < 1024; i++)
  42. {
  43. int x = a[i];
  44. s.s += x;
  45. t.s += x;
  46. u += x;
  47. }
  48. if (t.s != s.s || u != s.s)
  49. abort ();
  50. return s.s;
  51. }
  52. int
  53. main ()
  54. {
  55. int i;
  56. for (i = 0; i < 1024; i++)
  57. a[i] = (i & 31) + (i / 128);
  58. S q;
  59. int s = foo (q).s;
  60. if (s != 19456)
  61. abort ();
  62. S r, v;
  63. if (bar (r, v) != s)
  64. abort ();
  65. }