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