mips.h (ISA_HAS_DSP, [...]): New macros.
[official-gcc.git] / gcc / testsuite / gcc.target / mips / mips-ps-1.c
blob39fb996615a25b39c2b5215cb35d78c218ffd212
1 /* { dg-do run { target mipsisa64*-*-* } } */
2 /* { dg-mips-options "-mips64 -O2 -mpaired-single -mhard-float -mgp64" } */
4 /* Test v2sf calculations */
5 #include <stdlib.h>
6 #include <stdio.h>
8 typedef float v2sf __attribute__ ((vector_size (8)));
10 v2sf A = {100, 200};
12 /* Init from float */
13 v2sf init (float a, float b)
15 return (v2sf) {a, b};
18 /* Move between registers */
19 v2sf move (v2sf a)
21 return a;
24 /* Load from memory */
25 v2sf load ()
27 return A;
30 /* Store to memory */
31 void store (v2sf a)
33 A = a;
36 /* Add */
37 v2sf add (v2sf a, v2sf b)
39 return a + b;
42 /* Subtract */
43 v2sf sub (v2sf a, v2sf b)
45 return a - b;
48 /* Negate */
49 v2sf neg (v2sf a)
51 return - a;
54 /* Multiply */
55 v2sf mul (v2sf a, v2sf b)
57 return a * b;
60 /* Multiply and add */
61 v2sf madd (v2sf a, v2sf b, v2sf c)
63 return a * b + c;
66 /* Multiply and subtract */
67 v2sf msub (v2sf a, v2sf b, v2sf c)
69 return a * b - c;
72 /* Negate Multiply and add */
73 v2sf nmadd (v2sf a, v2sf b, v2sf c)
75 return - (a * b + c);
78 /* Negate Multiply and subtract */
79 v2sf nmsub (v2sf a, v2sf b, v2sf c)
81 return - (a * b - c);
84 /* Conditional Move */
85 v2sf cond_move1 (v2sf a, v2sf b, long i)
87 if (i > 0)
88 return a;
89 else
90 return b;
93 /* Conditional Move */
94 v2sf cond_move2 (v2sf a, v2sf b, int i)
96 if (i > 0)
97 return a;
98 else
99 return b;
102 /* Conditional Move */
103 v2sf cond_move3 (v2sf a, v2sf b, float i)
105 if (i > 0.0)
106 return a;
107 else
108 return b;
111 /* Conditional Move */
112 v2sf cond_move4 (v2sf a, v2sf b, double i)
114 if (i > 0.0)
115 return a;
116 else
117 return b;
120 NOMIPS16 int main()
122 v2sf a, b, c, d, e, f;
123 float f1, f2;
125 f1 = 1.2;
126 f2 = 3.4;
127 a = init (f1, f2);
128 b = (v2sf) {1.2, 3.4};
129 if (!__builtin_mips_upper_c_eq_ps (a, b) ||
130 !__builtin_mips_lower_c_eq_ps (a, b))
131 abort ();
133 a = (v2sf) {1.2, 2.3};
134 b = (v2sf) {5.3, 6.1};
135 b = move (a);
137 if (!__builtin_mips_upper_c_eq_ps (a, b) ||
138 !__builtin_mips_lower_c_eq_ps (a, b))
139 abort ();
141 a = (v2sf) {1.2, 2.3};
142 b = (v2sf) {5.3, 6.1};
143 c = add (a, b);
144 d = (v2sf) {6.5, 8.4};
145 if (!__builtin_mips_upper_c_eq_ps (c, d) ||
146 !__builtin_mips_lower_c_eq_ps (c, d))
147 abort ();
149 a = (v2sf) {1, 12};
150 b = (v2sf) {5, 6};
151 c = sub (a, b);
152 d = (v2sf) {-4, 6};
153 if (!__builtin_mips_upper_c_eq_ps (c, d) ||
154 !__builtin_mips_lower_c_eq_ps (c, d))
155 abort ();
157 a = (v2sf) {1, 12};
158 b = (v2sf) {5, 6};
159 c = mul (a, b);
160 d = (v2sf) {5, 72};
161 if (!__builtin_mips_upper_c_eq_ps (c, d) ||
162 !__builtin_mips_lower_c_eq_ps (c, d))
163 abort ();
165 a = (v2sf) {1, 12};
166 b = (v2sf) {5, 6};
167 c = (v2sf) {5, 6};
168 d = madd (a, b, c);
169 e = (v2sf) {10, 78};
170 if (!__builtin_mips_upper_c_eq_ps (d, e) ||
171 !__builtin_mips_lower_c_eq_ps (d, e))
172 abort ();
174 a = (v2sf) {1, 12};
175 b = (v2sf) {5, 6};
176 c = (v2sf) {5, 6};
177 d = msub (a, b, c);
178 e = (v2sf) {0, 66};
179 if (!__builtin_mips_upper_c_eq_ps (d, e) ||
180 !__builtin_mips_lower_c_eq_ps (d, e))
181 abort ();
183 a = (v2sf) {1, 12};
184 b = (v2sf) {5, 6};
185 c = (v2sf) {5, 6};
186 d = nmadd (a, b, c);
187 e = (v2sf) {-10, -78};
188 if (!__builtin_mips_upper_c_eq_ps (d, e) ||
189 !__builtin_mips_lower_c_eq_ps (d, e))
190 abort ();
192 a = (v2sf) {1, 12};
193 b = (v2sf) {5, 6};
194 c = (v2sf) {5, 6};
195 d = nmsub (a, b, c);
196 e = (v2sf) {0, -66};
197 if (!__builtin_mips_upper_c_eq_ps (d, e) ||
198 !__builtin_mips_lower_c_eq_ps (d, e))
199 abort ();
201 a = (v2sf) {98, 12};
202 b = neg (a);
203 c = (v2sf) {-98, -12};
204 if (!__builtin_mips_upper_c_eq_ps (b, c) ||
205 !__builtin_mips_lower_c_eq_ps (b, c))
206 abort ();
208 a = (v2sf) {1, 12};
209 b = (v2sf) {5, 6};
210 c = cond_move1 (a, b, 1000);
211 if (!__builtin_mips_upper_c_eq_ps (c, a) ||
212 !__builtin_mips_lower_c_eq_ps (c, a))
213 abort ();
215 a = (v2sf) {1, 12};
216 b = (v2sf) {5, 6};
217 c = cond_move2 (a, b, -1000);
218 if (!__builtin_mips_upper_c_eq_ps (c, b) ||
219 !__builtin_mips_lower_c_eq_ps (c, b))
220 abort ();
222 a = (v2sf) {1, 12};
223 b = (v2sf) {5, 6};
224 c = cond_move3 (a, b, 9.0);
225 if (!__builtin_mips_upper_c_eq_ps (c, a) ||
226 !__builtin_mips_lower_c_eq_ps (c, a))
227 abort ();
229 a = (v2sf) {1, 12};
230 b = (v2sf) {5, 6};
231 c = cond_move4 (a, b, -10.0);
232 if (!__builtin_mips_upper_c_eq_ps (c, b) ||
233 !__builtin_mips_lower_c_eq_ps (c, b))
234 abort ();
236 a = (v2sf) {5, 12};
237 b = (v2sf) {5, 6};
238 c = (v2sf) {33, 123};
239 d = (v2sf) {8, 78};
240 e = __builtin_mips_movt_c_eq_ps (a, b, c, d);
241 f = (v2sf) {8, 123};
242 if (!__builtin_mips_upper_c_eq_ps (e, f) ||
243 !__builtin_mips_lower_c_eq_ps (e, f))
244 abort ();
246 a = (v2sf) {5, 12};
247 b = (v2sf) {5, 6};
248 c = (v2sf) {33, 123};
249 d = (v2sf) {8, 78};
250 e = __builtin_mips_movf_c_eq_ps (a, b, c, d);
251 f = (v2sf) {33, 78};
252 if (!__builtin_mips_upper_c_eq_ps (e, f) ||
253 !__builtin_mips_lower_c_eq_ps (e, f))
254 abort ();
256 a = load();
257 b = (v2sf) {100, 200};
258 if (!__builtin_mips_upper_c_eq_ps (a, b) ||
259 !__builtin_mips_lower_c_eq_ps (a, b))
260 abort ();
262 a = (v2sf) {123, 321};
263 store (a);
264 b = load();
265 if (!__builtin_mips_upper_c_eq_ps (a, b) ||
266 !__builtin_mips_lower_c_eq_ps (a, b))
267 abort ();
269 printf ("Test Passes\n");
270 exit (0);