[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vsx-builtin-11a.c
blobe962e121bd019b0c731a8dc3c495cbf4b2248a45
1 /* { dg-do run } */
2 /* { dg-require-effective-target vmx_hw } */
3 /* { dg-options "-maltivec" } */
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. */
9 #include <altivec.h>
11 extern void abort (void);
13 #define CONST0 (0)
14 #define CONST1 (1)
15 #define CONST2 (2)
16 #define CONST3 (3)
18 /* Test that indices > length of vector are applied modulo the vector
19 length. */
21 /* Test for vector residing in register. */
22 int s3 (vector int v)
24 return __builtin_vec_ext_v4si (v, 3);
27 int s1 (vector int v)
29 return __builtin_vec_ext_v4si (v, 1);
32 int s21 (vector int v)
34 return __builtin_vec_ext_v4si (v, 21);
37 int s30 (vector int v)
39 return __builtin_vec_ext_v4si (v, 30);
42 /* Test for vector residing in memory. */
43 int ms3 (vector int *vp)
45 return __builtin_vec_ext_v4si (*vp, 3);
48 int ms1(vector int *vp)
50 return __builtin_vec_ext_v4si (*vp, 1);
53 int ms21(vector int *vp)
55 return __builtin_vec_ext_v4si (*vp, 21);
58 int ms30(vector int *vp)
60 return __builtin_vec_ext_v4si (*vp, 30);
63 /* Test the same with variable indices. */
65 /* Test for variable selector and vector residing in register. */
66 __attribute__((noinline))
67 int ci (vector int v, int i)
69 return __builtin_vec_ext_v4si (v, i);
72 /* Test for variable selector and vector residing in memory. */
73 __attribute__((noinline))
74 int mci(vector int *vp, int i)
76 return __builtin_vec_ext_v4si (*vp, i);
80 int main (int argc, int *argv[]) {
81 vector int sv = { CONST0, CONST1, CONST2, CONST3 };
82 int s;
84 s = s3 (sv);
85 if (s != CONST3)
86 abort ();
88 s = s1 (sv);
89 if (s != CONST1)
90 abort ();
92 s = s21 (sv);
93 if (s != CONST1)
94 abort ();
96 s = s30 (sv);
97 if (s != CONST2)
98 abort ();
100 s = ms3 (&sv);
101 if (s != CONST3)
102 abort ();
104 s = ms1 (&sv);
105 if (s != CONST1)
106 abort ();
108 s = ms21 (&sv);
109 if (s != CONST1)
110 abort ();
112 s = ms30 (&sv);
113 if (s != CONST2)
114 abort ();
116 s = ci (sv, 5);
117 if (s != CONST1)
118 abort ();
120 s = ci (sv, 2);
121 if (s != CONST2)
122 abort ();
124 s = ci (sv, 15);
125 if (s != CONST3)
126 abort ();
128 s = ci (sv, 28);
129 if (s != CONST0)
130 abort ();
132 s = mci (&sv, 5);
133 if (s != CONST1)
134 abort ();
136 s = mci (&sv, 12);
137 if (s != CONST0)
138 abort ();
140 s = mci (&sv, 25);
141 if (s != CONST1)
142 abort ();
144 s = mci (&sv, 16);
145 if (s != CONST0)
146 abort ();
148 return 0;