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_speed(void)
46{
47 BYTE src1[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
48 BYTE src2[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
49 BYTE dst[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
50
51 if (!g_TestPrimitivesPerformance)
52 return TRUE;
53
54 if (winpr_RAND(src1, sizeof(src1)) < 0)
55 return FALSE;
56 if (winpr_RAND(src2, sizeof(src2)) < 0)
57 return FALSE;
58
59 return (speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->add_16s,
60 (speed_test_fkt)optimized->add_16s, src1, src2, dst, FUNC_TEST_SIZE));
61}
62
63int TestPrimitivesAdd(int argc, char* argv[])
64{
65
66 WINPR_UNUSED(argc);
67 WINPR_UNUSED(argv);
68
69 prim_test_setup(FALSE);
70 if (!test_add16s_func())
71 return -1;
72
73 if (g_TestPrimitivesPerformance)
74 {
75 if (!test_add16s_speed())
76 return -1;
77 }
78
79 return 0;
80}