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