15#include <freerdp/config.h>
17#include <winpr/sysinfo.h>
20#define FUNC_TEST_SIZE 65536
22static BOOL test_lShift_16s_func(
void)
25 INT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
26 INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
28 if (winpr_RAND(&val,
sizeof(val)) < 0)
30 if (winpr_RAND(src,
sizeof(src)) < 0)
34 status =
generic->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
36 if (status == PRIMITIVES_SUCCESS)
39 status = optimized->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
41 if (status == PRIMITIVES_SUCCESS)
45 status =
generic->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
47 if (status != PRIMITIVES_SUCCESS)
50 status = optimized->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
52 if (status != PRIMITIVES_SUCCESS)
56 status =
generic->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
58 if (status != PRIMITIVES_SUCCESS)
61 status = optimized->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
63 return (status == PRIMITIVES_SUCCESS);
66static BOOL test_lShift_16u_func(
void)
69 UINT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
70 UINT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
72 if (winpr_RAND(&val,
sizeof(val)) < 0)
74 if (winpr_RAND(src,
sizeof(src)) < 0)
79 status =
generic->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
81 if (status == PRIMITIVES_SUCCESS)
84 status = optimized->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
86 if (status == PRIMITIVES_SUCCESS)
90 status =
generic->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
92 if (status != PRIMITIVES_SUCCESS)
95 status = optimized->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
97 if (status != PRIMITIVES_SUCCESS)
101 status =
generic->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
103 if (status != PRIMITIVES_SUCCESS)
106 status = optimized->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
108 return (status == PRIMITIVES_SUCCESS);
111static BOOL test_rShift_16s_func(
void)
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;
117 if (winpr_RAND(&val,
sizeof(val)) < 0)
119 if (winpr_RAND(src,
sizeof(src)) < 0)
124 status =
generic->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
126 if (status == PRIMITIVES_SUCCESS)
129 status = optimized->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
131 if (status == PRIMITIVES_SUCCESS)
135 status =
generic->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
137 if (status != PRIMITIVES_SUCCESS)
140 status = optimized->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
142 if (status != PRIMITIVES_SUCCESS)
146 status =
generic->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
148 if (status != PRIMITIVES_SUCCESS)
151 status = optimized->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
153 return (status == PRIMITIVES_SUCCESS);
156static BOOL test_rShift_16u_func(
void)
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;
162 if (winpr_RAND(&val,
sizeof(val)) < 0)
164 if (winpr_RAND(src,
sizeof(src)) < 0)
168 status =
generic->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
170 if (status == PRIMITIVES_SUCCESS)
173 status = optimized->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
175 if (status == PRIMITIVES_SUCCESS)
179 status =
generic->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
181 if (status != PRIMITIVES_SUCCESS)
184 status = optimized->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
186 if (status != PRIMITIVES_SUCCESS)
190 status =
generic->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
192 if (status != PRIMITIVES_SUCCESS)
195 status = optimized->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
197 return (status == PRIMITIVES_SUCCESS);
200static BOOL test_ShiftWrapper_16s_func(
void)
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;
206 if (winpr_RAND(&tmp,
sizeof(tmp)) < 0)
208 if (winpr_RAND(src,
sizeof(src)) < 0)
210 INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
213 status =
generic->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
215 if (status == PRIMITIVES_SUCCESS)
218 status = optimized->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
220 if (status == PRIMITIVES_SUCCESS)
224 status =
generic->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
226 if (status != PRIMITIVES_SUCCESS)
229 status = optimized->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
231 if (status != PRIMITIVES_SUCCESS)
234 status =
generic->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
236 if (status != PRIMITIVES_SUCCESS)
239 status = optimized->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
241 if (status != PRIMITIVES_SUCCESS)
245 status =
generic->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
247 if (status != PRIMITIVES_SUCCESS)
250 status = optimized->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
252 if (status != PRIMITIVES_SUCCESS)
255 status =
generic->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
257 if (status != PRIMITIVES_SUCCESS)
260 status = optimized->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
262 return (status == PRIMITIVES_SUCCESS);
265static BOOL test_ShiftWrapper_16u_func(
void)
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;
271 if (winpr_RAND(&tmp,
sizeof(tmp)) < 0)
273 if (winpr_RAND(src,
sizeof(src)) < 0)
275 INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
278 status =
generic->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
279 if (status == PRIMITIVES_SUCCESS)
282 status = optimized->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
284 if (status == PRIMITIVES_SUCCESS)
288 status =
generic->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
290 if (status != PRIMITIVES_SUCCESS)
293 status = optimized->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
295 if (status != PRIMITIVES_SUCCESS)
298 status =
generic->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
300 if (status != PRIMITIVES_SUCCESS)
303 status = optimized->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
305 if (status != PRIMITIVES_SUCCESS)
309 status =
generic->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
311 if (status != PRIMITIVES_SUCCESS)
314 status = optimized->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
316 if (status != PRIMITIVES_SUCCESS)
319 status =
generic->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
321 if (status != PRIMITIVES_SUCCESS)
324 status = optimized->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
326 return (status == PRIMITIVES_SUCCESS);
330static BOOL test_lShift_16s_speed(
void)
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)
337 if (winpr_RAND(&val,
sizeof(val)))
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))
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))
353static BOOL test_lShift_16u_speed(
void)
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)
360 if (winpr_RAND(src,
sizeof(src)) < 0)
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))
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))
376static BOOL test_rShift_16s_speed(
void)
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)
383 if (winpr_RAND(&val,
sizeof(val)) < 0)
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))
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))
399static BOOL test_rShift_16u_speed(
void)
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)
406 if (winpr_RAND(src,
sizeof(src)) < 0)
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))
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))
421int TestPrimitivesShift(
int argc,
char* argv[])
425 prim_test_setup(FALSE);
427 if (!test_lShift_16s_func())
430 if (g_TestPrimitivesPerformance)
432 if (!test_lShift_16s_speed())
436 if (!test_lShift_16u_func())
439 if (g_TestPrimitivesPerformance)
441 if (!test_lShift_16u_speed())
445 if (!test_rShift_16s_func())
448 if (g_TestPrimitivesPerformance)
450 if (!test_rShift_16s_speed())
454 if (!test_rShift_16u_func())
457 if (g_TestPrimitivesPerformance)
459 if (!test_rShift_16u_speed())
463 if (!test_ShiftWrapper_16s_func())
466 if (!test_ShiftWrapper_16u_func())