15 #include <freerdp/config.h>
17 #include <winpr/sysinfo.h>
19 #include "prim_test.h"
21 #define FUNC_TEST_SIZE 65536
23 #define VALUE (0xA5A5A5A5U)
26 static BOOL test_and_32u_impl(
const char* name, __andC_32u_t fkt,
const UINT32* src,
27 const UINT32 val, UINT32* dst,
size_t size)
29 pstatus_t status = fkt(src, val, dst, size);
30 if (status != PRIMITIVES_SUCCESS)
33 for (
size_t i = 0; i < size; ++i)
35 if (dst[i] != (src[i] & val))
38 printf(
"AND %s FAIL[%" PRIuz
"] 0x%08" PRIx32
"&0x%08" PRIx32
"=0x%08" PRIx32
39 ", got 0x%08" PRIx32
"\n",
40 name, i, src[i], val, (src[i] & val), dst[i]);
49 static BOOL test_and_32u_func(
void)
51 UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
52 UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 };
54 winpr_RAND(src,
sizeof(src));
56 if (!test_and_32u_impl(
"generic->andC_32u aligned", generic->andC_32u, src + 1, VALUE, dst + 1,
59 if (!test_and_32u_impl(
"generic->andC_32u unaligned", generic->andC_32u, src + 1, VALUE,
60 dst + 2, FUNC_TEST_SIZE))
62 if (!test_and_32u_impl(
"optimized->andC_32u aligned", optimized->andC_32u, src + 1, VALUE,
63 dst + 1, FUNC_TEST_SIZE))
65 if (!test_and_32u_impl(
"optimized->andC_32u unaligned", optimized->andC_32u, src + 1, VALUE,
66 dst + 2, FUNC_TEST_SIZE))
73 static BOOL test_and_32u_speed(
void)
75 UINT32 ALIGN(src[MAX_TEST_SIZE + 3]) = { 0 };
76 UINT32 ALIGN(dst[MAX_TEST_SIZE + 3]) = { 0 };
78 winpr_RAND(src,
sizeof(src));
80 if (!speed_test(
"andC_32u",
"aligned", g_Iterations, (speed_test_fkt)generic->andC_32u,
81 (speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 1, MAX_TEST_SIZE))
83 if (!speed_test(
"andC_32u",
"unaligned", g_Iterations, (speed_test_fkt)generic->andC_32u,
84 (speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 2, MAX_TEST_SIZE))
91 static BOOL check(
const UINT32* src,
const UINT32* dst, UINT32 size, UINT32 value)
93 for (UINT32 i = 0; i < size; ++i)
95 if (dst[i] != (src[i] | value))
97 printf(
"OR-general general FAIL[%" PRIu32
"] 0x%08" PRIx32
"&0x%08" PRIx32
98 "=0x%08" PRIx32
", got 0x%08" PRIx32
"\n",
99 i, src[i], value, src[i] | value, dst[i]);
107 static BOOL test_or_32u_func(
void)
109 pstatus_t status = 0;
110 UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
111 UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 };
113 winpr_RAND(src,
sizeof(src));
115 status =
generic->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
116 if (status != PRIMITIVES_SUCCESS)
119 if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
122 status = optimized->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
123 if (status != PRIMITIVES_SUCCESS)
126 if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
133 static BOOL test_or_32u_speed(
void)
135 UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
136 UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 };
138 winpr_RAND(src,
sizeof(src));
140 if (!speed_test(
"add16s",
"aligned", g_Iterations, (speed_test_fkt)generic->orC_32u,
141 (speed_test_fkt)optimized->orC_32u, src + 1, VALUE, dst + 1, FUNC_TEST_SIZE))
147 int TestPrimitivesAndOr(
int argc,
char* argv[])
152 prim_test_setup(FALSE);
154 if (!test_and_32u_func())
157 if (!test_or_32u_func())
160 if (g_TestPrimitivesPerformance)
162 if (!test_and_32u_speed())
164 if (!test_or_32u_speed())