(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c/
examples-4/
simd-7.c
       1  /* { dg-do run { target vect_simd_clones } } */
       2  /* { dg-additional-options "-msse2" { target sse2_runtime } } */
       3  /* { dg-additional-options "-mavx" { target avx_runtime } } */
       4  
       5  #include <stdio.h>
       6  #include <stdlib.h>
       7  
       8  #define N 30
       9  int a[N], a_ref[N], b[N];
      10  
      11  #pragma omp declare simd inbranch
      12  int fib( int n )
      13  {
      14    if (n <= 1)
      15      return n;
      16    else
      17      return fib(n-1) + fib(n-2);
      18  }
      19  
      20  void fib_ref()
      21  {
      22    int i;
      23  
      24    a_ref[0] = 0;
      25    a_ref[1] = 1;
      26  
      27    for (i=2; i < N; i++)
      28      a_ref[i] = a_ref[i-2] + a_ref[i-1];
      29  }
      30  
      31  int main(void)
      32  {
      33    int i;
      34  
      35  #pragma omp simd
      36    for (i=0; i < N; i++)
      37      b[i] = i;
      38  
      39  #pragma omp simd
      40    for (i=0; i < N; i++)
      41      a[i] = fib(b[i]);
      42  
      43    fib_ref ();
      44  
      45    for (i=0; i < N; i++)
      46      if (a[i] != a_ref[i])
      47        abort ();
      48  
      49    return 0;
      50  }