15#include <freerdp/config.h> 
   17#include <winpr/sysinfo.h> 
   20#define FUNC_TEST_SIZE 65536 
   22static BOOL test_lShift_16s_func(
void)
 
   25  INT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
 
   26  INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
 
   28  winpr_RAND(&val, 
sizeof(val));
 
   29  winpr_RAND(src, 
sizeof(src));
 
   32  status = 
generic->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
   34  if (status == PRIMITIVES_SUCCESS)
 
   37  status = optimized->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
   39  if (status == PRIMITIVES_SUCCESS)
 
   43  status = 
generic->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
   45  if (status != PRIMITIVES_SUCCESS)
 
   48  status = optimized->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
   50  if (status != PRIMITIVES_SUCCESS)
 
   54  status = 
generic->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
   56  if (status != PRIMITIVES_SUCCESS)
 
   59  status = optimized->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
   61  if (status != PRIMITIVES_SUCCESS)
 
   67static BOOL test_lShift_16u_func(
void)
 
   70  UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
 
   71  UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
 
   73  winpr_RAND(&val, 
sizeof(val));
 
   74  winpr_RAND(src, 
sizeof(src));
 
   78  status = 
generic->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
   80  if (status == PRIMITIVES_SUCCESS)
 
   83  status = optimized->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
   85  if (status == PRIMITIVES_SUCCESS)
 
   89  status = 
generic->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
   91  if (status != PRIMITIVES_SUCCESS)
 
   94  status = optimized->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
   96  if (status != PRIMITIVES_SUCCESS)
 
  100  status = 
generic->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  102  if (status != PRIMITIVES_SUCCESS)
 
  105  status = optimized->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  107  if (status != PRIMITIVES_SUCCESS)
 
  113static BOOL test_rShift_16s_func(
void)
 
  115  pstatus_t status = 0;
 
  116  INT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
 
  117  INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
 
  119  winpr_RAND(&val, 
sizeof(val));
 
  120  winpr_RAND(src, 
sizeof(src));
 
  124  status = 
generic->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  126  if (status == PRIMITIVES_SUCCESS)
 
  129  status = optimized->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  131  if (status == PRIMITIVES_SUCCESS)
 
  135  status = 
generic->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  137  if (status != PRIMITIVES_SUCCESS)
 
  140  status = optimized->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  142  if (status != PRIMITIVES_SUCCESS)
 
  146  status = 
generic->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  148  if (status != PRIMITIVES_SUCCESS)
 
  151  status = optimized->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  153  if (status != PRIMITIVES_SUCCESS)
 
  159static BOOL test_rShift_16u_func(
void)
 
  161  pstatus_t status = 0;
 
  162  UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]);
 
  163  UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]);
 
  165  winpr_RAND(&val, 
sizeof(val));
 
  166  winpr_RAND(src, 
sizeof(src));
 
  169  status = 
generic->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  171  if (status == PRIMITIVES_SUCCESS)
 
  174  status = optimized->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  176  if (status == PRIMITIVES_SUCCESS)
 
  180  status = 
generic->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  182  if (status != PRIMITIVES_SUCCESS)
 
  185  status = optimized->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  187  if (status != PRIMITIVES_SUCCESS)
 
  191  status = 
generic->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  193  if (status != PRIMITIVES_SUCCESS)
 
  196  status = optimized->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  198  if (status != PRIMITIVES_SUCCESS)
 
  204static BOOL test_ShiftWrapper_16s_func(
void)
 
  206  pstatus_t status = 0;
 
  207  INT16 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
 
  208  INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]) = { 0 };
 
  210  winpr_RAND(&tmp, 
sizeof(tmp));
 
  211  winpr_RAND(src, 
sizeof(src));
 
  212  INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
 
  215  status = 
generic->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  217  if (status == PRIMITIVES_SUCCESS)
 
  220  status = optimized->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  222  if (status == PRIMITIVES_SUCCESS)
 
  226  status = 
generic->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  228  if (status != PRIMITIVES_SUCCESS)
 
  231  status = optimized->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  233  if (status != PRIMITIVES_SUCCESS)
 
  236  status = 
generic->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
 
  238  if (status != PRIMITIVES_SUCCESS)
 
  241  status = optimized->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
 
  243  if (status != PRIMITIVES_SUCCESS)
 
  247  status = 
generic->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  249  if (status != PRIMITIVES_SUCCESS)
 
  252  status = optimized->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  254  if (status != PRIMITIVES_SUCCESS)
 
  257  status = 
generic->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
 
  259  if (status != PRIMITIVES_SUCCESS)
 
  262  status = optimized->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
 
  264  if (status != PRIMITIVES_SUCCESS)
 
  270static BOOL test_ShiftWrapper_16u_func(
void)
 
  272  pstatus_t status = 0;
 
  273  UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 };
 
  274  UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]) = { 0 };
 
  276  winpr_RAND(&tmp, 
sizeof(tmp));
 
  277  winpr_RAND(src, 
sizeof(src));
 
  278  INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16);
 
  281  status = 
generic->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  282  if (status == PRIMITIVES_SUCCESS)
 
  285  status = optimized->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE);
 
  287  if (status == PRIMITIVES_SUCCESS)
 
  291  status = 
generic->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  293  if (status != PRIMITIVES_SUCCESS)
 
  296  status = optimized->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE);
 
  298  if (status != PRIMITIVES_SUCCESS)
 
  301  status = 
generic->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
 
  303  if (status != PRIMITIVES_SUCCESS)
 
  306  status = optimized->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE);
 
  308  if (status != PRIMITIVES_SUCCESS)
 
  312  status = 
generic->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  314  if (status != PRIMITIVES_SUCCESS)
 
  317  status = optimized->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE);
 
  319  if (status != PRIMITIVES_SUCCESS)
 
  322  status = 
generic->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
 
  324  if (status != PRIMITIVES_SUCCESS)
 
  327  status = optimized->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE);
 
  329  if (status != PRIMITIVES_SUCCESS)
 
  336static BOOL test_lShift_16s_speed(
void)
 
  339  INT16 ALIGN(src[MAX_TEST_SIZE + 1]);
 
  340  INT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
 
  341  winpr_RAND(src, 
sizeof(src));
 
  342  winpr_RAND(&val, 
sizeof(val));
 
  345  if (!speed_test(
"lShift_16s", 
"aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
 
  346                  (speed_test_fkt)optimized->lShiftC_16s, src, val, dst, MAX_TEST_SIZE))
 
  349  if (!speed_test(
"lShift_16s", 
"unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s,
 
  350                  (speed_test_fkt)optimized->lShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
 
  357static BOOL test_lShift_16u_speed(
void)
 
  360  UINT16 ALIGN(src[MAX_TEST_SIZE + 1]);
 
  361  UINT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
 
  362  winpr_RAND(&val, 
sizeof(val));
 
  363  winpr_RAND(src, 
sizeof(src));
 
  366  if (!speed_test(
"lShift_16u", 
"aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
 
  367                  (speed_test_fkt)optimized->lShiftC_16u, src, val, dst, MAX_TEST_SIZE))
 
  370  if (!speed_test(
"lShift_16u", 
"unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u,
 
  371                  (speed_test_fkt)optimized->lShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE))
 
  378static BOOL test_rShift_16s_speed(
void)
 
  381  INT16 ALIGN(src[MAX_TEST_SIZE + 1]);
 
  382  INT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
 
  383  winpr_RAND(src, 
sizeof(src));
 
  384  winpr_RAND(&val, 
sizeof(val));
 
  387  if (!speed_test(
"rShift_16s", 
"aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
 
  388                  (speed_test_fkt)optimized->rShiftC_16s, src, val, dst, MAX_TEST_SIZE))
 
  391  if (!speed_test(
"rShift_16s", 
"unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s,
 
  392                  (speed_test_fkt)optimized->rShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE))
 
  399static BOOL test_rShift_16u_speed(
void)
 
  402  UINT16 ALIGN(src[MAX_TEST_SIZE + 1]);
 
  403  UINT16 ALIGN(dst[MAX_TEST_SIZE + 1]);
 
  404  winpr_RAND(&val, 
sizeof(val));
 
  405  winpr_RAND(src, 
sizeof(src));
 
  408  if (!speed_test(
"rShift_16u", 
"aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u,
 
  409                  (speed_test_fkt)optimized->rShiftC_16u, src, val, dst, MAX_TEST_SIZE))
 
  412  if (!speed_test(
"rShift_16u", 
"unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u,
 
  413                  (speed_test_fkt)optimized->rShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE))
 
  419int TestPrimitivesShift(
int argc, 
char* argv[])
 
  423  prim_test_setup(FALSE);
 
  425  if (!test_lShift_16s_func())
 
  428  if (g_TestPrimitivesPerformance)
 
  430    if (!test_lShift_16s_speed())
 
  434  if (!test_lShift_16u_func())
 
  437  if (g_TestPrimitivesPerformance)
 
  439    if (!test_lShift_16u_speed())
 
  443  if (!test_rShift_16s_func())
 
  446  if (g_TestPrimitivesPerformance)
 
  448    if (!test_rShift_16s_speed())
 
  452  if (!test_rShift_16u_func())
 
  455  if (g_TestPrimitivesPerformance)
 
  457    if (!test_rShift_16u_speed())
 
  461  if (!test_ShiftWrapper_16s_func())
 
  464  if (!test_ShiftWrapper_16u_func())