(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
vect/
vect-all.c
       1  /* { dg-require-effective-target vect_int } */
       2  /* { dg-require-effective-target vect_float } */
       3  /* { dg-add-options bind_pic_locally } */
       4  
       5  #include <stdarg.h>
       6  #include "tree-vect.h"
       7  
       8  #define N 16
       9  
      10  int iadd_results[N] = {0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90};
      11  float fadd_results[N] = {0.0,6.0,12.0,18.0,24.0,30.0,36.0,42.0,48.0,54.0,60.0,66.0,72.0,78.0,84.0,90.0};
      12  float fmul_results[N] = {0.0,3.0,12.0,27.0,48.0,75.0,108.0,147.0,192.0,243.0,300.0,363.0,432.0,507.0,588.0,675.0};
      13  float fresults1[N] = {192.00,240.00,288.00,336.00,384.00,432.00,480.00,528.00,48.00,54.00,60.00,66.00,72.00,78.00,84.00,90.00};
      14  float fresults2[N] = {0.00,6.00,12.00,18.00,24.00,30.00,36.00,42.00,0.00,54.00,120.00,198.00,288.00,390.00,504.00,630.00};
      15  
      16  /****************************************************/
      17  __attribute__ ((noinline))
      18  void icheck_results (int *a, int *results)
      19  {
      20    int i;
      21    for (i = 0; i < N; i++)
      22      {
      23        if (a[i] != results[i])
      24  	abort ();
      25      }
      26  }
      27  
      28  __attribute__ ((noinline))
      29  void fcheck_results (float *a, float *results)
      30  {
      31    int i;
      32    for (i = 0; i < N; i++)
      33      {
      34        if (a[i] != results[i])
      35  	abort ();
      36      }
      37  }   
      38  
      39  __attribute__ ((noinline)) void 
      40  fbar_mul (float *a)
      41  {
      42    fcheck_results (a, fmul_results);
      43  } 
      44  
      45  __attribute__ ((noinline)) void 
      46  fbar_add (float *a)
      47  {
      48    fcheck_results (a, fadd_results);
      49  } 
      50  
      51  __attribute__ ((noinline)) void 
      52  ibar_add (int *a)
      53  {
      54    icheck_results (a, iadd_results);
      55  } 
      56  
      57  __attribute__ ((noinline)) void 
      58  fbar1 (float *a)
      59  {
      60    fcheck_results (a, fresults1);
      61  } 
      62  
      63  __attribute__ ((noinline)) void 
      64  fbar2 (float *a)
      65  {
      66    fcheck_results (a, fresults2);
      67  } 
      68  
      69  float a[N];
      70  float e[N];
      71  float b[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
      72  float c[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
      73  float d[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30};
      74  int ic[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
      75  int ib[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
      76  int ia[N];
      77  char cb[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
      78  char ca[N];
      79  short sa[N];
      80  
      81  /* All of the loops below are currently vectorizable.  */
      82  
      83  __attribute__ ((noinline)) int
      84  main1 ()
      85  {
      86    int i,j;
      87  
      88    /* Test 1: copy chars.  */
      89    for (i = 0; i < N; i++)
      90      {
      91        ca[i] = cb[i];
      92      }
      93    /* check results:  */
      94    for (i = 0; i < N; i++)
      95      {
      96        if (ca[i] != cb[i])
      97  	abort ();
      98      }
      99  
     100  
     101    /* Test 2: fp mult.  */
     102    for (i = 0; i < N; i++)
     103      {
     104        a[i] = b[i] * c[i];
     105      }
     106    fbar_mul (a);
     107  
     108  
     109    /* Test 3: mixed types (int, fp), same nunits in vector.  */
     110    for (i = 0; i < N; i++)
     111      {
     112        a[i] = b[i] + c[i] + d[i];
     113        e[i] = b[i] + c[i] + d[i];
     114        ia[i] = ib[i] + ic[i];
     115      }
     116    ibar_add (ia);
     117    fbar_add (a);
     118    fbar_add (e);
     119  
     120  
     121    /* Test 4: access with offset.  */
     122    for (i = 0; i < N/2; i++)
     123      {
     124        a[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i];
     125        e[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i];
     126      }
     127    fbar1 (a);
     128    fbar2 (e);
     129  
     130  
     131    /* Test 5: access with offset */
     132    for (i = 1; i <=N-4; i++)
     133      {
     134        a[i+3] = b[i-1];
     135      }
     136    /* check results:  */
     137    for (i = 1; i <=N-4; i++)
     138      {
     139        if (a[i+3] != b[i-1])
     140  	abort ();
     141      }
     142  
     143  
     144    /* Test 6 - loop induction with stride != 1.  */
     145    i = 0;
     146    j = 0;
     147    while (i < 5*N)
     148      {
     149        a[j] = c[j];
     150        i += 5;
     151        j++;
     152      }
     153    /* check results:  */
     154    for (i = 0; i <N; i++)
     155      {
     156        if (a[i] != c[i])
     157          abort ();
     158      }
     159  
     160  
     161    /* Test 7 - reverse access.  */
     162    for (i = N; i > 0; i--)
     163      {
     164        a[N-i] = d[N-i];
     165      }
     166    /* check results:  */
     167    for (i = 0; i <N; i++)
     168      {
     169        if (a[i] != d[i])
     170          abort ();
     171      }
     172  
     173  
     174    /* Tests 8,9,10 - constants.  */
     175    for (i = 0; i < N; i++)
     176      {
     177        a[i] = 5.0;
     178      }
     179    /* check results:  */
     180    for (i = 0; i < N; i++)
     181      {
     182        if (a[i] != 5.0)
     183          abort ();
     184      }
     185  
     186    for (i = 0; i < N; i++)
     187      {
     188        sa[i] = 5;
     189      }
     190    /* check results:  */
     191    for (i = 0; i < N; i++)
     192      {
     193        if (sa[i] != 5)
     194          abort ();
     195      }
     196  
     197    for (i = 0; i < N; i++)
     198      {
     199        ia[i] = ib[i] + 5;
     200      }
     201    /* check results:  */
     202    for (i = 0; i < N; i++)
     203      {
     204        if (ia[i] != ib[i] + 5)
     205          abort ();
     206      }
     207  
     208    return 0;
     209  }
     210  
     211  int main (void)
     212  {
     213    check_vect ();
     214  
     215    return main1 ();
     216  }
     217  
     218  /* { dg-final { scan-tree-dump-times "vectorized 10 loops" 1 "vect" } } */
     219  /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" { target { { vect_aligned_arrays } && {! vect_sizes_32B_16B} } } } } */
     220  /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 1 "vect" { target { {! vect_aligned_arrays } && {vect_sizes_32B_16B} } } } } */
     221  /* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 0 "vect" } } */