[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vsx-builtin-9c.c
blob3bec1474954dc6ef4ec88258e080dc59810bd99c
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/vmx
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)
21 #define CONST8 (8)
22 #define CONST9 (9)
23 #define CONSTA (10)
24 #define CONSTB (11)
25 #define CONSTC (12)
26 #define CONSTD (13)
27 #define CONSTE (14)
28 #define CONSTF (15)
31 /* Test that indices > length of vector are applied modulo the vector
32 length. */
34 /* Test for vector residing in register. */
35 vector signed char c0 (vector signed char v, signed char x)
37 return vec_insert (x, v, 0);
40 vector signed char c9 (vector signed char v, signed char x)
42 return vec_insert (x, v, 9);
45 vector signed char c21 (vector signed char v, signed char x)
47 return vec_insert (x, v, 21);
50 vector signed char c30 (vector signed char v, signed char x)
52 return vec_insert (x, v, 30);
55 /* Test for vector residing in memory. */
56 vector signed char mc0 (vector signed char *vp, signed char x)
58 return vec_insert (x, *vp, 0);
61 vector signed char mc9 (vector signed char *vp, signed char x)
63 return vec_insert (x, *vp, 9);
66 vector signed char mc21 (vector signed char *vp, signed char x)
68 return vec_insert (x, *vp, 21);
71 vector signed char mc30 (vector signed char *vp, signed char x)
73 return vec_insert (x, *vp, 30);
76 /* Test the same with variable indices. */
78 /* Test for variable selector and vector residing in register. */
79 __attribute__((noinline))
80 vector signed char ci (vector signed char v, int i, signed char x)
82 return vec_insert (x, v, i);
85 /* Test for variable selector and vector residing in memory. */
86 __attribute__((noinline))
87 vector signed char mci(vector signed char *vp, int i, signed char x) {
88 return vec_insert (x, *vp, i);
92 int main (int argc, char *argv[]) {
93 vector signed char cv = { CONST0, CONST1, CONST2, CONST3,
94 CONST4, CONST5, CONST6, CONST7,
95 CONST8, CONST9, CONSTA, CONSTB,
96 CONSTC, CONSTD, CONSTE, CONSTF };
97 signed char c;
99 cv = c0 (cv, CONSTF);
100 if (cv [0] != CONSTF)
101 abort ();
103 cv = c9 (cv, CONST7);
104 if (cv [9] != CONST7)
105 abort ();
107 cv = c21 (cv, CONSTA);
108 if (cv [5] != CONSTA)
109 abort ();
111 cv = c30 (cv, CONSTC);
112 if (cv [14] != CONSTC)
113 abort ();
115 cv = mc0 (&cv, CONSTB);
116 if (cv [0] != CONSTB)
117 abort ();
119 cv = mc9 (&cv, CONST1);
120 if (cv [9] != CONST1)
121 abort ();
123 cv = mc21 (&cv, CONST7);
124 if (cv [5] != CONST7)
125 abort ();
127 cv = mc30 (&cv, CONST2);
128 if (cv [14] != CONST2)
129 abort ();
131 cv = ci (cv, 8, CONST4);
132 if (cv [8] != CONST4)
133 abort ();
135 cv = ci (cv, 13, CONSTB);
136 if (cv [13] != CONSTB)
137 abort ();
139 cv = ci (cv, 23, CONST3);
140 if (cv [7] != CONST3)
141 abort ();
143 cv = ci (cv, 31, CONST2);
144 if (cv [15] != CONST2)
145 abort ();
147 cv = mci (&cv, 5, CONST1);
148 if (cv [5] != CONST1)
149 abort ();
151 cv = mci (&cv, 12, CONST3);
152 if (cv [12] != CONST3)
153 abort ();
155 cv = mci (&cv, 25, CONST5);
156 if (cv [9] != CONST5)
157 abort ();
159 cv = mci (&cv, 16, CONSTD);
160 if (cv [0] != CONSTD)
161 abort ();
163 return 0;