Added : cmake configuration file, from Dmitry Cherepanov

git-svn-id: https://lz4.googlecode.com/svn/trunk@62 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
This commit is contained in:
yann.collet.73@gmail.com 2012-04-08 15:18:12 +00:00
parent ee1c281947
commit 6cedd1f252
5 changed files with 109 additions and 57 deletions

14
bench.c
View File

@ -173,9 +173,9 @@ static U32 BMK_checksum_MMH3A (char* buff, U32 length)
k1 *= c1;
k1 = _rotl(k1,15);
k1 *= c2;
h1 ^= k1;
h1 = _rotl(h1,13);
h1 = _rotl(h1,13);
h1 = h1*5+0xe6546b64;
}
@ -200,7 +200,7 @@ static U32 BMK_checksum_MMH3A (char* buff, U32 length)
h1 ^= h1 >> 16;
return h1;
}
}
static size_t BMK_findMaxMem(U64 requiredMem)
@ -365,9 +365,9 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
milliTime = BMK_GetMilliStart();
while(BMK_GetMilliStart() == milliTime);
milliTime = BMK_GetMilliStart();
while(BMK_GetMilliSpan(milliTime) < TIMELOOP)
while(BMK_GetMilliSpan(milliTime) < TIMELOOP)
{
for (chunkNb=0; chunkNb<nbChunks; chunkNb++)
for (chunkNb=0; chunkNb<nbChunks; chunkNb++)
chunkP[chunkNb].outputSize = compP.compressionFunction(chunkP[chunkNb].inputBuffer, chunkP[chunkNb].outputBuffer, chunkP[chunkNb].inputSize);
nb_loops++;
}
@ -379,7 +379,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%), %6.1f MB/s\r", loopNb, infilename, (int)benchedsize, (int)cSize, ratio, (double)benchedsize / fastestC / 1000.);
// Decompression
// Decompression
{ size_t i; for (i=0; i<benchedsize; i++) in_buff[i]=0; } // zeroing area, for CRC checking
nb_loops = 0;
@ -402,7 +402,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
if (crcc!=crcd) { DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", infilename, (unsigned)crcc, (unsigned)crcd); break; }
}
if (crcc==crcd)
if (crcc==crcd)
{
if (ratio<100.)
DISPLAY("%-16.16s : %9i -> %9i (%5.2f%%), %6.1f MB/s , %6.1f MB/s\n", infilename, (int)benchedsize, (int)cSize, ratio, (double)benchedsize / fastestC / 1000., (double)benchedsize / fastestD / 1000.);

52
cmake/CMakeLists.txt Normal file
View File

@ -0,0 +1,52 @@
PROJECT(LZ4)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ASN.1 Compiler")
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH r51)
#set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING_LGPL)
set(VERSION_STRING " \"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\" ")
include(CPack)
cmake_minimum_required (VERSION 2.6)
INCLUDE (CheckTypeSize)
check_type_size("void *" SIZEOF_VOID_P)
IF( ${SIZEOF_VOID_P} STREQUAL "8" )
set (CMAKE_SYSTEM_PROCESSOR "64bit")
MESSAGE( STATUS "64 bit architecture detected size of void * is " ${SIZEOF_VOID_P})
ENDIF()
set(SRC_DIR ../)
set(LZ4_SRCS_LIB ${SRC_DIR}lz4.c ${SRC_DIR}lz4.h )
set(LZ4_SRCS ${LZ4_SRCS_LIB} ${SRC_DIR}bench.c ${SRC_DIR}lz4demo.c )
# EXECUTABLES FOR 32 Bit and 64 versions
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "64bit")
add_executable(lz4demo64 ${LZ4_SRCS})
install(TARGETS lz4demo64 RUNTIME DESTINATION "./")
endif()
add_executable(lz4demo32 ${LZ4_SRCS})
install(TARGETS lz4demo32 RUNTIME DESTINATION "./")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "64bit")
SET_TARGET_PROPERTIES(lz4demo32 PROPERTIES
COMPILE_FLAGS PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
endif()
#warnings
ADD_DEFINITIONS("-Wall")
ADD_DEFINITIONS("-W")
ADD_DEFINITIONS("-Wundef")
ADD_DEFINITIONS("-Wcast-align")
ADD_DEFINITIONS("-Wno-implicit-function-declaration")
ADD_DEFINITIONS("-Os -march=native -std=c99")
INCLUDE_DIRECTORIES (${SRC_DIR})
#target_link_libraries(lz4 ${LZ4_SRCS_LIB})

54
lz4.c
View File

@ -70,7 +70,7 @@
#define LZ4_ARCH64 0
#endif
// Little Endian or Big Endian ?
// Little Endian or Big Endian ?
#if (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(_ARCH_PPC) || defined(__PPC__) || defined(__PPC) || defined(PPC) || defined(__powerpc__) || defined(__powerpc) || defined(powerpc) || ((defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) )
#define LZ4_BIG_ENDIAN 1
#else
@ -105,7 +105,7 @@
#include <intrin.h> // _BitScanForward
#endif
#ifdef _MSC_VER
#ifdef _MSC_VER
#define lz4_bswap16(x) _byteswap_ushort(x)
#else
#define lz4_bswap16(x) ((unsigned short int) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
@ -148,7 +148,7 @@
#endif
#ifndef LZ4_FORCE_UNALIGNED_ACCESS
#pragma pack(push, 1)
#pragma pack(push, 1)
#endif
typedef struct _U16_S { U16 v; } U16_S;
@ -156,7 +156,7 @@ typedef struct _U32_S { U32 v; } U32_S;
typedef struct _U64_S { U64 v; } U64_S;
#ifndef LZ4_FORCE_UNALIGNED_ACCESS
#pragma pack(pop)
#pragma pack(pop)
#endif
#define A64(x) (((U64_S *)(x))->v)
@ -253,7 +253,7 @@ inline static int LZ4_NbCommonBytes (register U64 val)
_BitScanReverse64( &r, val );
return (int)(r>>3);
#elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_clzll(val) >> 3);
return (__builtin_clzll(val) >> 3);
#else
int r;
if (!(val>>32)) { r=4; } else { r=0; val>>=32; }
@ -267,7 +267,7 @@ inline static int LZ4_NbCommonBytes (register U64 val)
_BitScanForward64( &r, val );
return (int)(r>>3);
#elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_ctzll(val) >> 3);
return (__builtin_ctzll(val) >> 3);
#else
static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 };
return DeBruijnBytePos[((U64)((val & -val) * 0x0218A392CDABBD3F)) >> 58];
@ -285,7 +285,7 @@ inline static int LZ4_NbCommonBytes (register U32 val)
_BitScanReverse( &r, val );
return (int)(r>>3);
#elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_clz(val) >> 3);
return (__builtin_clz(val) >> 3);
#else
int r;
if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
@ -298,7 +298,7 @@ inline static int LZ4_NbCommonBytes (register U32 val)
_BitScanForward( &r, val );
return (int)(r>>3);
#elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
return (__builtin_ctz(val) >> 3);
return (__builtin_ctz(val) >> 3);
#else
static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };
return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
@ -328,7 +328,7 @@ int LZ4_compressCtx(void** ctx,
const char* source,
char* dest,
int isize)
{
{
#if HEAPMODE
struct refTables *srt = (struct refTables *) (*ctx);
HTYPE* HashTable;
@ -336,7 +336,7 @@ int LZ4_compressCtx(void** ctx,
HTYPE HashTable[HASHTABLESIZE] = {0};
#endif
const BYTE* ip = (BYTE*) source;
const BYTE* ip = (BYTE*) source;
INITBASE(base);
const BYTE* anchor = ip;
const BYTE* const iend = ip + isize;
@ -344,16 +344,16 @@ int LZ4_compressCtx(void** ctx,
#define matchlimit (iend - LASTLITERALS)
BYTE* op = (BYTE*) dest;
int len, length;
const int skipStrength = SKIPSTRENGTH;
U32 forwardH;
// Init
// Init
if (isize<MINLENGTH) goto _last_literals;
#if HEAPMODE
if (*ctx == NULL)
if (*ctx == NULL)
{
srt = (struct refTables *) malloc ( sizeof(struct refTables) );
*ctx = (void*) srt;
@ -368,9 +368,9 @@ int LZ4_compressCtx(void** ctx,
// First Byte
HashTable[LZ4_HASH_VALUE(ip)] = ip - base;
ip++; forwardH = LZ4_HASH_VALUE(ip);
// Main Loop
for ( ; ; )
for ( ; ; )
{
int findMatchAttempts = (1U << skipStrength) + 3;
const BYTE* forwardIp = ip;
@ -398,7 +398,7 @@ int LZ4_compressCtx(void** ctx,
// Encode Literal length
length = 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; }
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);
// Copy Literals
@ -426,7 +426,7 @@ _endCount:
// Encode MatchLength
len = (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;
else *token += len;
// Test end of chunk
if (ip > mflimit) { anchor = ip; break; }
@ -440,7 +440,7 @@ _endCount:
if ((ref > ip - (MAX_DISTANCE + 1)) && (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }
// Prepare next loop
anchor = ip++;
anchor = ip++;
forwardH = LZ4_HASH_VALUE(ip);
}
@ -493,10 +493,10 @@ int LZ4_compress64kCtx(void** ctx,
U32 forwardH;
// Init
// Init
if (isize<MINLENGTH) goto _last_literals;
#if HEAPMODE
if (*ctx == NULL)
if (*ctx == NULL)
{
srt = (struct refTables *) malloc ( sizeof(struct refTables) );
*ctx = (void*) srt;
@ -568,7 +568,7 @@ _endCount:
// Encode MatchLength
len = (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;
else *token += len;
// Test end of chunk
if (ip > mflimit) { anchor = ip; break; }
@ -595,7 +595,7 @@ _last_literals:
else *op++ = (lastRun<<ML_BITS);
memcpy(op, anchor, iend - anchor);
op += iend-anchor;
}
}
// End
return (int) (((char*)op)-dest);
@ -637,7 +637,7 @@ int LZ4_compress(const char* source,
int LZ4_uncompress(const char* source,
char* dest,
int osize)
{
{
// Local Variables
const BYTE* restrict ip = (const BYTE*) source;
const BYTE* restrict ref;
@ -672,7 +672,7 @@ int LZ4_uncompress(const char* source,
// get offset
LZ4_READ_LITTLEENDIAN_16(ref,cpy,ip); ip+=2;
if (ref < (BYTE* const)dest) goto _output_error;
if (ref < (BYTE* const)dest) goto _output_error;
// get matchlength
if ((length=(token&ML_MASK)) == ML_MASK) { for (;*ip==255;length+=255) {ip++;} length += *ip++; }
@ -697,7 +697,7 @@ int LZ4_uncompress(const char* source,
cpy = op + length - (STEPSIZE-4);
if (cpy>oend-COPYLENGTH)
{
if (cpy > oend) goto _output_error;
if (cpy > oend) goto _output_error;
LZ4_SECURECOPY(ref, op, (oend-COPYLENGTH));
while(op<cpy) *op++=*ref++;
op=cpy;
@ -722,7 +722,7 @@ int LZ4_uncompress_unknownOutputSize(
char* dest,
int isize,
int maxOutputSize)
{
{
// Local Variables
const BYTE* restrict ip = (const BYTE*) source;
const BYTE* const iend = ip + isize;
@ -786,7 +786,7 @@ int LZ4_uncompress_unknownOutputSize(
cpy = op + length - (STEPSIZE-4);
if (cpy>oend-COPYLENGTH)
{
if (cpy > oend) goto _output_error;
if (cpy > oend) goto _output_error;
LZ4_SECURECOPY(ref, op, (oend-COPYLENGTH));
while(op<cpy) *op++=*ref++;
op=cpy;

6
lz4.h
View File

@ -7,14 +7,14 @@
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -46,7 +46,7 @@ LZ4_compress() :
isize : is the input size. Max supported value is ~1.9GB
return : the number of bytes written in buffer dest
or 0 if the compression fails (if LZ4_COMPRESSMIN is set)
note : destination buffer must be already allocated.
note : destination buffer must be already allocated.
destination buffer must be sized to handle worst cases situations (input data not compressible)
worst case size evaluation is provided by function LZ4_compressBound()

View File

@ -34,7 +34,7 @@
#include <stdlib.h> // malloc
#include <string.h> // strcmp
#include <time.h> // clock
#ifdef _WIN32
#ifdef _WIN32
#include <io.h> // _setmode
#include <fcntl.h> // _O_BINARY
#endif
@ -47,7 +47,7 @@
//**************************************
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
#if defined(_MSC_VER) // Visual Studio
#if defined(_MSC_VER) // Visual Studio
#define swap32 _byteswap_ulong
#elif GCC_VERSION >= 402
#define swap32 __builtin_bswap32
@ -105,7 +105,7 @@ int usage()
DISPLAY( " -d : decompression \n");
DISPLAY( " -b : benchmark with files\n");
DISPLAY( " -t : check compressed file \n");
DISPLAY( " -h : help (this text)\n");
DISPLAY( " -h : help (this text)\n");
DISPLAY( "input : can be 'stdin' (pipe) or a filename\n");
DISPLAY( "output : can be 'stdout'(pipe) or a filename or 'null'\n");
return 0;
@ -145,7 +145,7 @@ int get_fileHandle(char* input_filename, char* output_filename, FILE** pfinput,
} else {
*pfoutput = fopen( output_filename, "wb" );
}
if ( *pfinput==0 ) { DISPLAY( "Pb opening %s\n", input_filename); return 2; }
if ( *pfoutput==0) { DISPLAY( "Pb opening %s\n", output_filename); return 3; }
@ -171,12 +171,12 @@ int compress_file(char* input_filename, char* output_filename)
start = clock();
r = get_fileHandle(input_filename, output_filename, &finput, &foutput);
if (r) return r;
// Allocate Memory
in_buff = (char*)malloc(CHUNKSIZE);
out_buff = (char*)malloc(LZ4_compressBound(CHUNKSIZE));
if (!in_buff || !out_buff) { DISPLAY("Allocation error : not enough memory\n"); return 8; }
// Write Archive Header
u32var = ARCHIVE_MAGICNUMBER;
LITTLE_ENDIAN32(u32var);
@ -184,8 +184,8 @@ int compress_file(char* input_filename, char* output_filename)
fwrite(out_buff, 1, ARCHIVE_MAGICNUMBER_SIZE, foutput);
// Main Loop
while (1)
{
while (1)
{
int outSize;
// Read Block
int inSize = fread(in_buff, 1, CHUNKSIZE, finput);
@ -205,7 +205,7 @@ int compress_file(char* input_filename, char* output_filename)
// Status
end = clock();
DISPLAY( "Compressed %llu bytes into %llu bytes ==> %.2f%%\n",
DISPLAY( "Compressed %llu bytes into %llu bytes ==> %.2f%%\n",
(unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100);
{
double seconds = (double)(end - start)/CLOCKS_PER_SEC;
@ -245,7 +245,7 @@ int decode_file(char* input_filename, char* output_filename)
in_buff = (char*)malloc(LZ4_compressBound(CHUNKSIZE));
out_buff = (char*)malloc(CHUNKSIZE);
if (!in_buff || !out_buff) { DISPLAY("Allocation error : not enough memory\n"); return 7; }
// Check Archive Header
uselessRet = fread(out_buff, 1, ARCHIVE_MAGICNUMBER_SIZE, finput);
nextSize = *(unsigned int*)out_buff;
@ -259,8 +259,8 @@ int decode_file(char* input_filename, char* output_filename)
LITTLE_ENDIAN32(nextSize);
// Main Loop
while (1)
{
while (1)
{
// Read Block
uselessRet = fread(in_buff, 1, nextSize, finput);
@ -302,7 +302,7 @@ int decode_file(char* input_filename, char* output_filename)
}
int main(int argc, char** argv)
int main(int argc, char** argv)
{
int i,
compression=1, // default action if no argument
@ -311,7 +311,7 @@ int main(int argc, char** argv)
filenamesStart=2;
char* input_filename=0;
char* output_filename=0;
#ifdef _WIN32
#ifdef _WIN32
char nulmark[] = "nul";
#else
char nulmark[] = "/dev/null";
@ -333,7 +333,7 @@ int main(int argc, char** argv)
if (argument[0]=='-')
{
argument ++;
// Display help on usage
if ( argument[0] =='h' ) { usage(); return 0; }
@ -360,11 +360,11 @@ int main(int argc, char** argv)
if (!input_filename) { input_filename=argument; filenamesStart=i; continue; }
// second provided filename is output
if (!output_filename)
{
output_filename=argument;
if (!output_filename)
{
output_filename=argument;
if (!strcmp (output_filename, nullinput)) output_filename = nulmark;
continue;
continue;
}
}
@ -373,7 +373,7 @@ int main(int argc, char** argv)
if (bench) return BMK_benchFile(argv+filenamesStart, argc-filenamesStart, 0);
// No output filename
// No output filename
if (!output_filename) { badusage(); return 1; }
if (decode) return decode_file(input_filename, output_filename);