FreeRDP
TestPrimitivesShift.c
1 /* test_shift.c
2  * vi:ts=4 sw=4
3  *
4  * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License. You may obtain
7  * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 #include <freerdp/config.h>
16 
17 #include <winpr/sysinfo.h>
18 #include "prim_test.h"
19 
20 #define FUNC_TEST_SIZE 65536
21 
22 static BOOL test_lShift_16s_func(void)
23 {
24  pstatus_t status = 0;
25  INT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
26  INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
27  UINT32 val = 0;
28  winpr_RAND(&val, sizeof(val));
29  winpr_RAND(src, sizeof(src));
30  val = val % 16;
31  /* Negative tests */
32  status = generic->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
33 
34  if (status == PRIMITIVES_SUCCESS)
35  return FALSE;
36 
37  status = optimized->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
38 
39  if (status == PRIMITIVES_SUCCESS)
40  return FALSE;
41 
42  /* Aligned */
43  status = generic->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
44 
45  if (status != PRIMITIVES_SUCCESS)
46  return FALSE;
47 
48  status = optimized->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
49 
50  if (status != PRIMITIVES_SUCCESS)
51  return FALSE;
52 
53  /* Unaligned */
54  status = generic->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
55 
56  if (status != PRIMITIVES_SUCCESS)
57  return FALSE;
58 
59  status = optimized->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
60 
61  if (status != PRIMITIVES_SUCCESS)
62  return FALSE;
63 
64  return TRUE;
65 }
66 
67 static BOOL test_lShift_16u_func(void)
68 {
69  pstatus_t status = 0;
70  UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
71  UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
72  UINT32 val = 0;
73  winpr_RAND(&val, sizeof(val));
74  winpr_RAND(src, sizeof(src));
75  val = val % 16;
76 
77  /* Negative tests */
78  status = generic->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
79 
80  if (status == PRIMITIVES_SUCCESS)
81  return FALSE;
82 
83  status = optimized->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
84 
85  if (status == PRIMITIVES_SUCCESS)
86  return FALSE;
87 
88  /* Aligned */
89  status = generic->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
90 
91  if (status != PRIMITIVES_SUCCESS)
92  return FALSE;
93 
94  status = optimized->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
95 
96  if (status != PRIMITIVES_SUCCESS)
97  return FALSE;
98 
99  /* Unaligned */
100  status = generic->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
101 
102  if (status != PRIMITIVES_SUCCESS)
103  return FALSE;
104 
105  status = optimized->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
106 
107  if (status != PRIMITIVES_SUCCESS)
108  return FALSE;
109 
110  return TRUE;
111 }
112 
113 static BOOL test_rShift_16s_func(void)
114 {
115  pstatus_t status = 0;
116  INT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
117  INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
118  UINT32 val = 0;
119  winpr_RAND(&val, sizeof(val));
120  winpr_RAND(src, sizeof(src));
121  val = val % 16;
122 
123  /* Negative Tests */
124  status = generic->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
125 
126  if (status == PRIMITIVES_SUCCESS)
127  return FALSE;
128 
129  status = optimized->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
130 
131  if (status == PRIMITIVES_SUCCESS)
132  return FALSE;
133 
134  /* Aligned */
135  status = generic->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
136 
137  if (status != PRIMITIVES_SUCCESS)
138  return FALSE;
139 
140  status = optimized->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
141 
142  if (status != PRIMITIVES_SUCCESS)
143  return FALSE;
144 
145  /* Unaligned */
146  status = generic->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
147 
148  if (status != PRIMITIVES_SUCCESS)
149  return FALSE;
150 
151  status = optimized->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
152 
153  if (status != PRIMITIVES_SUCCESS)
154  return FALSE;
155 
156  return TRUE;
157 }
158 
159 static BOOL test_rShift_16u_func(void)
160 {
161  pstatus_t status = 0;
162  UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
163  UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
164  UINT32 val = 0;
165  winpr_RAND(&val, sizeof(val));
166  winpr_RAND(src, sizeof(src));
167  val = val % 16;
168  /* Negative tests */
169  status = generic->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
170 
171  if (status == PRIMITIVES_SUCCESS)
172  return FALSE;
173 
174  status = optimized->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
175 
176  if (status == PRIMITIVES_SUCCESS)
177  return FALSE;
178 
179  /* Aligned */
180  status = generic->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
181 
182  if (status != PRIMITIVES_SUCCESS)
183  return FALSE;
184 
185  status = optimized->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
186 
187  if (status != PRIMITIVES_SUCCESS)
188  return FALSE;
189 
190  /* Unaligned */
191  status = generic->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
192 
193  if (status != PRIMITIVES_SUCCESS)
194  return FALSE;
195 
196  status = optimized->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
197 
198  if (status != PRIMITIVES_SUCCESS)
199  return FALSE;
200 
201  return TRUE;
202 }
203 
204 static BOOL test_ShiftWrapper_16s_func(void)
205 {
206  pstatus_t status = 0;
207  INT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
208  INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
209  UINT32 tmp = 0;
210  INT32 val = 0;
211  winpr_RAND(&tmp, sizeof(tmp));
212  winpr_RAND(src, sizeof(src));
213  val = tmp % 16;
214 
215  /* Negative tests */
216  status = generic->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
217 
218  if (status == PRIMITIVES_SUCCESS)
219  return FALSE;
220 
221  status = optimized->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
222 
223  if (status == PRIMITIVES_SUCCESS)
224  return FALSE;
225 
226  /* Aligned */
227  status = generic->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
228 
229  if (status != PRIMITIVES_SUCCESS)
230  return FALSE;
231 
232  status = optimized->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
233 
234  if (status != PRIMITIVES_SUCCESS)
235  return FALSE;
236 
237  status = generic->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
238 
239  if (status != PRIMITIVES_SUCCESS)
240  return FALSE;
241 
242  status = optimized->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
243 
244  if (status != PRIMITIVES_SUCCESS)
245  return FALSE;
246 
247  /* Unaligned */
248  status = generic->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
249 
250  if (status != PRIMITIVES_SUCCESS)
251  return FALSE;
252 
253  status = optimized->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
254 
255  if (status != PRIMITIVES_SUCCESS)
256  return FALSE;
257 
258  status = generic->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
259 
260  if (status != PRIMITIVES_SUCCESS)
261  return FALSE;
262 
263  status = optimized->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
264 
265  if (status != PRIMITIVES_SUCCESS)
266  return FALSE;
267 
268  return TRUE;
269 }
270 
271 static BOOL test_ShiftWrapper_16u_func(void)
272 {
273  pstatus_t status = 0;
274  UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
275  UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
276  UINT32 tmp = 0;
277  INT32 val = 0;
278  winpr_RAND(&tmp, sizeof(tmp));
279  winpr_RAND(src, sizeof(src));
280  val = tmp % 16;
281 
282  /* Negative */
283  status = generic->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
284  if (status == PRIMITIVES_SUCCESS)
285  return FALSE;
286 
287  status = optimized->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
288 
289  if (status == PRIMITIVES_SUCCESS)
290  return FALSE;
291 
292  /* Aligned */
293  status = generic->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
294 
295  if (status != PRIMITIVES_SUCCESS)
296  return FALSE;
297 
298  status = optimized->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
299 
300  if (status != PRIMITIVES_SUCCESS)
301  return FALSE;
302 
303  status = generic->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
304 
305  if (status != PRIMITIVES_SUCCESS)
306  return FALSE;
307 
308  status = optimized->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
309 
310  if (status != PRIMITIVES_SUCCESS)
311  return FALSE;
312 
313  /* Unaligned */
314  status = generic->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
315 
316  if (status != PRIMITIVES_SUCCESS)
317  return FALSE;
318 
319  status = optimized->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
320 
321  if (status != PRIMITIVES_SUCCESS)
322  return FALSE;
323 
324  status = generic->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
325 
326  if (status != PRIMITIVES_SUCCESS)
327  return FALSE;
328 
329  status = optimized->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
330 
331  if (status != PRIMITIVES_SUCCESS)
332  return FALSE;
333 
334  return TRUE;
335 }
336 
337 /* ------------------------------------------------------------------------- */
338 static BOOL test_lShift_16s_speed(void)
339 {
340  UINT32 val = 0;
341  INT16 ALIGN(src[MAX_TEST_SIZE + 1]);
342  INT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
343  winpr_RAND(src, sizeof(src));
344  winpr_RAND(&val, sizeof(val));
345 
346  val = val % 16;
347  if (!speed_test("lShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
348  (speed_test_fkt)optimized->lShiftC_16s, src, val, dst, MAX_TEST_SIZE))
349  return FALSE;
350 
351  if (!speed_test("lShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
352  (speed_test_fkt)optimized->lShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
353  return FALSE;
354 
355  return TRUE;
356 }
357 
358 /* ------------------------------------------------------------------------- */
359 static BOOL test_lShift_16u_speed(void)
360 {
361  UINT32 val = 0;
362  UINT16 ALIGN(src[MAX_TEST_SIZE + 1]);
363  UINT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
364  winpr_RAND(&val, sizeof(val));
365  winpr_RAND(src, sizeof(src));
366 
367  val = val % 16;
368  if (!speed_test("lShift_16u", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
369  (speed_test_fkt)optimized->lShiftC_16u, src, val, dst, MAX_TEST_SIZE))
370  return FALSE;
371 
372  if (!speed_test("lShift_16u", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
373  (speed_test_fkt)optimized->lShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE))
374  return FALSE;
375 
376  return TRUE;
377 }
378 
379 /* ------------------------------------------------------------------------- */
380 static BOOL test_rShift_16s_speed(void)
381 {
382  UINT32 val = 0;
383  INT16 ALIGN(src[MAX_TEST_SIZE + 1]);
384  INT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
385  winpr_RAND(src, sizeof(src));
386  winpr_RAND(&val, sizeof(val));
387 
388  val = val % 16;
389  if (!speed_test("rShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
390  (speed_test_fkt)optimized->rShiftC_16s, src, val, dst, MAX_TEST_SIZE))
391  return FALSE;
392 
393  if (!speed_test("rShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
394  (speed_test_fkt)optimized->rShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
395  return FALSE;
396 
397  return TRUE;
398 }
399 
400 /* ------------------------------------------------------------------------- */
401 static BOOL test_rShift_16u_speed(void)
402 {
403  UINT32 val = 0;
404  UINT16 ALIGN(src[MAX_TEST_SIZE + 1]);
405  UINT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
406  winpr_RAND(&val, sizeof(val));
407  winpr_RAND(src, sizeof(src));
408 
409  val = val % 16;
410  if (!speed_test("rShift_16u", "aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u,
411  (speed_test_fkt)optimized->rShiftC_16u, src, val, dst, MAX_TEST_SIZE))
412  return FALSE;
413 
414  if (!speed_test("rShift_16u", "unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u,
415  (speed_test_fkt)optimized->rShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE))
416  return FALSE;
417 
418  return TRUE;
419 }
420 
421 int TestPrimitivesShift(int argc, char* argv[])
422 {
423  WINPR_UNUSED(argc);
424  WINPR_UNUSED(argv);
425  prim_test_setup(FALSE);
426 
427  if (!test_lShift_16s_func())
428  return 1;
429 
430  if (g_TestPrimitivesPerformance)
431  {
432  if (!test_lShift_16s_speed())
433  return 1;
434  }
435 
436  if (!test_lShift_16u_func())
437  return 1;
438 
439  if (g_TestPrimitivesPerformance)
440  {
441  if (!test_lShift_16u_speed())
442  return 1;
443  }
444 
445  if (!test_rShift_16s_func())
446  return 1;
447 
448  if (g_TestPrimitivesPerformance)
449  {
450  if (!test_rShift_16s_speed())
451  return 1;
452  }
453 
454  if (!test_rShift_16u_func())
455  return 1;
456 
457  if (g_TestPrimitivesPerformance)
458  {
459  if (!test_rShift_16u_speed())
460  return 1;
461  }
462 
463  if (!test_ShiftWrapper_16s_func())
464  return 1;
465 
466  if (!test_ShiftWrapper_16u_func())
467  return 1;
468 
469  return 0;
470 }