FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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 ALIGN(src1[FUNC_TEST_SIZE + 3]) = { 0 };
27 INT16 ALIGN(src2[FUNC_TEST_SIZE + 3]) = { 0 };
28 INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]) = { 0 };
29 INT16 ALIGN(d2[FUNC_TEST_SIZE + 3]) = { 0 };
30
31 winpr_RAND(src1, sizeof(src1));
32 winpr_RAND(src2, sizeof(src2));
33 status = generic->add_16s(src1 + 1, src2 + 1, d1 + 1, FUNC_TEST_SIZE);
34 if (status != PRIMITIVES_SUCCESS)
35 return FALSE;
36
37 /* Unaligned */
38 status = optimized->add_16s(src1 + 1, src2 + 1, d2 + 2, FUNC_TEST_SIZE);
39 if (status != PRIMITIVES_SUCCESS)
40 return FALSE;
41
42 return TRUE;
43}
44
45/* ------------------------------------------------------------------------- */
46static BOOL test_add16s_speed(void)
47{
48 BYTE ALIGN(src1[MAX_TEST_SIZE + 3]);
49 BYTE ALIGN(src2[MAX_TEST_SIZE + 3]);
50 BYTE ALIGN(dst[MAX_TEST_SIZE + 3]);
51
52 if (!g_TestPrimitivesPerformance)
53 return TRUE;
54
55 winpr_RAND(src1, sizeof(src1));
56 winpr_RAND(src2, sizeof(src2));
57
58 if (!speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->add_16s,
59 (speed_test_fkt)optimized->add_16s, src1, src2, dst, FUNC_TEST_SIZE))
60 return FALSE;
61
62 return TRUE;
63}
64
65int TestPrimitivesAdd(int argc, char* argv[])
66{
67
68 WINPR_UNUSED(argc);
69 WINPR_UNUSED(argv);
70
71 prim_test_setup(FALSE);
72 if (!test_add16s_func())
73 return -1;
74
75 if (g_TestPrimitivesPerformance)
76 {
77 if (!test_add16s_speed())
78 return -1;
79 }
80
81 return 0;
82}