simd-17.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* { dg-do run } */
  2. /* { dg-options "-O2 -std=c99" } */
  3. /* { dg-additional-options "-msse2" { target sse2_runtime } } */
  4. /* { dg-additional-options "-mavx" { target avx_runtime } } */
  5. static inline void
  6. foo (int *b, int *i, int *j, int x)
  7. {
  8. *b = *b + x + (*i - *i) + (*j - *j);
  9. }
  10. int
  11. main ()
  12. {
  13. int b, c = 0;
  14. b = 7;
  15. #pragma omp simd linear(b:2) reduction(+:c)
  16. for (int i = 0; i < 64; i++)
  17. {
  18. c = c + (b != 7 + 2 * i);
  19. foo (&b, &i, &i, 2);
  20. }
  21. if (c || b != 7 + 64 * 2)
  22. __builtin_abort ();
  23. b = 7;
  24. #pragma omp simd linear(b:3) reduction(+:c)
  25. for (int i = 0; i < 64; i += 4)
  26. {
  27. c = c + (b != 7 + i / 4 * 3);
  28. foo (&b, &i, &i, 3);
  29. }
  30. if (c || b != 7 + 16 * 3)
  31. __builtin_abort ();
  32. b = 7;
  33. #pragma omp simd collapse (2) linear(b:2) reduction(+:c)
  34. for (int i = 0; i < 8; i++)
  35. for (int j = 0; j < 8; j++)
  36. {
  37. c = c + (b != 7 + 2 * j + 2 * 8 * i);
  38. foo (&b, &i, &j, 2);
  39. }
  40. if (c || b != 7 + 64 * 2)
  41. __builtin_abort ();
  42. b = 7;
  43. #pragma omp parallel for simd schedule (static, 4) linear(b:2) reduction(+:c)
  44. for (int i = 0; i < 64; i++)
  45. {
  46. c = c + (b != 7 + 2 * i);
  47. foo (&b, &i, &i, 2);
  48. }
  49. if (c || b != 7 + 64 * 2)
  50. __builtin_abort ();
  51. b = 7;
  52. #pragma omp parallel for simd schedule (static, 4) linear(b:3) reduction(+:c)
  53. for (int i = 0; i < 64; i += 4)
  54. {
  55. c = c + (b != 7 + i / 4 * 3);
  56. foo (&b, &i, &i, 3);
  57. }
  58. if (c || b != 7 + 16 * 3)
  59. __builtin_abort ();
  60. b = 7;
  61. #pragma omp parallel for simd collapse (2) schedule (static, 4) linear(b:2) reduction(+:c)
  62. for (int i = 0; i < 8; i++)
  63. for (int j = 0; j < 8; j++)
  64. {
  65. c = c + (b != 7 + 2 * j + 2 * 8 * i);
  66. foo (&b, &i, &j, 2);
  67. }
  68. if (c || b != 7 + 64 * 2)
  69. __builtin_abort ();
  70. return 0;
  71. }