Blame libfreerdp/primitives/test/TestPrimitivesAdd.c

Packit 1fb8d4
/* test_add.c
Packit 1fb8d4
 * vi:ts=4 sw=4
Packit 1fb8d4
 *
Packit 1fb8d4
 * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Packit 1fb8d4
 * not use this file except in compliance with the License. You may obtain
Packit 1fb8d4
 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
Packit 1fb8d4
 * or implied. See the License for the specific language governing
Packit 1fb8d4
 * permissions and limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef HAVE_CONFIG_H
Packit 1fb8d4
#include "config.h"
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#include <winpr/sysinfo.h>
Packit 1fb8d4
#include "prim_test.h"
Packit 1fb8d4
Packit Service 5a9772
#define FUNC_TEST_SIZE 65536
Packit 1fb8d4
/* ========================================================================= */
Packit 1fb8d4
static BOOL test_add16s_func(void)
Packit 1fb8d4
{
Packit 1fb8d4
	pstatus_t status;
Packit 1fb8d4
Packit 1fb8d4
	INT16 ALIGN(src1[FUNC_TEST_SIZE + 3]), ALIGN(src2[FUNC_TEST_SIZE + 3]),
Packit Service 5a9772
	    ALIGN(d1[FUNC_TEST_SIZE + 3]), ALIGN(d2[FUNC_TEST_SIZE + 3]);
Packit 1fb8d4
Packit 1fb8d4
	char testStr[256];
Packit 1fb8d4
	testStr[0] = '\0';
Packit 1fb8d4
	winpr_RAND((BYTE*)src1, sizeof(src1));
Packit 1fb8d4
	winpr_RAND((BYTE*)src2, sizeof(src2));
Packit 1fb8d4
	memset(d1, 0, sizeof(d1));
Packit 1fb8d4
	memset(d2, 0, sizeof(d2));
Packit 1fb8d4
	status = generic->add_16s(src1 + 1, src2 + 1, d1 + 1, FUNC_TEST_SIZE);
Packit 1fb8d4
	if (status != PRIMITIVES_SUCCESS)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	/* Unaligned */
Packit 1fb8d4
	status = optimized->add_16s(src1 + 1, src2 + 1, d2 + 2, FUNC_TEST_SIZE);
Packit 1fb8d4
	if (status != PRIMITIVES_SUCCESS)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
/* ------------------------------------------------------------------------- */
Packit 1fb8d4
static BOOL test_add16s_speed(void)
Packit 1fb8d4
{
Packit 1fb8d4
	BYTE ALIGN(src1[MAX_TEST_SIZE + 3]), ALIGN(src2[MAX_TEST_SIZE + 3]),
Packit Service 5a9772
	    ALIGN(dst[MAX_TEST_SIZE + 3]);
Packit 1fb8d4
Packit 1fb8d4
	if (!g_TestPrimitivesPerformance)
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
Packit 1fb8d4
	winpr_RAND(src1, sizeof(src1));
Packit 1fb8d4
	winpr_RAND(src2, sizeof(src2));
Packit 1fb8d4
Packit Service 5a9772
	if (!speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->add_16s,
Packit Service 5a9772
	                (speed_test_fkt)optimized->add_16s, src1, src2, dst, FUNC_TEST_SIZE))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int TestPrimitivesAdd(int argc, char* argv[])
Packit 1fb8d4
{
Packit 1fb8d4
	prim_test_setup(FALSE);
Packit 1fb8d4
	if (!test_add16s_func())
Packit 1fb8d4
		return -1;
Packit 1fb8d4
Packit 1fb8d4
	if (g_TestPrimitivesPerformance)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!test_add16s_speed())
Packit 1fb8d4
			return -1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}