diff options
-rw-r--r-- | programs/fullbench.c | 121 | ||||
-rw-r--r-- | programs/fuzzer.c | 72 | ||||
-rw-r--r-- | programs/lz4cli.c | 2 |
3 files changed, 20 insertions, 175 deletions
diff --git a/programs/fullbench.c b/programs/fullbench.c index 0d08a40..f1152a0 100644 --- a/programs/fullbench.c +++ b/programs/fullbench.c @@ -256,126 +256,6 @@ static U64 BMK_GetFileSize(char* infilename) /********************************************************* * Benchmark function *********************************************************/ -#ifdef __SSSE3__ - -#include <tmmintrin.h> - -/* Idea proposed by Terje Mathisen */ -static BYTE stepSize16[17] = {16,16,16,15,16,15,12,14,16,9,10,11,12,13,14,15,16}; -static __m128i replicateTable[17] = { - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}, - {0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0}, - {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3}, - {0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0}, - {0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3}, - {0,1,2,3,4,5,6,0,1,2,3,4,5,6,0,1}, - {0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7}, - {0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6}, - {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}, - {0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4}, - {0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3}, - {0,1,2,3,4,5,6,7,8,9,10,11,12,0,1,2}, - {0,1,2,3,4,5,6,7,8,9,10,11,12,13,0,1}, - {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0}, - {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; -static BYTE stepSize32[17] = {32,32,32,30,32,30,30,28,32,27,30,22,24,26,28,30,16}; -static __m128i replicateTable2[17] = { - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}, - {1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1}, - {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3}, - {1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1}, - {4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1}, - {2,3,4,5,6,0,1,2,3,4,5,6,0,1,2,3}, - {0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7}, - {7,8,0,1,2,3,4,5,6,7,8,0,1,2,3,4}, - {6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1}, - {5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9}, - {4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7}, - {3,4,5,6,7,8,9,10,11,12,0,1,2,3,4,5}, - {2,3,4,5,6,7,8,9,10,11,12,13,0,1,2,3}, - {1,2,3,4,5,6,7,8,9,10,11,12,13,14,0,1}, - {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; - -U32 lz4_decode_sse(BYTE* dest, BYTE* src, U32 srcLength) -{ - BYTE* d = dest, *e = src+srcLength; - unsigned token, lit_len, mat_len; - __m128i a; - BYTE* dstore, *msrc; - - if (!srcLength) return 0; - goto start; - - do { - U32 step; - unsigned mat_offset = src[0] + (src[1] << 8); - src += 2; - msrc = d - mat_offset; - if (mat_len == 15) { - do { - token = *src++; - mat_len += token; - } while (token == 255); - } - mat_len += 4; - - dstore = d; - d += mat_len; - - if (mat_offset <= 16) - { // Bulk store only! - __m128i a2; - a = _mm_loadu_si128((const __m128i *)msrc); - a2 = _mm_shuffle_epi8(a, replicateTable2[mat_offset]); - a = _mm_shuffle_epi8(a, replicateTable[mat_offset]); - step = stepSize32[mat_offset]; - do { - _mm_storeu_si128((__m128i *)dstore, a); - _mm_storeu_si128((__m128i *)(dstore+16), a2); - dstore += step; - } while (dstore < d); - } - else - { - do - { - a = _mm_loadu_si128((const __m128i *)msrc); - _mm_storeu_si128((__m128i *)dstore, a); - msrc += sizeof(a); - dstore += sizeof(a); - } while (dstore < d); - } -start: - token = *src++; - lit_len = token >> 4; - mat_len = token & 15; - if (token >= 0xf0) { // lit_len == 15 - do { - token = *src++; - lit_len += token; - } while (token == 255); - } - dstore = d; - msrc = src; - d += lit_len; - src += lit_len; - do { - a = _mm_loadu_si128((const __m128i *)msrc); - _mm_storeu_si128((__m128i *)dstore, a); - msrc += sizeof(a); - dstore += sizeof(a); - } while (dstore < d); - } while (src < e); - - return (U32)(d-dest); -} -#endif // __SSSE3__ - - static LZ4_stream_t LZ4_stream; static void local_LZ4_resetDictT(void) { @@ -1003,4 +883,3 @@ _exit_blockProperties: return fullSpeedBench(argv+filenamesStart, argc-filenamesStart); } - diff --git a/programs/fuzzer.c b/programs/fuzzer.c index 822e2ec..db7ad07 100644 --- a/programs/fuzzer.c +++ b/programs/fuzzer.c @@ -45,18 +45,12 @@ #include <stdlib.h> #include <stdio.h> /* fgets, sscanf */ #include <string.h> /* strcmp */ -#include "lz4.h" +#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */ +#include "lz4.h" /* LZ4_VERSION_STRING */ #include "lz4hc.h" #define XXH_STATIC_LINKING_ONLY #include "xxhash.h" -/* Use ftime() if gettimeofday() is not available on your target */ -#if defined(FUZ_LEGACY_TIMER) -# include <sys/timeb.h> /* timeb, ftime */ -#else -# include <sys/time.h> /* gettimeofday */ -#endif - /*-************************************ * Basic Types @@ -80,10 +74,6 @@ typedef unsigned long long U64; /*-************************************ * Constants **************************************/ -#ifndef LZ4_VERSION -# define LZ4_VERSION "" -#endif - #define NB_ATTEMPTS (1<<16) #define COMPRESSIBLE_NOISE_LENGTH (1 << 21) #define FUZ_MAX_BLOCK_SIZE (1 << 17) @@ -104,45 +94,16 @@ typedef unsigned long long U64; #define DISPLAY(...) fprintf(stderr, __VA_ARGS__) #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } static int g_displayLevel = 2; -static const U32 g_refreshRate = 250; -static U32 g_time = 0; +static const clock_t g_refreshRate = CLOCKS_PER_SEC * 25 / 100; +static clock_t g_time = 0; /*-******************************************************* * Fuzzer functions *********************************************************/ -#if defined(FUZ_LEGACY_TIMER) - -static U32 FUZ_GetMilliStart(void) +static clock_t FUZ_GetClockSpan(clock_t clockStart) { - struct timeb tb; - U32 nCount; - ftime( &tb ); - nCount = (U32) (((tb.time & 0xFFFFF) * 1000) + tb.millitm); - return nCount; -} - -#else - -static U32 FUZ_GetMilliStart(void) -{ - struct timeval tv; - U32 nCount; - gettimeofday(&tv, NULL); - nCount = (U32) (tv.tv_usec/1000 + (tv.tv_sec & 0xfffff) * 1000); - return nCount; -} - -#endif - - -static U32 FUZ_GetMilliSpan(U32 nTimeStart) -{ - U32 nCurrent = FUZ_GetMilliStart(); - U32 nSpan = nCurrent - nTimeStart; - if (nTimeStart > nCurrent) - nSpan += 0x100000 * 1000; - return nSpan; + return clock() - clockStart; /* works even if overflow; max span ~ 30mn */ } static U32 FUZ_rotl32(U32 u32, U32 nbBits) @@ -291,8 +252,8 @@ _overflowError: static void FUZ_displayUpdate(unsigned testNb) { - if ((FUZ_GetMilliSpan(g_time) > g_refreshRate) | (g_displayLevel>=3)) { - g_time = FUZ_GetMilliStart(); + if ((FUZ_GetClockSpan(g_time) > g_refreshRate) | (g_displayLevel>=3)) { + g_time = clock(); DISPLAY("\r%5u ", testNb); if (g_displayLevel>=3) fflush(stdout); } @@ -315,7 +276,7 @@ static void FUZ_findDiff(const void* buff1, const void* buff2) } -static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double compressibility, U32 duration) +static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double compressibility, U32 duration_s) { unsigned long long bytes = 0; unsigned long long cbytes = 0; @@ -338,12 +299,12 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c U32 coreRandState = seed; U32 randState = coreRandState ^ PRIME3; int result = 0; - const U32 startTime = FUZ_GetMilliStart(); + clock_t const clockStart = clock(); + clock_t const clockDuration = (clock_t)duration_s * CLOCKS_PER_SEC; /* init */ memset(&LZ4dict, 0, sizeof(LZ4dict)); - duration *= 1000; /* Create compressible test buffer */ CNBuffer = malloc(COMPRESSIBLE_NOISE_LENGTH); @@ -376,7 +337,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c } } /* Main test loop */ - for (cycleNb = startCycle; (cycleNb < nbCycles) || (FUZ_GetMilliSpan(startTime) < duration) ; cycleNb++) { + for (cycleNb = startCycle; (cycleNb < nbCycles) || (FUZ_GetClockSpan(clockStart) < clockDuration) ; cycleNb++) { U32 testNb = 0; char* dict; char* block; @@ -1183,10 +1144,15 @@ int main(int argc, char** argv) } } - printf("Starting LZ4 fuzzer (%i-bits, %s)\n", (int)(sizeof(size_t)*8), LZ4_VERSION); + printf("Starting LZ4 fuzzer (%i-bits, v%s)\n", (int)(sizeof(size_t)*8), LZ4_VERSION_STRING); - if (!seedset) seed = FUZ_GetMilliStart() % 10000; + if (!seedset) { + time_t const t = time(NULL); + U32 const h = XXH32(&t, sizeof(t), 1); + seed = h % 10000; + } printf("Seed = %u\n", seed); + if (proba!=FUZ_COMPRESSIBILITY_DEFAULT) printf("Compressibility : %i%%\n", proba); if ((seedset==0) && (testNb==0)) FUZ_unitTests(); diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 3e09073..8b391f9 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -90,7 +90,7 @@ ******************************/ #define COMPRESSOR_NAME "LZ4 command line interface" #define AUTHOR "Yann Collet" -#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION_STRING, AUTHOR +#define WELCOME_MESSAGE "*** %s %i-bits v%s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION_STRING, AUTHOR #define LZ4_EXTENSION ".lz4" #define LZ4CAT "lz4cat" #define UNLZ4 "unlz4" |