(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
vsx-builtin-19b.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		(31415926539LL)
      14  #define CONST1		(2 * 31415926539LL)
      15  
      16  /* Test that indices > length of vector are applied modulo the vector
      17     length.  */
      18  
      19  /* Test for vector residing in register.  */
      20  unsigned long long int e0 (vector unsigned long long int v)
      21  {
      22    return __builtin_vec_extract (v, 0);
      23  }
      24  
      25  unsigned long long int e3 (vector unsigned long long int v)
      26  {
      27    return __builtin_vec_extract (v, 3);
      28  }
      29  
      30  /* Test for vector residing in memory.  */
      31  unsigned long long int me0 (vector unsigned long long int *vp)
      32  {
      33    return __builtin_vec_extract (*vp, 0);
      34  }
      35  
      36  unsigned long long int me3 (vector unsigned long long int *vp)
      37  {
      38    return __builtin_vec_extract (*vp, 3);
      39  }
      40  
      41  /* Test the same with variable indices.  */
      42  
      43  /* Test for variable selector and vector residing in register.  */
      44  __attribute__((noinline))
      45  unsigned long long int ei (vector unsigned long long int v, int i)
      46  {
      47    return __builtin_vec_extract (v, i);
      48  }
      49  
      50  /* Test for variable selector and vector residing in memory.  */
      51  unsigned long long int mei (vector unsigned long long int *vp, int i)
      52  {
      53    return __builtin_vec_extract (*vp, i);
      54  }
      55  
      56  int main (int argc, char *argv[]) {
      57    vector unsigned long long int dv = { CONST0, CONST1 };
      58    unsigned long long int d;
      59  
      60    d = e0 (dv);
      61    if (d != CONST0)
      62      abort ();
      63  
      64    d = e3 (dv);
      65    if (d != CONST1)
      66      abort ();
      67  
      68    d = me0 (&dv);
      69    if (d != CONST0)
      70      abort ();
      71  
      72    d = me3 (&dv);
      73    if (d != CONST1)
      74      abort ();
      75  
      76    d = ei (dv, 0);
      77    if (d != CONST0)
      78      abort ();
      79  
      80    d = ei (dv, 1);
      81    if (d != CONST1)
      82      abort ();
      83  
      84    d = ei (dv, 2);
      85    if (d != CONST0)
      86      abort ();
      87  
      88    d = ei (dv, 3);
      89    if (d != CONST1)
      90      abort ();
      91  
      92    d = mei (&dv, 0);
      93    if (d != CONST0)
      94      abort ();
      95  
      96    d = mei (&dv, 1);
      97    if (d != CONST1)
      98      abort ();
      99  
     100    d = mei (&dv, 2);
     101    if (d != CONST0)
     102      abort ();
     103  
     104    d = mei (&dv, 3);
     105    if (d != CONST1)
     106      abort ();
     107  
     108    return 0;
     109  }