From 6cedd1f252cd091be19f6a56526a5106b5140943 Mon Sep 17 00:00:00 2001 From: "yann.collet.73@gmail.com" Date: Sun, 8 Apr 2012 15:18:12 +0000 Subject: [PATCH] Added : cmake configuration file, from Dmitry Cherepanov git-svn-id: https://lz4.googlecode.com/svn/trunk@62 650e7d94-2a16-8b24-b05c-7c0b3f6821cd --- bench.c | 14 +++++++------- cmake/CMakeLists.txt | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ lz4.c | 54 ++++++++++++++++++++++++++-------------------------- lz4.h | 6 +++--- lz4demo.c | 40 +++++++++++++++++++------------------- 5 files changed, 109 insertions(+), 57 deletions(-) create mode 100644 cmake/CMakeLists.txt diff --git a/bench.c b/bench.c index 5139e8a..af09ffd 100644 --- a/bench.c +++ b/bench.c @@ -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 %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 %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.); diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 0000000..345a6f4 --- /dev/null +++ b/cmake/CMakeLists.txt @@ -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}) + + diff --git a/lz4.c b/lz4.c index 21aa1c4..ba0d3fd 100644 --- a/lz4.c +++ b/lz4.c @@ -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 // _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=(int)RUN_MASK) { *token=(RUN_MASK< 254 ; len-=255) *op++ = 255; *op++ = (BYTE)len; } + if (length>=(int)RUN_MASK) { *token=(RUN_MASK< 254 ; len-=255) *op++ = 255; *op++ = (BYTE)len; } else *token = (length<=(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=(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<oend-COPYLENGTH) { - if (cpy > oend) goto _output_error; + if (cpy > oend) goto _output_error; LZ4_SECURECOPY(ref, op, (oend-COPYLENGTH)); while(opoend-COPYLENGTH) { - if (cpy > oend) goto _output_error; + if (cpy > oend) goto _output_error; LZ4_SECURECOPY(ref, op, (oend-COPYLENGTH)); while(op // malloc #include // strcmp #include // clock -#ifdef _WIN32 +#ifdef _WIN32 #include // _setmode #include // _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); -- 2.7.4