Commit Graph

133 Commits

Author SHA1 Message Date
W. Felix Handte
68c6bd17b8 Set Dictionary Context Pointer Rather than Copying the Context In 2018-03-12 14:58:43 -04:00
W. Felix Handte
73cc39327e Lookup Matches in Separate Dictionary Context 2018-03-12 14:58:43 -04:00
W. Felix Handte
62cb52b341 Initialize Current Offset to 1 2018-03-12 14:58:43 -04:00
W. Felix Handte
b3628cb0c5 Avoid Resetting the Context When Possible 2018-03-12 14:58:43 -04:00
W. Felix Handte
aa36e118f1 Const-ify Table Arg to LZ4_getPosition(OnHash) 2018-03-12 14:58:43 -04:00
W. Felix Handte
d6a3024dbb Add LZ4_compress_fast_safeExtState Function 2018-03-12 14:58:43 -04:00
W. Felix Handte
5709891de6 Add a Table Type Field to LZ4_stream_t 2018-03-12 14:58:43 -04:00
W. Felix Handte
6933f5ad9c Remove Obsolete Stream Functions to Free Space in LZ4_stream_t 2018-03-12 14:58:43 -04:00
W. Felix Handte
6d156fea56 Allow Empty Dictionaries 2018-03-12 14:58:43 -04:00
Yann Collet
7173a631db edge case : compress up to end-mflimit (12 bytes)
The LZ4 block format specification
states that the last match must start
at a minimum distance of 12 bytes from the end of the block.

However, out of an abundance of caution,
the reference implementation would actually stop searching matches
at 13 bytes from the end of the block.

This patch fixes this small detail.
The new version is now able to properly compress a limit case
such as `aaaaaaaabaaa\n`
as reported by Gao Xiang (@hsiangkao).

Obviously, it doesn't change a lot of things.
This is just one additional match candidate per block, with a maximum match length of 7 (since last 5 bytes must remain literals).

With default policy, blocks are 4 MB long, so it doesn't happen too often
Compressing silesia.tar at default level 1 saves 5 bytes (100930101 -> 100930096).
At max level 12, it saves a grand 16 bytes (77389871 -> 77389855).

The impact is a bit more visible when blocks are smaller, hence more numerous.
For example, compressing silesia with blocks of 64 KB (using -12 -B4D) saves 543 bytes (77304583 -> 77304040).
So the smaller the packet size, the more visible the impact.

And it happens we have a ton of scenarios with little blocks using LZ4 compression ...

And a useless "hooray" sidenote :
the patch improves the LZ4 compression record of silesia (using -12 -B7D --no-frame-crc) by 16 bytes (77270672 -> 77270656)
and the record on enwik9 by 44 bytes (371680396 -> 371680352) (previously claimed by [smallz4](http://create.stephan-brumme.com/smallz4/) ).
2018-02-24 11:47:53 -08:00
Yann Collet
219abab74b removed LZ4_copy8
better use memcpy() directly
2018-02-11 22:20:09 -08:00
Yann Collet
3ad3b0f850 slightly improved decompression speed (~+1-2%)
by making shortcut slightly more common
2018-02-11 01:43:20 -08:00
Ben Boeckel
c4671be550 intel: do not use __attribute__((packed)) on Windows
On Windows, the Intel compiler is closer to MSVC rather than GCC and
does not support the GCC attribute syntax.

Fixes #468
2018-02-08 09:15:27 -05:00
Yann Collet
6bbe45e1b8 remove register keyword
deprecated in newer C++ versions,
and dubious utility
2017-12-04 17:10:23 -08:00
Yann Collet
dac26084a9
Merge pull request #416 from lz4/newopt
Improve Optimal parser
2017-11-09 14:13:30 -08:00
Yann Collet
9221419c6f added LZ4_FORCEINLINE to counter gcc regression
as recommended by @terrelln
2017-11-06 17:29:27 -08:00
Yann Collet
d51f046628 2-stages LZ4_count
separate first branch from the rest of the compare loop
to get dedicated prediction.

measured a 3-4% compression speed improvement.
2017-11-06 15:42:50 -08:00
Sylvestre Ledru
4fed595dac Only ignore with C++17 2017-11-06 16:16:02 +01:00
Sylvestre Ledru
cca7618f09 When building with a C++ compiler, remove the 'register' keyword to silent a warning
For example, with clang:

lz4.c:XXX:36: error: 'register' storage class specifier is deprecated and incompatible with C++17 [-Werror,-Wdeprecated-register]
static unsigned LZ4_NbCommonBytes (register reg_t val)
                                   ^~~~~~~~~
2017-11-05 11:48:03 +01:00
Yann Collet
8e16eb0cd1 fixed last lost bytes in maximal mode
even gained 2 bytes on calgary.tar...
added conditional traces `g_debuglog_enable`
2017-11-02 14:53:06 -07:00
Yann Collet
15b0d229c1 Merge branch 'dev' into btopt 2017-10-31 17:55:01 -07:00
Yann Collet
a5731d6b26 minor change, to help store forwarding
in a marginal case (offset==4)
2017-10-31 15:51:56 -07:00
Yann Collet
9378f76e41 extended shortcut match length to 18 2017-10-31 14:20:25 -07:00
Yann Collet
ace334a4c9 minor : coding style : use ML_MASK constant 2017-10-31 12:22:15 -07:00
Yann Collet
3f173052ae added comments, as suggested by @terrelln 2017-10-31 11:49:57 -07:00
Yann Collet
e0914ff70c more complete shortcut - passes tests 2017-10-30 16:07:15 -07:00
Yann Collet
a31b7058cb small modification of lz4 decoder to shortcut common case (short branch). 2017-10-25 10:10:53 +02:00
Yann Collet
6cec68de39 added assert 2017-10-19 16:47:25 -07:00
Rei Odaira
73bcf90e51 Use the optimization level of O2 for the decompression functions on ppc64le with gcc, to avoid harmful unrolling and SIMDization with O3 2017-10-13 14:53:37 -05:00
Yann Collet
f6b31bf0d0 fix #404
static analyzer `cppcheck` complains about a shift-by-32 on a 32 bits value,
which is an undefined behavior.
However, the flagged code path is never triggered in 32-bits mode,
(actually, it's not even generated if DCE kicks in),
the shift-by-32 is necessarily performed on a 64-bits value.

While it doesn't change anything regarding lz4 code generation, for both 32 and 64 bits mode,
(can be checked by md5sum on the generated binary),
the shift has been rewritten in a way which should please this static analyzer,
since it now pretends to shift by 16 on 32-bits cpu (note : it doesn't matter since the code will not even be generated in this case).

Note : this is a blind fix, the new code has not been tested with cppcheck, because cppcheck only works on Windows.
Other static analyzer, such as scan-build, do not trigger this false positive.
2017-09-30 10:35:55 -07:00
Yann Collet
a30cba08f4 fixed a bunch of -Wcomma warnings
reported by @rvandermeulen (#398)
2017-09-10 14:32:38 -07:00
Yann Collet
b500c5282e fix #397 : decompression failed when using a combination of extDict + low memory address
Reported and fixed by @jscheid

Note : we are missing a test case to include it in the CI
2017-09-07 12:48:24 -07:00
Yann Collet
00418f7611 bench : made decompression speed evaluation same time as compression
minor : slightly modified an example do avoid disabling a gcc warning through #pragma
2017-09-07 12:12:36 -07:00
tcpan
f423d016cf FIX: added prefix to FORCE_INLINE to prevent redefinition error during compilation when used with other libraries that define FORCE_INLINE 2017-08-24 10:14:20 -04:00
Yann Collet
8593ba8831 Merge pull request #380 from lz4/dictID
Frame Dictionary API
2017-08-15 14:12:04 -07:00
Yann Collet
31f2cdf4d2 implemented dictionary compression in lz4frame
note : only compression API is implemented and tested
still to do : decompression API
2017-08-09 16:51:19 -07:00
Alex Deymo
76ef6d0ab0 Allow to predefine FORCE_INLINE macro.
FORCE_INLINE macro is defined based on the compiler used. When using
gcc, it will include "__attribute__((always_inline))" forcing gcc to
always inline all the functions marked as FORCE_INLINE. However, this
can cause a performance degradation of about 15%.

This patch allows to set the FORCE_INLINE macro from the compiler
command line to either "static" or "static inline" giving allowing it
to inline functions as needed when performing optimizations.
2017-08-07 10:34:33 +02:00
Yann Collet
6ad3a983db fix #369
The bug would make the bt search read one byte in an invalid memory region,
and make a branch decision based on its value.
Impact was small (missed compression opportunity).
It only happens in -BD mode, with extDict-prefix overlapping matches.

The bt match search is supposed to work also in extDict mode.
In which case, the match ptr can point into Dict.
When the match was overlapping Dict<->Prefix,
match[matchLength] would end up outside of Dict, in an invalid memory area.
The correction ensures that in such a case,
match[matchLength] ends up at intended location, inside prefix.
2017-06-26 11:29:05 -07:00
Yann Collet
a8dd86d93e changed macro HEAPMODE into LZ4_HEAPMODE
This macro is susceptible to be triggered from user side
typically through compiler flag (-DLZ4_HEAPMODE=1).
In which case, it makes sense to prefix the macro
since we want to reduce potential side-effect on namespace.
2017-05-01 22:32:21 -07:00
Yann Collet
e2827775ee make __packed memory access default for gcc
It's always as good or better then memcpy()
but depends on gcc-specific extension.

solves https://github.com/facebook/zstd/issues/620
2017-03-30 12:22:17 -07:00
Yann Collet
cd35f0d98c LZ4_compress_HC_destSize() uses LZ4HC_compress_generic() code path
Limits compression level to 10,
to remain compatible with Hash Chain.
2017-03-16 15:10:38 -07:00
Yann Collet
5eb547a608 fix #283 : implement LZ4_versionString(). 2016-12-04 20:05:36 +01:00
Yann Collet
a91983daa0 highly improved speed on -mx32 mode
Now -mx32 is fastest mode on x64 CPU
2016-11-18 17:05:06 -08:00
Yann Collet
8e1ea59ad6 attempt to fix sanitize32 package dependency 2016-11-17 18:30:46 -08:00
Yann Collet
1abecbc33c fix 32-bits mode.
Large File support for Mac OS-X in 32-bits mode
Fixed potential undefined behavior
Changed makefile for 32-bits mode
2016-11-17 13:02:06 -08:00
Yann Collet
4c5c711b7a fixed minor conversion warning 2016-11-14 14:53:15 -08:00
Yann Collet
f094f53144 silence a minor msan warning 2016-11-14 14:38:46 -08:00
Yann Collet
0fe5c187a5 fixed minor msan warning 2016-11-14 11:34:10 -08:00
Yann Collet
bb97e8a6fd fixed __GNUC__ macro 2016-11-12 13:30:02 -08:00
Yann Collet
3580d96980 enabled deprecation warnings on remaining obsolete functions 2016-11-12 08:48:42 -08:00