Milestone 5: deliver embedded RDP sessions and lifecycle hardening

This commit is contained in:
Keith Smith
2026-03-03 18:59:26 -07:00
parent 230a401386
commit 36006bd4aa
2941 changed files with 724359 additions and 77 deletions

View File

@@ -0,0 +1,39 @@
set(MODULE_NAME "TestPrimitives")
set(MODULE_PREFIX "TEST_FREERDP_PRIMITIVES")
disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR})
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
TestPrimitivesAdd.c
TestPrimitivesAlphaComp.c
TestPrimitivesAndOr.c
TestPrimitivesColors.c
TestPrimitivesCopy.c
TestPrimitivesSet.c
TestPrimitivesShift.c
TestPrimitivesSign.c
TestPrimitivesYUV.c
TestPrimitivesYCbCr.c
TestPrimitivesYCoCg.c
)
create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS})
set(${MODULE_PREFIX}_EXTRA_SRCS prim_test.c prim_test.h measure.h)
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS} ${${MODULE_PREFIX}_EXTRA_SRCS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Test")

View File

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

View File

@@ -0,0 +1,203 @@
/* test_alphaComp.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <freerdp/config.h>
#include <winpr/sysinfo.h>
#include "prim_test.h"
#define MAX_BLOCK_SIZE 256
#define SIZE_SQUARED (MAX_BLOCK_SIZE * MAX_BLOCK_SIZE)
/* ========================================================================= */
#define ALF(_c_) (((_c_)&0xFF000000U) >> 24)
#define RED(_c_) (((_c_)&0x00FF0000U) >> 16)
#define GRN(_c_) (((_c_)&0x0000FF00U) >> 8)
#define BLU(_c_) ((_c_)&0x000000FFU)
#define TOLERANCE 1
static inline const UINT32* PIXEL(const BYTE* _addr_, UINT32 _bytes_, UINT32 _x_, UINT32 _y_)
{
const BYTE* addr = _addr_ + 1ULL * _x_ * sizeof(UINT32) + 1ULL * _y_ * _bytes_;
return (const UINT32*)addr;
}
#define SRC1_WIDTH 6
#define SRC1_HEIGHT 6
#define SRC2_WIDTH 7
#define SRC2_HEIGHT 7
#define DST_WIDTH 9
#define DST_HEIGHT 9
#define TEST_WIDTH 4
#define TEST_HEIGHT 5
/* ------------------------------------------------------------------------- */
static UINT32 alpha_add(UINT32 c1, UINT32 c2)
{
UINT32 a1 = ALF(c1);
UINT32 r1 = RED(c1);
UINT32 g1 = GRN(c1);
UINT32 b1 = BLU(c1);
UINT32 a2 = ALF(c2);
UINT32 r2 = RED(c2);
UINT32 g2 = GRN(c2);
UINT32 b2 = BLU(c2);
UINT32 a3 = ((a1 * a1 + (255 - a1) * a2) / 255) & 0xff;
UINT32 r3 = ((a1 * r1 + (255 - a1) * r2) / 255) & 0xff;
UINT32 g3 = ((a1 * g1 + (255 - a1) * g2) / 255) & 0xff;
UINT32 b3 = ((a1 * b1 + (255 - a1) * b2) / 255) & 0xff;
return (a3 << 24) | (r3 << 16) | (g3 << 8) | b3;
}
/* ------------------------------------------------------------------------- */
static UINT32 colordist(UINT32 c1, UINT32 c2)
{
int d = 0;
int maxd = 0;
d = ABS((INT32)(ALF(c1) - ALF(c2)));
if (d > maxd)
maxd = d;
d = ABS((INT32)(RED(c1) - RED(c2)));
if (d > maxd)
maxd = d;
d = ABS((INT32)(GRN(c1) - GRN(c2)));
if (d > maxd)
maxd = d;
d = ABS((INT32)(BLU(c1) - BLU(c2)));
if (d > maxd)
maxd = d;
return maxd;
}
/* ------------------------------------------------------------------------- */
static BOOL check(const BYTE* pSrc1, UINT32 src1Step, const BYTE* pSrc2, UINT32 src2Step,
BYTE* pDst, UINT32 dstStep, UINT32 width, UINT32 height)
{
for (UINT32 y = 0; y < height; ++y)
{
for (UINT32 x = 0; x < width; ++x)
{
UINT32 s1 = *PIXEL(pSrc1, src1Step, x, y);
UINT32 s2 = *PIXEL(pSrc2, src2Step, x, y);
UINT32 c0 = alpha_add(s1, s2);
UINT32 c1 = *PIXEL(pDst, dstStep, x, y);
if (colordist(c0, c1) > TOLERANCE)
{
printf("alphaComp-general: [%" PRIu32 ",%" PRIu32 "] 0x%08" PRIx32 "+0x%08" PRIx32
"=0x%08" PRIx32 ", got 0x%08" PRIx32 "\n",
x, y, s1, s2, c0, c1);
return FALSE;
}
}
}
return TRUE;
}
static BOOL test_alphaComp_func(void)
{
pstatus_t status = 0;
BYTE src1[SRC1_WIDTH * SRC1_HEIGHT * 4] = WINPR_C_ARRAY_INIT;
BYTE src2[SRC2_WIDTH * SRC2_HEIGHT * 4] = WINPR_C_ARRAY_INIT;
BYTE dst1[DST_WIDTH * DST_HEIGHT * 4] = WINPR_C_ARRAY_INIT;
UINT32* ptr = nullptr;
if (winpr_RAND(src1, sizeof(src1)) < 0)
return FALSE;
/* Special-case the first two values */
src1[0] &= 0x00FFFFFFU;
src1[1] |= 0xFF000000U;
if (winpr_RAND(src2, sizeof(src2)) < 0)
return FALSE;
/* Set the second operand to fully-opaque. */
ptr = (UINT32*)src2;
for (UINT32 i = 0; i < sizeof(src2) / 4; ++i)
*ptr++ |= 0xFF000000U;
status = generic->alphaComp_argb(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1,
4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH,
TEST_HEIGHT))
return FALSE;
status = optimized->alphaComp_argb((const BYTE*)src1, 4 * SRC1_WIDTH, (const BYTE*)src2,
4 * SRC2_WIDTH, (BYTE*)dst1, 4 * DST_WIDTH, TEST_WIDTH,
TEST_HEIGHT);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH,
TEST_HEIGHT))
return FALSE;
return TRUE;
}
static int test_alphaComp_speed(void)
{
BYTE src1[SRC1_WIDTH * SRC1_HEIGHT] = WINPR_C_ARRAY_INIT;
BYTE src2[SRC2_WIDTH * SRC2_HEIGHT] = WINPR_C_ARRAY_INIT;
BYTE dst1[DST_WIDTH * DST_HEIGHT] = WINPR_C_ARRAY_INIT;
UINT32* ptr = nullptr;
if (winpr_RAND(src1, sizeof(src1)) < 0)
return -1;
/* Special-case the first two values */
src1[0] &= 0x00FFFFFFU;
src1[1] |= 0xFF000000U;
if (winpr_RAND(src2, sizeof(src2)) < 0)
return -1;
/* Set the second operand to fully-opaque. */
ptr = (UINT32*)src2;
for (UINT32 i = 0; i < sizeof(src2) / 4; ++i)
*ptr++ |= 0xFF000000U;
return (speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->alphaComp_argb,
(speed_test_fkt)optimized->alphaComp_argb, src1, 4 * SRC1_WIDTH, src2,
4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT));
}
int TestPrimitivesAlphaComp(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE);
if (!test_alphaComp_func())
return -1;
if (g_TestPrimitivesPerformance)
{
if (!test_alphaComp_speed())
return -1;
}
return 0;
}

View File

@@ -0,0 +1,171 @@
/* test_andor.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <freerdp/config.h>
#include <winpr/sysinfo.h>
#include "prim_test.h"
#define FUNC_TEST_SIZE 65536
#define VALUE (0xA5A5A5A5U)
/* ========================================================================= */
static BOOL test_and_32u_impl(const char* name, fn_andC_32u_t fkt, const UINT32* src,
const UINT32 val, UINT32* dst, size_t size)
{
pstatus_t status = fkt(src, val, dst, WINPR_ASSERTING_INT_CAST(int32_t, size));
if (status != PRIMITIVES_SUCCESS)
return FALSE;
for (size_t i = 0; i < size; ++i)
{
if (dst[i] != (src[i] & val))
{
printf("AND %s FAIL[%" PRIuz "] 0x%08" PRIx32 "&0x%08" PRIx32 "=0x%08" PRIx32
", got 0x%08" PRIx32 "\n",
name, i, src[i], val, (src[i] & val), dst[i]);
return FALSE;
}
}
return TRUE;
}
static BOOL test_and_32u_func(void)
{
UINT32 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 dst[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
if (!test_and_32u_impl("generic->andC_32u aligned", generic->andC_32u, src + 1, VALUE, dst + 1,
FUNC_TEST_SIZE))
return FALSE;
if (!test_and_32u_impl("generic->andC_32u unaligned", generic->andC_32u, src + 1, VALUE,
dst + 2, FUNC_TEST_SIZE))
return FALSE;
if (!test_and_32u_impl("optimized->andC_32u aligned", optimized->andC_32u, src + 1, VALUE,
dst + 1, FUNC_TEST_SIZE))
return FALSE;
if (!test_and_32u_impl("optimized->andC_32u unaligned", optimized->andC_32u, src + 1, VALUE,
dst + 2, FUNC_TEST_SIZE))
return FALSE;
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_and_32u_speed(void)
{
UINT32 src[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 dst[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
if (!speed_test("andC_32u", "aligned", g_Iterations, (speed_test_fkt)generic->andC_32u,
(speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 1, MAX_TEST_SIZE))
return FALSE;
if (!speed_test("andC_32u", "unaligned", g_Iterations, (speed_test_fkt)generic->andC_32u,
(speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 2, MAX_TEST_SIZE))
return FALSE;
return TRUE;
}
/* ========================================================================= */
static BOOL check(const UINT32* src, const UINT32* dst, UINT32 size, UINT32 value)
{
for (UINT32 i = 0; i < size; ++i)
{
if (dst[i] != (src[i] | value))
{
printf("OR-general general FAIL[%" PRIu32 "] 0x%08" PRIx32 "&0x%08" PRIx32
"=0x%08" PRIx32 ", got 0x%08" PRIx32 "\n",
i, src[i], value, src[i] | value, dst[i]);
return FALSE;
}
}
return TRUE;
}
static BOOL test_or_32u_func(void)
{
pstatus_t status = 0;
UINT32 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 dst[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
status = generic->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
return FALSE;
status = optimized->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
return FALSE;
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_or_32u_speed(void)
{
UINT32 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 dst[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
return (speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->orC_32u,
(speed_test_fkt)optimized->orC_32u, src + 1, VALUE, dst + 1,
FUNC_TEST_SIZE));
}
int TestPrimitivesAndOr(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE);
if (!test_and_32u_func())
return -1;
if (!test_or_32u_func())
return -1;
if (g_TestPrimitivesPerformance)
{
if (!test_and_32u_speed())
return -1;
if (!test_or_32u_speed())
return -1;
}
return 0;
}

View File

@@ -0,0 +1,291 @@
/* test_colors.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <freerdp/config.h>
#include <winpr/sysinfo.h>
#include <freerdp/utils/profiler.h>
#include "prim_test.h"
/* ------------------------------------------------------------------------- */
static BOOL test_RGBToRGB_16s8u_P3AC4R_func(prim_size_t roi, DWORD DstFormat)
{
INT16* r = nullptr;
INT16* g = nullptr;
INT16* b = nullptr;
BYTE* out1 = nullptr;
BYTE* out2 = nullptr;
BOOL failed = FALSE;
const INT16* ptrs[3];
const UINT32 rgbStride = roi.width * 2;
const UINT32 dstStride = roi.width * 4;
PROFILER_DEFINE(genericProf)
PROFILER_DEFINE(optProf)
PROFILER_CREATE(genericProf, "RGBToRGB_16s8u_P3AC4R-GENERIC")
PROFILER_CREATE(optProf, "RGBToRGB_16s8u_P3AC4R-OPTIMIZED")
r = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16);
g = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16);
b = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16);
out1 = winpr_aligned_calloc(1, 1ULL * dstStride * roi.height, 16);
out2 = winpr_aligned_calloc(1, 1ULL * dstStride * roi.height, 16);
if (!r || !g || !b || !out1 || !out2)
goto fail;
if (winpr_RAND(r, 1ULL * rgbStride * roi.height) < 0)
goto fail;
if (winpr_RAND(g, 1ULL * rgbStride * roi.height) < 0)
goto fail;
if (winpr_RAND(b, 1ULL * rgbStride * roi.height) < 0)
goto fail;
ptrs[0] = r;
ptrs[1] = g;
ptrs[2] = b;
PROFILER_ENTER(genericProf)
if (generic->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out1, dstStride, DstFormat, &roi) !=
PRIMITIVES_SUCCESS)
goto fail;
PROFILER_EXIT(genericProf)
PROFILER_ENTER(optProf)
if (optimized->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out2, dstStride, DstFormat, &roi) !=
PRIMITIVES_SUCCESS)
goto fail;
PROFILER_EXIT(optProf)
if (memcmp(out1, out2, 1ULL * dstStride * roi.height) != 0)
{
for (UINT64 i = 0; i < 1ull * roi.width * roi.height; ++i)
{
const UINT32 o1 = FreeRDPReadColor(out1 + 4 * i, DstFormat);
const UINT32 o2 = FreeRDPReadColor(out2 + 4 * i, DstFormat);
if (o1 != o2)
{
printf("RGBToRGB_16s8u_P3AC4R FAIL: out1[%" PRIu64 "]=0x%08" PRIx8 " out2[%" PRIu64
"]=0x%08" PRIx8 "\n",
i, out1[i], i, out2[i]);
failed = TRUE;
}
}
}
printf("Results for %" PRIu32 "x%" PRIu32 " [%s]\n", roi.width, roi.height,
FreeRDPGetColorFormatName(DstFormat));
PROFILER_PRINT_HEADER
PROFILER_PRINT(genericProf)
PROFILER_PRINT(optProf)
PROFILER_PRINT_FOOTER
fail:
PROFILER_FREE(genericProf)
PROFILER_FREE(optProf)
winpr_aligned_free(r);
winpr_aligned_free(g);
winpr_aligned_free(b);
winpr_aligned_free(out1);
winpr_aligned_free(out2);
return !failed;
}
/* ------------------------------------------------------------------------- */
static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(void)
{
union
{
const INT16** cpv;
INT16** pv;
} cnv;
const prim_size_t roi64x64 = { 64, 64 };
INT16 r[4096 + 1] = WINPR_C_ARRAY_INIT;
INT16 g[4096 + 1] = WINPR_C_ARRAY_INIT;
INT16 b[4096 + 1] = WINPR_C_ARRAY_INIT;
UINT32 dst[4096 + 1] = WINPR_C_ARRAY_INIT;
INT16* ptrs[3] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(r, sizeof(r)) < 0)
return FALSE;
if (winpr_RAND(g, sizeof(g)) < 0)
return FALSE;
if (winpr_RAND(b, sizeof(b)) < 0)
return FALSE;
/* clear upper bytes */
for (int i = 0; i < 4096; ++i)
{
r[i] &= 0x00FFU;
g[i] &= 0x00FFU;
b[i] &= 0x00FFU;
}
ptrs[0] = r + 1;
ptrs[1] = g + 1;
ptrs[2] = b + 1;
cnv.pv = ptrs;
if (!speed_test("RGBToRGB_16s8u_P3AC4R", "aligned", g_Iterations,
(speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
(speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, 64 * 2, (BYTE*)dst,
64 * 4, &roi64x64))
return FALSE;
if (!speed_test("RGBToRGB_16s8u_P3AC4R", "unaligned", g_Iterations,
(speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
(speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, 64 * 2,
((BYTE*)dst) + 1, 64 * 4, &roi64x64))
return FALSE;
return TRUE;
}
/* ========================================================================= */
static BOOL test_yCbCrToRGB_16s16s_P3P3_func(void)
{
pstatus_t status = 0;
INT16 y[4096] = WINPR_C_ARRAY_INIT;
INT16 cb[4096] = WINPR_C_ARRAY_INIT;
INT16 cr[4096] = WINPR_C_ARRAY_INIT;
INT16 r1[4096] = WINPR_C_ARRAY_INIT;
INT16 g1[4096] = WINPR_C_ARRAY_INIT;
INT16 b1[4096] = WINPR_C_ARRAY_INIT;
INT16 r2[4096] = WINPR_C_ARRAY_INIT;
INT16 g2[4096] = WINPR_C_ARRAY_INIT;
INT16 b2[4096] = WINPR_C_ARRAY_INIT;
const INT16* in[3];
INT16* out1[3];
INT16* out2[3];
prim_size_t roi = { 64, 64 };
if (winpr_RAND(y, sizeof(y)) < 0)
return FALSE;
if (winpr_RAND(cb, sizeof(cb)) < 0)
return FALSE;
if (winpr_RAND(cr, sizeof(cr)) < 0)
return FALSE;
/* Normalize to 11.5 fixed radix */
for (int i = 0; i < 4096; ++i)
{
y[i] &= 0x1FE0U;
cb[i] &= 0x1FE0U;
cr[i] &= 0x1FE0U;
}
in[0] = y;
in[1] = cb;
in[2] = cr;
out1[0] = r1;
out1[1] = g1;
out1[2] = b1;
out2[0] = r2;
out2[1] = g2;
out2[2] = b2;
status = generic->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out1, 64 * 2, &roi);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out2, 64 * 2, &roi);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
for (int i = 0; i < 4096; ++i)
{
if ((ABS(r1[i] - r2[i]) > 1) || (ABS(g1[i] - g2[i]) > 1) || (ABS(b1[i] - b2[i]) > 1))
{
printf("YCbCrToRGB-SSE FAIL[%d]: %" PRId16 ",%" PRId16 ",%" PRId16 " vs %" PRId16
",%" PRId16 ",%" PRId16 "\n",
i, r1[i], g1[i], b1[i], r2[i], g2[i], b2[i]);
return FALSE;
}
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
static int test_yCbCrToRGB_16s16s_P3P3_speed(void)
{
prim_size_t roi = { 64, 64 };
INT16 y[4096] = WINPR_C_ARRAY_INIT;
INT16 cb[4096] = WINPR_C_ARRAY_INIT;
INT16 cr[4096] = WINPR_C_ARRAY_INIT;
INT16 r[4096] = WINPR_C_ARRAY_INIT;
INT16 g[4096] = WINPR_C_ARRAY_INIT;
INT16 b[4096] = WINPR_C_ARRAY_INIT;
const INT16* input[3] = WINPR_C_ARRAY_INIT;
INT16* output[3] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(y, sizeof(y)) < 0)
return FALSE;
if (winpr_RAND(cb, sizeof(cb)) < 0)
return FALSE;
if (winpr_RAND(cr, sizeof(cr)) < 0)
return FALSE;
/* Normalize to 11.5 fixed radix */
for (int i = 0; i < 4096; ++i)
{
y[i] &= 0x1FE0U;
cb[i] &= 0x1FE0U;
cr[i] &= 0x1FE0U;
}
input[0] = y;
input[1] = cb;
input[2] = cr;
output[0] = r;
output[1] = g;
output[2] = b;
return (speed_test("yCbCrToRGB_16s16s_P3P3", "aligned", g_Iterations,
(speed_test_fkt)generic->yCbCrToRGB_16s16s_P3P3,
(speed_test_fkt)optimized->yCbCrToRGB_16s16s_P3P3, input, 64 * 2, output,
64 * 2, &roi));
}
int TestPrimitivesColors(int argc, char* argv[])
{
const DWORD formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_ABGR32,
PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32,
PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
prim_size_t roi = { 1920 / 4, 1080 / 4 };
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE);
for (UINT32 x = 0; x < sizeof(formats) / sizeof(formats[0]); x++)
{
if (!test_RGBToRGB_16s8u_P3AC4R_func(roi, formats[x]))
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_RGBToRGB_16s8u_P3AC4R_speed())
return 1;
}
if (!test_yCbCrToRGB_16s16s_P3P3_func())
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_yCbCrToRGB_16s16s_P3P3_speed())
return 1;
}
}
return 0;
}

View File

@@ -0,0 +1,296 @@
/* test_copy.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <stdio.h>
#include <freerdp/config.h>
#include <winpr/crypto.h>
#include <winpr/sysinfo.h>
#include "prim_test.h"
#define COPY_TESTSIZE (256 * 2 + 16 * 2 + 15 + 15)
/* ------------------------------------------------------------------------- */
static BOOL test_copy8u_func(void)
{
primitives_t* prims = primitives_get();
BYTE data[COPY_TESTSIZE + 15] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(data, sizeof(data)) < 0)
return FALSE;
for (int soff = 0; soff < 16; ++soff)
{
for (int doff = 0; doff < 16; ++doff)
{
for (int length = 1; length <= COPY_TESTSIZE - doff; ++length)
{
BYTE dest[COPY_TESTSIZE + 15] = WINPR_C_ARRAY_INIT;
if (prims->copy_8u(data + soff, dest + doff, length) != PRIMITIVES_SUCCESS)
return FALSE;
for (int i = 0; i < length; ++i)
{
if (dest[i + doff] != data[i + soff])
{
printf("COPY8U FAIL: off=%d len=%d, dest[%d]=0x%02" PRIx8 ""
"data[%d]=0x%02" PRIx8 "\n",
doff, length, i + doff, dest[i + doff], i + soff, data[i + soff]);
return FALSE;
}
}
}
}
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_copy8u_speed(void)
{
BYTE src[MAX_TEST_SIZE + 4] = WINPR_C_ARRAY_INIT;
BYTE dst[MAX_TEST_SIZE + 4] = WINPR_C_ARRAY_INIT;
if (!speed_test("copy_8u", "aligned", g_Iterations, (speed_test_fkt)generic->copy_8u,
(speed_test_fkt)optimized->copy_8u, src, dst, MAX_TEST_SIZE))
return FALSE;
if (!speed_test("copy_8u", "unaligned", g_Iterations, (speed_test_fkt)generic->copy_8u,
(speed_test_fkt)optimized->copy_8u, src + 1, dst + 1, MAX_TEST_SIZE))
return FALSE;
return TRUE;
}
static BYTE* rand_alloc(size_t w, size_t h, size_t bpp, size_t pad, BYTE** copy)
{
const size_t s = w * bpp + pad;
BYTE* ptr = calloc(s, h);
if (!ptr)
return nullptr;
if (winpr_RAND(ptr, s * h) < 0)
{
free(ptr);
return nullptr;
}
if (copy)
{
BYTE* ptr2 = calloc(s, h);
if (!ptr2)
{
free(ptr);
return nullptr;
}
memcpy(ptr2, ptr, s * h);
*copy = ptr2;
}
return ptr;
}
static size_t runcount = 0;
static BOOL test_copy_no_overlap_off(BOOL verbose, UINT32 srcFormat, UINT32 dstFormat, UINT32 flags,
UINT32 pad, UINT32 w, UINT32 h, UINT32 dxoff, UINT32 dyoff,
UINT32 sxoff, UINT32 syoff)
{
BOOL rc = FALSE;
primitives_t* gen = primitives_get_generic();
primitives_t* prims = primitives_get();
if (!gen || !prims)
return FALSE;
runcount++;
WINPR_ASSERT(dxoff < w);
WINPR_ASSERT(sxoff < w);
WINPR_ASSERT(dyoff < h);
WINPR_ASSERT(syoff < h);
const UINT32 sbpp = FreeRDPGetBytesPerPixel(srcFormat);
const UINT32 dbpp = FreeRDPGetBytesPerPixel(dstFormat);
if (verbose)
{
(void)fprintf(stderr,
"run src: %s, dst: %s [flags 0x%08" PRIx32 "] %" PRIu32 "x%" PRIu32
", soff=%" PRIu32 "x%" PRIu32 ", doff=%" PRIu32 "x%" PRIu32 ", pad=%" PRIu32
"\n",
FreeRDPGetColorFormatName(srcFormat), FreeRDPGetColorFormatName(dstFormat),
flags, w, h, sxoff, syoff, dxoff, dyoff, pad);
}
const UINT32 sstride = (w + sxoff) * sbpp + pad;
const UINT32 dstride = (w + dxoff) * dbpp + pad;
BYTE* dst2 = nullptr;
BYTE* src2 = nullptr;
BYTE* dst1 = rand_alloc(w + dxoff, h + dyoff, dbpp, pad, &dst2);
BYTE* src1 = rand_alloc(w + sxoff, h + syoff, sbpp, pad, &src2);
if (!dst1 || !dst2 || !src1 || !src2)
goto fail;
if (gen->copy_no_overlap(dst1, dstFormat, dstride, dxoff, dyoff, w, h, src1, srcFormat, sstride,
sxoff, syoff, nullptr, flags) != PRIMITIVES_SUCCESS)
goto fail;
if (memcmp(src1, src2, 1ULL * sstride * h) != 0)
goto fail;
if (prims->copy_no_overlap(dst2, dstFormat, dstride, dxoff, dyoff, w, h, src1, srcFormat,
sstride, sxoff, syoff, nullptr, flags) != PRIMITIVES_SUCCESS)
goto fail;
if (memcmp(src1, src2, 1ULL * sstride * h) != 0)
goto fail;
if (memcmp(dst1, dst2, 1ULL * dstride * h) != 0)
goto fail;
if (flags == FREERDP_KEEP_DST_ALPHA)
{
for (size_t y = 0; y < h; y++)
{
const BYTE* d1 = &dst1[(y + dyoff) * dstride];
const BYTE* d2 = &dst2[(y + dyoff) * dstride];
for (size_t x = 0; x < w; x++)
{
const UINT32 c1 = FreeRDPReadColor(&d1[(x + dxoff) * dbpp], dstFormat);
const UINT32 c2 = FreeRDPReadColor(&d2[(x + dxoff) * dbpp], dstFormat);
BYTE a1 = 0;
BYTE a2 = 0;
FreeRDPSplitColor(c1, dstFormat, nullptr, nullptr, nullptr, &a1, nullptr);
FreeRDPSplitColor(c2, dstFormat, nullptr, nullptr, nullptr, &a2, nullptr);
if (a1 != a2)
goto fail;
}
}
}
rc = TRUE;
fail:
if (!rc)
{
(void)fprintf(stderr, "failed to compare copy_no_overlap(%s -> %s [0x%08" PRIx32 "])\n",
FreeRDPGetColorFormatName(srcFormat), FreeRDPGetColorFormatName(dstFormat),
flags);
}
free(dst1);
free(dst2);
free(src1);
free(src2);
return rc;
}
static BOOL test_copy_no_overlap(BOOL verbose, UINT32 srcFormat, UINT32 dstFormat, UINT32 flags,
UINT32 width, UINT32 height)
{
BOOL rc = TRUE;
const UINT32 mw = 4;
const UINT32 mh = 4;
for (UINT32 dxoff = 0; dxoff < mw; dxoff++)
{
for (UINT32 dyoff = 0; dyoff <= mh; dyoff++)
{
for (UINT32 sxoff = 0; sxoff <= mw; sxoff++)
{
for (UINT32 syoff = 0; syoff <= mh; syoff++)
{
/* We need minimum alignment of 8 bytes.
* AVX2 can read 8 pixels (at most 8x4=32 bytes) per step
* if we have 24bpp input that is 24 bytes with 8 bytes read
* out of bound */
for (UINT32 pad = 8; pad <= 12; pad++)
{
if (!test_copy_no_overlap_off(verbose, srcFormat, dstFormat, flags, pad,
width, height, dxoff, dyoff, sxoff, syoff))
rc = FALSE;
}
}
}
}
}
return rc;
}
int TestPrimitivesCopy(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
const BOOL verbose = argc > 1;
prim_test_setup(FALSE);
if (!test_copy8u_func())
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_copy8u_speed())
return 1;
}
const UINT32 flags[] = {
FREERDP_FLIP_NONE,
FREERDP_KEEP_DST_ALPHA,
FREERDP_FLIP_HORIZONTAL,
FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_HORIZONTAL,
#if defined(TEST_ALL_FLAGS)
FREERDP_FLIP_VERTICAL,
FREERDP_FLIP_VERTICAL | FREERDP_FLIP_HORIZONTAL,
FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_VERTICAL,
FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_VERTICAL | FREERDP_FLIP_HORIZONTAL
#endif
};
const UINT32 formats[] = { PIXEL_FORMAT_BGRA32,
PIXEL_FORMAT_BGRX32,
PIXEL_FORMAT_BGR24
#if defined(TEST_ALL_FLAGS) /* Only the previous 3 have SIMD optimizations, so skip the rest */
,
PIXEL_FORMAT_RGB24,
PIXEL_FORMAT_ABGR32,
PIXEL_FORMAT_ARGB32,
PIXEL_FORMAT_XBGR32,
PIXEL_FORMAT_XRGB32,
PIXEL_FORMAT_RGBA32,
PIXEL_FORMAT_RGBX32
#endif
};
int rc = 0;
for (size_t z = 0; z < ARRAYSIZE(flags); z++)
{
const UINT32 flag = flags[z];
for (size_t x = 0; x < ARRAYSIZE(formats); x++)
{
const UINT32 sformat = formats[x];
for (size_t y = 0; y < ARRAYSIZE(formats); y++)
{
const UINT32 dformat = formats[y];
if (!test_copy_no_overlap(verbose, sformat, dformat, flag, 21, 17))
rc = -1;
}
}
}
if (verbose)
(void)fprintf(stderr, "runcount=%" PRIuz "\n", runcount);
return rc;
}

View File

@@ -0,0 +1,277 @@
/* test_set.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <freerdp/config.h>
#include <winpr/sysinfo.h>
#include "prim_test.h"
/* ------------------------------------------------------------------------- */
static BOOL check8(const BYTE* src, UINT32 length, UINT32 offset, BYTE value)
{
for (UINT32 i = 0; i < length; ++i)
{
if (src[offset + i] != value)
{
printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%02" PRIx8
"\n",
offset, length, i + offset, src[i + offset]);
return FALSE;
}
}
return TRUE;
}
static BOOL test_set8u_func(void)
{
pstatus_t status = 0;
for (UINT32 off = 0; off < 16; ++off)
{
BYTE dest[1024];
memset(dest, 3, sizeof(dest));
for (UINT32 len = 1; len < 48 - off; ++len)
{
status = generic->set_8u(0xa5, dest + off, len);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check8(dest, len, off, 0xa5))
return FALSE;
}
}
for (UINT32 off = 0; off < 16; ++off)
{
BYTE dest[1024];
memset(dest, 3, sizeof(dest));
for (UINT32 len = 1; len < 48 - off; ++len)
{
status = optimized->set_8u(0xa5, dest + off, len);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check8(dest, len, off, 0xa5))
return FALSE;
}
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_set8u_speed(void)
{
BYTE dest[1024];
BYTE value = 0;
for (UINT32 x = 0; x < 16; x++)
{
if (winpr_RAND(&value, sizeof(value)) < 0)
return FALSE;
if (!speed_test("set_8u", "", g_Iterations, (speed_test_fkt)generic->set_8u,
(speed_test_fkt)optimized->set_8u, value, dest + x, x))
return FALSE;
}
return TRUE;
}
static BOOL check32s(const INT32* src, UINT32 length, UINT32 offset, INT32 value)
{
for (UINT32 i = 0; i < length; ++i)
{
if (src[offset + i] != value)
{
printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32
"\n",
offset, length, i + offset, src[i + offset]);
return FALSE;
}
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_set32s_func(void)
{
pstatus_t status = 0;
const INT32 value = -0x12345678;
for (UINT32 off = 0; off < 16; ++off)
{
INT32 dest[1024] = WINPR_C_ARRAY_INIT;
for (UINT32 len = 1; len < 48 - off; ++len)
{
status = generic->set_32s(value, dest + off, len);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check32s(dest, len, off, value))
return FALSE;
}
}
for (UINT32 off = 0; off < 16; ++off)
{
INT32 dest[1024] = WINPR_C_ARRAY_INIT;
for (UINT32 len = 1; len < 48 - off; ++len)
{
status = optimized->set_32s(value, dest + off, len);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check32s(dest, len, off, value))
return FALSE;
}
}
return TRUE;
}
static BOOL check32u(const UINT32* src, UINT32 length, UINT32 offset, UINT32 value)
{
for (UINT32 i = 0; i < length; ++i)
{
if (src[offset + i] != value)
{
printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32
"\n",
offset, length, i + offset, src[i + offset]);
return FALSE;
}
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_set32u_func(void)
{
pstatus_t status = 0;
const UINT32 value = 0xABCDEF12;
for (UINT32 off = 0; off < 16; ++off)
{
UINT32 dest[1024] = WINPR_C_ARRAY_INIT;
for (UINT32 len = 1; len < 48 - off; ++len)
{
status = generic->set_32u(value, dest + off, len);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check32u(dest, len, off, value))
return FALSE;
}
}
for (UINT32 off = 0; off < 16; ++off)
{
UINT32 dest[1024] = WINPR_C_ARRAY_INIT;
for (UINT32 len = 1; len < 48 - off; ++len)
{
status = optimized->set_32u(value, dest + off, len);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (!check32u(dest, len, off, value))
return FALSE;
}
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_set32u_speed(void)
{
UINT32 dest[1024];
BYTE value = 0;
for (UINT32 x = 0; x < 16; x++)
{
if (winpr_RAND(&value, sizeof(value)) < 0)
return FALSE;
if (!speed_test("set_32u", "", g_Iterations, (speed_test_fkt)generic->set_32u,
(speed_test_fkt)optimized->set_32u, value, dest + x, x))
return FALSE;
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_set32s_speed(void)
{
INT32 dest[1024];
BYTE value = 0;
for (UINT32 x = 0; x < 16; x++)
{
if (winpr_RAND(&value, sizeof(value)) < 0)
return FALSE;
if (!speed_test("set_32s", "", g_Iterations, (speed_test_fkt)generic->set_32s,
(speed_test_fkt)optimized->set_32s, value, dest + x, x))
return FALSE;
}
return TRUE;
}
int TestPrimitivesSet(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE);
if (!test_set8u_func())
return -1;
if (!test_set32s_func())
return -1;
if (!test_set32u_func())
return -1;
if (g_TestPrimitivesPerformance)
{
if (!test_set8u_speed())
return -1;
if (!test_set32s_speed())
return -1;
if (!test_set32u_speed())
return -1;
}
return 0;
}

View File

@@ -0,0 +1,470 @@
/* test_shift.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <freerdp/config.h>
#include <winpr/sysinfo.h>
#include "prim_test.h"
#define FUNC_TEST_SIZE 65536
static BOOL test_lShift_16s_func(void)
{
pstatus_t status = 0;
INT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 val = 0;
if (winpr_RAND(&val, sizeof(val)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
val = val % 16;
/* Negative tests */
status = generic->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
/* Aligned */
status = generic->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
/* Unaligned */
status = generic->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
return (status == PRIMITIVES_SUCCESS);
}
static BOOL test_lShift_16u_func(void)
{
pstatus_t status = 0;
UINT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 val = 0;
if (winpr_RAND(&val, sizeof(val)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
val = val % 16;
/* Negative tests */
status = generic->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
/* Aligned */
status = generic->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
/* Unaligned */
status = generic->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
return (status == PRIMITIVES_SUCCESS);
}
static BOOL test_rShift_16s_func(void)
{
pstatus_t status = 0;
INT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 val = 0;
if (winpr_RAND(&val, sizeof(val)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
val = val % 16;
/* Negative Tests */
status = generic->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
/* Aligned */
status = generic->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
/* Unaligned */
status = generic->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
return (status == PRIMITIVES_SUCCESS);
}
static BOOL test_rShift_16u_func(void)
{
pstatus_t status = 0;
UINT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 val = 0;
if (winpr_RAND(&val, sizeof(val)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
val = val % 16;
/* Negative tests */
status = generic->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
/* Aligned */
status = generic->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
/* Unaligned */
status = generic->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
return (status == PRIMITIVES_SUCCESS);
}
static BOOL test_ShiftWrapper_16s_func(void)
{
pstatus_t status = 0;
INT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
INT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 tmp = 0;
if (winpr_RAND(&tmp, sizeof(tmp)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
/* Negative tests */
status = generic->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
/* Aligned */
status = generic->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = generic->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
/* Unaligned */
status = generic->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = generic->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
return (status == PRIMITIVES_SUCCESS);
}
static BOOL test_ShiftWrapper_16u_func(void)
{
pstatus_t status = 0;
UINT16 src[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT16 d1[FUNC_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
UINT32 tmp = 0;
if (winpr_RAND(&tmp, sizeof(tmp)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
/* Negative */
status = generic->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
if (status == PRIMITIVES_SUCCESS)
return FALSE;
/* Aligned */
status = generic->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = generic->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
/* Unaligned */
status = generic->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = generic->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
return (status == PRIMITIVES_SUCCESS);
}
/* ------------------------------------------------------------------------- */
static BOOL test_lShift_16s_speed(void)
{
UINT32 val = 0;
INT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
INT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
if (winpr_RAND(&val, sizeof(val)))
return FALSE;
val = val % 16;
if (!speed_test("lShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
(speed_test_fkt)optimized->lShiftC_16s, src, val, dst, MAX_TEST_SIZE))
return FALSE;
if (!speed_test("lShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
(speed_test_fkt)optimized->lShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
return FALSE;
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_lShift_16u_speed(void)
{
UINT32 val = 0;
UINT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
UINT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(&val, sizeof(val)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
val = val % 16;
if (!speed_test("lShift_16u", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
(speed_test_fkt)optimized->lShiftC_16u, src, val, dst, MAX_TEST_SIZE))
return FALSE;
if (!speed_test("lShift_16u", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
(speed_test_fkt)optimized->lShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE))
return FALSE;
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_rShift_16s_speed(void)
{
UINT32 val = 0;
INT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
INT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
if (winpr_RAND(&val, sizeof(val)) < 0)
return FALSE;
val = val % 16;
if (!speed_test("rShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
(speed_test_fkt)optimized->rShiftC_16s, src, val, dst, MAX_TEST_SIZE))
return FALSE;
if (!speed_test("rShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
(speed_test_fkt)optimized->rShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
return FALSE;
return TRUE;
}
/* ------------------------------------------------------------------------- */
static BOOL test_rShift_16u_speed(void)
{
UINT32 val = 0;
UINT16 src[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
UINT16 dst[MAX_TEST_SIZE + 1] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(&val, sizeof(val)) < 0)
return FALSE;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
val = val % 16;
if (!speed_test("rShift_16u", "aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u,
(speed_test_fkt)optimized->rShiftC_16u, src, val, dst, MAX_TEST_SIZE))
return FALSE;
if (!speed_test("rShift_16u", "unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u,
(speed_test_fkt)optimized->rShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE))
return FALSE;
return TRUE;
}
int TestPrimitivesShift(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE);
if (!test_lShift_16s_func())
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_lShift_16s_speed())
return 1;
}
if (!test_lShift_16u_func())
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_lShift_16u_speed())
return 1;
}
if (!test_rShift_16s_func())
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_rShift_16s_speed())
return 1;
}
if (!test_rShift_16u_func())
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_rShift_16u_speed())
return 1;
}
if (!test_ShiftWrapper_16s_func())
return 1;
if (!test_ShiftWrapper_16u_func())
return 1;
return 0;
}

View File

@@ -0,0 +1,95 @@
/* test_sign.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <freerdp/config.h>
#include <winpr/sysinfo.h>
#include "prim_test.h"
#define TEST_BUFFER_SIZE 65535
/* ------------------------------------------------------------------------- */
static BOOL test_sign16s_func(void)
{
pstatus_t status = 0;
INT16 src[TEST_BUFFER_SIZE + 16] = WINPR_C_ARRAY_INIT;
INT16 d1[TEST_BUFFER_SIZE + 16] = WINPR_C_ARRAY_INIT;
INT16 d2[TEST_BUFFER_SIZE + 16] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
status = generic->sign_16s(src + 1, d1 + 1, TEST_BUFFER_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->sign_16s(src + 1, d2 + 1, TEST_BUFFER_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (memcmp(d1, d2, sizeof(d1)) != 0)
return FALSE;
status = generic->sign_16s(src + 1, d1 + 2, TEST_BUFFER_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
status = optimized->sign_16s(src + 1, d2 + 2, TEST_BUFFER_SIZE);
if (status != PRIMITIVES_SUCCESS)
return FALSE;
if (memcmp(d1, d2, sizeof(d1)) != 0)
return FALSE;
return TRUE;
}
static int test_sign16s_speed(void)
{
INT16 src[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
INT16 dst[MAX_TEST_SIZE + 3] = WINPR_C_ARRAY_INIT;
if (winpr_RAND(src, sizeof(src)) < 0)
return FALSE;
if (!speed_test("sign16s", "aligned", g_Iterations, (speed_test_fkt)generic->sign_16s,
(speed_test_fkt)optimized->sign_16s, src + 1, dst + 1, MAX_TEST_SIZE))
return FALSE;
if (!speed_test("sign16s", "unaligned", g_Iterations, (speed_test_fkt)generic->sign_16s,
(speed_test_fkt)optimized->sign_16s, src + 1, dst + 2, MAX_TEST_SIZE))
return FALSE;
return TRUE;
}
int TestPrimitivesSign(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE);
if (!test_sign16s_func())
return 1;
if (g_TestPrimitivesPerformance)
{
if (!test_sign16s_speed())
return 1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,150 @@
/* test_YCoCg.c
* vi:ts=4 sw=4
*
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <freerdp/config.h>
#include <winpr/sysinfo.h>
#include "prim_test.h"
#include <freerdp/utils/profiler.h>
/* ------------------------------------------------------------------------- */
static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
{
pstatus_t status = -1;
BYTE* out_sse = nullptr;
BYTE* in = nullptr;
BYTE* out_c = nullptr;
const UINT32 srcStride = width * 4;
const UINT32 size = srcStride * height;
const UINT32 formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32,
PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
PROFILER_DEFINE(genericProf)
PROFILER_DEFINE(optProf)
in = winpr_aligned_calloc(1, size, 16);
out_c = winpr_aligned_calloc(1, size, 16);
out_sse = winpr_aligned_calloc(1, size, 16);
if (!in || !out_c || !out_sse)
goto fail;
if (winpr_RAND(in, size) < 0)
goto fail;
for (size_t x = 0; x < sizeof(formats) / sizeof(formats[0]); x++)
{
const UINT32 format = formats[x];
const UINT32 dstStride = width * FreeRDPGetBytesPerPixel(format);
const char* formatName = FreeRDPGetColorFormatName(format);
PROFILER_CREATE(genericProf, "YCoCgRToRGB_8u_AC4R-GENERIC")
PROFILER_CREATE(optProf, "YCoCgRToRGB_8u_AC4R-OPT")
PROFILER_ENTER(genericProf)
status = generic->YCoCgToRGB_8u_AC4R(in, WINPR_ASSERTING_INT_CAST(int, srcStride), out_c,
format, WINPR_ASSERTING_INT_CAST(int, dstStride),
width, height, 2, TRUE);
PROFILER_EXIT(genericProf)
if (status != PRIMITIVES_SUCCESS)
goto loop_fail;
PROFILER_ENTER(optProf)
status = optimized->YCoCgToRGB_8u_AC4R(
in, WINPR_ASSERTING_INT_CAST(int, srcStride), out_sse, format,
WINPR_ASSERTING_INT_CAST(int, dstStride), width, height, 2, TRUE);
PROFILER_EXIT(optProf)
if (status != PRIMITIVES_SUCCESS)
goto loop_fail;
if (memcmp(out_c, out_sse, 1ULL * dstStride * height) != 0)
{
for (size_t i = 0; i < 1ull * width * height; ++i)
{
const UINT32 c = FreeRDPReadColor(out_c + 4 * i, format);
const UINT32 sse = FreeRDPReadColor(out_sse + 4 * i, format);
if (c != sse)
{
printf("optimized->YCoCgRToRGB FAIL[%s] [%" PRIuz "]: 0x%08" PRIx32
" -> C 0x%08" PRIx32 " vs optimized 0x%08" PRIx32 "\n",
formatName, i, in[i + 1], c, sse);
status = -1;
}
}
}
printf("--------------------------- [%s] [%" PRIu32 "x%" PRIu32
"] ---------------------------\n",
formatName, width, height);
PROFILER_PRINT_HEADER
PROFILER_PRINT(genericProf)
PROFILER_PRINT(optProf)
PROFILER_PRINT_FOOTER
loop_fail:
PROFILER_FREE(genericProf)
PROFILER_FREE(optProf)
if (status != PRIMITIVES_SUCCESS)
goto fail;
}
fail:
winpr_aligned_free(in);
winpr_aligned_free(out_c);
winpr_aligned_free(out_sse);
return status == PRIMITIVES_SUCCESS;
}
int TestPrimitivesYCoCg(int argc, char* argv[])
{
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
prim_test_setup(FALSE);
/* Random resolution tests */
if (argc < 2)
{
for (UINT32 x = 0; x < 10; x++)
{
UINT32 w = 0;
UINT32 h = 0;
do
{
if (winpr_RAND(&w, sizeof(w)) < 0)
return -1;
w %= 2048 / 4;
} while (w < 16);
do
{
if (winpr_RAND(&h, sizeof(h)) < 0)
return -1;
h %= 2048 / 4;
} while (h < 16);
if (!test_YCoCgRToRGB_8u_AC4R_func(w, h))
return 1;
}
}
/* Test once with full HD/4 */
if (!test_YCoCgRToRGB_8u_AC4R_func(1920 / 4, 1080 / 4))
return 1;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,138 @@
/* measure.h
* Macros to help with performance measurement.
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License. Algorithms used by
* this code may be covered by patents by HP, Microsoft, or other parties.
*
* MEASURE_LOOP_START("measurement", 2000)
* code to be measured
* MEASURE_LOOP_STOP
* buffer flush and such
* MEASURE_SHOW_RESULTS
*
* Define GOOGLE_PROFILER if you want gperftools included.
*/
#ifndef TEST_MEASURE_H_INCLUDED
#define TEST_MEASURE_H_INCLUDED
#include <freerdp/config.h>
#include <time.h>
#include <winpr/string.h>
#include <winpr/sysinfo.h>
#ifndef _WIN32
#include <sys/param.h>
#endif
#include <winpr/crt.h>
#ifdef _WIN32
#define PROFILER_START(_prefix_)
#define PROFILER_STOP
#define MEASURE_LOOP_START(_prefix_, _count_)
#define MEASURE_LOOP_STOP
#define MEASURE_GET_RESULTS(_result_)
#define MEASURE_SHOW_RESULTS(_result_)
#define MEASURE_SHOW_RESULTS_SCALED(_scale_, _label_)
#define MEASURE_TIMED(_label_, _init_iter_, _test_time_, _result_, _call_)
#else
#ifdef GOOGLE_PROFILER
#include <gperftools/profiler.h>
#define PROFILER_START(_prefix_) \
do \
{ \
char _path[PATH_MAX]; \
sprintf_s(_path, sizeof(_path), "./%s.prof", (_prefix_)); \
ProfilerStart(_path); \
} while (0);
#define PROFILER_STOP \
do \
{ \
ProfilerStop(); \
} while (0);
#else
#define PROFILER_START(_prefix_)
#define PROFILER_STOP
#endif // GOOGLE_PROFILER
extern float measure_delta_time(UINT64 t0, UINT64 t1);
extern void measure_floatprint(float t, char* output, size_t len);
#define MEASURE_LOOP_START(_prefix_, _count_) \
{ \
int _count = (_count_); \
int _loop; \
char str1[32] = WINPR_C_ARRAY_INIT; \
char str2[32] = WINPR_C_ARRAY_INIT; \
char* _prefix = _strdup(_prefix_); \
const UINT64 start = winpr_GetTickCount64NS(); \
PROFILER_START(_prefix); \
_loop = (_count); \
do \
{
#define MEASURE_LOOP_STOP \
} \
while (--_loop) \
;
#define MEASURE_GET_RESULTS(_result_) \
PROFILER_STOP; \
const UINT64 stop = winpr_GetTickCount64NS(); \
const float delta = measure_delta_time(start, stop); \
(_result_) = (float)_count / delta; \
free(_prefix); \
}
#define MEASURE_SHOW_RESULTS(_result_) \
PROFILER_STOP; \
const UINT64 stop = winpr_GetTickCount64NS(); \
const float delta = measure_delta_time(start, stop); \
(_result_) = (float)_count / delta; \
measure_floatprint((float)_count / delta, str1); \
printf("%s: %9d iterations in %5.1f seconds = %s/s \n", _prefix, _count, delta, str1); \
free(_prefix); \
}
#define MEASURE_SHOW_RESULTS_SCALED(_scale_, _label_) \
PROFILER_STOP; \
const UINT64 stop = winpr_GetTickCount64NS(); \
const float delta = measure_delta_time(start, stop); \
measure_floatprint((float)_count / delta, str1); \
measure_floatprint((float)_count / delta * (_scale_), str2); \
printf("%s: %9d iterations in %5.1f seconds = %s/s = %s%s \n", _prefix, _count, delta, str1, \
str2, _label_); \
free(_prefix); \
}
#define MEASURE_TIMED(_label_, _init_iter_, _test_time_, _result_, _call_) \
{ \
float _r; \
MEASURE_LOOP_START(_label_, _init_iter_); \
_call_; \
MEASURE_LOOP_STOP; \
MEASURE_GET_RESULTS(_r); \
MEASURE_LOOP_START(_label_, _r* _test_time_); \
_call_; \
MEASURE_LOOP_STOP; \
MEASURE_SHOW_RESULTS(_result_); \
}
#endif
#endif // __MEASURE_H_INCLUDED__

View File

@@ -0,0 +1,94 @@
/* prim_test.c
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <freerdp/config.h>
#include "prim_test.h"
#ifndef _WIN32
#include <fcntl.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <winpr/sysinfo.h>
#include <winpr/platform.h>
#include <winpr/crypto.h>
primitives_t* generic = nullptr;
primitives_t* optimized = nullptr;
BOOL g_TestPrimitivesPerformance = FALSE;
UINT32 g_Iterations = 1000;
int test_sizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
/* ------------------------------------------------------------------------- */
float measure_delta_time(UINT64 t0, UINT64 t1)
{
INT64 diff = (INT64)(t1 - t0);
double retval = ((double)diff / 1000000000.0);
return (retval < 0.0) ? 0.0f : (float)retval;
}
/* ------------------------------------------------------------------------- */
void measure_floatprint(float t, char* output, size_t len)
{
/* I don't want to link against -lm, so avoid log,exp,... */
float f = 10.0f;
int i = 0;
while (t > f)
f *= 10.0f;
f /= 1000.0f;
i = ((int)(t / f + 0.5f)) * (int)f;
if (t < 0.0f)
(void)_snprintf(output, len, "%f", t);
else if (i == 0)
(void)_snprintf(output, len, "%d", (int)(t + 0.5f));
else if (t < 1e+3f)
(void)_snprintf(output, len, "%3d", i);
else if (t < 1e+6f)
(void)_snprintf(output, len, "%3d,%03d", i / 1000, i % 1000);
else if (t < 1e+9f)
(void)_snprintf(output, len, "%3d,%03d,000", i / 1000000, (i % 1000000) / 1000);
else if (t < 1e+12f)
(void)_snprintf(output, len, "%3d,%03d,000,000", i / 1000000000,
(i % 1000000000) / 1000000);
else
(void)_snprintf(output, len, "%f", t);
}
void prim_test_setup(BOOL performance)
{
generic = primitives_get_generic();
optimized = primitives_get();
g_TestPrimitivesPerformance = performance;
}
BOOL speed_test(const char* name, const char* dsc, UINT32 iterations, speed_test_fkt generic,
speed_test_fkt optimized, ...)
{
if (!name || !generic || !optimized || (iterations == 0))
return FALSE;
for (UINT32 i = 0; i < iterations; i++)
{
}
return TRUE;
}

View File

@@ -0,0 +1,48 @@
/* primtest.h
* vi:ts=4 sw=4
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License. Algorithms used by
* this code may be covered by patents by HP, Microsoft, or other parties.
*/
#ifndef FREERDP_LIB_PRIMTEST_H
#define FREERDP_LIB_PRIMTEST_H
#include <winpr/crt.h>
#include <winpr/spec.h>
#include <winpr/wtypes.h>
#include <winpr/platform.h>
#include <winpr/crypto.h>
#include <freerdp/primitives.h>
#include "measure.h"
#define ABS(_x_) ((_x_) < 0 ? (-(_x_)) : (_x_))
#define MAX_TEST_SIZE 4096
extern int test_sizes[];
#define NUM_TEST_SIZES 10
extern BOOL g_TestPrimitivesPerformance;
extern UINT32 g_Iterations;
extern primitives_t* generic;
extern primitives_t* optimized;
void prim_test_setup(BOOL performance);
typedef pstatus_t (*speed_test_fkt)();
BOOL speed_test(const char* name, const char* dsc, UINT32 iterations, speed_test_fkt generic,
speed_test_fkt optimized, ...);
#endif /* FREERDP_LIB_PRIMTEST_H */