(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
vsx-builtin-14c.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target vmx_hw } */
       3  /* { dg-options "-maltivec" } */
       4  
       5  /* This test should run the same on any target that supports altivec/vmx
       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		((float) (3.1415926539))
      14  #define CONST1		((float) (3.1415926539 * 2))
      15  #define CONST2		((float) (3.1415926539 * 3))
      16  #define CONST3		((float) (3.1415926539 * 4))
      17  
      18  /* Test that indices > length of vector are applied modulo the vector
      19     length.  */
      20  
      21  /* Test for vector residing in register.  */
      22  vector float e0(vector float v, float x)
      23  {
      24    return vec_insert (x, v, 0);
      25  }
      26  
      27  vector float e1(vector float v, float x)
      28  {
      29    return vec_insert (x, v, 1);
      30  }
      31  
      32  vector float e7(vector float v, float x)
      33  {
      34    return vec_insert (x, v, 7);
      35  }
      36  
      37  vector float e8(vector float v, float x)
      38  {
      39    return vec_insert (x, v, 8);
      40  }
      41  
      42  /* Test for vector residing in memory.  */
      43  vector float me0(vector float *vp, float x)
      44  {
      45    return vec_insert (x, *vp, 0);
      46  }
      47  
      48  vector float me1(vector float *vp, float x)
      49  {
      50    return vec_insert (x, *vp, 1);
      51  }
      52  
      53  vector float me13(vector float *vp, float x)
      54  {
      55    return vec_insert (x, *vp, 13);
      56  }
      57  
      58  vector float me15(vector float *vp, float x)
      59  {
      60    return vec_insert (x, *vp, 15);
      61  }
      62  
      63  /* Test the same with variable indices.  */
      64  
      65  /* Test for variable selector and vector residing in register.  */
      66  __attribute__((noinline))
      67  vector float ei(vector float v, int i, float x)
      68  {
      69    return vec_insert (x, v, i);
      70  }
      71  
      72  /* Test for variable selector and vector residing in memory.  */
      73  __attribute__((noinline))
      74  vector float mei(vector float *vp, int i, float x)
      75  {
      76    return vec_insert (x, *vp, i);
      77  }
      78  
      79  
      80  int main (int argc, char *argv[]) {
      81    vector float dv = { CONST0, CONST1, CONST2, CONST3 };
      82    float d;
      83  
      84    dv = e0 (dv, CONST3);
      85    if (dv [0] != CONST3)
      86      abort ();
      87  
      88    dv = e1 (dv, CONST0);
      89    if (dv [1] != CONST0)
      90      abort ();
      91  
      92    dv = e7 (dv, CONST2);
      93    if (dv [3] != CONST2)
      94      abort ();
      95  
      96    dv = e8 (dv, CONST1);
      97    if (dv [0] != CONST1)
      98      abort ();
      99  
     100    dv = me0 (&dv, CONST2);
     101    if (dv [0] != CONST2)
     102      abort ();
     103  
     104    dv = me1 (&dv, CONST3);
     105    if (dv [1] != CONST3)
     106      abort ();
     107  
     108    dv = me13 (&dv, CONST2);
     109    if (dv [1] != CONST2)
     110      abort ();
     111  
     112    dv = me15 (&dv, CONST1);
     113    if (dv [3] != CONST1)
     114      abort ();
     115  
     116    dv = ei (dv, 0, CONST3);
     117    if (dv [0] != CONST3)
     118      abort ();
     119  
     120    dv = ei (dv, 2, CONST1);
     121    if (dv [2] != CONST1)
     122      abort ();
     123  
     124    dv = ei (dv, 11, CONST0);
     125    if (dv [3] != CONST0)
     126      abort ();
     127  
     128    dv = ei (dv, 17, CONST2);
     129    if (dv [1] != CONST2)
     130      abort ();
     131  
     132    dv = mei (&dv, 0, CONST1);
     133    if (dv [0] != CONST1)
     134      abort ();
     135  
     136    dv = mei (&dv, 1, CONST0);
     137    if (dv [1] != CONST0)
     138      abort ();
     139  
     140    dv = mei (&dv, 15, CONST1);
     141    if (dv [3] != CONST1)
     142      abort ();
     143  
     144    dv = mei (&dv, 6, CONST0);
     145    if (dv [2] != CONST0)
     146      abort ();
     147  
     148    return 0;
     149  }