FreeRDP
Loading...
Searching...
No Matches
TestPrimitivesAndOr.c
1/* test_andor.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
19#include "prim_test.h"
20
21#define FUNC_TEST_SIZE 65536
22
23#define VALUE (0xA5A5A5A5U)
24
25/* ========================================================================= */
26static BOOL test_and_32u_impl(const char* name, fn_andC_32u_t fkt, const UINT32* src,
27 const UINT32 val, UINT32* dst, size_t size)
28{
29 pstatus_t status = fkt(src, val, dst, WINPR_ASSERTING_INT_CAST(int32_t, size));
30 if (status != PRIMITIVES_SUCCESS)
31 return FALSE;
32
33 for (size_t i = 0; i < size; ++i)
34 {
35 if (dst[i] != (src[i] & val))
36 {
37
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]);
41
42 return FALSE;
43 }
44 }
45
46 return TRUE;
47}
48
49static BOOL test_and_32u_func(void)
50{
51 UINT32 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
52 UINT32 dst[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
53
54 if (winpr_RAND(src, sizeof(src)) < 0)
55 return FALSE;
56
57 if (!test_and_32u_impl("generic->andC_32u aligned", generic->andC_32u, src + 1, VALUE, dst + 1,
58 FUNC_TEST_SIZE))
59 return FALSE;
60 if (!test_and_32u_impl("generic->andC_32u unaligned", generic->andC_32u, src + 1, VALUE,
61 dst + 2, FUNC_TEST_SIZE))
62 return FALSE;
63 if (!test_and_32u_impl("optimized->andC_32u aligned", optimized->andC_32u, src + 1, VALUE,
64 dst + 1, FUNC_TEST_SIZE))
65 return FALSE;
66 if (!test_and_32u_impl("optimized->andC_32u unaligned", optimized->andC_32u, src + 1, VALUE,
67 dst + 2, FUNC_TEST_SIZE))
68 return FALSE;
69
70 return TRUE;
71}
72
73/* ------------------------------------------------------------------------- */
74static BOOL test_and_32u_speed(void)
75{
76 UINT32 src[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
77 UINT32 dst[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
78
79 if (winpr_RAND(src, sizeof(src)) < 0)
80 return FALSE;
81
82 if (!speed_test("andC_32u", "aligned", g_Iterations, (speed_test_fkt)generic->andC_32u,
83 (speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 1, MAX_TEST_SIZE))
84 return FALSE;
85 if (!speed_test("andC_32u", "unaligned", g_Iterations, (speed_test_fkt)generic->andC_32u,
86 (speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 2, MAX_TEST_SIZE))
87 return FALSE;
88
89 return TRUE;
90}
91
92/* ========================================================================= */
93static BOOL check(const UINT32* src, const UINT32* dst, UINT32 size, UINT32 value)
94{
95 for (UINT32 i = 0; i < size; ++i)
96 {
97 if (dst[i] != (src[i] | value))
98 {
99 printf("OR-general general FAIL[%" PRIu32 "] 0x%08" PRIx32 "&0x%08" PRIx32
100 "=0x%08" PRIx32 ", got 0x%08" PRIx32 "\n",
101 i, src[i], value, src[i] | value, dst[i]);
102 return FALSE;
103 }
104 }
105
106 return TRUE;
107}
108
109static BOOL test_or_32u_func(void)
110{
111 pstatus_t status = 0;
112 UINT32 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
113 UINT32 dst[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
114
115 if (winpr_RAND(src, sizeof(src)) < 0)
116 return FALSE;
117
118 status = generic->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
119 if (status != PRIMITIVES_SUCCESS)
120 return FALSE;
121
122 if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
123 return FALSE;
124
125 status = optimized->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
126 if (status != PRIMITIVES_SUCCESS)
127 return FALSE;
128
129 if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
130 return FALSE;
131
132 return TRUE;
133}
134
135/* ------------------------------------------------------------------------- */
136static BOOL test_or_32u_speed(void)
137{
138 UINT32 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
139 UINT32 dst[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
140
141 if (winpr_RAND(src, sizeof(src)) < 0)
142 return FALSE;
143
144 return (speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->orC_32u,
145 (speed_test_fkt)optimized->orC_32u, src + 1, VALUE, dst + 1,
146 FUNC_TEST_SIZE));
147}
148
149int TestPrimitivesAndOr(int argc, char* argv[])
150{
151 WINPR_UNUSED(argc);
152 WINPR_UNUSED(argv);
153
154 prim_test_setup(FALSE);
155
156 if (!test_and_32u_func())
157 return -1;
158
159 if (!test_or_32u_func())
160 return -1;
161
162 if (g_TestPrimitivesPerformance)
163 {
164 if (!test_and_32u_speed())
165 return -1;
166 if (!test_or_32u_speed())
167 return -1;
168 }
169
170 return 0;
171}