FreeRDP
Loading...
Searching...
No Matches
TestPrimitivesAdd.c
1/* test_add.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_add16s_func(void)
23{
24 pstatus_t status = 0;
25
26 INT16 src1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
27 INT16 src2[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
28 INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
29 INT16 d2[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
30
31 if (winpr_RAND(src1, sizeof(src1)) < 0)
32 return FALSE;
33 if (winpr_RAND(src2, sizeof(src2)) < 0)
34 return FALSE;
35 status = generic->add_16s(src1 + 1, src2 + 1, d1 + 1, FUNC_TEST_SIZE);
36 if (status != PRIMITIVES_SUCCESS)
37 return FALSE;
38
39 /* Unaligned */
40 status = optimized->add_16s(src1 + 1, src2 + 1, d2 + 2, FUNC_TEST_SIZE);
41 return (status == PRIMITIVES_SUCCESS);
42}
43
44/* ------------------------------------------------------------------------- */
45static BOOL test_add16s_inplace_func(void)
46{
47 const UINT32 lengths[] = { 1, 7, 15, 16, 17, 33, FUNC_TEST_SIZE };
48 INT16 src1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
49 INT16 src2[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
50 INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
51 INT16 d2[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
52
53 for (size_t i = 0; i < ARRAYSIZE(lengths); i++)
54 {
55 /* Aligned and unaligned */
56 for (size_t offset = 0; offset < 2; offset++)
57 {
58 if (winpr_RAND(src1, sizeof(src1)) < 0)
59 return FALSE;
60 if (winpr_RAND(src2, sizeof(src2)) < 0)
61 return FALSE;
62 memcpy(d1, src1, sizeof(src1));
63 memcpy(d2, src2, sizeof(src2));
64
65 if (generic->add_16s_inplace(src1 + offset, src2 + offset, lengths[i]) !=
66 PRIMITIVES_SUCCESS)
67 return FALSE;
68 if (optimized->add_16s_inplace(d1 + offset, d2 + offset, lengths[i]) !=
69 PRIMITIVES_SUCCESS)
70 return FALSE;
71 if ((memcmp(src1, d1, sizeof(d1)) != 0) || (memcmp(src2, d2, sizeof(d2)) != 0))
72 {
73 (void)fprintf(stderr, "add_16s_inplace mismatch, len=%" PRIu32 "\n", lengths[i]);
74 return FALSE;
75 }
76 }
77 }
78
79 return TRUE;
80}
81
82/* ------------------------------------------------------------------------- */
83static BOOL test_add16s_speed(void)
84{
85 BYTE src1[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
86 BYTE src2[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
87 BYTE dst[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
88
89 if (!g_TestPrimitivesPerformance)
90 return TRUE;
91
92 if (winpr_RAND(src1, sizeof(src1)) < 0)
93 return FALSE;
94 if (winpr_RAND(src2, sizeof(src2)) < 0)
95 return FALSE;
96
97 return (speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->add_16s,
98 (speed_test_fkt)optimized->add_16s, src1, src2, dst, FUNC_TEST_SIZE));
99}
100
101int TestPrimitivesAdd(int argc, char* argv[])
102{
103
104 WINPR_UNUSED(argc);
105 WINPR_UNUSED(argv);
106
107 prim_test_setup(FALSE);
108 if (!test_add16s_func())
109 return -1;
110
111 if (!test_add16s_inplace_func())
112 return -1;
113
114 if (g_TestPrimitivesPerformance)
115 {
116 if (!test_add16s_speed())
117 return -1;
118 }
119
120 return 0;
121}