summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2012-08-13 07:30:58 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2012-08-13 07:30:58 (GMT)
commit6078c33f8c4b0a58e63308cdd6299075bef755ae (patch)
tree9ddcaecfe254a930e6c4bc82324cedf2bb5faf6f
parent4e11dc62baf8f4e01b588caa75718c028b23a091 (diff)
downloadlz4-6078c33f8c4b0a58e63308cdd6299075bef755ae.zip
lz4-6078c33f8c4b0a58e63308cdd6299075bef755ae.tar.gz
lz4-6078c33f8c4b0a58e63308cdd6299075bef755ae.tar.bz2
Fixed Visual 2005 issues (warning/linking)
git-svn-id: https://lz4.googlecode.com/svn/trunk@75 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
-rw-r--r--bench.c13
-rw-r--r--lz4.c23
-rw-r--r--lz4demo.c12
-rw-r--r--lz4hc.c38
4 files changed, 49 insertions, 37 deletions
diff --git a/bench.c b/bench.c
index 0595dfe..f379f99 100644
--- a/bench.c
+++ b/bench.c
@@ -25,8 +25,9 @@
//**************************************
// Compiler Options
//**************************************
-// Visual warning messages
+// Disable some Visual warning messages
#define _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_DEPRECATE // VS2005
// Under Linux at least, pull in the *64 commands
#define _LARGEFILE64_SOURCE
@@ -146,7 +147,7 @@ static int BMK_GetMilliStart()
struct timeb tb;
int nCount;
ftime( &tb );
- nCount = tb.millitm + (tb.time & 0xfffff) * 1000;
+ nCount = (int) (tb.millitm + (tb.time & 0xfffff) * 1000);
return nCount;
}
@@ -307,7 +308,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
// Alloc
chunkP = (struct chunkParameters*) malloc(((benchedsize / chunkSize)+1) * sizeof(struct chunkParameters));
in_buff = malloc((size_t )benchedsize);
- nbChunks = (benchedsize / chunkSize) + 1;
+ nbChunks = (int) (benchedsize / chunkSize) + 1;
maxCChunkSize = LZ4_compressBound(chunkSize);
out_buff_size = nbChunks * maxCChunkSize;
out_buff = malloc((size_t )out_buff_size);
@@ -332,7 +333,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
{
chunkP[i].id = i;
chunkP[i].inputBuffer = in; in += chunkSize;
- if ((int)remaining > chunkSize) { chunkP[i].inputSize = chunkSize; remaining -= chunkSize; } else { chunkP[i].inputSize = remaining; remaining = 0; }
+ if ((int)remaining > chunkSize) { chunkP[i].inputSize = chunkSize; remaining -= chunkSize; } else { chunkP[i].inputSize = (int)remaining; remaining = 0; }
chunkP[i].outputBuffer = out; out += maxCChunkSize;
chunkP[i].outputSize = 0;
}
@@ -352,7 +353,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
}
// Calculating input Checksum
- crcc = BMK_checksum_MMH3A(in_buff, benchedsize);
+ crcc = BMK_checksum_MMH3A(in_buff, (unsigned int)benchedsize);
// Bench
@@ -407,7 +408,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\r", loopNb, infilename, (int)benchedsize, (int)cSize, ratio, (double)benchedsize / fastestC / 1000., (double)benchedsize / fastestD / 1000.);
// CRC Checking
- crcd = BMK_checksum_MMH3A(in_buff, benchedsize);
+ crcd = BMK_checksum_MMH3A(in_buff, (unsigned int)benchedsize);
if (crcc!=crcd) { DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", infilename, (unsigned)crcc, (unsigned)crcd); break; }
}
diff --git a/lz4.c b/lz4.c
index ea327d5..8bb7a45 100644
--- a/lz4.c
+++ b/lz4.c
@@ -101,6 +101,7 @@
#ifdef _MSC_VER // Visual Studio
# define inline __forceinline // Visual is not C99, but supports some kind of inline
+# include <intrin.h> // For Visual 2005
# if LZ4_ARCH64 // 64-bit
# pragma intrinsic(_BitScanForward64) // For Visual 2005
# pragma intrinsic(_BitScanReverse64) // For Visual 2005
@@ -399,7 +400,7 @@ static inline int LZ4_compressCtx(void** ctx,
while ((ip>anchor) && (ref>(BYTE*)source) && unlikely(ip[-1]==ref[-1])) { ip--; ref--; }
// Encode Literal length
- length = ip - anchor;
+ length = (int)(ip - anchor);
token = op++;
if unlikely(op + length + (2 + 1 + LASTLITERALS) + (length>>8) >= oend) return 0; // Check output limit
#ifdef _MSC_VER
@@ -429,7 +430,7 @@ static inline int LZ4_compressCtx(void** ctx,
_next_match:
// Encode Offset
- LZ4_WRITE_LITTLEENDIAN_16(op,ip-ref);
+ LZ4_WRITE_LITTLEENDIAN_16(op,(U16)(ip-ref));
// Start Counting
ip+=MINMATCH; ref+=MINMATCH; // MinMatch verified
@@ -447,7 +448,7 @@ _next_match:
_endCount:
// Encode MatchLength
- len = (ip - anchor);
+ len = (int)(ip - anchor);
if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *op++ = 255; *op++ = 255; } if (len > 254) { len-=255; *op++ = 255; } *op++ = (BYTE)len; }
else *token += len;
@@ -470,7 +471,7 @@ _endCount:
_last_literals:
// Encode Last Literals
{
- int lastRun = iend - anchor;
+ int lastRun = (int)(iend - anchor);
if (((char*)op - dest) + lastRun + 1 + ((lastRun-15)/255) >= maxOutputSize) return 0;
if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
else *op++ = (lastRun<<ML_BITS);
@@ -555,7 +556,7 @@ static inline int LZ4_compress64kCtx(void** ctx,
forwardH = LZ4_HASH64K_VALUE(forwardIp);
ref = base + HashTable[h];
- HashTable[h] = ip - base;
+ HashTable[h] = (U16)(ip - base);
} while (A32(ref) != A32(ip));
@@ -563,7 +564,7 @@ static inline int LZ4_compress64kCtx(void** ctx,
while ((ip>anchor) && (ref>(BYTE*)source) && (ip[-1]==ref[-1])) { ip--; ref--; }
// Encode Literal length
- length = ip - anchor;
+ length = (int)(ip - anchor);
token = op++;
if unlikely(op + length + (2 + 1 + LASTLITERALS) + (length>>8) >= oend) return 0; // Check output limit
#ifdef _MSC_VER
@@ -593,7 +594,7 @@ static inline int LZ4_compress64kCtx(void** ctx,
_next_match:
// Encode Offset
- LZ4_WRITE_LITTLEENDIAN_16(op,ip-ref);
+ LZ4_WRITE_LITTLEENDIAN_16(op,(U16)(ip-ref));
// Start Counting
ip+=MINMATCH; ref+=MINMATCH; // MinMatch verified
@@ -611,7 +612,7 @@ _next_match:
_endCount:
// Encode MatchLength
- len = (ip - anchor);
+ len = (int)(ip - anchor);
if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *op++ = 255; *op++ = 255; } if (len > 254) { len-=255; *op++ = 255; } *op++ = (BYTE)len; }
else *token += len;
@@ -619,11 +620,11 @@ _endCount:
if (ip > mflimit) { anchor = ip; break; }
// Fill table
- HashTable[LZ4_HASH64K_VALUE(ip-2)] = ip - 2 - base;
+ HashTable[LZ4_HASH64K_VALUE(ip-2)] = (U16)(ip - 2 - base);
// Test next position
ref = base + HashTable[LZ4_HASH64K_VALUE(ip)];
- HashTable[LZ4_HASH64K_VALUE(ip)] = ip - base;
+ HashTable[LZ4_HASH64K_VALUE(ip)] = (U16)(ip - base);
if (A32(ref) == A32(ip)) { token = op++; *token=0; goto _next_match; }
// Prepare next loop
@@ -634,7 +635,7 @@ _endCount:
_last_literals:
// Encode Last Literals
{
- int lastRun = iend - anchor;
+ int lastRun = (int)(iend - anchor);
if (((char*)op - dest) + lastRun + 1 + ((lastRun)>>8) >= maxOutputSize) return 0;
if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
else *op++ = (lastRun<<ML_BITS);
diff --git a/lz4demo.c b/lz4demo.c
index 9bb3392..6367401 100644
--- a/lz4demo.c
+++ b/lz4demo.c
@@ -28,10 +28,12 @@
The license of the demo program is GPL.
*/
-//****************************
-// Warning messages
-//****************************
-#define _CRT_SECURE_NO_WARNINGS // Visual (must be first line)
+//**************************************
+// Compiler Options
+//**************************************
+// Disable some Visual warning messages
+#define _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_DEPRECATE // VS2005
//****************************
@@ -204,7 +206,7 @@ int compress_file(char* input_filename, char* output_filename, int compressionle
{
int outSize;
// Read Block
- int inSize = fread(in_buff, 1, CHUNKSIZE, finput);
+ int inSize = (int) fread(in_buff, (size_t)1, (size_t)CHUNKSIZE, finput);
if( inSize<=0 ) break;
filesize += inSize;
if (displayLevel) DISPLAY("Read : %i MB \r", (int)(filesize>>20));
diff --git a/lz4hc.c b/lz4hc.c
index cca755c..572ffb6 100644
--- a/lz4hc.c
+++ b/lz4hc.c
@@ -68,6 +68,14 @@
#ifdef _MSC_VER
#define inline __forceinline // Visual is not C99, but supports some kind of inline
+#include <intrin.h> // For Visual 2005
+# if LZ4_ARCH64 // 64-bit
+# pragma intrinsic(_BitScanForward64) // For Visual 2005
+# pragma intrinsic(_BitScanReverse64) // For Visual 2005
+# else
+# pragma intrinsic(_BitScanForward) // For Visual 2005
+# pragma intrinsic(_BitScanReverse) // For Visual 2005
+# endif
#endif
#ifdef _MSC_VER // Visual Studio
@@ -350,7 +358,7 @@ inline static int LZ4HC_InsertAndFindBestMatch (LZ4HC_Data_Structure* hc4, const
if ((ipt<matchlimit) && (*reft == *ipt)) ipt++;
_endCount:
- if (ipt-ip > ml) { ml = ipt-ip; *matchpos = ref; }
+ if (ipt-ip > ml) { ml = (int)(ipt-ip); *matchpos = ref; }
}
ref = GETNEXT(ref);
}
@@ -366,7 +374,7 @@ inline static int LZ4HC_InsertAndGetWiderMatch (LZ4HC_Data_Structure* hc4, const
INITBASE(base,hc4->base);
const BYTE* ref;
int nbAttempts = MAX_NB_ATTEMPTS;
- int delta = ip-startLimit;
+ int delta = (int)(ip-startLimit);
// First Match
LZ4HC_Insert(hc4, ip);
@@ -399,7 +407,7 @@ _endCount:
if ((ipt-startt) > longest)
{
- longest = ipt-startt;
+ longest = (int)(ipt-startt);
*matchpos = reft;
*startpos = startt;
}
@@ -417,7 +425,7 @@ inline static int LZ4_encodeSequence(const BYTE** ip, BYTE** op, const BYTE** an
BYTE* token;
// Encode Literal length
- length = *ip - *anchor;
+ length = (int)(*ip - *anchor);
token = (*op)++;
if (length>=(int)RUN_MASK) { *token=(RUN_MASK<<ML_BITS); len = length-RUN_MASK; for(; len > 254 ; len-=255) *(*op)++ = 255; *(*op)++ = (BYTE)len; }
else *token = (length<<ML_BITS);
@@ -426,7 +434,7 @@ inline static int LZ4_encodeSequence(const BYTE** ip, BYTE** op, const BYTE** an
LZ4_BLINDCOPY(*anchor, *op, length);
// Encode Offset
- LZ4_WRITE_LITTLEENDIAN_16(*op,*ip-ref);
+ LZ4_WRITE_LITTLEENDIAN_16(*op,(U16)(*ip-ref));
// Encode MatchLength
len = (int)(ml-MINMATCH);
@@ -519,8 +527,8 @@ _Search3:
int correction;
int new_ml = ml;
if (new_ml > OPTIMAL_ML) new_ml = OPTIMAL_ML;
- if (ip+new_ml > start2 + ml2 - MINMATCH) new_ml = start2 - ip + ml2 - MINMATCH;
- correction = new_ml - (start2 - ip);
+ if (ip+new_ml > start2 + ml2 - MINMATCH) new_ml = (int)(start2 - ip) + ml2 - MINMATCH;
+ correction = new_ml - (int)(start2 - ip);
if (correction > 0)
{
start2 += correction;
@@ -543,8 +551,8 @@ _Search3:
{
int correction;
if (ml > OPTIMAL_ML) ml = OPTIMAL_ML;
- if (ip+ml > start2 + ml2 - MINMATCH) ml = start2 - ip + ml2 - MINMATCH;
- correction = ml - (start2 - ip);
+ if (ip+ml > start2 + ml2 - MINMATCH) ml = (int)(start2 - ip) + ml2 - MINMATCH;
+ correction = ml - (int)(start2 - ip);
if (correction > 0)
{
start2 += correction;
@@ -554,7 +562,7 @@ _Search3:
}
else
{
- ml = start2 - ip;
+ ml = (int)(start2 - ip);
}
}
// Now, encode 2 sequences
@@ -570,7 +578,7 @@ _Search3:
{
if (start2 < ip+ml)
{
- int correction = (ip+ml) - start2;
+ int correction = (int)(ip+ml - start2);
start2 += correction;
ref2 += correction;
ml2 -= correction;
@@ -607,8 +615,8 @@ _Search3:
{
int correction;
if (ml > OPTIMAL_ML) ml = OPTIMAL_ML;
- if (ip + ml > start2 + ml2 - MINMATCH) ml = start2 - ip + ml2 - MINMATCH;
- correction = ml - (start2 - ip);
+ if (ip + ml > start2 + ml2 - MINMATCH) ml = (int)(start2 - ip) + ml2 - MINMATCH;
+ correction = ml - (int)(start2 - ip);
if (correction > 0)
{
start2 += correction;
@@ -618,7 +626,7 @@ _Search3:
}
else
{
- ml = start2 - ip;
+ ml = (int)(start2 - ip);
}
}
LZ4_encodeSequence(&ip, &op, &anchor, ml, ref);
@@ -637,7 +645,7 @@ _Search3:
// Encode Last Literals
{
- int lastRun = iend - anchor;
+ int lastRun = (int)(iend - anchor);
if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
else *op++ = (lastRun<<ML_BITS);
memcpy(op, anchor, iend - anchor);