(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
vsx-builtin-16b.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target vmx_hw } */
       3  /* { dg-options "-maltivec -O3" } */
       4  
       5  /* This test should run the same on any target that supports altivec/dfp
       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		(0)
      14  #define CONST1		(1)
      15  #define CONST2		(2)
      16  #define CONST3		(3)
      17  #define CONST4		(4)
      18  #define CONST5		(5)
      19  #define CONST6		(6)
      20  #define CONST7		(7)
      21  #define CONST8		(8)
      22  #define CONST9		(9)
      23  #define CONSTA		(10)
      24  #define CONSTB		(11)
      25  #define CONSTC		(12)
      26  #define CONSTD		(13)
      27  #define CONSTE		(14)
      28  #define CONSTF		(15)
      29  
      30  
      31  /* Test that indices > length of vector are applied modulo the vector
      32     length.  */
      33  
      34  /* Test for vector residing in register.  */
      35  unsigned char c0 (vector unsigned char v)
      36  {
      37    return __builtin_vec_extract (v, 0);
      38  }
      39  
      40  unsigned char c9 (vector unsigned char v)
      41  {
      42    return __builtin_vec_extract (v, 9);
      43  }
      44  
      45  unsigned char c21 (vector unsigned char v)
      46  {
      47    return __builtin_vec_extract (v, 21);
      48  }
      49  
      50  unsigned char c30 (vector unsigned char v)
      51  {
      52    return __builtin_vec_extract (v, 30);
      53  }
      54  
      55  /* Test for vector residing in memory.  */
      56  unsigned char mc0 (vector unsigned char *vp)
      57  {
      58    return __builtin_vec_extract (*vp, 0);
      59  }
      60  
      61  unsigned char mc9 (vector unsigned char *vp)
      62  {
      63    return __builtin_vec_extract (*vp, 9);
      64  }
      65  
      66  unsigned char mc21 (vector unsigned char *vp)
      67  {
      68    return __builtin_vec_extract (*vp, 21);
      69  }
      70  
      71  unsigned char mc30 (vector unsigned char *vp)
      72  {
      73    return __builtin_vec_extract (*vp, 30);
      74  }
      75  
      76  /* Test the same with variable indices.  */
      77  
      78  /* Test for variable selector and vector residing in register.  */
      79  __attribute__((noinline))
      80  unsigned char ci (vector unsigned char v, int i)
      81  {
      82    return __builtin_vec_extract (v, i);
      83  }
      84  
      85  /* Test for variable selector and vector residing in memory.  */
      86  __attribute__((noinline))
      87  unsigned char mci (vector unsigned char *vp, int i)
      88  {
      89    return __builtin_vec_extract (*vp, i);
      90  }
      91  
      92  
      93  int main (int argc, char *argv[]) {
      94    vector unsigned char cv = { CONST0, CONST1, CONST2, CONST3,
      95  			    CONST4, CONST5, CONST6, CONST7,
      96  			    CONST8, CONST9, CONSTA, CONSTB,
      97  			    CONSTC, CONSTD, CONSTE, CONSTF };
      98    unsigned char c;
      99  
     100    c = c0 (cv);
     101    if (c != CONST0)
     102      abort ();
     103  
     104    c = c9 (cv);
     105    if (c != CONST9)
     106      abort ();
     107  
     108    c = c21 (cv);
     109    if (c != CONST5)
     110      abort ();
     111  
     112    c = c30 (cv);
     113    if (c != CONSTE)
     114      abort ();
     115  
     116    c = mc0 (&cv);
     117    if (c != CONST0)
     118      abort ();
     119  
     120    c = mc9 (&cv);
     121    if (c != CONST9)
     122      abort ();
     123  
     124    c = mc21 (&cv);
     125    if (c != CONST5)
     126      abort ();
     127  
     128    c = mc30 (&cv);
     129    if (c != CONSTE)
     130      abort ();
     131  
     132    c = ci (cv, 8);
     133    if (c != CONST8)
     134      abort ();
     135  
     136    c = ci (cv, 13);
     137    if (c != CONSTD)
     138      abort ();
     139  
     140    c = ci (cv, 23);
     141    if (c != CONST7)
     142      abort ();
     143  
     144    c = ci (cv, 31);
     145    if (c != CONSTF)
     146      abort ();
     147  
     148    c = mci (&cv, 5);
     149    if (c != CONST5)
     150      abort ();
     151  
     152    c = mci (&cv, 12);
     153    if (c != CONSTC)
     154      abort ();
     155  
     156    c = mci (&cv, 25);
     157    if (c != CONST9)
     158      abort ();
     159  
     160    c = mci (&cv, 16);
     161    if (c != CONST0)
     162      abort ();
     163  
     164    return 0;
     165  }