simd-4.c 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* { dg-do run } */
  2. /* { dg-additional-options "-msse2" { target sse2_runtime } } */
  3. /* { dg-additional-options "-mavx" { target avx_runtime } } */
  4. #define N 128
  5. #define M 16
  6. #define EPS 0.0000000000000001
  7. #define SAFELEN 16
  8. #include <stdlib.h>
  9. void init(double *a, double *b, int n)
  10. {
  11. int i, s = -1;
  12. for ( i = 0; i < n; i++ )
  13. {
  14. a[i] = i*i*s;
  15. b[i] = a[i];
  16. s = -s;
  17. }
  18. }
  19. void work( double *b, int n, int m )
  20. {
  21. int i;
  22. #pragma omp simd safelen(SAFELEN)
  23. for (i = m; i < n; i++)
  24. b[i] = b[i-m] - 1.0f;
  25. }
  26. void work_ref( double *b, int n, int m )
  27. {
  28. int i;
  29. for (i = m; i < n; i++)
  30. b[i] = b[i-m] - 1.0f;
  31. }
  32. void check (double *a, double *b)
  33. {
  34. int i;
  35. for (i = 0; i < N; i++)
  36. if (a[i] - b[i] > EPS || b[i] - a[i] > EPS)
  37. abort ();
  38. }
  39. int main ()
  40. {
  41. double b[N], b_ref[N];
  42. init(b, b_ref, N);
  43. work(b, N, M);
  44. work(b_ref, N, M);
  45. check(b, b_ref);
  46. return 0;
  47. }