mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 14:07:08 -06:00
Update Fast LZMA2
This commit is contained in:
339
C/fast-lzma2/COPYING
Normal file
339
C/fast-lzma2/COPYING
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
11
C/fast-lzma2/LICENSE
Normal file
11
C/fast-lzma2/LICENSE
Normal file
@@ -0,0 +1,11 @@
|
||||
Copyright 2018-present Conor McCarthy
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. 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.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
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 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -124,7 +124,6 @@ FL2LIB_API unsigned long long FL2LIB_CALL FL2_findDecompressedSize(const void *s
|
||||
|
||||
|
||||
/*====== Helper functions ======*/
|
||||
#define FL2_COMPRESSBOUND(srcSize) ((srcSize) + (((srcSize) + 0xFFF) / 0x1000) * 3 + 6) /*!< calculates the maximum size of data stored in a sequence of uncompressed chunks */
|
||||
FL2LIB_API size_t FL2LIB_CALL FL2_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */
|
||||
FL2LIB_API unsigned FL2LIB_CALL FL2_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
|
||||
FL2LIB_API unsigned FL2LIB_CALL FL2_isTimedOut(size_t code); /*!< tells if a `size_t` function result is the timeout code */
|
||||
@@ -461,8 +460,9 @@ FL2LIB_API size_t FL2LIB_CALL FL2_decompressStream(FL2_DStream* fds, FL2_outBuff
|
||||
#define FL2_BLOCK_OVERLAP_MAX 14
|
||||
#define FL2_RESET_INTERVAL_MIN 1
|
||||
#define FL2_RESET_INTERVAL_MAX 16 /* small enough to fit FL2_DICTSIZE_MAX * FL2_RESET_INTERVAL_MAX in 32-bit size_t */
|
||||
#define FL2_BUFFER_SIZE_LOG_MIN 0
|
||||
#define FL2_BUFFER_SIZE_LOG_MAX 6
|
||||
#define FL2_BUFFER_RESIZE_MIN 0
|
||||
#define FL2_BUFFER_RESIZE_MAX 4
|
||||
#define FL2_BUFFER_RESIZE_DEFAULT 2
|
||||
#define FL2_CHAINLOG_MIN 4
|
||||
#define FL2_CHAINLOG_MAX 14
|
||||
#define FL2_HYBRIDCYCLES_MIN 1
|
||||
@@ -486,15 +486,13 @@ typedef enum {
|
||||
} FL2_strategy;
|
||||
|
||||
typedef struct {
|
||||
size_t dictionarySize; /* largest match distance : larger == more compression, more memory needed during decompression; >= 27 == more memory per byte, slower */
|
||||
size_t dictionarySize; /* largest match distance : larger == more compression, more memory needed during decompression; > 64Mb == more memory per byte, slower */
|
||||
unsigned overlapFraction; /* overlap between consecutive blocks in 1/16 units: larger == more compression, slower */
|
||||
unsigned chainLog; /* HC3 sliding window : larger == more compression, slower; hybrid mode only (ultra) */
|
||||
unsigned cyclesLog; /* nb of searches : larger == more compression, slower; hybrid mode only (ultra) */
|
||||
unsigned searchDepth; /* maximum depth for resolving string matches : larger == more compression, slower */
|
||||
unsigned fastLength; /* acceptable match size for parser : larger == more compression, slower; fast bytes parameter from 7-zip */
|
||||
unsigned fastLength; /* acceptable match size for parser : larger == more compression, slower; fast bytes parameter from 7-Zip */
|
||||
unsigned divideAndConquer; /* split long chains of 2-byte matches into shorter chains with a small overlap : faster, somewhat less compression; enabled by default */
|
||||
unsigned bufferLog; /* buffer size for processing match chains is (dictionarySize >> (12 - bufferLog)) : affects compression when divideAndConquer enabled; */
|
||||
/* when divideAndConquer disabled, affects speed in a hardware-dependent manner */
|
||||
FL2_strategy strategy; /* encoder strategy : fast, optimized or ultra (hybrid) */
|
||||
} FL2_compressionParameters;
|
||||
|
||||
@@ -521,11 +519,12 @@ typedef enum {
|
||||
FL2_p_resetInterval, /* For multithreaded decompression. A dictionary reset will occur
|
||||
* after each dictionarySize * resetInterval bytes of input.
|
||||
* Default = 4 */
|
||||
FL2_p_bufferLog, /* Buffering speeds up the matchfinder. Buffer size is
|
||||
* (dictionarySize >> (12 - bufferLog)) * 12 bytes. Higher number = slower,
|
||||
* better compression, higher memory usage. A CPU with a large memory cache
|
||||
FL2_p_bufferResize, /* Buffering speeds up the matchfinder. Buffer resize determines the percentage of
|
||||
* the normal buffer size used, which depends on dictionary size.
|
||||
* 0=50, 1=75, 2=100, 3=150, 4=200. Higher number = slower, better
|
||||
* compression, higher memory usage. A CPU with a large memory cache
|
||||
* may make effective use of a larger buffer.
|
||||
* Default = 4 */
|
||||
* Default = 2 */
|
||||
FL2_p_hybridChainLog, /* Size of the hybrid mode HC3 hash chain, as a power of 2.
|
||||
* Resulting table size is (1 << (chainLog+2)) bytes.
|
||||
* Larger tables result in better and slower compression.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "fast-lzma2.h"
|
||||
#include "fl2_errors.h"
|
||||
#include "fl2_internal.h"
|
||||
#include "lzma2_enc.h"
|
||||
|
||||
|
||||
/*-****************************************
|
||||
@@ -32,7 +33,7 @@ FL2LIB_API const char* FL2LIB_CALL FL2_versionString(void) { return FL2_VERSION_
|
||||
******************************************/
|
||||
FL2LIB_API size_t FL2LIB_CALL FL2_compressBound(size_t srcSize)
|
||||
{
|
||||
return FL2_COMPRESSBOUND(srcSize);
|
||||
return LZMA2_compressBound(srcSize);
|
||||
}
|
||||
|
||||
/*-****************************************
|
||||
@@ -84,6 +85,7 @@ FL2LIB_API const char* FL2LIB_CALL FL2_getErrorString(FL2_ErrorCode code)
|
||||
{
|
||||
case PREFIX(no_error): return "No error detected";
|
||||
case PREFIX(GENERIC): return "Error (generic)";
|
||||
case PREFIX(internal): return "Internal error (bug)";
|
||||
case PREFIX(corruption_detected): return "Corrupted block detected";
|
||||
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
||||
case PREFIX(parameter_unsupported): return "Unsupported parameter";
|
||||
|
||||
@@ -36,16 +36,16 @@
|
||||
#define FL2_MAX_CLEVEL 9
|
||||
|
||||
static const FL2_compressionParameters FL2_defaultCParameters[FL2_MAX_CLEVEL + 1] = {
|
||||
{ 0,0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 1, 7, 0, 6, 32, 1, 4, FL2_fast }, /* 1 */
|
||||
{ 2 MB, 2, 7, 0, 14, 32, 1, 4, FL2_fast }, /* 2 */
|
||||
{ 2 MB, 2, 7, 0, 14, 40, 1, 4, FL2_opt }, /* 3 */
|
||||
{ 4 MB, 2, 7, 0, 26, 40, 1, 4, FL2_opt }, /* 4 */
|
||||
{ 16 MB, 2, 8, 0, 42, 48, 1, 4, FL2_opt }, /* 5 */
|
||||
{ 16 MB, 2, 9, 1, 42, 48, 1, 4, FL2_ultra }, /* 6 */
|
||||
{ 32 MB, 2, 10, 1, 50, 64, 1, 4, FL2_ultra }, /* 7 */
|
||||
{ 64 MB, 2, 11, 2, 62, 96, 1, 3, FL2_ultra }, /* 8 */
|
||||
{ 64 MB, 4, 12, 3, 90, 273, 0, 3, FL2_ultra }, /* 9 */
|
||||
{ 0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 1, 7, 0, 6, 32, 1, FL2_fast }, /* 1 */
|
||||
{ 2 MB, 2, 7, 0, 14, 32, 1, FL2_fast }, /* 2 */
|
||||
{ 2 MB, 2, 7, 0, 14, 40, 1, FL2_opt }, /* 3 */
|
||||
{ 8 MB, 2, 7, 0, 26, 40, 1, FL2_opt }, /* 4 */
|
||||
{ 16 MB, 2, 8, 0, 42, 48, 1, FL2_opt }, /* 5 */
|
||||
{ 16 MB, 2, 9, 1, 42, 48, 1, FL2_ultra }, /* 6 */
|
||||
{ 32 MB, 2, 10, 1, 50, 64, 1, FL2_ultra }, /* 7 */
|
||||
{ 64 MB, 2, 11, 2, 62, 96, 1, FL2_ultra }, /* 8 */
|
||||
{ 128 MB, 2, 12, 3, 90, 128, 1, FL2_ultra }, /* 9 */
|
||||
};
|
||||
|
||||
#elif defined(FL2_7ZIP_BUILD)
|
||||
@@ -54,16 +54,16 @@ static const FL2_compressionParameters FL2_defaultCParameters[FL2_MAX_CLEVEL + 1
|
||||
#define FL2_MAX_CLEVEL 9
|
||||
|
||||
static const FL2_compressionParameters FL2_defaultCParameters[FL2_MAX_CLEVEL + 1] = {
|
||||
{ 0,0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 1, 7, 0, 6, 32, 1, 4, FL2_fast }, /* 1 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, 4, FL2_fast }, /* 2 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, 4, FL2_opt }, /* 3 */
|
||||
{ 4 MB, 2, 7, 0, 14, 32, 1, 4, FL2_opt }, /* 4 */
|
||||
{ 16 MB, 2, 9, 0, 42, 48, 1, 4, FL2_ultra }, /* 5 */
|
||||
{ 32 MB, 2, 10, 0, 50, 64, 1, 4, FL2_ultra }, /* 6 */
|
||||
{ 64 MB, 2, 11, 1, 62, 96, 1, 3, FL2_ultra }, /* 7 */
|
||||
{ 64 MB, 4, 12, 2, 90, 273, 1, 3, FL2_ultra }, /* 8 */
|
||||
{ 128 MB, 2, 14, 3, 254, 273, 0, 2, FL2_ultra } /* 9 */
|
||||
{ 0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 1, 7, 0, 6, 32, 1, FL2_fast }, /* 1 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, FL2_fast }, /* 2 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, FL2_opt }, /* 3 */
|
||||
{ 4 MB, 2, 7, 0, 14, 32, 1, FL2_opt }, /* 4 */
|
||||
{ 16 MB, 2, 9, 0, 42, 48, 1, FL2_ultra }, /* 5 */
|
||||
{ 32 MB, 2, 10, 0, 50, 64, 1, FL2_ultra }, /* 6 */
|
||||
{ 64 MB, 2, 11, 1, 62, 96, 1, FL2_ultra }, /* 7 */
|
||||
{ 64 MB, 4, 12, 2, 90, 273, 1, FL2_ultra }, /* 8 */
|
||||
{ 128 MB, 2, 14, 3, 254, 273, 0, FL2_ultra } /* 9 */
|
||||
};
|
||||
|
||||
#else
|
||||
@@ -72,33 +72,33 @@ static const FL2_compressionParameters FL2_defaultCParameters[FL2_MAX_CLEVEL + 1
|
||||
#define FL2_MAX_CLEVEL 10
|
||||
|
||||
static const FL2_compressionParameters FL2_defaultCParameters[FL2_MAX_CLEVEL + 1] = {
|
||||
{ 0,0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 1, 7, 0, 6, 32, 1, 4, FL2_fast }, /* 1 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, 4, FL2_fast }, /* 2 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, 4, FL2_opt }, /* 3 */
|
||||
{ 4 MB, 2, 7, 0, 26, 40, 1, 4, FL2_opt }, /* 4 */
|
||||
{ 8 MB, 2, 8, 0, 42, 48, 1, 4, FL2_opt }, /* 5 */
|
||||
{ 16 MB, 2, 9, 0, 42, 48, 1, 4, FL2_ultra }, /* 6 */
|
||||
{ 32 MB, 2, 10, 0, 50, 64, 1, 4, FL2_ultra }, /* 7 */
|
||||
{ 64 MB, 2, 11, 1, 62, 96, 1, 3, FL2_ultra }, /* 8 */
|
||||
{ 64 MB, 4, 12, 2, 90, 273, 1, 3, FL2_ultra }, /* 9 */
|
||||
{ 128 MB, 2, 14, 3, 254, 273, 0, 2, FL2_ultra } /* 10 */
|
||||
{ 0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 1, 7, 0, 6, 32, 1, FL2_fast }, /* 1 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, FL2_fast }, /* 2 */
|
||||
{ 2 MB, 2, 7, 0, 10, 32, 1, FL2_opt }, /* 3 */
|
||||
{ 4 MB, 2, 7, 0, 26, 40, 1, FL2_opt }, /* 4 */
|
||||
{ 8 MB, 2, 8, 0, 42, 48, 1, FL2_opt }, /* 5 */
|
||||
{ 16 MB, 2, 9, 0, 42, 48, 1, FL2_ultra }, /* 6 */
|
||||
{ 32 MB, 2, 10, 0, 50, 64, 1, FL2_ultra }, /* 7 */
|
||||
{ 64 MB, 2, 11, 1, 62, 96, 1, FL2_ultra }, /* 8 */
|
||||
{ 64 MB, 4, 12, 2, 90, 273, 1, FL2_ultra }, /* 9 */
|
||||
{ 128 MB, 2, 14, 3, 254, 273, 0, FL2_ultra } /* 10 */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static const FL2_compressionParameters FL2_highCParameters[FL2_MAX_HIGH_CLEVEL + 1] = {
|
||||
{ 0,0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 4, 9, 2, 254, 273, 0, 4, FL2_ultra }, /* 1 */
|
||||
{ 2 MB, 4, 10, 2, 254, 273, 0, 4, FL2_ultra }, /* 2 */
|
||||
{ 4 MB, 4, 11, 2, 254, 273, 0, 4, FL2_ultra }, /* 3 */
|
||||
{ 8 MB, 4, 12, 2, 254, 273, 0, 4, FL2_ultra }, /* 4 */
|
||||
{ 16 MB, 4, 13, 3, 254, 273, 0, 4, FL2_ultra }, /* 5 */
|
||||
{ 32 MB, 4, 14, 3, 254, 273, 0, 4, FL2_ultra }, /* 6 */
|
||||
{ 64 MB, 4, 14, 4, 254, 273, 0, 4, FL2_ultra }, /* 7 */
|
||||
{ 128 MB, 4, 14, 4, 254, 273, 0, 4, FL2_ultra }, /* 8 */
|
||||
{ 256 MB, 4, 14, 5, 254, 273, 0, 3, FL2_ultra }, /* 9 */
|
||||
{ 512 MB, 4, 14, 5, 254, 273, 0, 2, FL2_ultra } /* 10 */
|
||||
{ 0,0,0,0,0,0,0,0 },
|
||||
{ 1 MB, 4, 9, 2, 254, 273, 0, FL2_ultra }, /* 1 */
|
||||
{ 2 MB, 4, 10, 2, 254, 273, 0, FL2_ultra }, /* 2 */
|
||||
{ 4 MB, 4, 11, 2, 254, 273, 0, FL2_ultra }, /* 3 */
|
||||
{ 8 MB, 4, 12, 2, 254, 273, 0, FL2_ultra }, /* 4 */
|
||||
{ 16 MB, 4, 13, 3, 254, 273, 0, FL2_ultra }, /* 5 */
|
||||
{ 32 MB, 4, 14, 3, 254, 273, 0, FL2_ultra }, /* 6 */
|
||||
{ 64 MB, 4, 14, 4, 254, 273, 0, FL2_ultra }, /* 7 */
|
||||
{ 128 MB, 4, 14, 4, 254, 273, 0, FL2_ultra }, /* 8 */
|
||||
{ 256 MB, 4, 14, 5, 254, 273, 0, FL2_ultra }, /* 9 */
|
||||
{ 512 MB, 4, 14, 5, 254, 273, 0, FL2_ultra } /* 10 */
|
||||
};
|
||||
|
||||
#undef MB
|
||||
@@ -126,7 +126,7 @@ static void FL2_fillParameters(FL2_CCtx* const cctx, const FL2_compressionParame
|
||||
|
||||
RMF_parameters* const rParams = &cctx->params.rParams;
|
||||
rParams->dictionary_size = MIN(params->dictionarySize, FL2_DICTSIZE_MAX); /* allows for reduced dict in 32-bit version */
|
||||
rParams->match_buffer_log = RMF_BUFFER_LOG_BASE - params->bufferLog;
|
||||
rParams->match_buffer_resize = FL2_BUFFER_RESIZE_DEFAULT;
|
||||
rParams->overlap_fraction = params->overlapFraction;
|
||||
rParams->divide_and_conquer = params->divideAndConquer;
|
||||
rParams->depth = params->searchDepth;
|
||||
@@ -666,7 +666,7 @@ FL2LIB_API size_t FL2LIB_CALL FL2_CCtx_setParameter(FL2_CCtx* cctx, FL2_cParamet
|
||||
case FL2_p_dictionarySize:
|
||||
CLAMPCHECK(value, FL2_DICTSIZE_MIN, FL2_DICTSIZE_MAX);
|
||||
cctx->params.rParams.dictionary_size = value;
|
||||
break;
|
||||
break;
|
||||
|
||||
case FL2_p_overlapFraction:
|
||||
MAXCHECK(value, FL2_BLOCK_OVERLAP_MAX);
|
||||
@@ -679,9 +679,9 @@ FL2LIB_API size_t FL2LIB_CALL FL2_CCtx_setParameter(FL2_CCtx* cctx, FL2_cParamet
|
||||
cctx->params.cParams.reset_interval = (unsigned)value;
|
||||
break;
|
||||
|
||||
case FL2_p_bufferLog:
|
||||
MAXCHECK(value, FL2_BUFFER_SIZE_LOG_MAX);
|
||||
cctx->params.rParams.match_buffer_log = RMF_BUFFER_LOG_BASE - (unsigned)value;
|
||||
case FL2_p_bufferResize:
|
||||
MAXCHECK(value, FL2_BUFFER_RESIZE_MAX);
|
||||
cctx->params.rParams.match_buffer_resize = (unsigned)value;
|
||||
break;
|
||||
|
||||
case FL2_p_hybridChainLog:
|
||||
@@ -781,8 +781,8 @@ FL2LIB_API size_t FL2LIB_CALL FL2_CCtx_getParameter(FL2_CCtx* cctx, FL2_cParamet
|
||||
case FL2_p_resetInterval:
|
||||
return cctx->params.cParams.reset_interval;
|
||||
|
||||
case FL2_p_bufferLog:
|
||||
return RMF_BUFFER_LOG_BASE - cctx->params.rParams.match_buffer_log;
|
||||
case FL2_p_bufferResize:
|
||||
return cctx->params.rParams.match_buffer_resize;
|
||||
|
||||
case FL2_p_hybridChainLog:
|
||||
return cctx->params.cParams.second_dict_bits;
|
||||
@@ -1253,12 +1253,12 @@ FL2LIB_API size_t FL2LIB_CALL FL2_getLevelParameters(int compressionLevel, int h
|
||||
return FL2_error_no_error;
|
||||
}
|
||||
|
||||
static size_t FL2_memoryUsage_internal(size_t const dictionarySize, unsigned const bufferLog,
|
||||
static size_t FL2_memoryUsage_internal(size_t const dictionarySize, unsigned const bufferResize,
|
||||
unsigned const chainLog,
|
||||
FL2_strategy const strategy,
|
||||
unsigned const nbThreads)
|
||||
{
|
||||
return RMF_memoryUsage(dictionarySize, bufferLog, nbThreads)
|
||||
return RMF_memoryUsage(dictionarySize, bufferResize, nbThreads)
|
||||
+ LZMA2_encMemoryUsage(chainLog, strategy, nbThreads);
|
||||
}
|
||||
|
||||
@@ -1276,7 +1276,7 @@ FL2LIB_API size_t FL2LIB_CALL FL2_estimateCCtxSize_byParams(const FL2_compressio
|
||||
{
|
||||
nbThreads = FL2_checkNbThreads(nbThreads);
|
||||
return FL2_memoryUsage_internal(params->dictionarySize,
|
||||
params->bufferLog,
|
||||
FL2_BUFFER_RESIZE_DEFAULT,
|
||||
params->chainLog,
|
||||
params->strategy,
|
||||
nbThreads);
|
||||
@@ -1285,7 +1285,7 @@ FL2LIB_API size_t FL2LIB_CALL FL2_estimateCCtxSize_byParams(const FL2_compressio
|
||||
FL2LIB_API size_t FL2LIB_CALL FL2_estimateCCtxSize_usingCCtx(const FL2_CCtx * cctx)
|
||||
{
|
||||
return FL2_memoryUsage_internal(cctx->params.rParams.dictionary_size,
|
||||
cctx->params.rParams.match_buffer_log,
|
||||
cctx->params.rParams.match_buffer_resize,
|
||||
cctx->params.cParams.second_dict_bits,
|
||||
cctx->params.cParams.strategy,
|
||||
cctx->jobCount) + DICT_memUsage(&cctx->buf);
|
||||
|
||||
@@ -76,13 +76,21 @@ Public domain
|
||||
#define kInfinityPrice (1UL << 30U)
|
||||
#define kNullDist (U32)-1
|
||||
|
||||
#define kChunkSize ((1UL << 16U) - 8192U)
|
||||
#define kSqrtChunkSize 239U
|
||||
#define kMaxMatchEncodeSize 20
|
||||
#define kTempMinOutput (kMaxMatchEncodeSize * 4U)
|
||||
#define kTempBufferSize (kTempMinOutput + kOptimizerBufferSize + kOptimizerBufferSize / 16U)
|
||||
#define kMaxChunkUncompressedSize ((1UL << 21U) - kMatchLenMax)
|
||||
|
||||
#define kMaxChunkCompressedSize (1UL << 16U)
|
||||
/* Need to leave sufficient space for expanded output from a full opt buffer with bad starting probs */
|
||||
#define kChunkSize (kMaxChunkCompressedSize - 2048U)
|
||||
#define kSqrtChunkSize 252U
|
||||
|
||||
/* Hard to define where the match table read pos definitely catches up with the output size, but
|
||||
* 64 bytes of input expanding beyond 256 bytes right after an encoder reset is most likely impossible.
|
||||
* The encoder will error out if this happens. */
|
||||
#define kTempMinOutput 256U
|
||||
#define kTempBufferSize (kTempMinOutput + kOptimizerBufferSize + kOptimizerBufferSize / 4U)
|
||||
|
||||
#define kMaxChunkUncompressedSize (1UL << 21U)
|
||||
|
||||
#define kChunkHeaderSize 5U
|
||||
#define kChunkResetShift 5U
|
||||
#define kChunkUncompressedDictReset 1U
|
||||
@@ -199,6 +207,10 @@ struct LZMA2_ECtx_s
|
||||
FL2_strategy strategy;
|
||||
|
||||
RangeEncoder rc;
|
||||
/* Finish writing the chunk at this size */
|
||||
size_t chunk_size;
|
||||
/* Don't encode a symbol beyond this limit (used by fast mode) */
|
||||
size_t chunk_limit;
|
||||
|
||||
EncoderStates states;
|
||||
|
||||
@@ -222,6 +234,7 @@ struct LZMA2_ECtx_s
|
||||
ptrdiff_t hash_prev_index;
|
||||
ptrdiff_t hash_alloc_3;
|
||||
|
||||
/* Temp output buffer before space frees up in the match table */
|
||||
BYTE out_buf[kTempBufferSize];
|
||||
};
|
||||
|
||||
@@ -573,7 +586,8 @@ size_t LZMA_encodeChunkFast(LZMA2_ECtx *const enc,
|
||||
size_t const pos_mask = enc->pos_mask;
|
||||
size_t prev = index;
|
||||
unsigned const search_depth = tbl->params.depth;
|
||||
while (index < uncompressed_end && enc->rc.out_index < enc->rc.chunk_size) {
|
||||
|
||||
while (index < uncompressed_end && enc->rc.out_index < enc->chunk_size) {
|
||||
size_t max_len;
|
||||
const BYTE* data;
|
||||
/* Table of distance restrictions for short matches */
|
||||
@@ -670,57 +684,58 @@ size_t LZMA_encodeChunkFast(LZMA2_ECtx *const enc,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (next < uncompressed_end - 4) {
|
||||
++next;
|
||||
++next;
|
||||
/* Recheck next < uncompressed_end. uncompressed_end could be block.end so decrementing the max chunk size won't obviate the need. */
|
||||
if (next >= uncompressed_end)
|
||||
break;
|
||||
|
||||
next_match = RMF_getNextMatch(block, tbl, search_depth, struct_tbl, next);
|
||||
if (next_match.length < 4)
|
||||
break;
|
||||
next_match = RMF_getNextMatch(block, tbl, search_depth, struct_tbl, next);
|
||||
if (next_match.length < 4)
|
||||
break;
|
||||
|
||||
data = block.data + next;
|
||||
max_len = MIN(kMatchLenMax, block.end - next);
|
||||
best_rep.length = 0;
|
||||
data = block.data + next;
|
||||
max_len = MIN(kMatchLenMax, block.end - next);
|
||||
best_rep.length = 0;
|
||||
|
||||
for (rep_match.dist = 0; rep_match.dist < kNumReps; ++rep_match.dist) {
|
||||
const BYTE *data_2 = data - enc->states.reps[rep_match.dist] - 1;
|
||||
if (MEM_read16(data) != MEM_read16(data_2))
|
||||
continue;
|
||||
|
||||
rep_match.length = (U32)(ZSTD_count(data + 2, data_2 + 2, data + max_len) + 2);
|
||||
if (rep_match.length > best_rep.length)
|
||||
best_rep = rep_match;
|
||||
}
|
||||
if (best_rep.length >= 4) {
|
||||
int const gain2 = (int)(best_rep.length * 4 - (best_rep.dist >> 1));
|
||||
int const gain1 = (int)(best_match.length * 4 - ZSTD_highbit32((U32)best_match.dist + 1) + 1);
|
||||
if (gain2 > gain1) {
|
||||
DEBUGLOG(7, "Replace match (%u, %u) with rep (%u, %u)", best_match.length, best_match.dist, best_rep.length, best_rep.dist);
|
||||
best_match = best_rep;
|
||||
index = next;
|
||||
}
|
||||
}
|
||||
if (next_match.length >= 4 && next_match.dist != best_match.dist) {
|
||||
int const gain2 = (int)(next_match.length * 4 - ZSTD_highbit32((U32)next_match.dist + 1));
|
||||
int const gain1 = (int)(best_match.length * 4 - ZSTD_highbit32((U32)best_match.dist + 1) + 7);
|
||||
if (gain2 > gain1) {
|
||||
DEBUGLOG(7, "Replace match (%u, %u) with match (%u, %u)", best_match.length, best_match.dist, next_match.length, next_match.dist + kNumReps);
|
||||
best_match = next_match;
|
||||
best_match.dist += kNumReps;
|
||||
index = next;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (rep_match.dist = 0; rep_match.dist < kNumReps; ++rep_match.dist) {
|
||||
const BYTE *data_2 = data - enc->states.reps[rep_match.dist] - 1;
|
||||
if (MEM_read16(data) != MEM_read16(data_2))
|
||||
continue;
|
||||
|
||||
rep_match.length = (U32)(ZSTD_count(data + 2, data_2 + 2, data + max_len) + 2);
|
||||
if (rep_match.length > best_rep.length)
|
||||
best_rep = rep_match;
|
||||
}
|
||||
if (best_rep.length >= 4) {
|
||||
int const gain2 = (int)(best_rep.length * 4 - (best_rep.dist >> 1));
|
||||
int const gain1 = (int)(best_match.length * 4 - ZSTD_highbit32((U32)best_match.dist + 1) + 1);
|
||||
if (gain2 > gain1) {
|
||||
DEBUGLOG(7, "Replace match (%u, %u) with rep (%u, %u)", best_match.length, best_match.dist, best_rep.length, best_rep.dist);
|
||||
best_match = best_rep;
|
||||
index = next;
|
||||
}
|
||||
}
|
||||
if (next_match.dist != best_match.dist) {
|
||||
int const gain2 = (int)(next_match.length * 4 - ZSTD_highbit32((U32)next_match.dist + 1));
|
||||
int const gain1 = (int)(best_match.length * 4 - ZSTD_highbit32((U32)best_match.dist + 1) + 7);
|
||||
if (gain2 > gain1) {
|
||||
DEBUGLOG(7, "Replace match (%u, %u) with match (%u, %u)", best_match.length, best_match.dist, next_match.length, next_match.dist + kNumReps);
|
||||
best_match = next_match;
|
||||
best_match.dist += kNumReps;
|
||||
index = next;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
_encode:
|
||||
assert(index + best_match.length <= block.end);
|
||||
|
||||
/* Chunk overflow size is kOptimizerBufferSize + extra.
|
||||
* Unlikely for this limit to be hit. */
|
||||
size_t rc_end = enc->rc.chunk_size + kOptimizerBufferSize;
|
||||
while (prev < index && enc->rc.out_index < rc_end) {
|
||||
while (prev < index) {
|
||||
if (enc->rc.out_index >= enc->chunk_limit)
|
||||
return prev;
|
||||
|
||||
if (block.data[prev] != block.data[prev - enc->states.reps[0] - 1]) {
|
||||
LZMA_encodeLiteralBuf(enc, block.data, prev);
|
||||
++prev;
|
||||
@@ -730,8 +745,6 @@ _encode:
|
||||
++prev;
|
||||
}
|
||||
}
|
||||
if (prev < index)
|
||||
break;
|
||||
|
||||
if(best_match.length >= kMatchLenMin) {
|
||||
if (best_match.dist >= kNumReps) {
|
||||
@@ -746,7 +759,7 @@ _encode:
|
||||
}
|
||||
}
|
||||
}
|
||||
while (prev < index && enc->rc.out_index < enc->rc.chunk_size) {
|
||||
while (prev < index && enc->rc.out_index < enc->chunk_limit) {
|
||||
if (block.data[prev] != block.data[prev - enc->states.reps[0] - 1])
|
||||
LZMA_encodeLiteralBuf(enc, block.data, prev);
|
||||
else
|
||||
@@ -1532,8 +1545,10 @@ reverse:
|
||||
start_index += i;
|
||||
/* Do another round if there is a long match pending,
|
||||
* because the reps must be checked and the match encoded. */
|
||||
} while (match.length >= enc->fast_length && start_index < uncompressed_end && enc->rc.out_index < enc->rc.chunk_size);
|
||||
} while (match.length >= enc->fast_length && start_index < uncompressed_end && enc->rc.out_index < enc->chunk_size);
|
||||
|
||||
enc->len_end_max = len_end;
|
||||
|
||||
return start_index;
|
||||
}
|
||||
|
||||
@@ -1645,7 +1660,8 @@ size_t LZMA_encodeChunkBest(LZMA2_ECtx *const enc,
|
||||
LZMA_fillAlignPrices(enc);
|
||||
LZMA_lengthStates_updatePrices(enc, &enc->states.len_states);
|
||||
LZMA_lengthStates_updatePrices(enc, &enc->states.rep_len_states);
|
||||
while (index < uncompressed_end && enc->rc.out_index < enc->rc.chunk_size)
|
||||
|
||||
while (index < uncompressed_end && enc->rc.out_index < enc->chunk_size)
|
||||
{
|
||||
RMF_match const match = RMF_getMatch(block, tbl, search_depth, struct_tbl, index);
|
||||
if (match.length > 1) {
|
||||
@@ -1745,6 +1761,16 @@ BYTE LZMA2_getDictSizeProp(size_t const dictionary_size)
|
||||
return dict_size_prop;
|
||||
}
|
||||
|
||||
size_t LZMA2_compressBound(size_t src_size)
|
||||
{
|
||||
/* Minimum average uncompressed size. An average size of half kChunkSize should be assumed
|
||||
* to account for thread_count incomplete end chunks per block. LZMA expansion is < 2% so 1/16
|
||||
* is a safe overestimate. */
|
||||
static const unsigned chunk_min_avg = (kChunkSize - (kChunkSize / 16U)) / 2U;
|
||||
/* Maximum size of data stored in a sequence of uncompressed chunks */
|
||||
return src_size + ((src_size + chunk_min_avg - 1) / chunk_min_avg) * 3 + 6;
|
||||
}
|
||||
|
||||
size_t LZMA2_encMemoryUsage(unsigned const chain_log, FL2_strategy const strategy, unsigned const thread_count)
|
||||
{
|
||||
size_t size = sizeof(LZMA2_ECtx);
|
||||
@@ -1791,7 +1817,7 @@ static U32 LZMA2_isqrt(U32 op)
|
||||
return res;
|
||||
}
|
||||
|
||||
static BYTE LZMA2_chunkNotCompressible(const FL2_matchTable* const tbl,
|
||||
static BYTE LZMA2_isChunkIncompressible(const FL2_matchTable* const tbl,
|
||||
FL2_dataBlock const block, size_t const start,
|
||||
unsigned const strategy)
|
||||
{
|
||||
@@ -1883,27 +1909,27 @@ static BYTE LZMA2_chunkNotCompressible(const FL2_matchTable* const tbl,
|
||||
static size_t LZMA2_encodeChunk(LZMA2_ECtx *const enc,
|
||||
FL2_matchTable* const tbl,
|
||||
FL2_dataBlock const block,
|
||||
size_t const index, size_t const end)
|
||||
size_t const index, size_t const uncompressed_end)
|
||||
{
|
||||
/* Template-like inline functions */
|
||||
if (enc->strategy == FL2_fast) {
|
||||
if (tbl->is_struct) {
|
||||
return LZMA_encodeChunkFast(enc, block, tbl, 1,
|
||||
index, end);
|
||||
index, uncompressed_end);
|
||||
}
|
||||
else {
|
||||
return LZMA_encodeChunkFast(enc, block, tbl, 0,
|
||||
index, end);
|
||||
index, uncompressed_end);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (tbl->is_struct) {
|
||||
return LZMA_encodeChunkBest(enc, block, tbl, 1,
|
||||
index, end);
|
||||
index, uncompressed_end);
|
||||
}
|
||||
else {
|
||||
return LZMA_encodeChunkBest(enc, block, tbl, 0,
|
||||
index, end);
|
||||
index, uncompressed_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1918,24 +1944,29 @@ size_t LZMA2_encode(LZMA2_ECtx *const enc,
|
||||
int *const canceled)
|
||||
{
|
||||
size_t const start = block.start;
|
||||
|
||||
/* Output starts in the temp buffer */
|
||||
BYTE* out_dest = enc->out_buf;
|
||||
/* Each encoder writes a properties byte because the upstream encoder(s) could */
|
||||
enc->chunk_size = kTempMinOutput;
|
||||
enc->chunk_limit = kTempBufferSize - kMaxMatchEncodeSize * 2;
|
||||
|
||||
/* Each encoder writes a properties byte because the upstream encoder(s) could */
|
||||
/* write only uncompressed chunks with no properties. */
|
||||
BYTE encode_properties = 1;
|
||||
BYTE not_compressible = 0;
|
||||
BYTE incompressible = 0;
|
||||
|
||||
if (block.end <= block.start)
|
||||
return 0;
|
||||
|
||||
enc->lc = options->lc;
|
||||
enc->lp = MIN(options->lp, 4);
|
||||
enc->lp = MIN(options->lp, kNumLiteralPosBitsMax);
|
||||
|
||||
if (enc->lc + enc->lp > 4)
|
||||
enc->lc = 4 - enc->lp;
|
||||
if (enc->lc + enc->lp > kLcLpMax)
|
||||
enc->lc = kLcLpMax - enc->lp;
|
||||
|
||||
enc->pb = options->pb;
|
||||
enc->pb = MIN(options->pb, kNumPositionBitsMax);
|
||||
enc->strategy = options->strategy;
|
||||
enc->fast_length = options->fast_length;
|
||||
enc->fast_length = MIN(options->fast_length, kMatchLenMax);
|
||||
enc->match_cycles = MIN(options->match_cycles, kMatchesMax - 1);
|
||||
|
||||
LZMA2_reset(enc, block.end);
|
||||
@@ -1952,33 +1983,47 @@ size_t LZMA2_encode(LZMA2_ECtx *const enc,
|
||||
enc->hash_prev_index = (start >= (size_t)enc->hash_dict_3) ? (ptrdiff_t)(start - enc->hash_dict_3) : (ptrdiff_t)-1;
|
||||
}
|
||||
enc->len_end_max = kOptimizerBufferSize - 1;
|
||||
|
||||
/* Limit the matches near the end of this slice to not exceed block.end */
|
||||
RMF_limitLengths(tbl, block.end);
|
||||
for (size_t index = start; index < block.end;)
|
||||
{
|
||||
|
||||
for (size_t index = start; index < block.end;) {
|
||||
size_t header_size = (stream_prop >= 0) + (encode_properties ? kChunkHeaderSize + 1 : kChunkHeaderSize);
|
||||
EncoderStates saved_states;
|
||||
size_t next_index;
|
||||
|
||||
RC_reset(&enc->rc);
|
||||
RC_setOutputBuffer(&enc->rc, out_dest + header_size, kChunkSize);
|
||||
if (!not_compressible) {
|
||||
RC_setOutputBuffer(&enc->rc, out_dest + header_size);
|
||||
|
||||
if (!incompressible) {
|
||||
size_t cur = index;
|
||||
size_t const end = (enc->strategy == FL2_fast) ? MIN(block.end, index + kMaxChunkUncompressedSize)
|
||||
: MIN(block.end, index + kMaxChunkUncompressedSize - kOptimizerBufferSize);
|
||||
size_t const end = (enc->strategy == FL2_fast) ? MIN(block.end, index + kMaxChunkUncompressedSize - kMatchLenMax + 1)
|
||||
: MIN(block.end, index + kMaxChunkUncompressedSize - kOptimizerBufferSize + 2); /* last byte of opt_buf unused */
|
||||
|
||||
/* Copy states in case chunk is incompressible */
|
||||
saved_states = enc->states;
|
||||
|
||||
if (index == 0) {
|
||||
/* First byte of the dictionary */
|
||||
LZMA_encodeLiteral(enc, 0, block.data[0], 0);
|
||||
++cur;
|
||||
}
|
||||
if (index == start) {
|
||||
/* After four bytes we can write data to the match table because the */
|
||||
/* After kTempMinOutput bytes we can write data to the match table because the */
|
||||
/* compressed data will never catch up with the table position being read. */
|
||||
enc->rc.chunk_size = kTempMinOutput;
|
||||
cur = LZMA2_encodeChunk(enc, tbl, block, cur, end);
|
||||
enc->rc.chunk_size = kChunkSize;
|
||||
|
||||
if (header_size + enc->rc.out_index > kTempBufferSize)
|
||||
return FL2_ERROR(internal);
|
||||
|
||||
/* Switch to the match table as output buffer */
|
||||
out_dest = RMF_getTableAsOutputBuffer(tbl, start);
|
||||
memcpy(out_dest, enc->out_buf, header_size + enc->rc.out_index);
|
||||
enc->rc.out_buffer = out_dest + header_size;
|
||||
|
||||
/* Now encode up to the full chunk size */
|
||||
enc->chunk_size = kChunkSize;
|
||||
enc->chunk_limit = kMaxChunkCompressedSize - kMaxMatchEncodeSize * 2;
|
||||
}
|
||||
next_index = LZMA2_encodeChunk(enc, tbl, block, cur, end);
|
||||
RC_flush(&enc->rc);
|
||||
@@ -1989,19 +2034,20 @@ size_t LZMA2_encode(LZMA2_ECtx *const enc,
|
||||
size_t compressed_size = enc->rc.out_index;
|
||||
size_t uncompressed_size = next_index - index;
|
||||
|
||||
if (compressed_size > kMaxChunkCompressedSize)
|
||||
if (compressed_size > kMaxChunkCompressedSize || uncompressed_size > kMaxChunkUncompressedSize)
|
||||
return FL2_ERROR(internal);
|
||||
|
||||
BYTE* header = out_dest;
|
||||
|
||||
if (stream_prop >= 0)
|
||||
if (stream_prop >= 0) {
|
||||
*header++ = (BYTE)stream_prop;
|
||||
stream_prop = -1;
|
||||
stream_prop = -1;
|
||||
}
|
||||
|
||||
header[1] = (BYTE)((uncompressed_size - 1) >> 8);
|
||||
header[2] = (BYTE)(uncompressed_size - 1);
|
||||
/* Output an uncompressed chunk if necessary */
|
||||
if (not_compressible || uncompressed_size + 3 <= compressed_size + header_size) {
|
||||
if (incompressible || uncompressed_size + 3 <= compressed_size + header_size) {
|
||||
DEBUGLOG(6, "Storing chunk : was %u => %u", (unsigned)uncompressed_size, (unsigned)compressed_size);
|
||||
|
||||
header[0] = (index == 0) ? kChunkUncompressedDictReset : kChunkUncompressed;
|
||||
@@ -2011,7 +2057,9 @@ size_t LZMA2_encode(LZMA2_ECtx *const enc,
|
||||
|
||||
compressed_size = uncompressed_size;
|
||||
header_size = 3 + (header - out_dest);
|
||||
if (!not_compressible)
|
||||
|
||||
/* Restore states if compression was attempted */
|
||||
if (!incompressible)
|
||||
enc->states = saved_states;
|
||||
}
|
||||
else {
|
||||
@@ -2032,14 +2080,18 @@ size_t LZMA2_encode(LZMA2_ECtx *const enc,
|
||||
encode_properties = 0;
|
||||
}
|
||||
}
|
||||
if (not_compressible || uncompressed_size + 3 <= compressed_size + (compressed_size >> kRandomFilterMarginBits) + header_size) {
|
||||
if (incompressible || uncompressed_size + 3 <= compressed_size + (compressed_size >> kRandomFilterMarginBits) + header_size) {
|
||||
/* Test the next chunk for compressibility */
|
||||
not_compressible = LZMA2_chunkNotCompressible(tbl, block, next_index, enc->strategy);
|
||||
incompressible = LZMA2_isChunkIncompressible(tbl, block, next_index, enc->strategy);
|
||||
}
|
||||
out_dest += compressed_size + header_size;
|
||||
|
||||
/* Update progress concurrently with other encoder threads */
|
||||
FL2_atomic_add(*progress_in, (long)(next_index - index));
|
||||
FL2_atomic_add(*progress_out, (long)(compressed_size + header_size));
|
||||
|
||||
index = next_index;
|
||||
|
||||
if (*canceled)
|
||||
return FL2_ERROR(canceled);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,7 @@ extern "C" {
|
||||
#define kFastDistBits 12U
|
||||
|
||||
#define LZMA2_END_MARKER '\0'
|
||||
#define LZMA_MIN_DICT_BITS 12
|
||||
#define ENC_MIN_BYTES_PER_THREAD 0x20000
|
||||
#define ENC_MIN_BYTES_PER_THREAD 0x1C000 /* Enough for 8 threads, 1 Mb dict, 2/16 overlap */
|
||||
|
||||
|
||||
typedef struct LZMA2_ECtx_s LZMA2_ECtx;
|
||||
@@ -55,6 +54,8 @@ size_t LZMA2_encode(LZMA2_ECtx *const enc,
|
||||
|
||||
BYTE LZMA2_getDictSizeProp(size_t const dictionary_size);
|
||||
|
||||
size_t LZMA2_compressBound(size_t src_size);
|
||||
|
||||
size_t LZMA2_encMemoryUsage(unsigned const chain_log, FL2_strategy const strategy, unsigned const thread_count);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
|
||||
@@ -101,9 +101,7 @@ RMF_match RMF_getMatch(FL2_dataBlock block,
|
||||
size_t const length = GetMatchLength(tbl->table, index);
|
||||
size_t const dist = index - link - 1;
|
||||
|
||||
if (length > block.end - index)
|
||||
match.length = (U32)(block.end - index);
|
||||
else if (length == max_depth || length == STRUCTURED_MAX_LENGTH /* from HandleRepeat */)
|
||||
if (length == max_depth || length == STRUCTURED_MAX_LENGTH /* from HandleRepeat */)
|
||||
match.length = (U32)RMF_structuredExtendMatch(block.data, tbl->table, index, block.end, link, length);
|
||||
else
|
||||
match.length = (U32)length;
|
||||
@@ -125,9 +123,7 @@ RMF_match RMF_getMatch(FL2_dataBlock block,
|
||||
link &= RADIX_LINK_MASK;
|
||||
size_t const dist = index - link - 1;
|
||||
|
||||
if (length > block.end - index)
|
||||
match.length = (U32)(block.end - index);
|
||||
else if (length == max_depth || length == BITPACK_MAX_LENGTH /* from HandleRepeat */)
|
||||
if (length == max_depth || length == BITPACK_MAX_LENGTH /* from HandleRepeat */)
|
||||
match.length = (U32)RMF_bitpackExtendMatch(block.data, tbl->table, index, block.end, link, length);
|
||||
else
|
||||
match.length = (U32)length;
|
||||
@@ -162,9 +158,7 @@ RMF_match RMF_getNextMatch(FL2_dataBlock block,
|
||||
if (link - 1 == GetMatchLink(tbl->table, index - 1))
|
||||
return match;
|
||||
|
||||
if (length > block.end - index)
|
||||
match.length = (U32)(block.end - index);
|
||||
else if (length == max_depth || length == STRUCTURED_MAX_LENGTH /* from HandleRepeat */)
|
||||
if (length == max_depth || length == STRUCTURED_MAX_LENGTH /* from HandleRepeat */)
|
||||
match.length = (U32)RMF_structuredExtendMatch(block.data, tbl->table, index, block.end, link, length);
|
||||
else
|
||||
match.length = (U32)length;
|
||||
@@ -190,9 +184,7 @@ RMF_match RMF_getNextMatch(FL2_dataBlock block,
|
||||
if (link - 1 == (tbl->table[index - 1] & RADIX_LINK_MASK))
|
||||
return match;
|
||||
|
||||
if (length > block.end - index)
|
||||
match.length = (U32)(block.end - index);
|
||||
else if (length == max_depth || length == BITPACK_MAX_LENGTH /* from HandleRepeat */)
|
||||
if (length == max_depth || length == BITPACK_MAX_LENGTH /* from HandleRepeat */)
|
||||
match.length = (U32)RMF_bitpackExtendMatch(block.data, tbl->table, index, block.end, link, length);
|
||||
else
|
||||
match.length = (U32)length;
|
||||
|
||||
@@ -96,6 +96,7 @@ struct FL2_matchTable_s
|
||||
int is_struct;
|
||||
int alloc_struct;
|
||||
unsigned thread_count;
|
||||
size_t unreduced_dict_size;
|
||||
size_t progress;
|
||||
RMF_parameters params;
|
||||
RMF_builder** builders;
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
# pragma warning(disable : 4701) /* warning: 'rpt_head_next' may be used uninitialized in this function */
|
||||
#endif
|
||||
|
||||
#define MATCH_BUFFER_SHIFT 8;
|
||||
#define MATCH_BUFFER_ELBOW_BITS 17
|
||||
#define MATCH_BUFFER_ELBOW (1UL << MATCH_BUFFER_ELBOW_BITS)
|
||||
#define MIN_MATCH_BUFFER_SIZE 256U /* min buffer size at least FL2_SEARCH_DEPTH_MAX + 2 for bounded build */
|
||||
#define MAX_MATCH_BUFFER_SIZE (1UL << 24) /* max buffer size constrained by 24-bit link values */
|
||||
|
||||
@@ -110,15 +113,37 @@ static RMF_parameters RMF_clampParams(RMF_parameters params)
|
||||
if (val<(min)) val=(min); \
|
||||
else if (val>(max)) val=(max); \
|
||||
}
|
||||
# define MAXCLAMP(val,max) { \
|
||||
if (val>(max)) val=(max); \
|
||||
}
|
||||
CLAMP(params.dictionary_size, DICTIONARY_SIZE_MIN, MEM_64bits() ? DICTIONARY_SIZE_MAX_64 : DICTIONARY_SIZE_MAX_32);
|
||||
CLAMP(params.match_buffer_log, RMF_BUFFER_LOG_MIN, RMF_BUFFER_LOG_MAX);
|
||||
if (params.overlap_fraction > FL2_BLOCK_OVERLAP_MAX)
|
||||
params.overlap_fraction = FL2_BLOCK_OVERLAP_MAX;
|
||||
MAXCLAMP(params.match_buffer_resize, FL2_BUFFER_RESIZE_MAX);
|
||||
MAXCLAMP(params.overlap_fraction, FL2_BLOCK_OVERLAP_MAX);
|
||||
CLAMP(params.depth, FL2_SEARCH_DEPTH_MIN, FL2_SEARCH_DEPTH_MAX);
|
||||
return params;
|
||||
# undef MAXCLAMP
|
||||
# undef CLAMP
|
||||
}
|
||||
|
||||
static size_t RMF_calBufSize(size_t dictionary_size, unsigned buffer_resize)
|
||||
{
|
||||
size_t buffer_size = dictionary_size >> MATCH_BUFFER_SHIFT;
|
||||
if (buffer_size > MATCH_BUFFER_ELBOW) {
|
||||
size_t extra = 0;
|
||||
unsigned n = MATCH_BUFFER_ELBOW_BITS - 1;
|
||||
for (; (4UL << n) <= buffer_size; ++n)
|
||||
extra += MATCH_BUFFER_ELBOW >> 4;
|
||||
if((3UL << n) <= buffer_size)
|
||||
extra += MATCH_BUFFER_ELBOW >> 5;
|
||||
buffer_size = MATCH_BUFFER_ELBOW + extra;
|
||||
}
|
||||
if (buffer_resize > 2)
|
||||
buffer_size += buffer_size >> (4 - buffer_resize);
|
||||
else if (buffer_resize < 2)
|
||||
buffer_size -= buffer_size >> (buffer_resize + 1);
|
||||
return buffer_size;
|
||||
}
|
||||
|
||||
/* RMF_applyParameters_internal() :
|
||||
* Set parameters to those specified.
|
||||
* Create a builder table if none exists. Free an existing one if incompatible.
|
||||
@@ -134,7 +159,7 @@ static size_t RMF_applyParameters_internal(FL2_matchTable* const tbl, const RMF_
|
||||
|| (params->dictionary_size == tbl->params.dictionary_size && is_struct > tbl->alloc_struct))
|
||||
return FL2_ERROR(parameter_unsupported);
|
||||
|
||||
size_t const match_buffer_size = params->dictionary_size >> params->match_buffer_log;
|
||||
size_t const match_buffer_size = RMF_calBufSize(tbl->unreduced_dict_size, params->match_buffer_resize);
|
||||
tbl->params = *params;
|
||||
tbl->params.dictionary_size = dictionary_size;
|
||||
tbl->is_struct = is_struct;
|
||||
@@ -161,13 +186,8 @@ static size_t RMF_applyParameters_internal(FL2_matchTable* const tbl, const RMF_
|
||||
*/
|
||||
static void RMF_reduceDict(RMF_parameters* const params, size_t const dict_reduce)
|
||||
{
|
||||
if (dict_reduce) {
|
||||
for (size_t dict_size = params->dictionary_size; dict_size > DICTIONARY_SIZE_MIN && (dict_size >> 1) >= dict_reduce; dict_size >>= 1) {
|
||||
/* Use unchanged match buffer size for reduced dict */
|
||||
params->match_buffer_log = MAX(params->match_buffer_log - 1, RMF_BUFFER_LOG_MIN);
|
||||
}
|
||||
if (dict_reduce)
|
||||
params->dictionary_size = MIN(params->dictionary_size, MAX(dict_reduce, DICTIONARY_SIZE_MIN));
|
||||
}
|
||||
}
|
||||
|
||||
static void RMF_initListHeads(FL2_matchTable* const tbl)
|
||||
@@ -187,6 +207,7 @@ static void RMF_initListHeads(FL2_matchTable* const tbl)
|
||||
FL2_matchTable* RMF_createMatchTable(const RMF_parameters* const p, size_t const dict_reduce, unsigned const thread_count)
|
||||
{
|
||||
RMF_parameters params = RMF_clampParams(*p);
|
||||
size_t unreduced_dict_size = params.dictionary_size;
|
||||
RMF_reduceDict(¶ms, dict_reduce);
|
||||
|
||||
int const is_struct = RMF_isStruct(params.dictionary_size);
|
||||
@@ -195,7 +216,7 @@ FL2_matchTable* RMF_createMatchTable(const RMF_parameters* const p, size_t const
|
||||
DEBUGLOG(3, "RMF_createMatchTable : is_struct %d, dict %u", is_struct, (U32)dictionary_size);
|
||||
|
||||
size_t const table_bytes = is_struct ? ((dictionary_size + 3U) / 4U) * sizeof(RMF_unit)
|
||||
: dictionary_size * sizeof(U32);
|
||||
: dictionary_size * sizeof(U32);
|
||||
FL2_matchTable* const tbl = malloc(sizeof(FL2_matchTable) + table_bytes - sizeof(U32));
|
||||
if (tbl == NULL)
|
||||
return NULL;
|
||||
@@ -204,6 +225,7 @@ FL2_matchTable* RMF_createMatchTable(const RMF_parameters* const p, size_t const
|
||||
tbl->alloc_struct = is_struct;
|
||||
tbl->thread_count = thread_count + !thread_count;
|
||||
tbl->params = params;
|
||||
tbl->unreduced_dict_size = unreduced_dict_size;
|
||||
tbl->builders = NULL;
|
||||
|
||||
RMF_applyParameters_internal(tbl, ¶ms);
|
||||
@@ -298,7 +320,7 @@ typedef struct
|
||||
{
|
||||
size_t index;
|
||||
const BYTE* data_src;
|
||||
union src_data_u src;
|
||||
union src_data_u src;
|
||||
} BruteForceMatch;
|
||||
|
||||
static void RMF_bruteForceBuffered(RMF_builder* const tbl,
|
||||
@@ -705,10 +727,10 @@ BYTE* RMF_getTableAsOutputBuffer(FL2_matchTable* const tbl, size_t const index)
|
||||
return RMF_bitpackAsOutputBuffer(tbl, index);
|
||||
}
|
||||
|
||||
size_t RMF_memoryUsage(size_t const dict_size, unsigned const buffer_log, unsigned const thread_count)
|
||||
size_t RMF_memoryUsage(size_t const dict_size, unsigned const buffer_resize, unsigned const thread_count)
|
||||
{
|
||||
size_t size = (size_t)(4U + RMF_isStruct(dict_size)) * dict_size;
|
||||
size_t const buf_size = dict_size >> (RMF_BUFFER_LOG_BASE - buffer_log);
|
||||
size_t const buf_size = RMF_calBufSize(dict_size, buffer_resize);
|
||||
size += ((buf_size - 1) * sizeof(RMF_buildMatch) + sizeof(RMF_builder)) * thread_count;
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -24,14 +24,10 @@ typedef struct FL2_matchTable_s FL2_matchTable;
|
||||
|
||||
#define RMF_MIN_BYTES_PER_THREAD 1024
|
||||
|
||||
#define RMF_BUFFER_LOG_BASE 12
|
||||
#define RMF_BUFFER_LOG_MIN 6
|
||||
#define RMF_BUFFER_LOG_MAX 12
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t dictionary_size;
|
||||
unsigned match_buffer_log;
|
||||
unsigned match_buffer_resize;
|
||||
unsigned overlap_fraction;
|
||||
unsigned divide_and_conquer;
|
||||
unsigned depth;
|
||||
@@ -56,7 +52,7 @@ void RMF_resetIncompleteBuild(FL2_matchTable* const tbl);
|
||||
int RMF_integrityCheck(const FL2_matchTable* const tbl, const BYTE* const data, size_t const index, size_t const end, unsigned const max_depth);
|
||||
void RMF_limitLengths(FL2_matchTable* const tbl, size_t const index);
|
||||
BYTE* RMF_getTableAsOutputBuffer(FL2_matchTable* const tbl, size_t const index);
|
||||
size_t RMF_memoryUsage(size_t const dict_size, unsigned const buffer_log, unsigned const thread_count);
|
||||
size_t RMF_memoryUsage(size_t const dict_size, unsigned const buffer_resize, unsigned const thread_count);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void RC_printPriceTable()
|
||||
for (Probability i = 31; i <= kBitModelTotal - 31; ++i) {
|
||||
RangeEncoder rc;
|
||||
RC_reset(&rc);
|
||||
RC_setOutputBuffer(&rc, buf, sizeof(buf));
|
||||
RC_setOutputBuffer(&rc, buf);
|
||||
for (unsigned j = 0; j < test_size; ++j) {
|
||||
Probability prob = i;
|
||||
RC_encodeBit0(&rc, &prob);
|
||||
@@ -74,7 +74,7 @@ void RC_printPriceTable()
|
||||
RC_flush(&rc);
|
||||
table0[i >> kNumMoveReducingBits] += (unsigned)rc.out_index - 5;
|
||||
RC_reset(&rc);
|
||||
RC_setOutputBuffer(&rc, buf, sizeof(buf));
|
||||
RC_setOutputBuffer(&rc, buf);
|
||||
for (unsigned j = 0; j < test_size; ++j) {
|
||||
Probability prob = i;
|
||||
RC_encodeBit1(&rc, &prob);
|
||||
@@ -104,10 +104,9 @@ void RC_printPriceTable()
|
||||
|
||||
#endif
|
||||
|
||||
void RC_setOutputBuffer(RangeEncoder* const rc, BYTE *const out_buffer, size_t chunk_size)
|
||||
void RC_setOutputBuffer(RangeEncoder* const rc, BYTE *const out_buffer)
|
||||
{
|
||||
rc->out_buffer = out_buffer;
|
||||
rc->chunk_size = chunk_size;
|
||||
rc->out_index = 0;
|
||||
}
|
||||
|
||||
@@ -125,7 +124,8 @@ void FORCE_NOINLINE RC_shiftLow(RangeEncoder* const rc)
|
||||
{
|
||||
U64 low = rc->low;
|
||||
rc->low = (U32)(low << 8);
|
||||
if (low < 0xFF000000 || low > 0xFFFFFFFF) {
|
||||
/* VC15 compiles 'if (low < 0xFF000000 || low > 0xFFFFFFFF)' to this single-branch conditional */
|
||||
if (low + 0xFFFFFFFF01000000 > 0xFFFFFF) {
|
||||
BYTE high = (BYTE)(low >> 32);
|
||||
rc->out_buffer[rc->out_index++] = rc->cache + high;
|
||||
rc->cache = (BYTE)(low >> 24);
|
||||
|
||||
@@ -40,7 +40,6 @@ typedef struct
|
||||
{
|
||||
BYTE *out_buffer;
|
||||
size_t out_index;
|
||||
size_t chunk_size;
|
||||
U64 cache_size;
|
||||
U64 low;
|
||||
U32 range;
|
||||
@@ -49,7 +48,7 @@ typedef struct
|
||||
|
||||
void RC_reset(RangeEncoder* const rc);
|
||||
|
||||
void RC_setOutputBuffer(RangeEncoder* const rc, BYTE *const out_buffer, size_t chunk_size);
|
||||
void RC_setOutputBuffer(RangeEncoder* const rc, BYTE *const out_buffer);
|
||||
|
||||
void FORCE_NOINLINE RC_shiftLow(RangeEncoder* const rc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user