Commit Graph

514 Commits

Author SHA1 Message Date
Yann Collet
ba115386fa update code comment on LZ4 streaming interface
notably regarding LZ4_saveDict() speed advantage,
answering #477.
2018-02-26 13:31:18 -08:00
Yann Collet
550b40849f merge lz4opt.h into lz4hc.c
Having a dedicated file for optimal parser
made sense during its creation,
it allowed Przemyslaw to work more freely on lz4opt, with less dependency on lz4hc,
moreover, the optimal parser was more complex, with its own search functions.

Since the optimal was rewritten last year, it's now a lot lighter.
It makes more sense now to integrate it directly inside lz4hc.c,
making it easier to edit (editors are a bit "lost" inside a `*.h` dependent on its #include position),
it also reduces the number of files in the project,
which fits pretty well with lz4 objectives.
(adding lz4hc requires "just" lz4hc.h and lz4hc.c).
2018-02-25 00:32:09 -08: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
71e16fa11a
Merge pull request #471 from lz4/fasterHC
Faster HC
2018-02-20 21:04:07 -08:00
Yann Collet
25b16e8a2e added one assert()
suggested by @terrelln
2018-02-20 15:25:45 -08:00
Yann Collet
d74f079748 update API doc regarding double-buffer strategy
answering question #473
2018-02-18 11:00:33 -08:00
Yann Collet
d3a13397d9 slight hc speed benefit (~+1%)
by optimizing countback
2018-02-12 00:01:58 -08:00
Yann Collet
219abab74b removed LZ4_copy8
better use memcpy() directly
2018-02-11 22:20:09 -08:00
Yann Collet
2b674bf02f slightly improved hc compression speed (+~1-2%)
by removing bad candidates faster.
2018-02-11 02:45:36 -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
ea25250c99 fixed code comment as detected in #466
Also clarified a few API code comments
and updated associated html documentation
2018-02-07 02:21:25 -08:00
Nick Terrell
e832a3d87a Clarify the requirements of the LZ4 streaming API 2018-02-01 16:08:59 -08:00
Yann Collet
5fd3ac7904 Merge branch 'dev' into frameCompress 2018-01-31 17:18:57 -08:00
Yann Collet
87fb7a1d03 refactored frameCompress example
to better reflect LZ4F API usage.
2018-01-31 14:33:16 -08:00
Asger Hautop Drewsen
c129f480e7 Always prefer c++14 attributes if available 2018-01-31 20:24:44 +01:00
Asger Hautop Drewsen
865bd83e13 Ensure LZ4_DEPRECATED("...") is before LZ4LIB_API
When using clang++ with std c++14 or c++17 you would get the error "an attribute list cannot appear here" when including "lz4.h" as the visibility attribute is before the c++ attribute.
This ensures that the [[deprecated]] c++ attribute is before everything
else in the function declarations.
2018-01-31 13:33:07 +01:00
Nick Terrell
30e92f320c [lz4hc] level == 0 means default, not level 1 2018-01-22 12:50:06 -08:00
Po-Chuan Hsieh
75b81bbbf0 Change file format back to ASCII (from UTF-8)
- Replace U+00A0 by space
- Fix build failure of archivers/py-borgbackup in FreeBSD

Reference: https://bugs.FreeBSD.org/225235
2018-01-18 03:13:05 +08:00
Yann Collet
5e7780d2d8 lz4frame : removed some intermediate stage from LZ4F_decompress()
ensure some strange jump cases are not possible
(they were already not possible, but static analyzer couldn't understand it).
2018-01-14 00:15:07 -08:00
Yann Collet
18b4c66d25 ensure a ptr is non-null
with an assert()
to help static analyzer understanding this condition.
2018-01-13 22:47:46 -08:00
Yann Collet
4d61ebc9c8 modified formulation for LZ4F_compressBound()
previous version used an intentional overflow,
which is defined since it uses unsigned type,
but static analyzer complain about it.
2018-01-13 22:39:39 -08:00
Po-Chuan Hsieh
47bf1a9f01 Fix lz4 version 2018-01-14 06:38:03 +08:00
Yann Collet
c423dc21bd updated LZ4F_decompress() documentation 2018-01-13 13:16:31 -08:00
Yann Collet
58199f1311
Merge pull request #443 from terrelln/440
[lz4f] Skip memcpy() on empty dictionary
2018-01-10 19:06:21 +01:00
W. Felix Handte
ebef34fe79 Add Option to Make lz4frame_static.h Functions Visible in Shared Objects
In some contexts, *cough*like at facebook*cough*, dynamic linking is used in
contexts which aren't truly dynamic. That is, the guarantee is maintained that
a program will only ever execute against the library version it was compiled
to interact with.

For those situations, introduce a compile-time flag that overrides hiding
these unstable APIs in shared objects.
2018-01-08 14:46:22 -05:00
Yann Collet
0b203b04f6
Merge pull request #434 from lz4/pattern
conditional pattern analysis
2018-01-06 06:58:41 +01:00
Nick Terrell
c2dd686e96 [lz4f] Skip memcpy() on empty dictionary 2018-01-05 14:30:49 -08:00
Yann Collet
7d2f30c7d1 lz4opt supports _destSize
no longer limited to level 9
2017-12-22 12:47:59 +01:00
Yann Collet
9753ac4c91 conditional pattern analysis
Pattern analysis (currently limited to long ranges of identical bytes)
is actually detrimental to performance
when `nbSearches` is low.

Reason is : `nbSearches` provides a built-in protection for these cases.
The problem with patterns is that they dramatically increase the number of candidates to visit.
But with a low nbSearches, the match finder just aborts early.

In such cases, pattern analysis adds some complexity without reducing total nb of candidates.
It actually increases compression ratio a little bit, by filtering only "good" candidates,
but at a measurable speed cost, so it's not a good trade-off.

This patch makes pattern analysis optional.
It's enabled for levels 8+ only.
2017-12-22 08:07:25 +01:00
Yann Collet
55da545e7a new level 10
lz4opt is only competitive vs lz4hc level 10.
Below that level, it doesn't match the speed / compression effectiveness of regular hc parser.

This patch propose to extend lz4opt to levels 10-12.
The new level 10 tend to compress a bit better and a bit faster than previous one (mileage vary depending on file)

The only downside is that `limitedDestSize` mode is now limited to max level 9 (vs 10),
since it's only compatible with regular HC parser.
(Note : I suspect it's possible to convert lz4opt to support it too, but haven't spent time into it).
2017-12-20 14:14:01 +01: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
da8bed4b01 API : changed a few variables' names for clarity
updated relevant doc.
This patch has no impact on ABI/API, nor on binary generation.
2017-11-20 10:27:05 -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
dc3ed5b6a7 added code comments 2017-11-08 17:56:20 -08:00
Yann Collet
63f6039fb3 added constant TRAILING_LITERALS
which is more explicit than its value `3`.
reported by @terrelln
2017-11-08 17:47:24 -08:00
Yann Collet
f93b595718 lz4opt: simplified match finder invocation to LZ4HC_FindLongerMatch() 2017-11-08 17:11:51 -08:00
Yann Collet
fa03a9d3d9 added code comments 2017-11-08 08:42:59 -08:00
Yann Collet
b07d36245a fixed LZ4HC_reverseCountPattern()
for multi-bytes patterns
(which is not useful for the time being)
2017-11-07 17:58:59 -08:00
Yann Collet
897f5e9834 removed the ip++ at the beginning of block
The first byte used to be skipped
to avoid a infinite self-comparison.
This is no longer necessary, since init() ensures that index starts at 64K.

The first byte is also useless to search when each block is independent,
but it's no longer the case when blocks are linked.

Removing the first-byte-skip saves
about 10 bytes / MB on files compressed with -BD4 (linked blocks 64Kb),
which feels correct as each MB has 16 blocks of 64KB.
2017-11-07 17:37:31 -08:00
Yann Collet
71fd08c17d removed legacy version of LZ4HC_InsertAndFindBestMatch() 2017-11-07 11:33:40 -08:00
Yann Collet
c49f66f2ad ensure pattern is a 1-byte repetition 2017-11-07 11:29:28 -08:00
Yann Collet
5512a5f1a9 removed useless (1 && ...) condition
as reported by @terrelln
2017-11-07 11:22:57 -08:00
Yann Collet
7130bfe573 improved LZ4HC_reverseCountPattern() :
works for any repetitive pattern of length 1, 2 or 4 (but not 3!)
works for any endianess
2017-11-07 11:05:48 -08:00
Yann Collet
a004c1fbee fixed LZ4HC_countPattern()
- works with byte values other than `0`
- works for any repetitive pattern of length 1, 2 or 4 (but not 3!)
- works for little and big endian systems
- preserve speed of previous implementation
2017-11-07 10:53:29 -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
aa99163752 fixed minor static analyzer warning
dead assignment
2017-11-03 12:33:55 -07:00
Yann Collet
89821ac7a1 minor comment edit 2017-11-03 11:49:56 -07:00
Yann Collet
1025546347 unified HC levels
LZ4_setCompressionLevel() can be users accross the whole range of HC levels
No more transition issue between Optimal and HC modes
2017-11-03 11:28:28 -07:00
Yann Collet
a1f4a0d983 moved ctx->end handling from parsers
responsibility better handled one layer above (LZ4HC_compress_generic())
2017-11-03 10:48:55 -07:00
Yann Collet
c9bbad53ff removed ctx->searchNum
nbSearches now transmitted directly as function parameter
easier to track and debug
2017-11-03 10:30:52 -07:00
Yann Collet
e2eca62046 LZ4_compress_HC_continue_destSize() now compatible with optimal parser
levels 11+
2017-11-03 02:03:19 -07:00
Yann Collet
3b222d2d96 removes matches[] table
saves stack space
clearer match finder interface (no more table to fill)
2017-11-03 01:37:43 -07:00
Yann Collet
320e1d51ac removed useless parameter from hash chain matchfinder
used to be present for compatibility with binary tree matchfinder
2017-11-03 01:20:30 -07:00
Yann Collet
81667a1e96 removed code and reference to binary tree match finder
reduced size of LZ4HC state
2017-11-03 01:18:12 -07:00
Yann Collet
82c1aed419 improved level 11 speed 2017-11-03 00:59:05 -07:00
Yann Collet
890c0553d0 optimized skip strategy for level 12 2017-11-03 00:15:52 -07:00
Yann Collet
05d78eb817 new level 11 uses 512 attempts 2017-11-02 19:50:08 -07:00
Yann Collet
a1c5343d89 more generic skip formula
improving speed
2017-11-02 18:54:18 -07:00
Yann Collet
e06cb03c11 small adaptations for intermediate level 11 2017-11-02 16:25:10 -07:00
Yann Collet
4b81885800 partial search, while preserving compression ratio
tag interesting places
2017-11-02 15:37:18 -07:00
Yann Collet
bd992f12e4 searching match leading strictly farther does not work
sometimes, it's better to re-use same match but start it later,
in order to get shorter matchlength code
2017-11-02 15:05:45 -07: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
0ff4df1b94 changed strategy : opt[] path is complete after each match
previous strategy would leave a few "bad choices"
on the ground they would be fixed later,
but that requires passing through each position to make the fix
and cannot give the end position of the last useful match.
2017-11-02 13:44:57 -07:00
Yann Collet
cc4a109b0d
Merge pull request #415 from lz4/fasterDecodingXp
Faster decoding xp
2017-11-01 09:58:49 -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
931c5c20d0 fixed minor overflow mistake in optimal parser
saving 20 bytes on calgary.tar
2017-10-30 17:47:54 -07:00
Yann Collet
ab4bd93f59 fixed minor initialization warning 2017-10-30 16:10:25 -07:00
Yann Collet
e0914ff70c more complete shortcut - passes tests 2017-10-30 16:07:15 -07:00
mikir
63a7f34fee
Separated visibility from LZ4LIB_API macro. 2017-10-30 13:44:24 +01: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
16a4337473 added hash chain with conditional length
not a success yet
2017-10-25 07:07:08 +02:00
Yann Collet
a12cdf00c3 lz4opt: added hash chain search 2017-10-20 17:04:29 -07:00
Yann Collet
fd6bd5107b switched many types to int 2017-10-20 15:33:52 -07:00
Yann Collet
d813134619 removed SET_PRICE macro 2017-10-20 13:44:49 -07:00
Yann Collet
fa064c8a8c removed one macro usage 2017-10-20 13:32:45 -07:00
Yann Collet
ee62faee08 minor refactor
reduce variable scope
remove one macro usage
2017-10-20 12:05:00 -07:00
Yann Collet
fc879fe170 lz4opt: refactor sequence reverse traversal 2017-10-20 11:32:15 -07:00
Yann Collet
c058753393 refactor variable matchnum
separate initial and iterative search
renamed nb_matches
2017-10-20 11:24:56 -07:00
Yann Collet
7bb0a617ee simplified initial cost conditions
llen integrated in opt[]
2017-10-20 11:00:10 -07:00
Yann Collet
6cec68de39 added assert 2017-10-19 16:47:25 -07:00
Yann Collet
ac2ad52257 renamed last_pos into last_match_pos 2017-10-19 16:43:36 -07:00
Yann Collet
708e2cbb60 simplified early exit when single solution 2017-10-19 16:39:40 -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
a4314829db fused getLongerMatch and getWiderMatch 2017-10-09 01:50:28 -07:00
Yann Collet
97c18f5f0e re-inserted last byte test in widerMatch 2017-10-09 01:44:05 -07:00
Yann Collet
bdca63ed69 early out is not better 2017-10-09 00:36:47 -07:00
Yann Collet
1ee17e4eb8 optional fuse 2017-10-09 00:31:12 -07:00
Yann Collet
b9459faeb2 improved search of rep-1 patterns 2017-10-08 23:55:42 -07:00
Yann Collet
f1fa91d6fc insertAndFindBestMatch defers to insertAndGetWiderMatch 2017-10-08 23:40:21 -07:00
Yann Collet
87968517f9 fixed decoding block checksum in lz4frame 2017-10-04 15:24:08 -07: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
ceb868f442 minor lz4frame code refactor
try to improve code readability.
minor optimization on condition to preserve history.
2017-09-23 15:06:24 -07:00