simd-4.c 953 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* { dg-do run } */
  2. /* { dg-options "-O2" } */
  3. /* { dg-additional-options "-msse2" { target sse2_runtime } } */
  4. /* { dg-additional-options "-mavx" { target avx_runtime } } */
  5. extern void abort ();
  6. int a[1024] __attribute__((aligned (32))) = { 1 };
  7. struct S { int s; };
  8. #pragma omp declare reduction (+:struct S:omp_out.s += omp_in.s)
  9. #pragma omp declare reduction (foo:struct S:omp_out.s += omp_in.s)
  10. #pragma omp declare reduction (foo:int:omp_out += omp_in)
  11. __attribute__((noinline, noclone)) int
  12. foo (void)
  13. {
  14. int i, u = 0;
  15. struct S s, t;
  16. s.s = 0; t.s = 0;
  17. #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u)
  18. for (i = 0; i < 1024; i++)
  19. {
  20. int x = a[i];
  21. s.s += x;
  22. t.s += x;
  23. u += x;
  24. }
  25. if (t.s != s.s || u != s.s)
  26. abort ();
  27. return s.s;
  28. }
  29. int
  30. main ()
  31. {
  32. int i;
  33. for (i = 0; i < 1024; i++)
  34. a[i] = (i & 31) + (i / 128);
  35. int s = foo ();
  36. if (s != 19456)
  37. abort ();
  38. return 0;
  39. }