aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c/examples-4/simd-4.c
blob: 1aa0425010d3fc6b5f546e69f0aa12aeb68fffb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* { dg-do run } */
/* { dg-additional-options "-msse2" { target sse2_runtime } } */
/* { dg-additional-options "-mavx" { target avx_runtime } } */

#define N 128
#define M 16
#define EPS 0.0000000000000001
#define SAFELEN 16

#include <stdlib.h>

void init(double *a, double *b, int n)
{
  int i, s = -1;
  for ( i = 0; i < n; i++ )
  {
    a[i] = i*i*s;
    b[i] = a[i];
    s = -s;
  }
}

void work( double *b, int n, int m )
{
   int i;
   #pragma omp simd safelen(SAFELEN)
   for (i = m; i < n; i++)
      b[i] = b[i-m] - 1.0f;
}

void work_ref( double *b, int n, int m )
{
   int i;
   for (i = m; i < n; i++)
      b[i] = b[i-m] - 1.0f;
}

void check (double *a, double *b)
{
  int i;
  for (i = 0; i < N; i++)
    if (a[i] - b[i] > EPS || b[i] - a[i] > EPS)
      abort ();
}

int main ()
{
  double b[N], b_ref[N];

  init(b, b_ref, N);

  work(b, N, M);
  work(b_ref, N, M);

  check(b, b_ref);

  return 0;
}