FreeRDP
Loading...
Searching...
No Matches
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
22static BOOL test_lShift_16s_func(void)
23{
24 pstatus_t status = 0;
25 INT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
26 INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
27 UINT32 val = 0;
28 if (winpr_RAND(&val, sizeof(val)) < 0)
29 return FALSE;
30 if (winpr_RAND(src, sizeof(src)) < 0)
31 return FALSE;
32 val = val % 16;
33 /* Negative tests */
34 status = generic->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
35
36 if (status == PRIMITIVES_SUCCESS)
37 return FALSE;
38
39 status = optimized->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
40
41 if (status == PRIMITIVES_SUCCESS)
42 return FALSE;
43
44 /* Aligned */
45 status = generic->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
46
47 if (status != PRIMITIVES_SUCCESS)
48 return FALSE;
49
50 status = optimized->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
51
52 if (status != PRIMITIVES_SUCCESS)
53 return FALSE;
54
55 /* Unaligned */
56 status = generic->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
57
58 if (status != PRIMITIVES_SUCCESS)
59 return FALSE;
60
61 status = optimized->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
62
63 return (status == PRIMITIVES_SUCCESS);
64}
65
66static BOOL test_lShift_16u_func(void)
67{
68 pstatus_t status = 0;
69 UINT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
70 UINT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
71 UINT32 val = 0;
72 if (winpr_RAND(&val, sizeof(val)) < 0)
73 return FALSE;
74 if (winpr_RAND(src, sizeof(src)) < 0)
75 return FALSE;
76 val = val % 16;
77
78 /* Negative tests */
79 status = generic->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
80
81 if (status == PRIMITIVES_SUCCESS)
82 return FALSE;
83
84 status = optimized->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
85
86 if (status == PRIMITIVES_SUCCESS)
87 return FALSE;
88
89 /* Aligned */
90 status = generic->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
91
92 if (status != PRIMITIVES_SUCCESS)
93 return FALSE;
94
95 status = optimized->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
96
97 if (status != PRIMITIVES_SUCCESS)
98 return FALSE;
99
100 /* Unaligned */
101 status = generic->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
102
103 if (status != PRIMITIVES_SUCCESS)
104 return FALSE;
105
106 status = optimized->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
107
108 return (status == PRIMITIVES_SUCCESS);
109}
110
111static BOOL test_rShift_16s_func(void)
112{
113 pstatus_t status = 0;
114 INT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
115 INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
116 UINT32 val = 0;
117 if (winpr_RAND(&val, sizeof(val)) < 0)
118 return FALSE;
119 if (winpr_RAND(src, sizeof(src)) < 0)
120 return FALSE;
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 return (status == PRIMITIVES_SUCCESS);
154}
155
156static BOOL test_rShift_16u_func(void)
157{
158 pstatus_t status = 0;
159 UINT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
160 UINT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
161 UINT32 val = 0;
162 if (winpr_RAND(&val, sizeof(val)) < 0)
163 return FALSE;
164 if (winpr_RAND(src, sizeof(src)) < 0)
165 return FALSE;
166 val = val % 16;
167 /* Negative tests */
168 status = generic->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
169
170 if (status == PRIMITIVES_SUCCESS)
171 return FALSE;
172
173 status = optimized->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
174
175 if (status == PRIMITIVES_SUCCESS)
176 return FALSE;
177
178 /* Aligned */
179 status = generic->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
180
181 if (status != PRIMITIVES_SUCCESS)
182 return FALSE;
183
184 status = optimized->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
185
186 if (status != PRIMITIVES_SUCCESS)
187 return FALSE;
188
189 /* Unaligned */
190 status = generic->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
191
192 if (status != PRIMITIVES_SUCCESS)
193 return FALSE;
194
195 status = optimized->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
196
197 return (status == PRIMITIVES_SUCCESS);
198}
199
200static BOOL test_ShiftWrapper_16s_func(void)
201{
202 pstatus_t status = 0;
203 INT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
204 INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
205 UINT32 tmp = 0;
206 if (winpr_RAND(&tmp, sizeof(tmp)) < 0)
207 return FALSE;
208 if (winpr_RAND(src, sizeof(src)) < 0)
209 return FALSE;
210 INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
211
212 /* Negative tests */
213 status = generic->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
214
215 if (status == PRIMITIVES_SUCCESS)
216 return FALSE;
217
218 status = optimized->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
219
220 if (status == PRIMITIVES_SUCCESS)
221 return FALSE;
222
223 /* Aligned */
224 status = generic->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
225
226 if (status != PRIMITIVES_SUCCESS)
227 return FALSE;
228
229 status = optimized->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
230
231 if (status != PRIMITIVES_SUCCESS)
232 return FALSE;
233
234 status = generic->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
235
236 if (status != PRIMITIVES_SUCCESS)
237 return FALSE;
238
239 status = optimized->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
240
241 if (status != PRIMITIVES_SUCCESS)
242 return FALSE;
243
244 /* Unaligned */
245 status = generic->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
246
247 if (status != PRIMITIVES_SUCCESS)
248 return FALSE;
249
250 status = optimized->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
251
252 if (status != PRIMITIVES_SUCCESS)
253 return FALSE;
254
255 status = generic->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
256
257 if (status != PRIMITIVES_SUCCESS)
258 return FALSE;
259
260 status = optimized->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
261
262 return (status == PRIMITIVES_SUCCESS);
263}
264
265static BOOL test_ShiftWrapper_16u_func(void)
266{
267 pstatus_t status = 0;
268 UINT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
269 UINT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
270 UINT32 tmp = 0;
271 if (winpr_RAND(&tmp, sizeof(tmp)) < 0)
272 return FALSE;
273 if (winpr_RAND(src, sizeof(src)) < 0)
274 return FALSE;
275 INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
276
277 /* Negative */
278 status = generic->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
279 if (status == PRIMITIVES_SUCCESS)
280 return FALSE;
281
282 status = optimized->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
283
284 if (status == PRIMITIVES_SUCCESS)
285 return FALSE;
286
287 /* Aligned */
288 status = generic->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
289
290 if (status != PRIMITIVES_SUCCESS)
291 return FALSE;
292
293 status = optimized->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
294
295 if (status != PRIMITIVES_SUCCESS)
296 return FALSE;
297
298 status = generic->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
299
300 if (status != PRIMITIVES_SUCCESS)
301 return FALSE;
302
303 status = optimized->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
304
305 if (status != PRIMITIVES_SUCCESS)
306 return FALSE;
307
308 /* Unaligned */
309 status = generic->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
310
311 if (status != PRIMITIVES_SUCCESS)
312 return FALSE;
313
314 status = optimized->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
315
316 if (status != PRIMITIVES_SUCCESS)
317 return FALSE;
318
319 status = generic->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
320
321 if (status != PRIMITIVES_SUCCESS)
322 return FALSE;
323
324 status = optimized->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
325
326 return (status == PRIMITIVES_SUCCESS);
327}
328
329/* ------------------------------------------------------------------------- */
330static BOOL test_lShift_16s_speed(void)
331{
332 UINT32 val = 0;
333 INT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
334 INT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
335 if (winpr_RAND(src, sizeof(src)) < 0)
336 return FALSE;
337 if (winpr_RAND(&val, sizeof(val)))
338 return FALSE;
339
340 val = val % 16;
341 if (!speed_test("lShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
342 (speed_test_fkt)optimized->lShiftC_16s, src, val, dst, MAX_TEST_SIZE))
343 return FALSE;
344
345 if (!speed_test("lShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
346 (speed_test_fkt)optimized->lShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
347 return FALSE;
348
349 return TRUE;
350}
351
352/* ------------------------------------------------------------------------- */
353static BOOL test_lShift_16u_speed(void)
354{
355 UINT32 val = 0;
356 UINT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
357 UINT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
358 if (winpr_RAND(&val, sizeof(val)) < 0)
359 return FALSE;
360 if (winpr_RAND(src, sizeof(src)) < 0)
361 return FALSE;
362
363 val = val % 16;
364 if (!speed_test("lShift_16u", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
365 (speed_test_fkt)optimized->lShiftC_16u, src, val, dst, MAX_TEST_SIZE))
366 return FALSE;
367
368 if (!speed_test("lShift_16u", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
369 (speed_test_fkt)optimized->lShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE))
370 return FALSE;
371
372 return TRUE;
373}
374
375/* ------------------------------------------------------------------------- */
376static BOOL test_rShift_16s_speed(void)
377{
378 UINT32 val = 0;
379 INT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
380 INT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
381 if (winpr_RAND(src, sizeof(src)) < 0)
382 return FALSE;
383 if (winpr_RAND(&val, sizeof(val)) < 0)
384 return FALSE;
385
386 val = val % 16;
387 if (!speed_test("rShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
388 (speed_test_fkt)optimized->rShiftC_16s, src, val, dst, MAX_TEST_SIZE))
389 return FALSE;
390
391 if (!speed_test("rShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
392 (speed_test_fkt)optimized->rShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
393 return FALSE;
394
395 return TRUE;
396}
397
398/* ------------------------------------------------------------------------- */
399static BOOL test_rShift_16u_speed(void)
400{
401 UINT32 val = 0;
402 UINT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
403 UINT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
404 if (winpr_RAND(&val, sizeof(val)) < 0)
405 return FALSE;
406 if (winpr_RAND(src, sizeof(src)) < 0)
407 return FALSE;
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
421int 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}