if (str->cchString > 1024)
return -1;
- if (Stream_GetRemainingLength(s) < (str->cchString * 2))
+ if (Stream_GetRemainingLength(s) < (size_t) (str->cchString * 2))
return -1;
Stream_Read(s, &(str->wString), (str->cchString * 2)); /* String (variable) */
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
if ((beg + header->Length) > end)
{
- if (Stream_GetRemainingLength(s) < ((beg + header->Length) - end))
+ if (Stream_GetRemainingLength(s) < (size_t) ((beg + header->Length) - end))
return -1;
Stream_SetPosition(s, (beg + header->Length));
pad = 340 - (RDPGFX_HEADER_SIZE + 12 + (pdu.monitorCount * 20));
- if (Stream_GetRemainingLength(s) < pad)
+ if (Stream_GetRemainingLength(s) < (size_t) pad)
return -1;
Stream_Seek(s, pad); /* pad (total size is 340 bytes) */
Stream_Read_UINT16(s, pdu.importedEntriesCount); /* cacheSlot (2 bytes) */
- if (Stream_GetRemainingLength(s) < (pdu.importedEntriesCount * 2))
+ if (Stream_GetRemainingLength(s) < (size_t) (pdu.importedEntriesCount * 2))
return -1;
pdu.cacheSlots = (UINT16*) calloc(pdu.importedEntriesCount, sizeof(UINT16));
rdpgfx_read_color32(s, &(pdu.fillPixel)); /* fillPixel (4 bytes) */
Stream_Read_UINT16(s, pdu.fillRectCount); /* fillRectCount (2 bytes) */
- if (Stream_GetRemainingLength(s) < (pdu.fillRectCount * 8))
+ if (Stream_GetRemainingLength(s) < (size_t) (pdu.fillRectCount * 8))
return -1;
pdu.fillRects = (RDPGFX_RECT16*) calloc(pdu.fillRectCount, sizeof(RDPGFX_RECT16));
rdpgfx_read_rect16(s, &(pdu.rectSrc)); /* rectSrc (8 bytes ) */
Stream_Read_UINT16(s, pdu.destPtsCount); /* destPtsCount (2 bytes) */
- if (Stream_GetRemainingLength(s) < (pdu.destPtsCount * 4))
+ if (Stream_GetRemainingLength(s) < (size_t) (pdu.destPtsCount * 4))
return -1;
pdu.destPts = (RDPGFX_POINT16*) calloc(pdu.destPtsCount, sizeof(RDPGFX_POINT16));
Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */
Stream_Read_UINT16(s, pdu.destPtsCount); /* destPtsCount (2 bytes) */
- if (Stream_GetRemainingLength(s) < (pdu.destPtsCount * 4))
+ if (Stream_GetRemainingLength(s) < (size_t) (pdu.destPtsCount * 4))
return -1;
pdu.destPts = (RDPGFX_POINT16*) calloc(pdu.destPtsCount, sizeof(RDPGFX_POINT16));
s = Stream_New(pDstData, DstSize);
- while (Stream_GetPosition(s) < Stream_Length(s))
+ while (((size_t) Stream_GetPosition(s)) < Stream_Length(s))
{
status = rdpgfx_recv_pdu(callback, s);
if (!glyphData)
return -1010;
- if ((nWidth * nHeight) > glyphEntry->count)
+ if ((nWidth * nHeight) > (int) glyphEntry->count)
return -1011;
nSrcStep = nWidth * 4;
pSrcPixel8 = glyphData;
pDstPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)];
- for (y = 0; y < nHeight; y++)
+ for (y = 0; y < (UINT32) nHeight; y++)
{
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
pSrcPixel8 += nSrcStep;
suboffset = 0;
residualData = &pSrcData[offset];
- if ((nWidth * nHeight * 4) > clear->TempSize)
+ if ((nWidth * nHeight * 4) > (int) clear->TempSize)
{
clear->TempSize = (nWidth * nHeight * 4);
clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize);
if (pixelIndex != pixelCount)
return -1019;
- for (y = 0; y < nHeight; y++)
+ for (y = 0; y < (UINT32) nHeight; y++)
{
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
pSrcPixel8 += nSrcStep;
if (height > nHeight)
return -1043;
- if ((width * height * 4) > clear->TempSize)
+ if (((UINT32) (width * height * 4)) > clear->TempSize)
{
clear->TempSize = (width * height * 4);
clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize);
pDstPixel8 = glyphData;
pSrcPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)];
- for (y = 0; y < nHeight; y++)
+ for (y = 0; y < (UINT32) nHeight; y++)
{
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
pDstPixel8 += nSrcStep;
#include <winpr/crt.h>
#include <winpr/print.h>
+#include <winpr/sysinfo.h>
#include <winpr/bitstream.h>
#include "rfx_bitstream.h"
_k = (_param >> LSGR); \
}
+static BOOL g_LZCNT = FALSE;
+
+static INLINE UINT32 lzcnt_s(UINT32 x)
+{
+ if (!x)
+ return 32;
+
+ if (!g_LZCNT)
+ {
+ UINT32 y;
+ int n = 32;
+ y = x >> 16; if (y != 0) { n = n - 16; x = y; }
+ y = x >> 8; if (y != 0) { n = n - 8; x = y; }
+ y = x >> 4; if (y != 0) { n = n - 4; x = y; }
+ y = x >> 2; if (y != 0) { n = n - 2; x = y; }
+ y = x >> 1; if (y != 0) return n - 2;
+ return n - x;
+ }
+
+ return __lzcnt(x);
+}
+
int rfx_rlgr_decode(const BYTE* pSrcData, UINT32 SrcSize, INT16* pDstData, UINT32 DstSize, int mode)
{
int vk;
wBitStream* bs;
wBitStream s_bs;
+ g_LZCNT = IsProcessorFeaturePresentEx(PF_EX_LZCNT);
+
k = 1;
kp = k << LSGR;
/* count number of leading 0s */
- cnt = __lzcnt(bs->accumulator);
+ cnt = lzcnt_s(bs->accumulator);
nbits = BitStream_GetRemainingLength(bs);
{
BitStream_Shift32(bs);
- cnt = __lzcnt(bs->accumulator);
+ cnt = lzcnt_s(bs->accumulator);
nbits = BitStream_GetRemainingLength(bs);
/* count number of leading 1s */
- cnt = __lzcnt(~(bs->accumulator));
+ cnt = lzcnt_s(~(bs->accumulator));
nbits = BitStream_GetRemainingLength(bs);
{
BitStream_Shift32(bs);
- cnt = __lzcnt(~(bs->accumulator));
+ cnt = lzcnt_s(~(bs->accumulator));
nbits = BitStream_GetRemainingLength(bs);
/* count number of leading 1s */
- cnt = __lzcnt(~(bs->accumulator));
+ cnt = lzcnt_s(~(bs->accumulator));
nbits = BitStream_GetRemainingLength(bs);
{
BitStream_Shift32(bs);
- cnt = __lzcnt(~(bs->accumulator));
+ cnt = lzcnt_s(~(bs->accumulator));
nbits = BitStream_GetRemainingLength(bs);
if (code)
{
mag = (UINT32) code;
- nIdx = 32 - __lzcnt(mag);
+ nIdx = 32 - lzcnt_s(mag);
}
if (BitStream_GetRemainingLength(bs) < nIdx)
*/
bytes_read = (Stream_GetPosition(s) - position) - 1;
- return (Stream_GetRemainingLength(s) >= (*li - bytes_read));
+ return (Stream_GetRemainingLength(s) >= (size_t) (*li - bytes_read));
}
/**
return _val16 ? ((UINT16) (__builtin_clz((UINT32) _val16) - 16)) : 16;
}
-static INLINE UINT64 __lzcnt64(UINT64 _val64) {
- return _val64 ? ((UINT64) __builtin_clzll(_val64)) : 64;
-}
-
#else
static INLINE UINT32 __lzcnt(UINT32 x) {
return ((UINT16) __lzcnt((UINT32) x));
}
-static INLINE UINT64 __lzcnt64(UINT64 x) {
- return 0; /* TODO */
-}
-
#endif
#endif
WINPR_API BOOL IsProcessorFeaturePresentEx(DWORD ProcessorFeature);
/* extended flags */
-#define PF_EX_3DNOW_PREFETCH 1
-#define PF_EX_SSSE3 2
-#define PF_EX_SSE41 3
-#define PF_EX_SSE42 4
-#define PF_EX_AVX 5
-#define PF_EX_FMA 6
-#define PF_EX_AVX_AES 7
-#define PF_EX_AVX2 8
-#define PF_EX_ARM_VFP1 9
-#define PF_EX_ARM_VFP3D16 10
-#define PF_EX_ARM_VFP4 11
-#define PF_EX_ARM_IDIVA 12
-#define PF_EX_ARM_IDIVT 13
-#define PF_EX_AVX_PCLMULQDQ 14
+#define PF_EX_LZCNT 1
+#define PF_EX_3DNOW_PREFETCH 2
+#define PF_EX_SSSE3 3
+#define PF_EX_SSE41 4
+#define PF_EX_SSE42 5
+#define PF_EX_AVX 6
+#define PF_EX_FMA 7
+#define PF_EX_AVX_AES 8
+#define PF_EX_AVX2 9
+#define PF_EX_ARM_VFP1 10
+#define PF_EX_ARM_VFP3D16 11
+#define PF_EX_ARM_VFP4 12
+#define PF_EX_ARM_IDIVA 13
+#define PF_EX_ARM_IDIVT 14
+#define PF_EX_AVX_PCLMULQDQ 15
/*
* some "aliases" for the standard defines
-#include <stdio.h>
#include <winpr/crt.h>
+#include <winpr/sysinfo.h>
#include <winpr/windows.h>
-int test_lzcnt()
+static BOOL g_LZCNT = FALSE;
+
+static INLINE UINT32 lzcnt_s(UINT32 x)
{
- if (__lzcnt(0x0) != 32) {
- fprintf(stderr, "__lzcnt(0x0) != 32\n");
- return -1;
- }
+ if (!x)
+ return 32;
+
+ if (!g_LZCNT)
+ {
+ UINT32 y;
+ int n = 32;
+ y = x >> 16; if (y != 0) { n = n - 16; x = y; }
+ y = x >> 8; if (y != 0) { n = n - 8; x = y; }
+ y = x >> 4; if (y != 0) { n = n - 4; x = y; }
+ y = x >> 2; if (y != 0) { n = n - 2; x = y; }
+ y = x >> 1; if (y != 0) return n - 2;
+ return n - x;
+ }
+
+ return __lzcnt(x);
+}
- if (__lzcnt(0x1) != 31) {
- fprintf(stderr, "__lzcnt(0x1) != 31\n");
+int test_lzcnt()
+{
+ if (lzcnt_s(0x1) != 31) {
+ fprintf(stderr, "__lzcnt(0x1) != 31: %d\n", __lzcnt(0x1));
return -1;
}
- if (__lzcnt(0xFF) != 24) {
+ if (lzcnt_s(0xFF) != 24) {
fprintf(stderr, "__lzcnt(0xFF) != 24\n");
return -1;
}
- if (__lzcnt(0xFFFF) != 16) {
+ if (lzcnt_s(0xFFFF) != 16) {
fprintf(stderr, "__lzcnt(0xFFFF) != 16\n");
return -1;
}
- if (__lzcnt(0xFFFFFF) != 8) {
+ if (lzcnt_s(0xFFFFFF) != 8) {
fprintf(stderr, "__lzcnt(0xFFFFFF) != 8\n");
return -1;
}
- if (__lzcnt(0xFFFFFFFF) != 0) {
+ if (lzcnt_s(0xFFFFFFFF) != 0) {
fprintf(stderr, "__lzcnt(0xFFFFFFFF) != 0\n");
return -1;
}
int test_lzcnt16()
{
- if (__lzcnt16(0x0) != 16) {
- fprintf(stderr, "__lzcnt16(0x0) != 16\n");
- return -1;
- }
-
if (__lzcnt16(0x1) != 15) {
fprintf(stderr, "__lzcnt16(0x1) != 15\n");
return -1;
return 1;
}
-int test_lzcnt64()
+int TestIntrinsics(int argc, char* argv[])
{
- if (__lzcnt64(0x0) != 64) {
- fprintf(stderr, "__lzcnt64(0x0) != 64\n");
- return -1;
- }
+ g_LZCNT = IsProcessorFeaturePresentEx(PF_EX_LZCNT);
- if (__lzcnt64(0x1) != 63) {
- fprintf(stderr, "__lzcnt64(0x1) != 63\n");
- return -1;
- }
+ printf("LZCNT available: %d\n", g_LZCNT);
- if (__lzcnt64(0xFF) != 56) {
- fprintf(stderr, "__lzcnt64(0xFF) != 56\n");
- return -1;
- }
-
- if (__lzcnt64(0xFFFF) != 48) {
- fprintf(stderr, "__lzcnt64(0xFFFF) != 48\n");
- return -1;
- }
-
- if (__lzcnt64(0xFFFFFF) != 40) {
- fprintf(stderr, "__lzcnt64(0xFFFFFF) != 40\n");
- return -1;
- }
-
- if (__lzcnt64(0xFFFFFFFF) != 32) {
- fprintf(stderr, "__lzcnt64(0xFFFFFFFF) != 32\n");
- return -1;
- }
-
- return 1;
-}
-
-int TestIntrinsics(int argc, char* argv[])
-{
test_lzcnt();
- test_lzcnt16();
- test_lzcnt64();
+ //test_lzcnt16();
return 0;
}
-
#define D_BIT_3DN (1<<30)
#define C_BIT_SSE3 (1<<0)
#define C_BIT_PCLMULQDQ (1<<1)
+#define C_BIT_LZCNT (1<<5)
#define C_BIT_3DNP (1<<8)
#define C_BIT_3DNP (1<<8)
#define C_BIT_SSSE3 (1<<9)
switch (ProcessorFeature)
{
+ case PF_EX_LZCNT:
+ if (c & C_BIT_LZCNT)
+ ret = TRUE;
+ break;
case PF_EX_3DNOW_PREFETCH:
if (c & C_BIT_3DNP)
ret = TRUE;