FreeRDP
Loading...
Searching...
No Matches
TestPrimitivesSign.c
1/* test_sign.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 TEST_BUFFER_SIZE 65535
21
22/* ------------------------------------------------------------------------- */
23static BOOL test_sign16s_func(void)
24{
25 pstatus_t status = 0;
26 INT16 src[TEST_BUFFER_SIZE + 16] = WINPR_C_ARRAY_INIT;
27 INT16 d1[TEST_BUFFER_SIZE + 16] = WINPR_C_ARRAY_INIT;
28 INT16 d2[TEST_BUFFER_SIZE + 16] = WINPR_C_ARRAY_INIT;
29 if (winpr_RAND(src, sizeof(src)) < 0)
30 return FALSE;
31 status = generic->sign_16s(src + 1, d1 + 1, TEST_BUFFER_SIZE);
32
33 if (status != PRIMITIVES_SUCCESS)
34 return FALSE;
35
36 status = optimized->sign_16s(src + 1, d2 + 1, TEST_BUFFER_SIZE);
37
38 if (status != PRIMITIVES_SUCCESS)
39 return FALSE;
40
41 if (memcmp(d1, d2, sizeof(d1)) != 0)
42 return FALSE;
43
44 status = generic->sign_16s(src + 1, d1 + 2, TEST_BUFFER_SIZE);
45
46 if (status != PRIMITIVES_SUCCESS)
47 return FALSE;
48
49 status = optimized->sign_16s(src + 1, d2 + 2, TEST_BUFFER_SIZE);
50
51 if (status != PRIMITIVES_SUCCESS)
52 return FALSE;
53
54 if (memcmp(d1, d2, sizeof(d1)) != 0)
55 return FALSE;
56
57 return TRUE;
58}
59
60static int test_sign16s_speed(void)
61{
62 INT16 src[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
63 INT16 dst[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
64 if (winpr_RAND(src, sizeof(src)) < 0)
65 return FALSE;
66
67 if (!speed_test("sign16s", "aligned", g_Iterations, (speed_test_fkt)generic->sign_16s,
68 (speed_test_fkt)optimized->sign_16s, src + 1, dst + 1, MAX_TEST_SIZE))
69 return FALSE;
70
71 if (!speed_test("sign16s", "unaligned", g_Iterations, (speed_test_fkt)generic->sign_16s,
72 (speed_test_fkt)optimized->sign_16s, src + 1, dst + 2, MAX_TEST_SIZE))
73 return FALSE;
74
75 return TRUE;
76}
77
78int TestPrimitivesSign(int argc, char* argv[])
79{
80 WINPR_UNUSED(argc);
81 WINPR_UNUSED(argv);
82
83 prim_test_setup(FALSE);
84
85 if (!test_sign16s_func())
86 return 1;
87
88 if (g_TestPrimitivesPerformance)
89 {
90 if (!test_sign16s_speed())
91 return 1;
92 }
93
94 return 0;
95}