(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
vsx-builtin-15b.c
       1  /* { dg-do run { target int128 } } */
       2  /* { dg-require-effective-target vsx_hw } */
       3  /* { dg-options "-mvsx -O3" } */
       4  
       5  /* This test should run the same on any target that supports vsx
       6     instructions.  Intentionally not specifying cpu in order to test
       7     all code generation paths.  */
       8  
       9  #include <altivec.h>
      10  
      11  extern void abort (void);
      12  
      13  #define CONST0		(3.1415926539)
      14  #define CONST1		(3.1415926539 * 2)
      15  
      16  
      17  /* Test that indices > length of vector are applied modulo the vector
      18     length.  */
      19  
      20  /* Test for vector residing in register.  */
      21  double e0(vector double v){ return __builtin_vec_ext_v2df (v, 0); }
      22  double e1(vector double v){ return __builtin_vec_ext_v2df (v, 1); }
      23  double e2(vector double v){ return __builtin_vec_ext_v2df (v, 2); }
      24  double e3(vector double v){ return __builtin_vec_ext_v2df (v, 3); }
      25  
      26  /* Test for vector residing in memory.  */
      27  double me0(vector double *vp){ return __builtin_vec_ext_v2df (*vp, 0); }
      28  double me1(vector double *vp){ return __builtin_vec_ext_v2df (*vp, 1); }
      29  double me2(vector double *vp){ return __builtin_vec_ext_v2df (*vp, 2); }
      30  double me3(vector double *vp){ return __builtin_vec_ext_v2df (*vp, 3); }
      31  
      32  /* Test the same with variable indices.  */
      33  
      34  /* Test for variable selector and vector residing in register.  */
      35  __attribute__((noinline))
      36  double ei(vector double v, int i){ return __builtin_vec_ext_v2df (v, i); }
      37  
      38  /* Test for variable selector and vector residing in memory.  */
      39  double mei(vector double *vp, int i){ return __builtin_vec_ext_v2df (*vp, i); }
      40  
      41  
      42  int main (int argc, char *argv[]) {
      43    vector double dv;
      44    double d;
      45    dv[0] = CONST0;
      46    dv[1] = CONST1;
      47  
      48    d = e0 (dv);
      49    if (d != CONST0)
      50      abort ();
      51  
      52    d = e1 (dv);
      53    if (d != CONST1)
      54      abort ();
      55  
      56    d = e2 (dv);
      57    if (d != CONST0)
      58      abort ();
      59  
      60    d = e3 (dv);
      61    if (d != CONST1)
      62      abort ();
      63  
      64    d = me0 (&dv);
      65    if (d != CONST0)
      66      abort ();
      67  
      68    d = me1 (&dv);
      69    if (d != CONST1)
      70      abort ();
      71  
      72    d = me2 (&dv);
      73    if (d != CONST0)
      74      abort ();
      75  
      76    d = me3 (&dv);
      77    if (d != CONST1)
      78      abort ();
      79  
      80    d = ei (dv, 0);
      81    if (d != CONST0)
      82      abort ();
      83  
      84    d = ei (dv, 1);
      85    if (d != CONST1)
      86      abort ();
      87  
      88    d = ei (dv, 2);
      89    if (d != CONST0)
      90      abort ();
      91  
      92    d = ei (dv, 3);
      93    if (d != CONST1)
      94      abort ();
      95  
      96    d = mei (&dv, 0);
      97    if (d != CONST0)
      98      abort ();
      99  
     100    d = mei (&dv, 1);
     101    if (d != CONST1)
     102      abort ();
     103  
     104    d = mei (&dv, 2);
     105    if (d != CONST0)
     106      abort ();
     107  
     108    d = mei (&dv, 3);
     109    if (d != CONST1)
     110      abort ();
     111  
     112    return 0;
     113  }