[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vsx-builtin-10b.c
blob6300b0e22304e025216dc426d027706099c36a96
1 /* { dg-do run } */
2 /* { dg-require-effective-target vmx_hw } */
3 /* { dg-options "-maltivec -O3" } */
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)
17 #define CONST4 (4)
18 #define CONST5 (5)
19 #define CONST6 (6)
20 #define CONST7 (7)
23 /* Test that indices > length of vector are applied modulo the vector
24 length. */
26 /* Test for vector residing in register. */
27 short s3 (vector short v)
29 return __builtin_vec_ext_v8hi (v, 3);
32 short s7 (vector short v)
34 return __builtin_vec_ext_v8hi (v, 7);
37 short s21 (vector short v)
39 return __builtin_vec_ext_v8hi (v, 21);
42 short s30 (vector short v)
44 return __builtin_vec_ext_v8hi (v, 30);
47 /* Test for vector residing in memory. */
48 short ms3 (vector short *vp)
50 return __builtin_vec_ext_v8hi (*vp, 3);
53 short ms7 (vector short *vp)
55 return __builtin_vec_ext_v8hi (*vp, 7);
58 short ms21 (vector short *vp)
60 return __builtin_vec_ext_v8hi (*vp, 21);
63 short ms30 (vector short *vp)
65 return __builtin_vec_ext_v8hi (*vp, 30);
68 /* Test the same with variable indices. */
70 /* Test for variable selector and vector residing in register. */
71 __attribute__((noinline))
72 short ci (vector short v, int i)
74 return __builtin_vec_ext_v8hi (v, i);
77 /* Test for variable selector and vector residing in memory. */
78 __attribute__((noinline))
79 short mci (vector short *vp, int i)
81 return __builtin_vec_ext_v8hi (*vp, i);
85 int main (int argc, short *argv[]) {
86 vector short sv = {
87 CONST0, CONST1, CONST2, CONST3, CONST4, CONST5, CONST6, CONST7 };
88 short s;
90 s = s3 (sv);
91 if (s != CONST3)
92 abort ();
94 s = s7 (sv);
95 if (s != CONST7)
96 abort ();
98 s = s21 (sv);
99 if (s != CONST5)
100 abort ();
102 s = s30 (sv);
103 if (s != CONST6)
104 abort ();
106 s = ms3 (&sv);
107 if (s != CONST3)
108 abort ();
110 s = ms7 (&sv);
111 if (s != CONST7)
112 abort ();
114 s = ms21 (&sv);
115 if (s != CONST5)
116 abort ();
118 s = ms30 (&sv);
119 if (s != CONST6)
120 abort ();
122 s = ci (sv, 5);
123 if (s != CONST5)
124 abort ();
126 s = ci (sv, 2);
127 if (s != CONST2)
128 abort ();
130 s = ci (sv, 15);
131 if (s != CONST7)
132 abort ();
134 s = ci (sv, 28);
135 if (s != CONST4)
136 abort ();
138 s = mci (&sv, 5);
139 if (s != CONST5)
140 abort ();
142 s = mci (&sv, 12);
143 if (s != CONST4)
144 abort ();
146 s = mci (&sv, 25);
147 if (s != CONST1)
148 abort ();
150 s = mci (&sv, 16);
151 if (s != CONST0)
152 abort ();
154 return 0;