libfreerdp-primitives: code style cleanup

This commit is contained in:
Marc-André Moreau
2013-01-19 15:16:28 -05:00
parent 1032c69e3f
commit 49ee48e8d0
13 changed files with 223 additions and 147 deletions

View File

@@ -397,6 +397,7 @@ int transport_read(rdpTransport* transport, STREAM* s)
int stream_bytes;
int transport_status;
pdu_bytes = 0;
transport_status = 0;
/* first check if we have header */

View File

@@ -19,15 +19,19 @@
#endif
#include <string.h>
#include <freerdp/types.h>
#include <freerdp/primitives.h>
#ifdef WITH_SSE2
# include <emmintrin.h>
# include <pmmintrin.h>
#include <emmintrin.h>
#include <pmmintrin.h>
#endif /* WITH_SSE2 */
#ifdef WITH_IPP
# include <ipps.h>
#include <ipps.h>
#endif /* WITH_IPP */
#include "prim_internal.h"
#include "prim_templates.h"

View File

@@ -25,15 +25,19 @@
#endif
#include <string.h>
#include <freerdp/types.h>
#include <freerdp/primitives.h>
#include "prim_internal.h"
#ifdef WITH_SSE2
# include <emmintrin.h>
# include <pmmintrin.h>
#include <emmintrin.h>
#include <pmmintrin.h>
#endif /* WITH_SSE2 */
#ifdef WITH_IPP
# include <ippi.h>
#include <ippi.h>
#endif /* WITH_IPP */
#define ALPHA(_k_) (((_k_) & 0xFF000000U) >> 24)

View File

@@ -18,15 +18,19 @@
#endif
#include <string.h>
#include <freerdp/types.h>
#include <freerdp/primitives.h>
#ifdef WITH_SSE2
# include <emmintrin.h>
# include <pmmintrin.h>
#include <emmintrin.h>
#include <pmmintrin.h>
#endif /* WITH_SSE2 */
#ifdef WITH_IPP
# include <ipps.h>
#include <ipps.h>
#endif /* WITH_IPP */
#include "prim_internal.h"
#include "prim_templates.h"
@@ -39,8 +43,12 @@ PRIM_STATIC pstatus_t general_andC_32u(
UINT32 *pDst,
INT32 len)
{
if (val == 0) return PRIMITIVES_SUCCESS;
while (len--) *pDst++ = *pSrc++ & val;
if (val == 0)
return PRIMITIVES_SUCCESS;
while (len--)
*pDst++ = *pSrc++ & val;
return PRIMITIVES_SUCCESS;
}
@@ -53,8 +61,12 @@ PRIM_STATIC pstatus_t general_orC_32u(
UINT32 *pDst,
INT32 len)
{
if (val == 0) return PRIMITIVES_SUCCESS;
while (len--) *pDst++ = *pSrc++ | val;
if (val == 0)
return PRIMITIVES_SUCCESS;
while (len--)
*pDst++ = *pSrc++ | val;
return PRIMITIVES_SUCCESS;
}
@@ -76,6 +88,7 @@ void primitives_init_andor(
/* Start with the default. */
prims->andC_32u = general_andC_32u;
prims->orC_32u = general_orC_32u;
#if defined(WITH_IPP)
prims->andC_32u = (__andC_32u_t) ippsAndC_32u;
prims->orC_32u = (__orC_32u_t) ippsOrC_32u;

View File

@@ -18,15 +18,19 @@
#endif
#include <string.h>
#include <freerdp/types.h>
#include <freerdp/primitives.h>
#ifdef WITH_SSE2
# include <emmintrin.h>
# include <pmmintrin.h>
#include <emmintrin.h>
#include <pmmintrin.h>
#endif /* WITH_SSE2 */
#ifdef WITH_IPP
# include <ipps.h>
#include <ipps.h>
#endif /* WITH_IPP */
#include "prim_internal.h"
#include "prim_templates.h"

View File

@@ -18,12 +18,15 @@
#endif
#include <string.h>
#include <freerdp/types.h>
#include <freerdp/primitives.h>
#ifdef WITH_SSE2
# include <emmintrin.h>
# include <tmmintrin.h>
#include <emmintrin.h>
#include <tmmintrin.h>
#endif /* WITH_SSE2 */
#include "prim_internal.h"
/* ----------------------------------------------------------------------------

View File

@@ -23,13 +23,15 @@
#include <stdlib.h>
#include <freerdp/primitives.h>
#include "prim_internal.h"
#ifdef ANDROID
# include "cpu-features.h"
#include "cpu-features.h"
#endif
/* Singleton pointer used throughout the program when requested. */
static primitives_t *pPrimitives = NULL;
static primitives_t* pPrimitives = NULL;
#define D_BIT_MMX (1<<23)
#define D_BIT_SSE (1<<25)
@@ -40,14 +42,14 @@ static primitives_t *pPrimitives = NULL;
#define C_BIT_SSSE3 (1<<9)
#define C_BIT_SSE41 (1<<19)
#define C_BIT_SSE42 (1<<20)
#define C_BIT_XGETBV (1<<27)
#define C_BIT_XGETBV (1<<27)
#define C_BIT_AVX (1<<28)
#define C_BITS_AVX (C_BIT_XGETBV|C_BIT_AVX)
#define E_BIT_XMM (1<<1)
#define E_BIT_YMM (1<<2)
#define E_BITS_AVX (E_BIT_XMM|E_BIT_YMM)
#define C_BIT_FMA (1<<11)
#define C_BIT_AVX_AES (1<<24)
#define C_BIT_AVX_AES (1<<24)
/* If x86 */
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) \
@@ -60,6 +62,7 @@ static primitives_t *pPrimitives = NULL;
/* If GCC */
# ifdef __GNUC__
# define xgetbv(_func_, _lo_, _hi_) \
__asm__ __volatile__ ("xgetbv" : "=a" (_lo_), "=d" (_hi_) : "c" (_func_))
@@ -90,36 +93,50 @@ static void cpuid(
);
}
static void set_hints(
primitives_hints_t *hints)
static void set_hints(primitives_hints_t* hints)
{
unsigned a, b, c, d;
cpuid(1, &a, &b, &c, &d);
if (d & D_BIT_MMX) hints->x86_flags |= PRIM_X86_MMX_AVAILABLE;
if (d & D_BIT_SSE) hints->x86_flags |= PRIM_X86_SSE_AVAILABLE;
if (d & D_BIT_SSE2) hints->x86_flags |= PRIM_X86_SSE2_AVAILABLE;
if (d & D_BIT_3DN) hints->x86_flags |= PRIM_X86_3DNOW_AVAILABLE;
if (c & C_BIT_3DNP) hints->x86_flags |= PRIM_X86_3DNOW_PREFETCH_AVAILABLE;
if (c & C_BIT_SSE3) hints->x86_flags |= PRIM_X86_SSE3_AVAILABLE;
if (c & C_BIT_SSSE3) hints->x86_flags |= PRIM_X86_SSSE3_AVAILABLE;
if (c & C_BIT_SSE41) hints->x86_flags |= PRIM_X86_SSE41_AVAILABLE;
if (c & C_BIT_SSE42) hints->x86_flags |= PRIM_X86_SSE42_AVAILABLE;
if (d & D_BIT_MMX)
hints->x86_flags |= PRIM_X86_MMX_AVAILABLE;
if (d & D_BIT_SSE)
hints->x86_flags |= PRIM_X86_SSE_AVAILABLE;
if (d & D_BIT_SSE2)
hints->x86_flags |= PRIM_X86_SSE2_AVAILABLE;
if (d & D_BIT_3DN)
hints->x86_flags |= PRIM_X86_3DNOW_AVAILABLE;
if (c & C_BIT_3DNP)
hints->x86_flags |= PRIM_X86_3DNOW_PREFETCH_AVAILABLE;
if (c & C_BIT_SSE3)
hints->x86_flags |= PRIM_X86_SSE3_AVAILABLE;
if (c & C_BIT_SSSE3)
hints->x86_flags |= PRIM_X86_SSSE3_AVAILABLE;
if (c & C_BIT_SSE41)
hints->x86_flags |= PRIM_X86_SSE41_AVAILABLE;
if (c & C_BIT_SSE42)
hints->x86_flags |= PRIM_X86_SSE42_AVAILABLE;
if ((c & C_BITS_AVX) == C_BITS_AVX)
{
int e, f;
xgetbv(0, e, f);
if ((e & E_BITS_AVX) == E_BITS_AVX)
{
hints->x86_flags |= PRIM_X86_AVX_AVAILABLE;
if (c & C_BIT_FMA) hints->x86_flags |= PRIM_X86_FMA_AVAILABLE;
if (c & C_BIT_AVX_AES) hints->x86_flags |= PRIM_X86_AVX_AES_AVAILABLE;
if (c & C_BIT_FMA)
hints->x86_flags |= PRIM_X86_FMA_AVAILABLE;
if (c & C_BIT_AVX_AES)
hints->x86_flags |= PRIM_X86_AVX_AES_AVAILABLE;
}
}
/* TODO: AVX2: set eax=7, ecx=0, cpuid, check ebx-bit5 */
}
# else
static void set_hints(
primitives_hints_t *hints)
static void set_hints(primitives_hints_t* hints)
{
/* x86 non-GCC: TODO */
}
@@ -167,12 +184,14 @@ static void set_hints(
/* ------------------------------------------------------------------------- */
void primitives_init(void)
{
primitives_hints_t *hints;
primitives_hints_t* hints;
if (pPrimitives == NULL)
{
pPrimitives = calloc(1, sizeof(primitives_t));
if (pPrimitives == NULL) return;
if (pPrimitives == NULL)
return;
}
hints = calloc(1, sizeof(primitives_hints_t));
@@ -191,17 +210,19 @@ void primitives_init(void)
}
/* ------------------------------------------------------------------------- */
primitives_t *primitives_get(void)
primitives_t* primitives_get(void)
{
if (pPrimitives == NULL) primitives_init();
if (pPrimitives == NULL)
primitives_init();
return pPrimitives;
}
/* ------------------------------------------------------------------------- */
UINT32 primitives_get_flags(
const primitives_t *prims)
UINT32 primitives_get_flags(const primitives_t* prims)
{
primitives_hints_t *hints = (primitives_hints_t *) (prims->hints);
primitives_hints_t* hints = (primitives_hints_t*) (prims->hints);
#ifdef i386
return hints->x86_flags;
#elif defined(__arm__)
@@ -212,69 +233,81 @@ UINT32 primitives_get_flags(
}
/* ------------------------------------------------------------------------- */
void primitives_flags_str(
const primitives_t *prims,
char *str,
size_t len)
typedef struct
{
UINT32 flag;
const char *str;
} flagpair_t;
static const flagpair_t x86_flags[] =
{
{ PRIM_X86_MMX_AVAILABLE, "MMX" },
{ PRIM_X86_3DNOW_AVAILABLE, "3DNow" },
{ PRIM_X86_3DNOW_PREFETCH_AVAILABLE, "3DNow-PF" },
{ PRIM_X86_SSE_AVAILABLE, "SSE" },
{ PRIM_X86_SSE2_AVAILABLE, "SSE2" },
{ PRIM_X86_SSE3_AVAILABLE, "SSE3" },
{ PRIM_X86_SSSE3_AVAILABLE, "SSSE3" },
{ PRIM_X86_SSE41_AVAILABLE, "SSE4.1" },
{ PRIM_X86_SSE42_AVAILABLE, "SSE4.2" },
{ PRIM_X86_AVX_AVAILABLE, "AVX" },
{ PRIM_X86_FMA_AVAILABLE, "FMA" },
{ PRIM_X86_AVX_AES_AVAILABLE, "AVX-AES" },
{ PRIM_X86_AVX2_AVAILABLE, "AVX2" },
};
static const flagpair_t arm_flags[] =
{
{ PRIM_ARM_VFP1_AVAILABLE, "VFP1" },
{ PRIM_ARM_VFP2_AVAILABLE, "VFP2" },
{ PRIM_ARM_VFP3_AVAILABLE, "VFP3" },
{ PRIM_ARM_VFP4_AVAILABLE, "VFP4" },
{ PRIM_ARM_FPA_AVAILABLE, "FPA" },
{ PRIM_ARM_FPE_AVAILABLE, "FPE" },
{ PRIM_ARM_IWMMXT_AVAILABLE, "IWMMXT" },
{ PRIM_ARM_NEON_AVAILABLE, "NEON" },
};
void primitives_flags_str(const primitives_t* prims, char* str, size_t len)
{
typedef struct
{
UINT32 flag;
const char *str;
} flagpair_t;
static const flagpair_t x86_flags[] =
{
{ PRIM_X86_MMX_AVAILABLE, "MMX" },
{ PRIM_X86_3DNOW_AVAILABLE, "3DNow" },
{ PRIM_X86_3DNOW_PREFETCH_AVAILABLE, "3DNow-PF" },
{ PRIM_X86_SSE_AVAILABLE, "SSE" },
{ PRIM_X86_SSE2_AVAILABLE, "SSE2" },
{ PRIM_X86_SSE3_AVAILABLE, "SSE3" },
{ PRIM_X86_SSSE3_AVAILABLE, "SSSE3" },
{ PRIM_X86_SSE41_AVAILABLE, "SSE4.1" },
{ PRIM_X86_SSE42_AVAILABLE, "SSE4.2" },
{ PRIM_X86_AVX_AVAILABLE, "AVX" },
{ PRIM_X86_FMA_AVAILABLE, "FMA" },
{ PRIM_X86_AVX_AES_AVAILABLE, "AVX-AES" },
{ PRIM_X86_AVX2_AVAILABLE, "AVX2" },
};
static const flagpair_t arm_flags[] =
{
{ PRIM_ARM_VFP1_AVAILABLE, "VFP1" },
{ PRIM_ARM_VFP2_AVAILABLE, "VFP2" },
{ PRIM_ARM_VFP3_AVAILABLE, "VFP3" },
{ PRIM_ARM_VFP4_AVAILABLE, "VFP4" },
{ PRIM_ARM_FPA_AVAILABLE, "FPA" },
{ PRIM_ARM_FPE_AVAILABLE, "FPE" },
{ PRIM_ARM_IWMMXT_AVAILABLE, "IWMMXT" },
{ PRIM_ARM_NEON_AVAILABLE, "NEON" },
};
int i;
primitives_hints_t *hints;
primitives_hints_t* hints;
*str = '\0';
--len; /* for the '/0' */
hints = (primitives_hints_t *) (prims->hints);
for (i=0; i<sizeof(x86_flags)/sizeof(flagpair_t); ++i)
hints = (primitives_hints_t*) (prims->hints);
for (i = 0; i < sizeof(x86_flags) / sizeof(flagpair_t); ++i)
{
if (hints->x86_flags & x86_flags[i].flag)
{
int slen = strlen(x86_flags[i].str) + 1;
if (len < slen) break;
if (*str != '\0') strcat(str, " ");
if (len < slen)
break;
if (*str != '\0')
strcat(str, " ");
strcat(str, x86_flags[i].str);
len -= slen;
}
}
for (i=0; i<sizeof(arm_flags)/sizeof(flagpair_t); ++i)
for (i = 0; i < sizeof(arm_flags) / sizeof(flagpair_t); ++i)
{
if (hints->arm_flags & arm_flags[i].flag)
{
int slen = strlen(arm_flags[i].str) + 1;
if (len < slen) break;
if (*str != '\0') strcat(str, " ");
if (len < slen)
break;
if (*str != '\0')
strcat(str, " ");
strcat(str, arm_flags[i].str);
len -= slen;
}
@@ -284,7 +317,8 @@ void primitives_flags_str(
/* ------------------------------------------------------------------------- */
void primitives_deinit(void)
{
if (pPrimitives == NULL) return;
if (pPrimitives == NULL)
return;
/* Call each section's de-initialization routine. */
primitives_deinit_add(pPrimitives);
@@ -296,7 +330,9 @@ void primitives_deinit(void)
primitives_deinit_sign(pPrimitives);
primitives_deinit_colors(pPrimitives);
if (pPrimitives->hints != NULL) free((void *) (pPrimitives->hints));
free((void *) pPrimitives);
if (pPrimitives->hints != NULL)
free((void*) (pPrimitives->hints));
free((void*) pPrimitives);
pPrimitives = NULL;
}

View File

@@ -133,77 +133,83 @@ void _floatprint(
#define TEST_SET8 (1<<1)
#define TEST_SET32S (1<<2)
#define TEST_SET32U (1<<3)
#define TEST_SIGN16S (1<<4)
#define TEST_SIGN16S (1<<4)
#define TEST_ADD16S (1<<5)
#define TEST_LSHIFT16S (1<<6)
#define TEST_LSHIFT16U (1<<7)
#define TEST_RSHIFT16S (1<<8)
#define TEST_RSHIFT16U (1<<9)
#define TEST_LSHIFT16S (1<<6)
#define TEST_LSHIFT16U (1<<7)
#define TEST_RSHIFT16S (1<<8)
#define TEST_RSHIFT16U (1<<9)
#define TEST_RGB (1<<10)
#define TEST_ALPHA (1<<11)
#define TEST_AND (1<<12)
#define TEST_OR (1<<13)
/* Specific types of testing: */
#define TEST_FUNCTIONALITY (1<<0)
#define TEST_PERFORMANCE (1<<1)
#define TEST_FUNCTIONALITY (1<<0)
#define TEST_PERFORMANCE (1<<1)
/* ------------------------------------------------------------------------- */
int main(
int argc,
char **argv)
typedef struct
{
typedef struct
{
const char *testStr;
UINT32 bits;
} test_t;
static const test_t testList[] =
{
{ "all", 0xFFFFFFFFU },
{ "copy", TEST_COPY8 },
{ "copy8", TEST_COPY8 },
{ "set", TEST_SET8|TEST_SET32S|TEST_SET32U },
{ "set8", TEST_SET8 },
{ "set32", TEST_SET32S|TEST_SET32U },
{ "set32s", TEST_SET32S },
{ "set32u", TEST_SET32U },
{ "sign", TEST_SIGN16S },
{ "sign16s", TEST_SIGN16S },
{ "add", TEST_ADD16S },
{ "add16s", TEST_ADD16S },
{ "lshift", TEST_LSHIFT16S|TEST_LSHIFT16U },
{ "rshift", TEST_RSHIFT16S|TEST_RSHIFT16U },
{ "shift", TEST_LSHIFT16S|TEST_LSHIFT16U|TEST_RSHIFT16S|TEST_RSHIFT16U },
{ "lshift16s", TEST_LSHIFT16S },
{ "lshift16u", TEST_LSHIFT16U },
{ "rshift16s", TEST_RSHIFT16S },
{ "rshift16u", TEST_RSHIFT16U },
{ "rgb", TEST_RGB },
{ "color", TEST_RGB },
{ "colors", TEST_RGB },
{ "alpha", TEST_ALPHA },
{ "and", TEST_AND },
{ "or", TEST_OR },
};
const char *testStr;
UINT32 bits;
} test_t;
static const test_t testList[] =
{
{ "all", 0xFFFFFFFFU },
{ "copy", TEST_COPY8 },
{ "copy8", TEST_COPY8 },
{ "set", TEST_SET8|TEST_SET32S|TEST_SET32U },
{ "set8", TEST_SET8 },
{ "set32", TEST_SET32S|TEST_SET32U },
{ "set32s", TEST_SET32S },
{ "set32u", TEST_SET32U },
{ "sign", TEST_SIGN16S },
{ "sign16s", TEST_SIGN16S },
{ "add", TEST_ADD16S },
{ "add16s", TEST_ADD16S },
{ "lshift", TEST_LSHIFT16S|TEST_LSHIFT16U },
{ "rshift", TEST_RSHIFT16S|TEST_RSHIFT16U },
{ "shift", TEST_LSHIFT16S|TEST_LSHIFT16U|TEST_RSHIFT16S|TEST_RSHIFT16U },
{ "lshift16s", TEST_LSHIFT16S },
{ "lshift16u", TEST_LSHIFT16U },
{ "rshift16s", TEST_RSHIFT16S },
{ "rshift16u", TEST_RSHIFT16U },
{ "rgb", TEST_RGB },
{ "color", TEST_RGB },
{ "colors", TEST_RGB },
{ "alpha", TEST_ALPHA },
{ "and", TEST_AND },
{ "or", TEST_OR }
};
#define NUMTESTS (sizeof(testList)/sizeof(test_t))
static const test_t testTypeList[] =
{
{ "functionality", TEST_FUNCTIONALITY },
{ "performance", TEST_PERFORMANCE },
};
static const test_t testTypeList[] =
{
{ "functionality", TEST_FUNCTIONALITY },
{ "performance", TEST_PERFORMANCE },
};
#define NUMTESTTYPES (sizeof(testTypeList)/sizeof(test_t))
int main(int argc, char** argv)
{
int i;
char hints[256];
UINT32 testSet = 0;
UINT32 testTypes = 0;
int i;
int results = SUCCESS;
/* Parse command line for the test set. */
for (i=1; i<argc; ++i)
for (i = 1; i < argc; ++i)
{
BOOL found = 0;
int j;
BOOL found = 0;
for (j=0; j<NUMTESTS; ++j)
{
if (strcasecmp(argv[i], testList[j].testStr) == 0)
@@ -239,8 +245,11 @@ int main(
else fprintf(stderr, "Unknown parameter '%s'!\n", argv[i]);
}
}
if (testSet == 0) testSet = 0xffffffff;
if (testTypes == 0) testTypes = 0xffffffff;
if (testSet == 0)
testSet = 0xffffffff;
if (testTypes == 0)
testTypes = 0xffffffff;
primitives_init();

View File

@@ -64,6 +64,7 @@ extern int test_copy8u_speed(void);
extern int test_set8u_func(void);
extern int test_set32s_func(void);
extern int test_set32u_func(void);
extern int test_set8u_speed(void);
extern int test_set32s_speed(void);
extern int test_set32u_speed(void);

View File

@@ -225,5 +225,6 @@ int test_alphaComp_speed(void)
alphaComp_speed("alphaComp", "unaligned",
(BYTE *) src1+1, (BYTE *) src2, 0, (BYTE *) dst,
block_size, NUM_BLOCK_SIZES, ALPHA_PRETEST_ITERATIONS, TEST_TIME);
return SUCCESS;
}

View File

@@ -219,9 +219,9 @@ int test_set32u_func(void)
int len;
for (len=1; len<512-off; ++len)
{
int i;
memset(dest, 0, sizeof(dest));
ipp_wrapper_set_32u(0xdeadbeefU, dest+off, len);
int i;
for (i=0; i<len; ++i)
{
if (dest[off+i] != 0xdeadbeefU)

View File

@@ -165,7 +165,7 @@ void xf_xshm_init(xfInfo* xfi)
shmctl(xfi->fb_shm_info.shmid, IPC_RMID, 0);
printf("display: %p root_window: %p width: %d height: %d depth: %d\n",
xfi->display, xfi->root_window, xfi->fb_image->width, xfi->fb_image->height, xfi->fb_image->depth);
xfi->display, (void*) xfi->root_window, xfi->fb_image->width, xfi->fb_image->height, xfi->fb_image->depth);
xfi->fb_pixmap = XShmCreatePixmap(xfi->display,
xfi->root_window, xfi->fb_image->data, &(xfi->fb_shm_info),

View File

@@ -98,7 +98,7 @@ int schannel_recv(PSecurityFunctionTable table, HANDLE hPipe, PCtxtHandle phCont
{
BYTE* ioBuffer;
UINT32 ioBufferLength;
BYTE* pMessageBuffer;
//BYTE* pMessageBuffer;
SecBuffer Buffers[4];
SecBufferDesc Message;
SECURITY_STATUS status;