mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-26 20:12:44 +00:00
MFV: xz 5.6.2.
MFC after: 4 weeks
This commit is contained in:
commit
3b35e7ee8d
@ -2,22 +2,20 @@
|
||||
Authors of XZ Utils
|
||||
===================
|
||||
|
||||
XZ Utils is developed and maintained by Lasse Collin
|
||||
<lasse.collin@tukaani.org> and Jia Tan <jiat0218@gmail.com>.
|
||||
XZ Utils is developed and maintained by
|
||||
Lasse Collin <lasse.collin@tukaani.org>.
|
||||
|
||||
Major parts of liblzma are based on code written by Igor Pavlov,
|
||||
specifically the LZMA SDK <https://7-zip.org/sdk.html>. Without
|
||||
this code, XZ Utils wouldn't exist.
|
||||
|
||||
The SHA-256 implementation in liblzma is based on the code found from
|
||||
7-Zip <https://7-zip.org/>, which has a modified version of the SHA-256
|
||||
code found from Crypto++ <https://www.cryptopp.com/>. The SHA-256 code
|
||||
in Crypto++ was written by Kevin Springle and Wei Dai.
|
||||
The SHA-256 implementation in liblzma is based on code written by
|
||||
Wei Dai in Crypto++ Library <https://www.cryptopp.com/>.
|
||||
|
||||
Some scripts have been adapted from gzip. The original versions
|
||||
were written by Jean-loup Gailly, Charles Levert, and Paul Eggert.
|
||||
Andrew Dudman helped adapting the scripts and their man pages for
|
||||
XZ Utils.
|
||||
A few scripts have been adapted from GNU gzip. The original
|
||||
versions were written by Jean-loup Gailly, Charles Levert, and
|
||||
Paul Eggert. Andrew Dudman helped adapting the scripts and their
|
||||
man pages for XZ Utils.
|
||||
|
||||
The initial version of the threaded .xz decompressor was written
|
||||
by Sebastian Andrzej Siewior.
|
||||
@ -25,15 +23,36 @@ Authors of XZ Utils
|
||||
The initial version of the .lz (lzip) decoder was written
|
||||
by Michał Górny.
|
||||
|
||||
CLMUL-accelerated CRC code was contributed by Ilya Kurdyukov.
|
||||
Architecture-specific CRC optimizations were contributed by
|
||||
Ilya Kurdyukov, Hans Jansen, and Chenxi Mao.
|
||||
|
||||
Other authors:
|
||||
- Jonathan Nieder
|
||||
- Joachim Henke
|
||||
|
||||
The GNU Autotools-based build system contains files from many authors,
|
||||
which I'm not trying to list here.
|
||||
Special author: Jia Tan was a co-maintainer in 2022-2024. He and
|
||||
the team behind him inserted a backdoor (CVE-2024-3094) into
|
||||
XZ Utils 5.6.0 and 5.6.1 releases. He suddenly disappeared when
|
||||
this was discovered.
|
||||
|
||||
Several people have contributed fixes or reported bugs. Most of them
|
||||
are mentioned in the file THANKS.
|
||||
Many people have contributed improvements or reported bugs.
|
||||
Most of these people are mentioned in the file THANKS.
|
||||
|
||||
The translations of the command line tools and man pages have been
|
||||
contributed by many people via the Translation Project:
|
||||
|
||||
- https://translationproject.org/domain/xz.html
|
||||
- https://translationproject.org/domain/xz-man.html
|
||||
|
||||
The authors of the translated man pages are in the header comments
|
||||
of the man page files. In the source package, the authors of the
|
||||
translations are in po/*.po and po4a/*.po files.
|
||||
|
||||
Third-party code whose authors aren't listed here:
|
||||
|
||||
- GNU getopt_long() in the 'lib' directory is included for
|
||||
platforms that don't have a usable getopt_long().
|
||||
|
||||
- The build system files from GNU Autoconf, GNU Automake,
|
||||
GNU Libtool, GNU Gettext, Autoconf Archive, and related files.
|
||||
|
||||
|
@ -3,74 +3,81 @@ XZ Utils Licensing
|
||||
==================
|
||||
|
||||
Different licenses apply to different files in this package. Here
|
||||
is a rough summary of which licenses apply to which parts of this
|
||||
package (but check the individual files to be sure!):
|
||||
is a summary of which licenses apply to which parts of this package:
|
||||
|
||||
- liblzma is in the public domain.
|
||||
- liblzma is under the BSD Zero Clause License (0BSD).
|
||||
|
||||
- xz, xzdec, and lzmadec command line tools are in the public
|
||||
domain unless GNU getopt_long had to be compiled and linked
|
||||
in from the lib directory. The getopt_long code is under
|
||||
GNU LGPLv2.1+.
|
||||
- The command line tools xz, xzdec, lzmadec, and lzmainfo are
|
||||
under 0BSD except that, on systems that don't have a usable
|
||||
getopt_long, GNU getopt_long is compiled and linked in from the
|
||||
'lib' directory. The getopt_long code is under GNU LGPLv2.1+.
|
||||
|
||||
- The scripts to grep, diff, and view compressed files have been
|
||||
adapted from gzip. These scripts and their documentation are
|
||||
under GNU GPLv2+.
|
||||
adapted from GNU gzip. These scripts (xzgrep, xzdiff, xzless,
|
||||
and xzmore) are under GNU GPLv2+. The man pages of the scripts
|
||||
are under 0BSD; they aren't based on the man pages of GNU gzip.
|
||||
|
||||
- All the documentation in the doc directory and most of the
|
||||
XZ Utils specific documentation files in other directories
|
||||
are in the public domain.
|
||||
- Most of the XZ Utils specific documentation that is in
|
||||
plain text files (like README, INSTALL, PACKAGERS, NEWS,
|
||||
and ChangeLog) are under 0BSD unless stated otherwise in
|
||||
the file itself. The files xz-file-format.txt and
|
||||
lzma-file-format.xt are in the public domain but may
|
||||
be distributed under the terms of 0BSD too.
|
||||
|
||||
Note: The JavaScript files (under the MIT license) have
|
||||
been removed from the Doxygen-generated HTML version of the
|
||||
liblzma API documentation. Doxygen itself is under the GNU GPL
|
||||
but the remaining files generated by Doxygen are not affected
|
||||
by the licenses used in Doxygen because Doxygen licensing has
|
||||
the following exception:
|
||||
- Translated messages and man pages are under 0BSD except that
|
||||
some old translations are in the public domain.
|
||||
|
||||
"Documents produced by doxygen are derivative works
|
||||
derived from the input used in their production;
|
||||
they are not affected by this license."
|
||||
- Test files and test code in the 'tests' directory, and
|
||||
debugging utilities in the 'debug' directory are under
|
||||
the BSD Zero Clause License (0BSD).
|
||||
|
||||
- Translated messages are in the public domain.
|
||||
- The GNU Autotools based build system contains files that are
|
||||
under GNU GPLv2+, GNU GPLv3+, and a few permissive licenses.
|
||||
These files don't affect the licensing of the binaries being
|
||||
built.
|
||||
|
||||
- The build system contains public domain files, and files that
|
||||
are under GNU GPLv2+ or GNU GPLv3+. None of these files end up
|
||||
in the binaries being built.
|
||||
- The 'extra' directory contains files that are under various
|
||||
free software licenses. These aren't built or installed as
|
||||
part of XZ Utils.
|
||||
|
||||
- Test files and test code in the tests directory, and debugging
|
||||
utilities in the debug directory are in the public domain.
|
||||
For the files under the BSD Zero Clause License (0BSD), if
|
||||
a copyright notice is needed, the following is sufficient:
|
||||
|
||||
- The extra directory may contain public domain files, and files
|
||||
that are under various free software licenses.
|
||||
Copyright (C) The XZ Utils authors and contributors
|
||||
|
||||
You can do whatever you want with the files that have been put into
|
||||
the public domain. If you find public domain legally problematic,
|
||||
take the previous sentence as a license grant. If you still find
|
||||
the lack of copyright legally problematic, you have too many
|
||||
lawyers.
|
||||
|
||||
As usual, this software is provided "as is", without any warranty.
|
||||
|
||||
If you copy significant amounts of public domain code from XZ Utils
|
||||
If you copy significant amounts of 0BSD-licensed code from XZ Utils
|
||||
into your project, acknowledging this somewhere in your software is
|
||||
polite (especially if it is proprietary, non-free software), but
|
||||
naturally it is not legally required. Here is an example of a good
|
||||
notice to put into "about box" or into documentation:
|
||||
it is not legally required by the license terms. Here is an example
|
||||
of a good notice to put into "about box" or into documentation:
|
||||
|
||||
This software includes code from XZ Utils <https://tukaani.org/xz/>.
|
||||
|
||||
The following license texts are included in the following files:
|
||||
- COPYING.0BSD: BSD Zero Clause License
|
||||
- COPYING.LGPLv2.1: GNU Lesser General Public License version 2.1
|
||||
- COPYING.GPLv2: GNU General Public License version 2
|
||||
- COPYING.GPLv3: GNU General Public License version 3
|
||||
|
||||
Note that the toolchain (compiler, linker etc.) may add some code
|
||||
pieces that are copyrighted. Thus, it is possible that e.g. liblzma
|
||||
binary wouldn't actually be in the public domain in its entirety
|
||||
even though it contains no copyrighted code from the XZ Utils source
|
||||
package.
|
||||
A note about old XZ Utils releases:
|
||||
|
||||
If you have questions, don't hesitate to ask the author(s) for more
|
||||
information.
|
||||
XZ Utils releases 5.4.6 and older and 5.5.1alpha have a
|
||||
significant amount of code put into the public domain and
|
||||
that obviously remains so. The switch from public domain to
|
||||
0BSD for newer releases was made in Febrary 2024 because
|
||||
public domain has (real or perceived) legal ambiguities in
|
||||
some jurisdictions.
|
||||
|
||||
There is very little *practical* difference between public
|
||||
domain and 0BSD. The main difference likely is that one
|
||||
shouldn't claim that 0BSD-licensed code is in the public
|
||||
domain; 0BSD-licensed code is copyrighted but available under
|
||||
an extremely permissive license. Neither 0BSD nor public domain
|
||||
require retaining or reproducing author, copyright holder, or
|
||||
license notices when distributing the software. (Compare to,
|
||||
for example, BSD 2-Clause "Simplified" License which does have
|
||||
such requirements.)
|
||||
|
||||
If you have questions, don't hesitate to ask for more information.
|
||||
The contact information is in the README file.
|
||||
|
||||
|
11
contrib/xz/COPYING.0BSD
Normal file
11
contrib/xz/COPYING.0BSD
Normal file
@ -0,0 +1,11 @@
|
||||
Permission to use, copy, modify, and/or distribute this
|
||||
software for any purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
18110
contrib/xz/ChangeLog
18110
contrib/xz/ChangeLog
File diff suppressed because it is too large
Load Diff
@ -67,24 +67,25 @@ XZ Utils
|
||||
|
||||
1.1. Overall documentation
|
||||
|
||||
README This file
|
||||
README This file
|
||||
|
||||
INSTALL.generic Generic install instructions for those not familiar
|
||||
with packages using GNU Autotools
|
||||
INSTALL Installation instructions specific to XZ Utils
|
||||
PACKAGERS Information to packagers of XZ Utils
|
||||
INSTALL.generic Generic install instructions for those not
|
||||
familiar with packages using GNU Autotools
|
||||
INSTALL Installation instructions specific to XZ Utils
|
||||
PACKAGERS Information to packagers of XZ Utils
|
||||
|
||||
COPYING XZ Utils copyright and license information
|
||||
COPYING.GPLv2 GNU General Public License version 2
|
||||
COPYING.GPLv3 GNU General Public License version 3
|
||||
COPYING.LGPLv2.1 GNU Lesser General Public License version 2.1
|
||||
COPYING XZ Utils copyright and license information
|
||||
COPYING.0BSD BSD Zero Clause License
|
||||
COPYING.GPLv2 GNU General Public License version 2
|
||||
COPYING.GPLv3 GNU General Public License version 3
|
||||
COPYING.LGPLv2.1 GNU Lesser General Public License version 2.1
|
||||
|
||||
AUTHORS The main authors of XZ Utils
|
||||
THANKS Incomplete list of people who have helped making
|
||||
this software
|
||||
NEWS User-visible changes between XZ Utils releases
|
||||
ChangeLog Detailed list of changes (commit log)
|
||||
TODO Known bugs and some sort of to-do list
|
||||
AUTHORS The main authors of XZ Utils
|
||||
THANKS Incomplete list of people who have helped making
|
||||
this software
|
||||
NEWS User-visible changes between XZ Utils releases
|
||||
ChangeLog Detailed list of changes (commit log)
|
||||
TODO Known bugs and some sort of to-do list
|
||||
|
||||
Note that only some of the above files are included in binary
|
||||
packages.
|
||||
@ -94,9 +95,9 @@ XZ Utils
|
||||
|
||||
The command-line tools are documented as man pages. In source code
|
||||
releases (and possibly also in some binary packages), the man pages
|
||||
are also provided in plain text (ASCII only) and PDF formats in the
|
||||
directory "doc/man" to make the man pages more accessible to those
|
||||
whose operating system doesn't provide an easy way to view man pages.
|
||||
are also provided in plain text (ASCII only) format in the directory
|
||||
"doc/man" to make the man pages more accessible to those whose
|
||||
operating system doesn't provide an easy way to view man pages.
|
||||
|
||||
|
||||
1.3. Documentation for liblzma
|
||||
@ -297,11 +298,13 @@ XZ Utils
|
||||
6. Contact information
|
||||
----------------------
|
||||
|
||||
If you have questions, bug reports, patches etc. related to XZ Utils,
|
||||
the project maintainers Lasse Collin and Jia Tan can be reached via
|
||||
<xz@tukaani.org>.
|
||||
XZ Utils in general:
|
||||
- Home page: https://tukaani.org/xz/
|
||||
- Email to maintainer(s): xz@tukaani.org
|
||||
- IRC: #tukaani on Libera Chat
|
||||
- GitHub: https://github.com/tukaani-project/xz
|
||||
|
||||
You might find Lasse also from #tukaani on Libera Chat (IRC).
|
||||
The nick is Larhzu. The channel tends to be pretty quiet,
|
||||
so just ask your question and someone might wake up.
|
||||
Lead maintainer:
|
||||
- Email: Lasse Collin <lasse.collin@tukaani.org>
|
||||
- IRC: Larhzu on Libera Chat
|
||||
|
||||
|
@ -5,6 +5,7 @@ Thanks
|
||||
Some people have helped more, some less, but nevertheless everyone's help
|
||||
has been important. :-) In alphabetical order:
|
||||
- Mark Adler
|
||||
- Kian-Meng Ang
|
||||
- H. Peter Anvin
|
||||
- Jeff Bastian
|
||||
- Nelson H. F. Beebe
|
||||
@ -45,15 +46,18 @@ has been important. :-) In alphabetical order:
|
||||
- Vincent Fazio
|
||||
- Michael Felt
|
||||
- Michael Fox
|
||||
- Andres Freund
|
||||
- Mike Frysinger
|
||||
- Daniel Richard G.
|
||||
- Tomasz Gajc
|
||||
- Bjarni Ingi Gislason
|
||||
- John Paul Adrian Glaubitz
|
||||
- Bill Glessner
|
||||
- Matthew Good
|
||||
- Michał Górny
|
||||
- Jason Gorski
|
||||
- Juan Manuel Guerrero
|
||||
- Gabriela Gutierrez
|
||||
- Diederik de Haas
|
||||
- Joachim Henke
|
||||
- Christian Hesse
|
||||
@ -62,6 +66,7 @@ has been important. :-) In alphabetical order:
|
||||
- Nicholas Jackson
|
||||
- Sam James
|
||||
- Hajin Jang
|
||||
- Hans Jansen
|
||||
- Jouk Jansen
|
||||
- Jun I Jin
|
||||
- Kiyoshi Kanazawa
|
||||
@ -72,6 +77,7 @@ has been important. :-) In alphabetical order:
|
||||
- Richard Koch
|
||||
- Anton Kochkov
|
||||
- Ville Koskinen
|
||||
- Sergey Kosukhin
|
||||
- Marcin Kowalczyk
|
||||
- Jan Kratochvil
|
||||
- Christian Kujau
|
||||
@ -79,6 +85,7 @@ has been important. :-) In alphabetical order:
|
||||
- Ilya Kurdyukov
|
||||
- Peter Lawler
|
||||
- James M Leddy
|
||||
- Kelvin Lee
|
||||
- Vincent Lefevre
|
||||
- Hin-Tak Leung
|
||||
- Andraž 'ruskie' Levstik
|
||||
@ -89,6 +96,7 @@ has been important. :-) In alphabetical order:
|
||||
- Lorenzo De Liso
|
||||
- H.J. Lu
|
||||
- Bela Lubkin
|
||||
- Chenxi Mao
|
||||
- Gregory Margo
|
||||
- Julien Marrec
|
||||
- Ed Maste
|
||||
@ -144,12 +152,12 @@ has been important. :-) In alphabetical order:
|
||||
- Martin Storsjö
|
||||
- Jonathan Stott
|
||||
- Dan Stromberg
|
||||
- Jia Tan
|
||||
- Vincent Torri
|
||||
- Alexey Tourbin
|
||||
- Paul Townsend
|
||||
- Mohammed Adnène Trojette
|
||||
- Alexey Tourbin
|
||||
- Taiki Tsunekawa
|
||||
- Maksym Vatsyk
|
||||
- Loganaden Velvindron
|
||||
- Patrick J. Volkerding
|
||||
- Martin Väth
|
||||
@ -164,6 +172,7 @@ has been important. :-) In alphabetical order:
|
||||
- Charles Wilson
|
||||
- Lars Wirzenius
|
||||
- Pilorz Wojciech
|
||||
- Chien Wong
|
||||
- Ryan Young
|
||||
- Andreas Zieringer
|
||||
|
||||
|
@ -24,10 +24,6 @@ Known bugs
|
||||
|
||||
tuklib_exit() doesn't block signals => EINTR is possible.
|
||||
|
||||
SIGTSTP is not handled. If xz is stopped, the estimated remaining
|
||||
time and calculated (de)compression speed won't make sense in the
|
||||
progress indicator (xz --verbose).
|
||||
|
||||
If liblzma has created threads and fork() gets called, liblzma
|
||||
code will break in the child process unless it calls exec() and
|
||||
doesn't touch liblzma.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,53 +1,86 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: 0BSD
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
# Updates the Doxygen generated documentation files in the source tree.
|
||||
# If the doxygen command is not installed, it will exit with an error.
|
||||
# This script can generate Doxygen documentation for all source files or for
|
||||
# just liblzma API header files.
|
||||
# While it's possible to use the Doxyfile as is to generate liblzma API
|
||||
# documentation, it is recommended to use this script because this adds
|
||||
# the XZ Utils version number to the generated HTML.
|
||||
#
|
||||
# It is recommended to use this script to update the Doxygen-generated HTML
|
||||
# files since this will include the package version in the output and,
|
||||
# in case of liblzma API docs, strip JavaScript files from the output.
|
||||
# Other features:
|
||||
# - Generate documentation of the XZ Utils internals.
|
||||
# - Set input and output paths for out-of-tree builds.
|
||||
#
|
||||
#############################################################################
|
||||
#
|
||||
# Authors: Jia Tan
|
||||
# Lasse Collin
|
||||
#
|
||||
# This file has been put into the public domain.
|
||||
# You can do whatever you want with this file.
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
set -e
|
||||
|
||||
show_usage()
|
||||
{
|
||||
echo "Usage: $0 <api|internal> [ABS_TOP_SRCDIR ABS_OUTDIR]"
|
||||
echo
|
||||
echo "Supported modes:"
|
||||
echo " - 'api' (default): liblzma API docs into doc/api"
|
||||
echo " - 'internal': internal docs into doc/internal"
|
||||
echo
|
||||
echo "Absolute source and output dirs may be set" \
|
||||
"to do an out-of-tree build."
|
||||
echo "The output directory must already exist."
|
||||
exit 1
|
||||
}
|
||||
|
||||
case $1 in
|
||||
api|internal)
|
||||
;;
|
||||
*)
|
||||
show_usage
|
||||
;;
|
||||
esac
|
||||
|
||||
if type doxygen > /dev/null 2>&1; then
|
||||
:
|
||||
else
|
||||
echo "doxygen/update-doxygen: 'doxygen' command not found." >&2
|
||||
echo "doxygen/update-doxygen: Skipping Doxygen docs generation." >&2
|
||||
echo "$0: 'doxygen' command not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test ! -f Doxyfile; then
|
||||
cd `dirname "$0"` || exit 1
|
||||
if test ! -f Doxyfile; then
|
||||
echo "doxygen/update-doxygen: Cannot find Doxyfile" >&2
|
||||
exit 1
|
||||
fi
|
||||
case $# in
|
||||
1)
|
||||
# One argument: Building inside the source tree
|
||||
ABS_TOP_SRCDIR=`dirname "$0"`/..
|
||||
ABS_OUTDIR=$ABS_TOP_SRCDIR/doc
|
||||
;;
|
||||
3)
|
||||
# Three arguments: Possibly an out of tree build
|
||||
ABS_TOP_SRCDIR=$2
|
||||
ABS_OUTDIR=$3
|
||||
;;
|
||||
*)
|
||||
show_usage
|
||||
;;
|
||||
esac
|
||||
|
||||
if test ! -f "$ABS_TOP_SRCDIR/doxygen/Doxyfile"; then
|
||||
echo "$0: Source dir '$ABS_TOP_SRCDIR/doxygen/Doxyfile' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
if test ! -d "$ABS_OUTDIR"; then
|
||||
echo "$0: Output dir '$ABS_OUTDIR' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the package version so that it can be included in the generated docs.
|
||||
PACKAGE_VERSION=`cd .. && sh build-aux/version.sh` || exit 1
|
||||
PACKAGE_VERSION=`cd "$ABS_TOP_SRCDIR" && sh build-aux/version.sh`
|
||||
|
||||
# If no arguments are specified, default to generating liblzma API header
|
||||
# documentation only.
|
||||
case $1 in
|
||||
'' | api)
|
||||
api)
|
||||
# Remove old documentation before re-generating the new.
|
||||
rm -rf ../doc/api
|
||||
rm -rf "$ABS_OUTDIR/api"
|
||||
|
||||
# Generate the HTML documentation by preparing the Doxyfile
|
||||
# in stdin and piping the result to the doxygen command.
|
||||
@ -55,57 +88,27 @@ case $1 in
|
||||
# override any earlier assignment. So, we can use this
|
||||
# feature to override the tags that need to change between
|
||||
# "api" and "internal" modes.
|
||||
ABS_SRCDIR=$ABS_TOP_SRCDIR/src/liblzma/api
|
||||
(
|
||||
cat Doxyfile
|
||||
cat "$ABS_TOP_SRCDIR/doxygen/Doxyfile"
|
||||
echo "PROJECT_NUMBER = $PACKAGE_VERSION"
|
||||
) | doxygen -
|
||||
|
||||
# As of Doxygen 1.8.0 - 1.9.6 and the Doxyfile options we use,
|
||||
# the output is good without any JavaScript. Unfortunately
|
||||
# Doxygen doesn't have an option to disable JavaScript usage
|
||||
# completely so we strip it away with the hack below.
|
||||
#
|
||||
# Omitting the JavaScript code avoids some license hassle
|
||||
# as jquery.js is fairly big, it contains more than jQuery
|
||||
# itself, and doesn't include the actual license text (it
|
||||
# only refers to the MIT license by name).
|
||||
echo "Stripping JavaScript from Doxygen output..."
|
||||
for F in ../doc/api/*.html
|
||||
do
|
||||
sed 's/<script [^>]*><\/script>//g
|
||||
s/onclick="[^"]*"//g' \
|
||||
"$F" > ../doc/api/tmp
|
||||
mv -f ../doc/api/tmp "$F"
|
||||
done
|
||||
rm -f ../doc/api/*.js
|
||||
echo "OUTPUT_DIRECTORY = $ABS_OUTDIR"
|
||||
echo "STRIP_FROM_PATH = $ABS_SRCDIR"
|
||||
echo "INPUT = $ABS_SRCDIR"
|
||||
) | doxygen -q -
|
||||
;;
|
||||
|
||||
internal)
|
||||
# The docs from internal aren't for distribution so
|
||||
# the JavaScript files aren't an issue here.
|
||||
rm -rf ../doc/internal
|
||||
rm -rf "$ABS_OUTDIR/internal"
|
||||
(
|
||||
cat Doxyfile
|
||||
echo "PROJECT_NUMBER = $PACKAGE_VERSION"
|
||||
cat "$ABS_TOP_SRCDIR/doxygen/Doxyfile"
|
||||
echo 'PROJECT_NAME = "XZ Utils"'
|
||||
echo 'STRIP_FROM_PATH = ../src'
|
||||
echo 'INPUT = ../src'
|
||||
echo "PROJECT_NUMBER = $PACKAGE_VERSION"
|
||||
echo "OUTPUT_DIRECTORY = $ABS_OUTDIR"
|
||||
echo "STRIP_FROM_PATH = $ABS_TOP_SRCDIR"
|
||||
echo "INPUT = $ABS_TOP_SRCDIR/src"
|
||||
echo 'HTML_OUTPUT = internal'
|
||||
echo 'EXTRACT_PRIVATE = YES'
|
||||
echo 'EXTRACT_STATIC = YES'
|
||||
echo 'EXTRACT_LOCAL_CLASSES = YES'
|
||||
echo 'SEARCHENGINE = YES'
|
||||
) | doxygen -
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "doxygen/update-doxygen: Error: mode argument '$1'" \
|
||||
"is not supported." >&2
|
||||
echo "doxygen/update-doxygen: Supported modes:" >&2
|
||||
echo "doxygen/update-doxygen: - 'api' (default):" \
|
||||
"liblzma API docs into doc/api" >&2
|
||||
echo "doxygen/update-doxygen: - 'internal':"\
|
||||
"internal docs into doc/internal" >&2
|
||||
exit 1
|
||||
) | doxygen -q -
|
||||
;;
|
||||
esac
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file mythread.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MYTHREAD_H
|
||||
@ -112,6 +111,25 @@ mythread_sigmask(int how, const sigset_t *restrict set,
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
// MinGW-w64 with winpthreads:
|
||||
//
|
||||
// NOTE: Typical builds with MinGW-w64 don't use this code (MYTHREAD_POSIX).
|
||||
// Instead, native Windows threading APIs are used (MYTHREAD_VISTA or
|
||||
// MYTHREAD_WIN95).
|
||||
//
|
||||
// MinGW-w64 has _sigset_t (an integer type) in <sys/types.h>.
|
||||
// If _POSIX was #defined, the header would add the alias sigset_t too.
|
||||
// Let's keep this working even without _POSIX.
|
||||
//
|
||||
// There are no functions that actually do something with sigset_t
|
||||
// because signals barely exist on Windows. The sigfillset macro below
|
||||
// is just to silence warnings. There is no sigfillset() in MinGW-w64.
|
||||
#ifdef __MINGW32__
|
||||
# include <sys/types.h>
|
||||
# define sigset_t _sigset_t
|
||||
# define sigfillset(set_ptr) do { *(set_ptr) = 0; } while (0)
|
||||
#endif
|
||||
|
||||
#define MYTHREAD_RET_TYPE void *
|
||||
#define MYTHREAD_RET_VALUE NULL
|
||||
|
||||
@ -140,11 +158,13 @@ typedef struct timespec mythread_condtime;
|
||||
|
||||
// Use pthread_sigmask() to set the signal mask in multi-threaded programs.
|
||||
// Do nothing on OpenVMS since it lacks pthread_sigmask().
|
||||
// Do nothing on MinGW-w64 too to silence warnings (its pthread_sigmask()
|
||||
// is #defined to 0 so it's a no-op).
|
||||
static inline void
|
||||
mythread_sigmask(int how, const sigset_t *restrict set,
|
||||
sigset_t *restrict oset)
|
||||
{
|
||||
#ifdef __VMS
|
||||
#if defined(__VMS) || defined(__MINGW32__)
|
||||
(void)how;
|
||||
(void)set;
|
||||
(void)oset;
|
||||
@ -180,7 +200,7 @@ mythread_join(mythread thread)
|
||||
}
|
||||
|
||||
|
||||
// Initiatlizes a mutex. Returns zero on success and non-zero on error.
|
||||
// Initializes a mutex. Returns zero on success and non-zero on error.
|
||||
static inline int
|
||||
mythread_mutex_init(mythread_mutex *mutex)
|
||||
{
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file sysdefs.h
|
||||
@ -8,9 +10,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_SYSDEFS_H
|
||||
@ -159,13 +158,16 @@ typedef unsigned char _Bool;
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// As of MSVC 2013, inline and restrict are supported with
|
||||
// non-standard keywords.
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
# ifndef inline
|
||||
// Visual Studio 2013 update 2 supports only __inline, not inline.
|
||||
// MSVC v19.0 / VS 2015 and newer support both.
|
||||
//
|
||||
// MSVC v19.27 (VS 2019 version 16.7) added support for restrict.
|
||||
// Older ones support only __restrict.
|
||||
#ifdef _MSC_VER
|
||||
# if _MSC_VER < 1900 && !defined(inline)
|
||||
# define inline __inline
|
||||
# endif
|
||||
# ifndef restrict
|
||||
# if _MSC_VER < 1927 && !defined(restrict)
|
||||
# define restrict __restrict
|
||||
# endif
|
||||
#endif
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_common.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_COMMON_H
|
||||
@ -57,8 +56,28 @@
|
||||
# define TUKLIB_GNUC_REQ(major, minor) 0
|
||||
#endif
|
||||
|
||||
#if TUKLIB_GNUC_REQ(2, 5)
|
||||
// tuklib_attr_noreturn attribute is used to mark functions as non-returning.
|
||||
// We cannot use "noreturn" as the macro name because then C23 code that
|
||||
// uses [[noreturn]] would break as it would expand to [[ [[noreturn]] ]].
|
||||
//
|
||||
// tuklib_attr_noreturn must be used at the beginning of function declaration
|
||||
// to work in all cases. The [[noreturn]] syntax is the most limiting, it
|
||||
// must be even before any GNU C's __attribute__ keywords:
|
||||
//
|
||||
// tuklib_attr_noreturn
|
||||
// __attribute__((nonnull(1)))
|
||||
// extern void foo(const char *s);
|
||||
//
|
||||
// FIXME: Update __STDC_VERSION__ for the final C23 version. 202000 is used
|
||||
// by GCC 13 and Clang 15 with -std=c2x.
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000
|
||||
# define tuklib_attr_noreturn [[noreturn]]
|
||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112
|
||||
# define tuklib_attr_noreturn _Noreturn
|
||||
#elif TUKLIB_GNUC_REQ(2, 5)
|
||||
# define tuklib_attr_noreturn __attribute__((__noreturn__))
|
||||
#elif defined(_MSC_VER)
|
||||
# define tuklib_attr_noreturn __declspec(noreturn)
|
||||
#else
|
||||
# define tuklib_attr_noreturn
|
||||
#endif
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
// If config.h isn't available, assume that the headers required by
|
||||
// tuklib_common.h are available. This is required by crc32_tablegen.c.
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_cpucores.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "tuklib_cpucores.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_cpucores.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_CPUCORES_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_exit.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "tuklib_common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_exit.h
|
||||
@ -6,9 +8,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_EXIT_H
|
||||
@ -18,8 +17,8 @@
|
||||
TUKLIB_DECLS_BEGIN
|
||||
|
||||
#define tuklib_exit TUKLIB_SYMBOL(tuklib_exit)
|
||||
extern void tuklib_exit(int status, int err_status, int show_error)
|
||||
tuklib_attr_noreturn;
|
||||
tuklib_attr_noreturn
|
||||
extern void tuklib_exit(int status, int err_status, int show_error);
|
||||
|
||||
TUKLIB_DECLS_END
|
||||
#endif
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_gettext.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_GETTEXT_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_integer.h
|
||||
@ -14,7 +16,7 @@
|
||||
///
|
||||
/// Endianness-converting integer operations (these can be macros!)
|
||||
/// (XX = 16, 32, or 64; Y = b or l):
|
||||
/// - Byte swapping: bswapXX(num)
|
||||
/// - Byte swapping: byteswapXX(num)
|
||||
/// - Byte order conversions to/from native (byteswaps if Y isn't
|
||||
/// the native endianness): convXXYe(num)
|
||||
/// - Unaligned reads: readXXYe(ptr)
|
||||
@ -37,9 +39,6 @@
|
||||
// Authors: Lasse Collin
|
||||
// Joachim Henke
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_INTEGER_H
|
||||
@ -67,38 +66,41 @@
|
||||
|
||||
#if defined(HAVE___BUILTIN_BSWAPXX)
|
||||
// GCC >= 4.8 and Clang
|
||||
# define bswap16(n) __builtin_bswap16(n)
|
||||
# define bswap32(n) __builtin_bswap32(n)
|
||||
# define bswap64(n) __builtin_bswap64(n)
|
||||
# define byteswap16(num) __builtin_bswap16(num)
|
||||
# define byteswap32(num) __builtin_bswap32(num)
|
||||
# define byteswap64(num) __builtin_bswap64(num)
|
||||
|
||||
#elif defined(HAVE_BYTESWAP_H)
|
||||
// glibc, uClibc, dietlibc
|
||||
# include <byteswap.h>
|
||||
# ifdef HAVE_BSWAP_16
|
||||
# define bswap16(num) bswap_16(num)
|
||||
# define byteswap16(num) bswap_16(num)
|
||||
# endif
|
||||
# ifdef HAVE_BSWAP_32
|
||||
# define bswap32(num) bswap_32(num)
|
||||
# define byteswap32(num) bswap_32(num)
|
||||
# endif
|
||||
# ifdef HAVE_BSWAP_64
|
||||
# define bswap64(num) bswap_64(num)
|
||||
# define byteswap64(num) bswap_64(num)
|
||||
# endif
|
||||
|
||||
#elif defined(HAVE_SYS_ENDIAN_H)
|
||||
// *BSDs and Darwin
|
||||
# include <sys/endian.h>
|
||||
# define byteswap16(num) bswap16(num)
|
||||
# define byteswap32(num) bswap32(num)
|
||||
# define byteswap64(num) bswap64(num)
|
||||
|
||||
#elif defined(HAVE_SYS_BYTEORDER_H)
|
||||
// Solaris
|
||||
# include <sys/byteorder.h>
|
||||
# ifdef BSWAP_16
|
||||
# define bswap16(num) BSWAP_16(num)
|
||||
# define byteswap16(num) BSWAP_16(num)
|
||||
# endif
|
||||
# ifdef BSWAP_32
|
||||
# define bswap32(num) BSWAP_32(num)
|
||||
# define byteswap32(num) BSWAP_32(num)
|
||||
# endif
|
||||
# ifdef BSWAP_64
|
||||
# define bswap64(num) BSWAP_64(num)
|
||||
# define byteswap64(num) BSWAP_64(num)
|
||||
# endif
|
||||
# ifdef BE_16
|
||||
# define conv16be(num) BE_16(num)
|
||||
@ -120,15 +122,15 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef bswap16
|
||||
# define bswap16(n) (uint16_t)( \
|
||||
#ifndef byteswap16
|
||||
# define byteswap16(n) (uint16_t)( \
|
||||
(((n) & 0x00FFU) << 8) \
|
||||
| (((n) & 0xFF00U) >> 8) \
|
||||
)
|
||||
#endif
|
||||
|
||||
#ifndef bswap32
|
||||
# define bswap32(n) (uint32_t)( \
|
||||
#ifndef byteswap32
|
||||
# define byteswap32(n) (uint32_t)( \
|
||||
(((n) & UINT32_C(0x000000FF)) << 24) \
|
||||
| (((n) & UINT32_C(0x0000FF00)) << 8) \
|
||||
| (((n) & UINT32_C(0x00FF0000)) >> 8) \
|
||||
@ -136,8 +138,8 @@
|
||||
)
|
||||
#endif
|
||||
|
||||
#ifndef bswap64
|
||||
# define bswap64(n) (uint64_t)( \
|
||||
#ifndef byteswap64
|
||||
# define byteswap64(n) (uint64_t)( \
|
||||
(((n) & UINT64_C(0x00000000000000FF)) << 56) \
|
||||
| (((n) & UINT64_C(0x000000000000FF00)) << 40) \
|
||||
| (((n) & UINT64_C(0x0000000000FF0000)) << 24) \
|
||||
@ -161,23 +163,23 @@
|
||||
# define conv64be(num) ((uint64_t)(num))
|
||||
# endif
|
||||
# ifndef conv16le
|
||||
# define conv16le(num) bswap16(num)
|
||||
# define conv16le(num) byteswap16(num)
|
||||
# endif
|
||||
# ifndef conv32le
|
||||
# define conv32le(num) bswap32(num)
|
||||
# define conv32le(num) byteswap32(num)
|
||||
# endif
|
||||
# ifndef conv64le
|
||||
# define conv64le(num) bswap64(num)
|
||||
# define conv64le(num) byteswap64(num)
|
||||
# endif
|
||||
#else
|
||||
# ifndef conv16be
|
||||
# define conv16be(num) bswap16(num)
|
||||
# define conv16be(num) byteswap16(num)
|
||||
# endif
|
||||
# ifndef conv32be
|
||||
# define conv32be(num) bswap32(num)
|
||||
# define conv32be(num) byteswap32(num)
|
||||
# endif
|
||||
# ifndef conv64be
|
||||
# define conv64be(num) bswap64(num)
|
||||
# define conv64be(num) byteswap64(num)
|
||||
# endif
|
||||
# ifndef conv16le
|
||||
# define conv16le(num) ((uint16_t)(num))
|
||||
@ -251,7 +253,7 @@
|
||||
// was one instruction longer.
|
||||
//
|
||||
// Conclusion: At least in case of GCC and Clang, byte-by-byte code is
|
||||
// the best choise for strict-align archs to do unaligned access.
|
||||
// the best choice for strict-align archs to do unaligned access.
|
||||
//
|
||||
// See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111502
|
||||
//
|
||||
@ -625,7 +627,7 @@ write64le(uint8_t *buf, uint64_t num)
|
||||
// aligned but some compilers have language extensions to do that. With
|
||||
// such language extensions the memcpy() method gives excellent results.
|
||||
//
|
||||
// What to do on a strict-align system when no known language extentensions
|
||||
// What to do on a strict-align system when no known language extensions
|
||||
// are available? Falling back to byte-by-byte access would be safe but ruin
|
||||
// optimizations that have been made specifically with aligned access in mind.
|
||||
// As a compromise, aligned reads will fall back to non-compliant type punning
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_mbstr.h
|
||||
@ -10,9 +12,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_MBSTR_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_mbstr_fw.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "tuklib_mbstr.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_mbstr_width.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "tuklib_mbstr.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_open_stdxxx.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "tuklib_open_stdxxx.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_open_stdxxx.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_OPEN_STDXXX_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_physmem.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "tuklib_physmem.h"
|
||||
@ -73,23 +72,20 @@
|
||||
#endif
|
||||
|
||||
|
||||
// With GCC >= 8.1 with -Wextra and Clang >= 13 with -Wcast-function-type
|
||||
// will warn about the Windows-specific code.
|
||||
#if defined(__has_warning)
|
||||
# if __has_warning("-Wcast-function-type")
|
||||
# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
|
||||
# endif
|
||||
#elif TUKLIB_GNUC_REQ(8,1)
|
||||
# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
|
||||
#endif
|
||||
|
||||
|
||||
extern uint64_t
|
||||
tuklib_physmem(void)
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
// This requires Windows 2000 or later.
|
||||
MEMORYSTATUSEX meminfo;
|
||||
meminfo.dwLength = sizeof(meminfo);
|
||||
if (GlobalMemoryStatusEx(&meminfo))
|
||||
ret = meminfo.ullTotalPhys;
|
||||
|
||||
/*
|
||||
// Old version that is compatible with even Win95:
|
||||
if ((GetVersion() & 0xFF) >= 5) {
|
||||
// Windows 2000 and later have GlobalMemoryStatusEx() which
|
||||
// supports reporting values greater than 4 GiB. To keep the
|
||||
@ -125,6 +121,7 @@ tuklib_physmem(void)
|
||||
GlobalMemoryStatus(&meminfo);
|
||||
ret = meminfo.dwTotalPhys;
|
||||
}
|
||||
*/
|
||||
|
||||
#elif defined(__OS2__)
|
||||
unsigned long mem;
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_physmem.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_PHYSMEM_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_progname.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "tuklib_progname.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file tuklib_progname.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TUKLIB_PROGNAME_H
|
||||
|
@ -1,31 +1,30 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file api/lzma.h
|
||||
* \brief The public API of liblzma data compression library
|
||||
* \mainpage
|
||||
*
|
||||
* liblzma is a public domain general-purpose data compression library with
|
||||
* a zlib-like API. The native file format is .xz, but also the old .lzma
|
||||
* format and raw (no headers) streams are supported. Multiple compression
|
||||
* algorithms (filters) are supported. Currently LZMA2 is the primary filter.
|
||||
* liblzma is a general-purpose data compression library with a zlib-like API.
|
||||
* The native file format is .xz, but also the old .lzma format and raw (no
|
||||
* headers) streams are supported. Multiple compression algorithms (filters)
|
||||
* are supported. Currently LZMA2 is the primary filter.
|
||||
*
|
||||
* liblzma is part of XZ Utils <https://tukaani.org/xz/>. XZ Utils includes
|
||||
* a gzip-like command line tool named xz and some other tools. XZ Utils
|
||||
* is developed and maintained by Lasse Collin and Jia Tan.
|
||||
* liblzma is part of XZ Utils <https://tukaani.org/xz/>. XZ Utils
|
||||
* includes a gzip-like command line tool named xz and some other tools.
|
||||
* XZ Utils is developed and maintained by Lasse Collin.
|
||||
*
|
||||
* Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
|
||||
* <https://7-zip.org/sdk.html>.
|
||||
* Major parts of liblzma are based on code written by Igor Pavlov,
|
||||
* specifically the LZMA SDK <https://7-zip.org/sdk.html>.
|
||||
*
|
||||
* The SHA-256 implementation is based on the public domain code found from
|
||||
* 7-Zip <https://7-zip.org/>, which has a modified version of the public
|
||||
* domain SHA-256 code found from Crypto++ <https://www.cryptopp.com/>.
|
||||
* The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
|
||||
* The SHA-256 implementation in liblzma is based on code written by
|
||||
* Wei Dai in Crypto++ Library <https://www.cryptopp.com/>.
|
||||
*
|
||||
* liblzma is distributed under the BSD Zero Clause License (0BSD).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/base.h
|
||||
* \brief Data types and functions used in many places in liblzma API
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -21,8 +20,8 @@
|
||||
*
|
||||
* This is here because C89 doesn't have stdbool.h. To set a value for
|
||||
* variables having type lzma_bool, you can use
|
||||
* - C99's `true' and `false' from stdbool.h;
|
||||
* - C++'s internal `true' and `false'; or
|
||||
* - C99's 'true' and 'false' from stdbool.h;
|
||||
* - C++'s internal 'true' and 'false'; or
|
||||
* - integers one (true) and zero (false).
|
||||
*/
|
||||
typedef unsigned char lzma_bool;
|
||||
@ -258,7 +257,7 @@ typedef enum {
|
||||
*/
|
||||
|
||||
/*
|
||||
* These eumerations may be used internally by liblzma
|
||||
* These enumerations may be used internally by liblzma
|
||||
* but they will never be returned to applications.
|
||||
*/
|
||||
LZMA_RET_INTERNAL1 = 101,
|
||||
@ -273,13 +272,13 @@ typedef enum {
|
||||
|
||||
|
||||
/**
|
||||
* \brief The `action' argument for lzma_code()
|
||||
* \brief The 'action' argument for lzma_code()
|
||||
*
|
||||
* After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, LZMA_FULL_BARRIER,
|
||||
* or LZMA_FINISH, the same `action' must be used until lzma_code() returns
|
||||
* or LZMA_FINISH, the same 'action' must be used until lzma_code() returns
|
||||
* LZMA_STREAM_END. Also, the amount of input (that is, strm->avail_in) must
|
||||
* not be modified by the application until lzma_code() returns
|
||||
* LZMA_STREAM_END. Changing the `action' or modifying the amount of input
|
||||
* LZMA_STREAM_END. Changing the 'action' or modifying the amount of input
|
||||
* will make lzma_code() return LZMA_PROG_ERROR.
|
||||
*/
|
||||
typedef enum {
|
||||
@ -393,8 +392,8 @@ typedef enum {
|
||||
* Single-threaded mode only: liblzma doesn't make an internal copy of
|
||||
* lzma_allocator. Thus, it is OK to change these function pointers in
|
||||
* the middle of the coding process, but obviously it must be done
|
||||
* carefully to make sure that the replacement `free' can deallocate
|
||||
* memory allocated by the earlier `alloc' function(s).
|
||||
* carefully to make sure that the replacement 'free' can deallocate
|
||||
* memory allocated by the earlier 'alloc' function(s).
|
||||
*
|
||||
* Multithreaded mode: liblzma might internally store pointers to the
|
||||
* lzma_allocator given via the lzma_stream structure. The application
|
||||
@ -422,7 +421,7 @@ typedef struct {
|
||||
* liblzma never sets this to zero.
|
||||
*
|
||||
* \return Pointer to the beginning of a memory block of
|
||||
* `size' bytes, or NULL if allocation fails
|
||||
* 'size' bytes, or NULL if allocation fails
|
||||
* for some reason. When allocation fails, functions
|
||||
* of liblzma return LZMA_MEM_ERROR.
|
||||
*
|
||||
@ -622,7 +621,7 @@ typedef struct {
|
||||
* to and get output from liblzma.
|
||||
*
|
||||
* See the description of the coder-specific initialization function to find
|
||||
* out what `action' values are supported by the coder.
|
||||
* out what 'action' values are supported by the coder.
|
||||
*
|
||||
* \param strm Pointer to lzma_stream that is at least initialized
|
||||
* with LZMA_STREAM_INIT.
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/bcj.h
|
||||
* \brief Branch/Call/Jump conversion filters
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -53,6 +52,11 @@
|
||||
*/
|
||||
#define LZMA_FILTER_ARM64 LZMA_VLI_C(0x0A)
|
||||
|
||||
/**
|
||||
* \brief Filter for RISC-V binaries
|
||||
*/
|
||||
#define LZMA_FILTER_RISCV LZMA_VLI_C(0x0B)
|
||||
|
||||
|
||||
/**
|
||||
* \brief Options for BCJ filters
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/block.h
|
||||
* \brief .xz Block handling
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/check.h
|
||||
* \brief Integrity checks
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/container.h
|
||||
* \brief File formats
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -297,7 +296,7 @@ extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
|
||||
* to call lzma_end() after failed initialization.
|
||||
*
|
||||
* If initialization succeeds, use lzma_code() to do the actual encoding.
|
||||
* Valid values for `action' (the second argument of lzma_code()) are
|
||||
* Valid values for 'action' (the second argument of lzma_code()) are
|
||||
* LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
|
||||
* there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.
|
||||
*
|
||||
@ -679,13 +678,13 @@ extern LZMA_API(lzma_ret) lzma_microlzma_encoder(
|
||||
* supported by liblzma, only the .xz and .lz formats allow concatenated
|
||||
* files. Concatenated files are not allowed with the legacy .lzma format.
|
||||
*
|
||||
* This flag also affects the usage of the `action' argument for lzma_code().
|
||||
* This flag also affects the usage of the 'action' argument for lzma_code().
|
||||
* When LZMA_CONCATENATED is used, lzma_code() won't return LZMA_STREAM_END
|
||||
* unless LZMA_FINISH is used as `action'. Thus, the application has to set
|
||||
* unless LZMA_FINISH is used as 'action'. Thus, the application has to set
|
||||
* LZMA_FINISH in the same way as it does when encoding.
|
||||
*
|
||||
* If LZMA_CONCATENATED is not used, the decoders still accept LZMA_FINISH
|
||||
* as `action' for lzma_code(), but the usage of LZMA_FINISH isn't required.
|
||||
* as 'action' for lzma_code(), but the usage of LZMA_FINISH isn't required.
|
||||
*/
|
||||
#define LZMA_CONCATENATED UINT32_C(0x08)
|
||||
|
||||
@ -793,7 +792,7 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder_mt(
|
||||
* as it doesn't support any decoder flags. It will return LZMA_STREAM_END
|
||||
* after one .lzma stream.)
|
||||
*
|
||||
* \param strm Pointer to lzma_stream that is at least initialized
|
||||
* \param strm Pointer to lzma_stream that is at least initialized
|
||||
* with LZMA_STREAM_INIT.
|
||||
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
||||
* to effectively disable the limiter. liblzma
|
||||
@ -819,7 +818,7 @@ extern LZMA_API(lzma_ret) lzma_auto_decoder(
|
||||
/**
|
||||
* \brief Initialize .lzma decoder (legacy file format)
|
||||
*
|
||||
* Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* Valid 'action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* There is no need to use LZMA_FINISH, but it's allowed because it may
|
||||
* simplify certain types of applications.
|
||||
*
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/delta.h
|
||||
* \brief Delta filter
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/filter.h
|
||||
* \brief Common filter related types and functions
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -43,7 +42,7 @@ typedef struct {
|
||||
/**
|
||||
* \brief Filter ID
|
||||
*
|
||||
* Use constants whose name begin with `LZMA_FILTER_' to specify
|
||||
* Use constants whose name begin with 'LZMA_FILTER_' to specify
|
||||
* different filters. In an array of lzma_filter structures, use
|
||||
* LZMA_VLI_UNKNOWN to indicate end of filters.
|
||||
*
|
||||
@ -199,7 +198,7 @@ extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters)
|
||||
*
|
||||
* This function may be useful when implementing custom file formats.
|
||||
*
|
||||
* The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
|
||||
* The 'action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
|
||||
* filter chain supports it), or LZMA_FINISH.
|
||||
*
|
||||
* \param strm Pointer to lzma_stream that is at least
|
||||
@ -223,7 +222,7 @@ extern LZMA_API(lzma_ret) lzma_raw_encoder(
|
||||
*
|
||||
* The initialization of raw decoder goes similarly to raw encoder.
|
||||
*
|
||||
* The `action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. Using
|
||||
* The 'action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. Using
|
||||
* LZMA_FINISH is not required, it is supported just for convenience.
|
||||
*
|
||||
* \param strm Pointer to lzma_stream that is at least
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/hardware.h
|
||||
* \brief Hardware information
|
||||
@ -23,9 +25,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/index.h
|
||||
* \brief Handling of .xz Index and related information
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -234,7 +233,7 @@ typedef struct {
|
||||
} block;
|
||||
|
||||
/**
|
||||
* \private Internal struct.
|
||||
* \private Internal data
|
||||
*
|
||||
* Internal data which is used to store the state of the iterator.
|
||||
* The exact format may vary between liblzma versions, so don't
|
||||
@ -301,6 +300,28 @@ typedef enum {
|
||||
} lzma_index_iter_mode;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Mask for return value from lzma_index_checks() for check none
|
||||
*
|
||||
* \note This and the other CHECK_MASK macros were added in 5.5.1alpha.
|
||||
*/
|
||||
#define LZMA_INDEX_CHECK_MASK_NONE (UINT32_C(1) << LZMA_CHECK_NONE)
|
||||
|
||||
/**
|
||||
* \brief Mask for return value from lzma_index_checks() for check CRC32
|
||||
*/
|
||||
#define LZMA_INDEX_CHECK_MASK_CRC32 (UINT32_C(1) << LZMA_CHECK_CRC32)
|
||||
|
||||
/**
|
||||
* \brief Mask for return value from lzma_index_checks() for check CRC64
|
||||
*/
|
||||
#define LZMA_INDEX_CHECK_MASK_CRC64 (UINT32_C(1) << LZMA_CHECK_CRC64)
|
||||
|
||||
/**
|
||||
* \brief Mask for return value from lzma_index_checks() for check SHA256
|
||||
*/
|
||||
#define LZMA_INDEX_CHECK_MASK_SHA256 (UINT32_C(1) << LZMA_CHECK_SHA256)
|
||||
|
||||
/**
|
||||
* \brief Calculate memory usage of lzma_index
|
||||
*
|
||||
@ -431,6 +452,7 @@ extern LZMA_API(lzma_ret) lzma_index_stream_flags(
|
||||
* showing the Check types to the user.
|
||||
*
|
||||
* The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10.
|
||||
* These masks are defined for convenience as LZMA_INDEX_CHECK_MASK_XXX
|
||||
*
|
||||
* \param i Pointer to lzma_index structure
|
||||
*
|
||||
@ -651,7 +673,7 @@ extern LZMA_API(lzma_bool) lzma_index_iter_locate(
|
||||
* function succeeds, the memory allocated for src
|
||||
* is freed or moved to be part of dest, and all
|
||||
* iterators pointing to src will become invalid.
|
||||
* \param allocator lzma_allocator for custom allocator functions.
|
||||
* \param allocator lzma_allocator for custom allocator functions.
|
||||
* Set to NULL to use malloc() and free().
|
||||
*
|
||||
* \return Possible lzma_ret values:
|
||||
@ -686,7 +708,7 @@ extern LZMA_API(lzma_index *) lzma_index_dup(
|
||||
* \param strm Pointer to properly prepared lzma_stream
|
||||
* \param i Pointer to lzma_index which should be encoded.
|
||||
*
|
||||
* The valid `action' values for lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* The valid 'action' values for lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* It is enough to use only one of them (you can choose freely).
|
||||
*
|
||||
* \return Possible lzma_ret values:
|
||||
@ -715,7 +737,7 @@ extern LZMA_API(lzma_ret) lzma_index_encoder(
|
||||
* don't allow 0 here and return LZMA_PROG_ERROR;
|
||||
* later versions treat 0 as if 1 had been specified.
|
||||
*
|
||||
* Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* Valid 'action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* There is no need to use LZMA_FINISH, but it's allowed because it may
|
||||
* simplify certain types of applications.
|
||||
*
|
||||
@ -771,7 +793,7 @@ extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i,
|
||||
* lzma_index is allowed to require. The value
|
||||
* pointed by this pointer is modified if and only
|
||||
* if LZMA_MEMLIMIT_ERROR is returned.
|
||||
* \param allocator lzma_allocator for custom allocator functions.
|
||||
* \param allocator lzma_allocator for custom allocator functions.
|
||||
* Set to NULL to use malloc() and free().
|
||||
* \param in Beginning of the input buffer
|
||||
* \param in_pos The next byte will be read from in[*in_pos].
|
||||
@ -819,10 +841,10 @@ extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
|
||||
* expect to see the same exact value for the same file if you change the
|
||||
* input buffer size or switch to a different liblzma version.
|
||||
*
|
||||
* Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* Valid 'action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* You only need to use LZMA_RUN; LZMA_FINISH is only supported because it
|
||||
* might be convenient for some applications. If you use LZMA_FINISH and if
|
||||
* lzma_code() asks the application to seek, remember to reset `action' back
|
||||
* lzma_code() asks the application to seek, remember to reset 'action' back
|
||||
* to LZMA_RUN unless you hit the end of the file again.
|
||||
*
|
||||
* Possible return values from lzma_code():
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/index_hash.h
|
||||
* \brief Validate Index by using a hash function
|
||||
@ -9,9 +11,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/lzma12.h
|
||||
* \brief LZMA1 and LZMA2 filters
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -289,7 +288,7 @@ typedef struct {
|
||||
* \brief Number of literal context bits
|
||||
*
|
||||
* How many of the highest bits of the previous uncompressed
|
||||
* eight-bit byte (also known as `literal') are taken into
|
||||
* eight-bit byte (also known as 'literal') are taken into
|
||||
* account when predicting the bits of the next literal.
|
||||
*
|
||||
* E.g. in typical English text, an upper-case letter is
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/stream_flags.h
|
||||
* \brief .xz Stream Header and Stream Footer encoder and decoder
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/version.h
|
||||
* \brief Version number
|
||||
@ -6,9 +8,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -20,10 +19,10 @@
|
||||
#define LZMA_VERSION_MAJOR 5
|
||||
|
||||
/** \brief Minor version number of the liblzma release. */
|
||||
#define LZMA_VERSION_MINOR 4
|
||||
#define LZMA_VERSION_MINOR 6
|
||||
|
||||
/** \brief Patch version number of the liblzma release. */
|
||||
#define LZMA_VERSION_PATCH 5
|
||||
#define LZMA_VERSION_PATCH 2
|
||||
|
||||
/**
|
||||
* \brief Version stability marker
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/**
|
||||
* \file lzma/vli.h
|
||||
* \brief Variable-length integer handling
|
||||
@ -17,9 +19,6 @@
|
||||
|
||||
/*
|
||||
* Author: Lasse Collin
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef LZMA_H_INTERNAL
|
||||
@ -68,9 +67,8 @@ typedef uint64_t lzma_vli;
|
||||
* This is useful to test that application has given acceptable values
|
||||
* for example in the uncompressed_size and compressed_size variables.
|
||||
*
|
||||
* \return True if the integer is representable as VLI or if it
|
||||
* indicates unknown value. False if the integer cannot be
|
||||
* represented as VLI.
|
||||
* \return True if the integer is representable as a VLI or if it
|
||||
* indicates an unknown value. False otherwise.
|
||||
*/
|
||||
#define lzma_vli_is_valid(vli) \
|
||||
((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN)
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file check.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "check.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file check.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_CHECK_H
|
||||
|
122
contrib/xz/src/liblzma/check/crc32_arm64.h
Normal file
122
contrib/xz/src/liblzma/check/crc32_arm64.h
Normal file
@ -0,0 +1,122 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc32_arm64.h
|
||||
/// \brief CRC32 calculation with ARM64 optimization
|
||||
//
|
||||
// Authors: Chenxi Mao
|
||||
// Jia Tan
|
||||
// Hans Jansen
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_CRC32_ARM64_H
|
||||
#define LZMA_CRC32_ARM64_H
|
||||
|
||||
// MSVC always has the CRC intrinsics available when building for ARM64
|
||||
// there is no need to include any header files.
|
||||
#ifndef _MSC_VER
|
||||
# include <arm_acle.h>
|
||||
#endif
|
||||
|
||||
// If both versions are going to be built, we need runtime detection
|
||||
// to check if the instructions are supported.
|
||||
#if defined(CRC32_GENERIC) && defined(CRC32_ARCH_OPTIMIZED)
|
||||
# if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
|
||||
# include <sys/auxv.h>
|
||||
# elif defined(_WIN32)
|
||||
# include <processthreadsapi.h>
|
||||
# elif defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME)
|
||||
# include <sys/sysctl.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Some EDG-based compilers support ARM64 and define __GNUC__
|
||||
// (such as Nvidia's nvcc), but do not support function attributes.
|
||||
//
|
||||
// NOTE: Build systems check for this too, keep them in sync with this.
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
|
||||
# define crc_attr_target __attribute__((__target__("+crc")))
|
||||
#else
|
||||
# define crc_attr_target
|
||||
#endif
|
||||
|
||||
|
||||
crc_attr_target
|
||||
static uint32_t
|
||||
crc32_arch_optimized(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
{
|
||||
crc = ~crc;
|
||||
|
||||
// Align the input buffer because this was shown to be
|
||||
// significantly faster than unaligned accesses.
|
||||
const size_t align_amount = my_min(size, (0U - (uintptr_t)buf) & 7);
|
||||
|
||||
for (const uint8_t *limit = buf + align_amount; buf < limit; ++buf)
|
||||
crc = __crc32b(crc, *buf);
|
||||
|
||||
size -= align_amount;
|
||||
|
||||
// Process 8 bytes at a time. The end point is determined by
|
||||
// ignoring the least significant three bits of size to ensure
|
||||
// we do not process past the bounds of the buffer. This guarantees
|
||||
// that limit is a multiple of 8 and is strictly less than size.
|
||||
for (const uint8_t *limit = buf + (size & ~(size_t)7);
|
||||
buf < limit; buf += 8)
|
||||
crc = __crc32d(crc, aligned_read64le(buf));
|
||||
|
||||
// Process the remaining bytes that are not 8 byte aligned.
|
||||
for (const uint8_t *limit = buf + (size & 7); buf < limit; ++buf)
|
||||
crc = __crc32b(crc, *buf);
|
||||
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
|
||||
#if defined(CRC32_GENERIC) && defined(CRC32_ARCH_OPTIMIZED)
|
||||
static inline bool
|
||||
is_arch_extension_supported(void)
|
||||
{
|
||||
#if defined(HAVE_GETAUXVAL)
|
||||
return (getauxval(AT_HWCAP) & HWCAP_CRC32) != 0;
|
||||
|
||||
#elif defined(HAVE_ELF_AUX_INFO)
|
||||
unsigned long feature_flags;
|
||||
|
||||
if (elf_aux_info(AT_HWCAP, &feature_flags, sizeof(feature_flags)) != 0)
|
||||
return false;
|
||||
|
||||
return (feature_flags & HWCAP_CRC32) != 0;
|
||||
|
||||
#elif defined(_WIN32)
|
||||
return IsProcessorFeaturePresent(
|
||||
PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
|
||||
|
||||
#elif defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME)
|
||||
int has_crc32 = 0;
|
||||
size_t size = sizeof(has_crc32);
|
||||
|
||||
// The sysctlbyname() function requires a string identifier for the
|
||||
// CPU feature it tests. The Apple documentation lists the string
|
||||
// "hw.optional.armv8_crc32", which can be found here:
|
||||
// https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3915619
|
||||
if (sysctlbyname("hw.optional.armv8_crc32", &has_crc32,
|
||||
&size, NULL, 0) != 0)
|
||||
return false;
|
||||
|
||||
return has_crc32;
|
||||
|
||||
#else
|
||||
// If a runtime detection method cannot be found, then this must
|
||||
// be a compile time error. The checks in crc_common.h should ensure
|
||||
// a runtime detection method is always found if this function is
|
||||
// built. It would be possible to just return false here, but this
|
||||
// is inefficient for binary size and runtime since only the generic
|
||||
// method could ever be used.
|
||||
# error Runtime detection method unavailable.
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LZMA_CRC32_ARM64_H
|
@ -1,35 +1,40 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc32.c
|
||||
/// \brief CRC32 calculation
|
||||
///
|
||||
/// Calculate the CRC32 using the slice-by-eight algorithm.
|
||||
/// It is explained in this document:
|
||||
/// http://www.intel.com/technology/comms/perfnet/download/CRC_generators.pdf
|
||||
/// The code in this file is not the same as in Intel's paper, but
|
||||
/// the basic principle is identical.
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
// Authors: Lasse Collin
|
||||
// Ilya Kurdyukov
|
||||
// Hans Jansen
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "check.h"
|
||||
#include "crc_macros.h"
|
||||
#include "crc_common.h"
|
||||
|
||||
#if defined(CRC_X86_CLMUL)
|
||||
# define BUILDING_CRC32_CLMUL
|
||||
# include "crc_x86_clmul.h"
|
||||
#elif defined(CRC32_ARM64)
|
||||
# include "crc32_arm64.h"
|
||||
#endif
|
||||
|
||||
|
||||
// If you make any changes, do some benchmarking! Seemingly unrelated
|
||||
// changes can very easily ruin the performance (and very probably is
|
||||
// very compiler dependent).
|
||||
extern LZMA_API(uint32_t)
|
||||
lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
#ifdef CRC32_GENERIC
|
||||
|
||||
///////////////////
|
||||
// Generic CRC32 //
|
||||
///////////////////
|
||||
|
||||
static uint32_t
|
||||
crc32_generic(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
{
|
||||
crc = ~crc;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
crc = bswap32(crc);
|
||||
crc = byteswap32(crc);
|
||||
#endif
|
||||
|
||||
if (size > 8) {
|
||||
@ -75,8 +80,125 @@ lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
crc = lzma_crc32_table[0][*buf++ ^ A(crc)] ^ S8(crc);
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
crc = bswap32(crc);
|
||||
crc = byteswap32(crc);
|
||||
#endif
|
||||
|
||||
return ~crc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(CRC32_GENERIC) && defined(CRC32_ARCH_OPTIMIZED)
|
||||
|
||||
//////////////////////////
|
||||
// Function dispatching //
|
||||
//////////////////////////
|
||||
|
||||
// If both the generic and arch-optimized implementations are built, then
|
||||
// the function to use is selected at runtime because the system running
|
||||
// the binary might not have the arch-specific instruction set extension(s)
|
||||
// available. The dispatch methods in order of priority:
|
||||
//
|
||||
// 1. Constructor. This method uses __attribute__((__constructor__)) to
|
||||
// set crc32_func at load time. This avoids extra computation (and any
|
||||
// unlikely threading bugs) on the first call to lzma_crc32() to decide
|
||||
// which implementation should be used.
|
||||
//
|
||||
// 2. First Call Resolution. On the very first call to lzma_crc32(), the
|
||||
// call will be directed to crc32_dispatch() instead. This will set the
|
||||
// appropriate implementation function and will not be called again.
|
||||
// This method does not use any kind of locking but is safe because if
|
||||
// multiple threads run the dispatcher simultaneously then they will all
|
||||
// set crc32_func to the same value.
|
||||
|
||||
typedef uint32_t (*crc32_func_type)(
|
||||
const uint8_t *buf, size_t size, uint32_t crc);
|
||||
|
||||
// This resolver is shared between all dispatch methods.
|
||||
static crc32_func_type
|
||||
crc32_resolve(void)
|
||||
{
|
||||
return is_arch_extension_supported()
|
||||
? &crc32_arch_optimized : &crc32_generic;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
||||
// Constructor method.
|
||||
# define CRC32_SET_FUNC_ATTR __attribute__((__constructor__))
|
||||
static crc32_func_type crc32_func;
|
||||
#else
|
||||
// First Call Resolution method.
|
||||
# define CRC32_SET_FUNC_ATTR
|
||||
static uint32_t crc32_dispatch(const uint8_t *buf, size_t size, uint32_t crc);
|
||||
static crc32_func_type crc32_func = &crc32_dispatch;
|
||||
#endif
|
||||
|
||||
CRC32_SET_FUNC_ATTR
|
||||
static void
|
||||
crc32_set_func(void)
|
||||
{
|
||||
crc32_func = crc32_resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
||||
static uint32_t
|
||||
crc32_dispatch(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
{
|
||||
// When __attribute__((__constructor__)) isn't supported, set the
|
||||
// function pointer without any locking. If multiple threads run
|
||||
// the detection code in parallel, they will all end up setting
|
||||
// the pointer to the same value. This avoids the use of
|
||||
// mythread_once() on every call to lzma_crc32() but this likely
|
||||
// isn't strictly standards compliant. Let's change it if it breaks.
|
||||
crc32_set_func();
|
||||
return crc32_func(buf, size, crc);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
extern LZMA_API(uint32_t)
|
||||
lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
{
|
||||
#if defined(CRC32_GENERIC) && defined(CRC32_ARCH_OPTIMIZED)
|
||||
// On x86-64, if CLMUL is available, it is the best for non-tiny
|
||||
// inputs, being over twice as fast as the generic slice-by-four
|
||||
// version. However, for size <= 16 it's different. In the extreme
|
||||
// case of size == 1 the generic version can be five times faster.
|
||||
// At size >= 8 the CLMUL starts to become reasonable. It
|
||||
// varies depending on the alignment of buf too.
|
||||
//
|
||||
// The above doesn't include the overhead of mythread_once().
|
||||
// At least on x86-64 GNU/Linux, pthread_once() is very fast but
|
||||
// it still makes lzma_crc32(buf, 1, crc) 50-100 % slower. When
|
||||
// size reaches 12-16 bytes the overhead becomes negligible.
|
||||
//
|
||||
// So using the generic version for size <= 16 may give better
|
||||
// performance with tiny inputs but if such inputs happen rarely
|
||||
// it's not so obvious because then the lookup table of the
|
||||
// generic version may not be in the processor cache.
|
||||
#ifdef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
if (size <= 16)
|
||||
return crc32_generic(buf, size, crc);
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
||||
// See crc32_dispatch(). This would be the alternative which uses
|
||||
// locking and doesn't use crc32_dispatch(). Note that on Windows
|
||||
// this method needs Vista threads.
|
||||
mythread_once(crc64_set_func);
|
||||
#endif
|
||||
*/
|
||||
return crc32_func(buf, size, crc);
|
||||
|
||||
#elif defined(CRC32_ARCH_OPTIMIZED)
|
||||
return crc32_arch_optimized(buf, size, crc);
|
||||
|
||||
#else
|
||||
return crc32_generic(buf, size, crc);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc32_small.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "check.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc32_table.c
|
||||
@ -5,18 +7,36 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
// FIXME: Compared to crc_common.h this has to check for __x86_64__ too
|
||||
// so that in 32-bit builds crc32_x86.S won't break due to a missing table.
|
||||
#if defined(HAVE_USABLE_CLMUL) && ((defined(__x86_64__) && defined(__SSSE3__) \
|
||||
&& defined(__SSE4_1__) && defined(__PCLMUL__)) \
|
||||
|| (defined(__e2k__) && __iset__ >= 6))
|
||||
# define NO_CRC32_TABLE
|
||||
|
||||
#elif defined(HAVE_ARM64_CRC32) \
|
||||
&& !defined(WORDS_BIGENDIAN) \
|
||||
&& defined(__ARM_FEATURE_CRC32)
|
||||
# define NO_CRC32_TABLE
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(HAVE_ENCODERS) && defined(NO_CRC32_TABLE)
|
||||
// No table needed. Use a typedef to avoid an empty translation unit.
|
||||
typedef void lzma_crc32_dummy;
|
||||
|
||||
#else
|
||||
// Having the declaration here silences clang -Wmissing-variable-declarations.
|
||||
extern const uint32_t lzma_crc32_table[8][256];
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# include "crc32_table_be.h"
|
||||
#else
|
||||
# include "crc32_table_le.h"
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
# include "crc32_table_be.h"
|
||||
# else
|
||||
# include "crc32_table_le.h"
|
||||
# endif
|
||||
#endif
|
||||
|
@ -1,4 +1,6 @@
|
||||
/* This file has been automatically generated by crc32_tablegen.c. */
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
// This file has been generated by crc32_tablegen.c.
|
||||
|
||||
const uint32_t lzma_crc32_table[8][256] = {
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
/* This file has been automatically generated by crc32_tablegen.c. */
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
// This file has been generated by crc32_tablegen.c.
|
||||
|
||||
const uint32_t lzma_crc32_table[8][256] = {
|
||||
{
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc32_tablegen.c
|
||||
@ -9,9 +11,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h>
|
||||
@ -44,7 +43,7 @@ init_crc32_table(void)
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
for (size_t s = 0; s < 8; ++s)
|
||||
for (size_t b = 0; b < 256; ++b)
|
||||
crc32_table[s][b] = bswap32(crc32_table[s][b]);
|
||||
crc32_table[s][b] = byteswap32(crc32_table[s][b]);
|
||||
#endif
|
||||
|
||||
return;
|
||||
@ -54,9 +53,11 @@ init_crc32_table(void)
|
||||
static void
|
||||
print_crc32_table(void)
|
||||
{
|
||||
printf("/* This file has been automatically generated by "
|
||||
"crc32_tablegen.c. */\n\n"
|
||||
"const uint32_t lzma_crc32_table[8][256] = {\n\t{");
|
||||
// Split the SPDX string so that it won't accidentally match
|
||||
// when tools search for the string.
|
||||
printf("// SPDX" "-License-Identifier" ": 0BSD\n\n"
|
||||
"// This file has been generated by crc32_tablegen.c.\n\n"
|
||||
"const uint32_t lzma_crc32_table[8][256] = {\n\t{");
|
||||
|
||||
for (size_t s = 0; s < 8; ++s) {
|
||||
for (size_t b = 0; b < 256; ++b) {
|
||||
@ -82,9 +83,11 @@ print_crc32_table(void)
|
||||
static void
|
||||
print_lz_table(void)
|
||||
{
|
||||
printf("/* This file has been automatically generated by "
|
||||
"crc32_tablegen.c. */\n\n"
|
||||
"const uint32_t lzma_lz_hash_table[256] = {");
|
||||
// Split the SPDX string so that it won't accidentally match
|
||||
// when tools search for the string.
|
||||
printf("// SPDX" "-License-Identifier" ": 0BSD\n\n"
|
||||
"// This file has been generated by crc32_tablegen.c.\n\n"
|
||||
"const uint32_t lzma_lz_hash_table[256] = {");
|
||||
|
||||
for (size_t b = 0; b < 256; ++b) {
|
||||
if ((b % 4) == 0)
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/*
|
||||
* Speed-optimized CRC32 using slicing-by-eight algorithm
|
||||
*
|
||||
@ -11,9 +13,6 @@
|
||||
* Authors: Igor Pavlov (original version)
|
||||
* Lasse Collin (AT&T syntax, PIC support, better portability)
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*
|
||||
* This code needs lzma_crc32_table, which can be created using the
|
||||
* following C code:
|
||||
|
||||
|
@ -1,85 +1,30 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc64.c
|
||||
/// \brief CRC64 calculation
|
||||
///
|
||||
/// There are two methods in this file. crc64_generic uses the
|
||||
/// the slice-by-four algorithm. This is the same idea that is
|
||||
/// used in crc32_fast.c, but for CRC64 we use only four tables
|
||||
/// instead of eight to avoid increasing CPU cache usage.
|
||||
///
|
||||
/// crc64_clmul uses 32/64-bit x86 SSSE3, SSE4.1, and CLMUL instructions.
|
||||
/// It was derived from
|
||||
/// https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf
|
||||
/// and the public domain code from https://github.com/rawrunprotected/crc
|
||||
/// (URLs were checked on 2022-11-07).
|
||||
///
|
||||
/// FIXME: Builds for 32-bit x86 use crc64_x86.S by default instead
|
||||
/// of this file and thus CLMUL version isn't available on 32-bit x86
|
||||
/// unless configured with --disable-assembler. Even then the lookup table
|
||||
/// isn't omitted in crc64_table.c since it doesn't know that assembly
|
||||
/// code has been disabled.
|
||||
//
|
||||
// Authors: Lasse Collin
|
||||
// Ilya Kurdyukov
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "check.h"
|
||||
#include "crc_common.h"
|
||||
|
||||
#undef CRC_GENERIC
|
||||
#undef CRC_CLMUL
|
||||
#undef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
|
||||
// If CLMUL cannot be used then only the generic slice-by-four is built.
|
||||
#if !defined(HAVE_USABLE_CLMUL)
|
||||
# define CRC_GENERIC 1
|
||||
|
||||
// If CLMUL is allowed unconditionally in the compiler options then the
|
||||
// generic version can be omitted. Note that this doesn't work with MSVC
|
||||
// as I don't know how to detect the features here.
|
||||
//
|
||||
// NOTE: Keep this this in sync with crc64_table.c.
|
||||
#elif (defined(__SSSE3__) && defined(__SSE4_1__) && defined(__PCLMUL__)) \
|
||||
|| (defined(__e2k__) && __iset__ >= 6)
|
||||
# define CRC_CLMUL 1
|
||||
|
||||
// Otherwise build both and detect at runtime which version to use.
|
||||
#else
|
||||
# define CRC_GENERIC 1
|
||||
# define CRC_CLMUL 1
|
||||
|
||||
/*
|
||||
// The generic code is much faster with 1-8-byte inputs and has
|
||||
// similar performance up to 16 bytes at least in microbenchmarks
|
||||
// (it depends on input buffer alignment too). If both versions are
|
||||
// built, this #define will use the generic version for inputs up to
|
||||
// 16 bytes and CLMUL for bigger inputs. It saves a little in code
|
||||
// size since the special cases for 0-16-byte inputs will be omitted
|
||||
// from the CLMUL code.
|
||||
# define CRC_USE_GENERIC_FOR_SMALL_INPUTS 1
|
||||
*/
|
||||
|
||||
# if defined(_MSC_VER)
|
||||
# include <intrin.h>
|
||||
# elif defined(HAVE_CPUID_H)
|
||||
# include <cpuid.h>
|
||||
# endif
|
||||
#if defined(CRC_X86_CLMUL)
|
||||
# define BUILDING_CRC64_CLMUL
|
||||
# include "crc_x86_clmul.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CRC64_GENERIC
|
||||
|
||||
/////////////////////////////////
|
||||
// Generic slice-by-four CRC64 //
|
||||
/////////////////////////////////
|
||||
|
||||
#ifdef CRC_GENERIC
|
||||
|
||||
#include "crc_macros.h"
|
||||
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# define A1(x) ((x) >> 56)
|
||||
#else
|
||||
@ -94,7 +39,7 @@ crc64_generic(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
crc = ~crc;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
crc = bswap64(crc);
|
||||
crc = byteswap64(crc);
|
||||
#endif
|
||||
|
||||
if (size > 4) {
|
||||
@ -128,7 +73,7 @@ crc64_generic(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
crc = bswap64(crc);
|
||||
crc = byteswap64(crc);
|
||||
#endif
|
||||
|
||||
return ~crc;
|
||||
@ -136,336 +81,40 @@ crc64_generic(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
#endif
|
||||
|
||||
|
||||
/////////////////////
|
||||
// x86 CLMUL CRC64 //
|
||||
/////////////////////
|
||||
#if defined(CRC64_GENERIC) && defined(CRC64_ARCH_OPTIMIZED)
|
||||
|
||||
#ifdef CRC_CLMUL
|
||||
//////////////////////////
|
||||
// Function dispatching //
|
||||
//////////////////////////
|
||||
|
||||
#include <immintrin.h>
|
||||
// If both the generic and arch-optimized implementations are usable, then
|
||||
// the function that is used is selected at runtime. See crc32_fast.c.
|
||||
|
||||
typedef uint64_t (*crc64_func_type)(
|
||||
const uint8_t *buf, size_t size, uint64_t crc);
|
||||
|
||||
/*
|
||||
// These functions were used to generate the constants
|
||||
// at the top of crc64_clmul().
|
||||
static uint64_t
|
||||
calc_lo(uint64_t poly)
|
||||
static crc64_func_type
|
||||
crc64_resolve(void)
|
||||
{
|
||||
uint64_t a = poly;
|
||||
uint64_t b = 0;
|
||||
|
||||
for (unsigned i = 0; i < 64; ++i) {
|
||||
b = (b >> 1) | (a << 63);
|
||||
a = (a >> 1) ^ (a & 1 ? poly : 0);
|
||||
}
|
||||
|
||||
return b;
|
||||
return is_arch_extension_supported()
|
||||
? &crc64_arch_optimized : &crc64_generic;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
calc_hi(uint64_t poly, uint64_t a)
|
||||
{
|
||||
for (unsigned i = 0; i < 64; ++i)
|
||||
a = (a >> 1) ^ (a & 1 ? poly : 0);
|
||||
|
||||
return a;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
#define MASK_L(in, mask, r) \
|
||||
r = _mm_shuffle_epi8(in, mask)
|
||||
|
||||
#define MASK_H(in, mask, r) \
|
||||
r = _mm_shuffle_epi8(in, _mm_xor_si128(mask, vsign))
|
||||
|
||||
#define MASK_LH(in, mask, low, high) \
|
||||
MASK_L(in, mask, low); \
|
||||
MASK_H(in, mask, high)
|
||||
|
||||
|
||||
// MSVC (VS2015 - VS2022) produces bad 32-bit x86 code from the CLMUL CRC
|
||||
// code when optimizations are enabled (release build). According to the bug
|
||||
// report, the ebx register is corrupted and the calculated result is wrong.
|
||||
// Trying to workaround the problem with "__asm mov ebx, ebx" didn't help.
|
||||
// The following pragma works and performance is still good. x86-64 builds
|
||||
// aren't affected by this problem.
|
||||
//
|
||||
// NOTE: Another pragma after the function restores the optimizations.
|
||||
// If the #if condition here is updated, the other one must be updated too.
|
||||
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) \
|
||||
&& defined(_M_IX86)
|
||||
# pragma optimize("g", off)
|
||||
#endif
|
||||
|
||||
// EDG-based compilers (Intel's classic compiler and compiler for E2K) can
|
||||
// define __GNUC__ but the attribute must not be used with them.
|
||||
// The new Clang-based ICX needs the attribute.
|
||||
//
|
||||
// NOTE: Build systems check for this too, keep them in sync with this.
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
|
||||
__attribute__((__target__("ssse3,sse4.1,pclmul")))
|
||||
#endif
|
||||
// The intrinsics use 16-byte-aligned reads from buf, thus they may read
|
||||
// up to 15 bytes before or after the buffer (depending on the alignment
|
||||
// of the buf argument). The values of the extra bytes are ignored.
|
||||
// This unavoidably trips -fsanitize=address so address sanitizier has
|
||||
// to be disabled for this function.
|
||||
#if lzma_has_attribute(__no_sanitize_address__)
|
||||
__attribute__((__no_sanitize_address__))
|
||||
#endif
|
||||
static uint64_t
|
||||
crc64_clmul(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
{
|
||||
// The prototypes of the intrinsics use signed types while most of
|
||||
// the values are treated as unsigned here. These warnings in this
|
||||
// function have been checked and found to be harmless so silence them.
|
||||
#if TUKLIB_GNUC_REQ(4, 6) || defined(__clang__)
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
# pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
|
||||
#ifndef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
// The code assumes that there is at least one byte of input.
|
||||
if (size == 0)
|
||||
return crc;
|
||||
#endif
|
||||
|
||||
// const uint64_t poly = 0xc96c5795d7870f42; // CRC polynomial
|
||||
const uint64_t p = 0x92d8af2baf0e1e85; // (poly << 1) | 1
|
||||
const uint64_t mu = 0x9c3e466c172963d5; // (calc_lo(poly) << 1) | 1
|
||||
const uint64_t k2 = 0xdabe95afc7875f40; // calc_hi(poly, 1)
|
||||
const uint64_t k1 = 0xe05dd497ca393ae4; // calc_hi(poly, k2)
|
||||
const __m128i vfold0 = _mm_set_epi64x(p, mu);
|
||||
const __m128i vfold1 = _mm_set_epi64x(k2, k1);
|
||||
|
||||
// Create a vector with 8-bit values 0 to 15. This is used to
|
||||
// construct control masks for _mm_blendv_epi8 and _mm_shuffle_epi8.
|
||||
const __m128i vramp = _mm_setr_epi32(
|
||||
0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c);
|
||||
|
||||
// This is used to inverse the control mask of _mm_shuffle_epi8
|
||||
// so that bytes that wouldn't be picked with the original mask
|
||||
// will be picked and vice versa.
|
||||
const __m128i vsign = _mm_set1_epi8(0x80);
|
||||
|
||||
// Memory addresses A to D and the distances between them:
|
||||
//
|
||||
// A B C D
|
||||
// [skip_start][size][skip_end]
|
||||
// [ size2 ]
|
||||
//
|
||||
// A and D are 16-byte aligned. B and C are 1-byte aligned.
|
||||
// skip_start and skip_end are 0-15 bytes. size is at least 1 byte.
|
||||
//
|
||||
// A = aligned_buf will initially point to this address.
|
||||
// B = The address pointed by the caller-supplied buf.
|
||||
// C = buf + size == aligned_buf + size2
|
||||
// D = buf + size + skip_end == aligned_buf + size2 + skip_end
|
||||
const size_t skip_start = (size_t)((uintptr_t)buf & 15);
|
||||
const size_t skip_end = (size_t)((0U - (uintptr_t)(buf + size)) & 15);
|
||||
const __m128i *aligned_buf = (const __m128i *)(
|
||||
(uintptr_t)buf & ~(uintptr_t)15);
|
||||
|
||||
// If size2 <= 16 then the whole input fits into a single 16-byte
|
||||
// vector. If size2 > 16 then at least two 16-byte vectors must
|
||||
// be processed. If size2 > 16 && size <= 16 then there is only
|
||||
// one 16-byte vector's worth of input but it is unaligned in memory.
|
||||
//
|
||||
// NOTE: There is no integer overflow here if the arguments are valid.
|
||||
// If this overflowed, buf + size would too.
|
||||
size_t size2 = skip_start + size;
|
||||
|
||||
// Masks to be used with _mm_blendv_epi8 and _mm_shuffle_epi8:
|
||||
// The first skip_start or skip_end bytes in the vectors will have
|
||||
// the high bit (0x80) set. _mm_blendv_epi8 and _mm_shuffle_epi8
|
||||
// will produce zeros for these positions. (Bitwise-xor of these
|
||||
// masks with vsign will produce the opposite behavior.)
|
||||
const __m128i mask_start
|
||||
= _mm_sub_epi8(vramp, _mm_set1_epi8(skip_start));
|
||||
const __m128i mask_end = _mm_sub_epi8(vramp, _mm_set1_epi8(skip_end));
|
||||
|
||||
// Get the first 1-16 bytes into data0. If loading less than 16 bytes,
|
||||
// the bytes are loaded to the high bits of the vector and the least
|
||||
// significant positions are filled with zeros.
|
||||
const __m128i data0 = _mm_blendv_epi8(_mm_load_si128(aligned_buf),
|
||||
_mm_setzero_si128(), mask_start);
|
||||
++aligned_buf;
|
||||
|
||||
#if defined(__i386__) || defined(_M_IX86)
|
||||
const __m128i initial_crc = _mm_set_epi64x(0, ~crc);
|
||||
#else
|
||||
// GCC and Clang would produce good code with _mm_set_epi64x
|
||||
// but MSVC needs _mm_cvtsi64_si128 on x86-64.
|
||||
const __m128i initial_crc = _mm_cvtsi64_si128(~crc);
|
||||
#endif
|
||||
|
||||
__m128i v0, v1, v2, v3;
|
||||
|
||||
#ifndef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
if (size <= 16) {
|
||||
// Right-shift initial_crc by 1-16 bytes based on "size"
|
||||
// and store the result in v1 (high bytes) and v0 (low bytes).
|
||||
//
|
||||
// NOTE: The highest 8 bytes of initial_crc are zeros so
|
||||
// v1 will be filled with zeros if size >= 8. The highest 8
|
||||
// bytes of v1 will always become zeros.
|
||||
//
|
||||
// [ v1 ][ v0 ]
|
||||
// [ initial_crc ] size == 1
|
||||
// [ initial_crc ] size == 2
|
||||
// [ initial_crc ] size == 15
|
||||
// [ initial_crc ] size == 16 (all in v0)
|
||||
const __m128i mask_low = _mm_add_epi8(
|
||||
vramp, _mm_set1_epi8(size - 16));
|
||||
MASK_LH(initial_crc, mask_low, v0, v1);
|
||||
|
||||
if (size2 <= 16) {
|
||||
// There are 1-16 bytes of input and it is all
|
||||
// in data0. Copy the input bytes to v3. If there
|
||||
// are fewer than 16 bytes, the low bytes in v3
|
||||
// will be filled with zeros. That is, the input
|
||||
// bytes are stored to the same position as
|
||||
// (part of) initial_crc is in v0.
|
||||
MASK_L(data0, mask_end, v3);
|
||||
} else {
|
||||
// There are 2-16 bytes of input but not all bytes
|
||||
// are in data0.
|
||||
const __m128i data1 = _mm_load_si128(aligned_buf);
|
||||
|
||||
// Collect the 2-16 input bytes from data0 and data1
|
||||
// to v2 and v3, and bitwise-xor them with the
|
||||
// low bits of initial_crc in v0. Note that the
|
||||
// the second xor is below this else-block as it
|
||||
// is shared with the other branch.
|
||||
MASK_H(data0, mask_end, v2);
|
||||
MASK_L(data1, mask_end, v3);
|
||||
v0 = _mm_xor_si128(v0, v2);
|
||||
}
|
||||
|
||||
v0 = _mm_xor_si128(v0, v3);
|
||||
v1 = _mm_alignr_epi8(v1, v0, 8);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
const __m128i data1 = _mm_load_si128(aligned_buf);
|
||||
MASK_LH(initial_crc, mask_start, v0, v1);
|
||||
v0 = _mm_xor_si128(v0, data0);
|
||||
v1 = _mm_xor_si128(v1, data1);
|
||||
|
||||
#define FOLD \
|
||||
v1 = _mm_xor_si128(v1, _mm_clmulepi64_si128(v0, vfold1, 0x00)); \
|
||||
v0 = _mm_xor_si128(v1, _mm_clmulepi64_si128(v0, vfold1, 0x11));
|
||||
|
||||
while (size2 > 32) {
|
||||
++aligned_buf;
|
||||
size2 -= 16;
|
||||
FOLD
|
||||
v1 = _mm_load_si128(aligned_buf);
|
||||
}
|
||||
|
||||
if (size2 < 32) {
|
||||
MASK_H(v0, mask_end, v2);
|
||||
MASK_L(v0, mask_end, v0);
|
||||
MASK_L(v1, mask_end, v3);
|
||||
v1 = _mm_or_si128(v2, v3);
|
||||
}
|
||||
|
||||
FOLD
|
||||
v1 = _mm_srli_si128(v0, 8);
|
||||
#undef FOLD
|
||||
}
|
||||
|
||||
v1 = _mm_xor_si128(_mm_clmulepi64_si128(v0, vfold1, 0x10), v1);
|
||||
v0 = _mm_clmulepi64_si128(v1, vfold0, 0x00);
|
||||
v2 = _mm_clmulepi64_si128(v0, vfold0, 0x10);
|
||||
v0 = _mm_xor_si128(_mm_xor_si128(v2, _mm_slli_si128(v0, 8)), v1);
|
||||
|
||||
#if defined(__i386__) || defined(_M_IX86)
|
||||
return ~(((uint64_t)(uint32_t)_mm_extract_epi32(v0, 3) << 32) |
|
||||
(uint64_t)(uint32_t)_mm_extract_epi32(v0, 2));
|
||||
#else
|
||||
return ~(uint64_t)_mm_extract_epi64(v0, 1);
|
||||
#endif
|
||||
|
||||
#if TUKLIB_GNUC_REQ(4, 6) || defined(__clang__)
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) \
|
||||
&& defined(_M_IX86)
|
||||
# pragma optimize("", on)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////
|
||||
// Detect CPU support //
|
||||
////////////////////////
|
||||
|
||||
#if defined(CRC_GENERIC) && defined(CRC_CLMUL)
|
||||
static inline bool
|
||||
is_clmul_supported(void)
|
||||
{
|
||||
int success = 1;
|
||||
uint32_t r[4]; // eax, ebx, ecx, edx
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// This needs <intrin.h> with MSVC. ICC has it as a built-in
|
||||
// on all platforms.
|
||||
__cpuid(r, 1);
|
||||
#elif defined(HAVE_CPUID_H)
|
||||
// Compared to just using __asm__ to run CPUID, this also checks
|
||||
// that CPUID is supported and saves and restores ebx as that is
|
||||
// needed with GCC < 5 with position-independent code (PIC).
|
||||
success = __get_cpuid(1, &r[0], &r[1], &r[2], &r[3]);
|
||||
#else
|
||||
// Just a fallback that shouldn't be needed.
|
||||
__asm__("cpuid\n\t"
|
||||
: "=a"(r[0]), "=b"(r[1]), "=c"(r[2]), "=d"(r[3])
|
||||
: "a"(1), "c"(0));
|
||||
#endif
|
||||
|
||||
// Returns true if these are supported:
|
||||
// CLMUL (bit 1 in ecx)
|
||||
// SSSE3 (bit 9 in ecx)
|
||||
// SSE4.1 (bit 19 in ecx)
|
||||
const uint32_t ecx_mask = (1 << 1) | (1 << 9) | (1 << 19);
|
||||
return success && (r[2] & ecx_mask) == ecx_mask;
|
||||
|
||||
// Alternative methods that weren't used:
|
||||
// - ICC's _may_i_use_cpu_feature: the other methods should work too.
|
||||
// - GCC >= 6 / Clang / ICX __builtin_cpu_supports("pclmul")
|
||||
//
|
||||
// CPUID decding is needed with MSVC anyway and older GCC. This keeps
|
||||
// the feature checks in the build system simpler too. The nice thing
|
||||
// about __builtin_cpu_supports would be that it generates very short
|
||||
// code as is it only reads a variable set at startup but a few bytes
|
||||
// doesn't matter here.
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
||||
# define CRC64_FUNC_INIT
|
||||
# define CRC64_SET_FUNC_ATTR __attribute__((__constructor__))
|
||||
static crc64_func_type crc64_func;
|
||||
#else
|
||||
# define CRC64_FUNC_INIT = &crc64_dispatch
|
||||
# define CRC64_SET_FUNC_ATTR
|
||||
static uint64_t crc64_dispatch(const uint8_t *buf, size_t size, uint64_t crc);
|
||||
static crc64_func_type crc64_func = &crc64_dispatch;
|
||||
#endif
|
||||
|
||||
|
||||
// Pointer to the the selected CRC64 method.
|
||||
static uint64_t (*crc64_func)(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
CRC64_FUNC_INIT;
|
||||
|
||||
|
||||
CRC64_SET_FUNC_ATTR
|
||||
static void
|
||||
crc64_set_func(void)
|
||||
{
|
||||
crc64_func = is_clmul_supported() ? &crc64_clmul : &crc64_generic;
|
||||
crc64_func = crc64_resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -474,12 +123,6 @@ crc64_set_func(void)
|
||||
static uint64_t
|
||||
crc64_dispatch(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
{
|
||||
// When __attribute__((__constructor__)) isn't supported, set the
|
||||
// function pointer without any locking. If multiple threads run
|
||||
// the detection code in parallel, they will all end up setting
|
||||
// the pointer to the same value. This avoids the use of
|
||||
// mythread_once() on every call to lzma_crc64() but this likely
|
||||
// isn't strictly standards compliant. Let's change it if it breaks.
|
||||
crc64_set_func();
|
||||
return crc64_func(buf, size, crc);
|
||||
}
|
||||
@ -490,47 +133,22 @@ crc64_dispatch(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
extern LZMA_API(uint64_t)
|
||||
lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
{
|
||||
#if defined(CRC_GENERIC) && defined(CRC_CLMUL)
|
||||
// If CLMUL is available, it is the best for non-tiny inputs,
|
||||
// being over twice as fast as the generic slice-by-four version.
|
||||
// However, for size <= 16 it's different. In the extreme case
|
||||
// of size == 1 the generic version can be five times faster.
|
||||
// At size >= 8 the CLMUL starts to become reasonable. It
|
||||
// varies depending on the alignment of buf too.
|
||||
//
|
||||
// The above doesn't include the overhead of mythread_once().
|
||||
// At least on x86-64 GNU/Linux, pthread_once() is very fast but
|
||||
// it still makes lzma_crc64(buf, 1, crc) 50-100 % slower. When
|
||||
// size reaches 12-16 bytes the overhead becomes negligible.
|
||||
//
|
||||
// So using the generic version for size <= 16 may give better
|
||||
// performance with tiny inputs but if such inputs happen rarely
|
||||
// it's not so obvious because then the lookup table of the
|
||||
// generic version may not be in the processor cache.
|
||||
#if defined(CRC64_GENERIC) && defined(CRC64_ARCH_OPTIMIZED)
|
||||
|
||||
#ifdef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
if (size <= 16)
|
||||
return crc64_generic(buf, size, crc);
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
||||
// See crc64_dispatch(). This would be the alternative which uses
|
||||
// locking and doesn't use crc64_dispatch(). Note that on Windows
|
||||
// this method needs Vista threads.
|
||||
mythread_once(crc64_set_func);
|
||||
#endif
|
||||
*/
|
||||
|
||||
return crc64_func(buf, size, crc);
|
||||
|
||||
#elif defined(CRC_CLMUL)
|
||||
// If CLMUL is used unconditionally without runtime CPU detection
|
||||
// then omitting the generic version and its 8 KiB lookup table
|
||||
// makes the library smaller.
|
||||
#elif defined(CRC64_ARCH_OPTIMIZED)
|
||||
// If arch-optimized version is used unconditionally without runtime
|
||||
// CPU detection then omitting the generic version and its 8 KiB
|
||||
// lookup table makes the library smaller.
|
||||
//
|
||||
// FIXME: Lookup table isn't currently omitted on 32-bit x86,
|
||||
// see crc64_table.c.
|
||||
return crc64_clmul(buf, size, crc);
|
||||
return crc64_arch_optimized(buf, size, crc);
|
||||
|
||||
#else
|
||||
return crc64_generic(buf, size, crc);
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc64_small.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "check.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc64_table.c
|
||||
@ -5,19 +7,21 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
// FIXME: Compared to crc64_fast.c this has to check for __x86_64__ too
|
||||
// FIXME: Compared to crc_common.h this has to check for __x86_64__ too
|
||||
// so that in 32-bit builds crc64_x86.S won't break due to a missing table.
|
||||
#if (defined(__x86_64__) && defined(__SSSE3__) \
|
||||
#if defined(HAVE_USABLE_CLMUL) && ((defined(__x86_64__) && defined(__SSSE3__) \
|
||||
&& defined(__SSE4_1__) && defined(__PCLMUL__)) \
|
||||
|| (defined(__e2k__) && __iset__ >= 6)
|
||||
|| (defined(__e2k__) && __iset__ >= 6))
|
||||
# define NO_CRC64_TABLE
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef NO_CRC64_TABLE
|
||||
// No table needed. Use a typedef to avoid an empty translation unit.
|
||||
typedef void lzma_crc64_dummy;
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
/* This file has been automatically generated by crc64_tablegen.c. */
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
// This file has been generated by crc64_tablegen.c.
|
||||
|
||||
const uint64_t lzma_crc64_table[4][256] = {
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
/* This file has been automatically generated by crc64_tablegen.c. */
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
// This file has been generated by crc64_tablegen.c.
|
||||
|
||||
const uint64_t lzma_crc64_table[4][256] = {
|
||||
{
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc64_tablegen.c
|
||||
@ -8,9 +10,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h>
|
||||
@ -43,7 +42,7 @@ init_crc64_table(void)
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
for (size_t s = 0; s < 4; ++s)
|
||||
for (size_t b = 0; b < 256; ++b)
|
||||
crc64_table[s][b] = bswap64(crc64_table[s][b]);
|
||||
crc64_table[s][b] = byteswap64(crc64_table[s][b]);
|
||||
#endif
|
||||
|
||||
return;
|
||||
@ -53,9 +52,11 @@ init_crc64_table(void)
|
||||
static void
|
||||
print_crc64_table(void)
|
||||
{
|
||||
printf("/* This file has been automatically generated by "
|
||||
"crc64_tablegen.c. */\n\n"
|
||||
"const uint64_t lzma_crc64_table[4][256] = {\n\t{");
|
||||
// Split the SPDX string so that it won't accidentally match
|
||||
// when tools search for the string.
|
||||
printf("// SPDX" "-License-Identifier" ": 0BSD\n\n"
|
||||
"// This file has been generated by crc64_tablegen.c.\n\n"
|
||||
"const uint64_t lzma_crc64_table[4][256] = {\n\t{");
|
||||
|
||||
for (size_t s = 0; s < 4; ++s) {
|
||||
for (size_t b = 0; b < 256; ++b) {
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* SPDX-License-Identifier: 0BSD */
|
||||
|
||||
/*
|
||||
* Speed-optimized CRC64 using slicing-by-four algorithm
|
||||
*
|
||||
@ -7,9 +9,6 @@
|
||||
* Authors: Igor Pavlov (original CRC32 assembly code)
|
||||
* Lasse Collin (CRC64 adaptation of the modified CRC32 code)
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*
|
||||
* This code needs lzma_crc64_table, which can be created using the
|
||||
* following C code:
|
||||
|
||||
|
137
contrib/xz/src/liblzma/check/crc_common.h
Normal file
137
contrib/xz/src/liblzma/check/crc_common.h
Normal file
@ -0,0 +1,137 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc_common.h
|
||||
/// \brief Some functions and macros for CRC32 and CRC64
|
||||
//
|
||||
// Authors: Lasse Collin
|
||||
// Ilya Kurdyukov
|
||||
// Hans Jansen
|
||||
// Jia Tan
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_CRC_COMMON_H
|
||||
#define LZMA_CRC_COMMON_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# define A(x) ((x) >> 24)
|
||||
# define B(x) (((x) >> 16) & 0xFF)
|
||||
# define C(x) (((x) >> 8) & 0xFF)
|
||||
# define D(x) ((x) & 0xFF)
|
||||
|
||||
# define S8(x) ((x) << 8)
|
||||
# define S32(x) ((x) << 32)
|
||||
|
||||
#else
|
||||
# define A(x) ((x) & 0xFF)
|
||||
# define B(x) (((x) >> 8) & 0xFF)
|
||||
# define C(x) (((x) >> 16) & 0xFF)
|
||||
# define D(x) ((x) >> 24)
|
||||
|
||||
# define S8(x) ((x) >> 8)
|
||||
# define S32(x) ((x) >> 32)
|
||||
#endif
|
||||
|
||||
|
||||
// CRC CLMUL code needs this because accessing input buffers that aren't
|
||||
// aligned to the vector size will inherently trip the address sanitizer.
|
||||
#if lzma_has_attribute(__no_sanitize_address__)
|
||||
# define crc_attr_no_sanitize_address \
|
||||
__attribute__((__no_sanitize_address__))
|
||||
#else
|
||||
# define crc_attr_no_sanitize_address
|
||||
#endif
|
||||
|
||||
// Keep this in sync with changes to crc32_arm64.h
|
||||
#if defined(_WIN32) || defined(HAVE_GETAUXVAL) \
|
||||
|| defined(HAVE_ELF_AUX_INFO) \
|
||||
|| (defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME))
|
||||
# define ARM64_RUNTIME_DETECTION 1
|
||||
#endif
|
||||
|
||||
|
||||
#undef CRC32_GENERIC
|
||||
#undef CRC64_GENERIC
|
||||
|
||||
#undef CRC32_ARCH_OPTIMIZED
|
||||
#undef CRC64_ARCH_OPTIMIZED
|
||||
|
||||
// The x86 CLMUL is used for both CRC32 and CRC64.
|
||||
#undef CRC_X86_CLMUL
|
||||
|
||||
#undef CRC32_ARM64
|
||||
#undef CRC64_ARM64_CLMUL
|
||||
|
||||
#undef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
|
||||
// ARM64 CRC32 instruction is only useful for CRC32. Currently, only
|
||||
// little endian is supported since we were unable to test on a big
|
||||
// endian machine.
|
||||
//
|
||||
// NOTE: Keep this and the next check in sync with the macro
|
||||
// NO_CRC32_TABLE in crc32_table.c
|
||||
#if defined(HAVE_ARM64_CRC32) && !defined(WORDS_BIGENDIAN)
|
||||
// Allow ARM64 CRC32 instruction without a runtime check if
|
||||
// __ARM_FEATURE_CRC32 is defined. GCC and Clang only define this if the
|
||||
// proper compiler options are used.
|
||||
# if defined(__ARM_FEATURE_CRC32)
|
||||
# define CRC32_ARCH_OPTIMIZED 1
|
||||
# define CRC32_ARM64 1
|
||||
# elif defined(ARM64_RUNTIME_DETECTION)
|
||||
# define CRC32_ARCH_OPTIMIZED 1
|
||||
# define CRC32_ARM64 1
|
||||
# define CRC32_GENERIC 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_USABLE_CLMUL)
|
||||
// If CLMUL is allowed unconditionally in the compiler options then the
|
||||
// generic version can be omitted. Note that this doesn't work with MSVC
|
||||
// as I don't know how to detect the features here.
|
||||
//
|
||||
// NOTE: Keep this in sync with the NO_CRC32_TABLE macro in crc32_table.c
|
||||
// and NO_CRC64_TABLE in crc64_table.c.
|
||||
# if (defined(__SSSE3__) && defined(__SSE4_1__) && defined(__PCLMUL__)) \
|
||||
|| (defined(__e2k__) && __iset__ >= 6)
|
||||
# define CRC32_ARCH_OPTIMIZED 1
|
||||
# define CRC64_ARCH_OPTIMIZED 1
|
||||
# define CRC_X86_CLMUL 1
|
||||
# else
|
||||
# define CRC32_GENERIC 1
|
||||
# define CRC64_GENERIC 1
|
||||
# define CRC32_ARCH_OPTIMIZED 1
|
||||
# define CRC64_ARCH_OPTIMIZED 1
|
||||
# define CRC_X86_CLMUL 1
|
||||
|
||||
/*
|
||||
// The generic code is much faster with 1-8-byte inputs and
|
||||
// has similar performance up to 16 bytes at least in
|
||||
// microbenchmarks (it depends on input buffer alignment
|
||||
// too). If both versions are built, this #define will use
|
||||
// the generic version for inputs up to 16 bytes and CLMUL
|
||||
// for bigger inputs. It saves a little in code size since
|
||||
// the special cases for 0-16-byte inputs will be omitted
|
||||
// from the CLMUL code.
|
||||
# define CRC_USE_GENERIC_FOR_SMALL_INPUTS 1
|
||||
*/
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// For CRC32 use the generic slice-by-eight implementation if no optimized
|
||||
// version is available.
|
||||
#if !defined(CRC32_ARCH_OPTIMIZED) && !defined(CRC32_GENERIC)
|
||||
# define CRC32_GENERIC 1
|
||||
#endif
|
||||
|
||||
// For CRC64 use the generic slice-by-four implementation if no optimized
|
||||
// version is available.
|
||||
#if !defined(CRC64_ARCH_OPTIMIZED) && !defined(CRC64_GENERIC)
|
||||
# define CRC64_GENERIC 1
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,30 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc_macros.h
|
||||
/// \brief Some endian-dependent macros for CRC32 and CRC64
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# define A(x) ((x) >> 24)
|
||||
# define B(x) (((x) >> 16) & 0xFF)
|
||||
# define C(x) (((x) >> 8) & 0xFF)
|
||||
# define D(x) ((x) & 0xFF)
|
||||
|
||||
# define S8(x) ((x) << 8)
|
||||
# define S32(x) ((x) << 32)
|
||||
|
||||
#else
|
||||
# define A(x) ((x) & 0xFF)
|
||||
# define B(x) (((x) >> 8) & 0xFF)
|
||||
# define C(x) (((x) >> 16) & 0xFF)
|
||||
# define D(x) ((x) >> 24)
|
||||
|
||||
# define S8(x) ((x) >> 8)
|
||||
# define S32(x) ((x) >> 32)
|
||||
#endif
|
428
contrib/xz/src/liblzma/check/crc_x86_clmul.h
Normal file
428
contrib/xz/src/liblzma/check/crc_x86_clmul.h
Normal file
@ -0,0 +1,428 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc_x86_clmul.h
|
||||
/// \brief CRC32 and CRC64 implementations using CLMUL instructions.
|
||||
///
|
||||
/// The CRC32 and CRC64 implementations use 32/64-bit x86 SSSE3, SSE4.1, and
|
||||
/// CLMUL instructions. This is compatible with Elbrus 2000 (E2K) too.
|
||||
///
|
||||
/// They were derived from
|
||||
/// https://www.researchgate.net/publication/263424619_Fast_CRC_computation
|
||||
/// and the public domain code from https://github.com/rawrunprotected/crc
|
||||
/// (URLs were checked on 2023-10-14).
|
||||
///
|
||||
/// While this file has both CRC32 and CRC64 implementations, only one
|
||||
/// should be built at a time to ensure that crc_simd_body() is inlined
|
||||
/// even with compilers with which lzma_always_inline expands to plain inline.
|
||||
/// The version to build is selected by defining BUILDING_CRC32_CLMUL or
|
||||
/// BUILDING_CRC64_CLMUL before including this file.
|
||||
///
|
||||
/// FIXME: Builds for 32-bit x86 use the assembly .S files by default
|
||||
/// unless configured with --disable-assembler. Even then the lookup table
|
||||
/// isn't omitted in crc64_table.c since it doesn't know that assembly
|
||||
/// code has been disabled.
|
||||
//
|
||||
// Authors: Ilya Kurdyukov
|
||||
// Hans Jansen
|
||||
// Lasse Collin
|
||||
// Jia Tan
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file must not be included more than once.
|
||||
#ifdef LZMA_CRC_X86_CLMUL_H
|
||||
# error crc_x86_clmul.h was included twice.
|
||||
#endif
|
||||
#define LZMA_CRC_X86_CLMUL_H
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# include <intrin.h>
|
||||
#elif defined(HAVE_CPUID_H)
|
||||
# include <cpuid.h>
|
||||
#endif
|
||||
|
||||
|
||||
// EDG-based compilers (Intel's classic compiler and compiler for E2K) can
|
||||
// define __GNUC__ but the attribute must not be used with them.
|
||||
// The new Clang-based ICX needs the attribute.
|
||||
//
|
||||
// NOTE: Build systems check for this too, keep them in sync with this.
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
|
||||
# define crc_attr_target \
|
||||
__attribute__((__target__("ssse3,sse4.1,pclmul")))
|
||||
#else
|
||||
# define crc_attr_target
|
||||
#endif
|
||||
|
||||
|
||||
#define MASK_L(in, mask, r) r = _mm_shuffle_epi8(in, mask)
|
||||
|
||||
#define MASK_H(in, mask, r) \
|
||||
r = _mm_shuffle_epi8(in, _mm_xor_si128(mask, vsign))
|
||||
|
||||
#define MASK_LH(in, mask, low, high) \
|
||||
MASK_L(in, mask, low); \
|
||||
MASK_H(in, mask, high)
|
||||
|
||||
|
||||
crc_attr_target
|
||||
crc_attr_no_sanitize_address
|
||||
static lzma_always_inline void
|
||||
crc_simd_body(const uint8_t *buf, const size_t size, __m128i *v0, __m128i *v1,
|
||||
const __m128i vfold16, const __m128i initial_crc)
|
||||
{
|
||||
// Create a vector with 8-bit values 0 to 15. This is used to
|
||||
// construct control masks for _mm_blendv_epi8 and _mm_shuffle_epi8.
|
||||
const __m128i vramp = _mm_setr_epi32(
|
||||
0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c);
|
||||
|
||||
// This is used to inverse the control mask of _mm_shuffle_epi8
|
||||
// so that bytes that wouldn't be picked with the original mask
|
||||
// will be picked and vice versa.
|
||||
const __m128i vsign = _mm_set1_epi8(-0x80);
|
||||
|
||||
// Memory addresses A to D and the distances between them:
|
||||
//
|
||||
// A B C D
|
||||
// [skip_start][size][skip_end]
|
||||
// [ size2 ]
|
||||
//
|
||||
// A and D are 16-byte aligned. B and C are 1-byte aligned.
|
||||
// skip_start and skip_end are 0-15 bytes. size is at least 1 byte.
|
||||
//
|
||||
// A = aligned_buf will initially point to this address.
|
||||
// B = The address pointed by the caller-supplied buf.
|
||||
// C = buf + size == aligned_buf + size2
|
||||
// D = buf + size + skip_end == aligned_buf + size2 + skip_end
|
||||
const size_t skip_start = (size_t)((uintptr_t)buf & 15);
|
||||
const size_t skip_end = (size_t)((0U - (uintptr_t)(buf + size)) & 15);
|
||||
const __m128i *aligned_buf = (const __m128i *)(
|
||||
(uintptr_t)buf & ~(uintptr_t)15);
|
||||
|
||||
// If size2 <= 16 then the whole input fits into a single 16-byte
|
||||
// vector. If size2 > 16 then at least two 16-byte vectors must
|
||||
// be processed. If size2 > 16 && size <= 16 then there is only
|
||||
// one 16-byte vector's worth of input but it is unaligned in memory.
|
||||
//
|
||||
// NOTE: There is no integer overflow here if the arguments
|
||||
// are valid. If this overflowed, buf + size would too.
|
||||
const size_t size2 = skip_start + size;
|
||||
|
||||
// Masks to be used with _mm_blendv_epi8 and _mm_shuffle_epi8:
|
||||
// The first skip_start or skip_end bytes in the vectors will have
|
||||
// the high bit (0x80) set. _mm_blendv_epi8 and _mm_shuffle_epi8
|
||||
// will produce zeros for these positions. (Bitwise-xor of these
|
||||
// masks with vsign will produce the opposite behavior.)
|
||||
const __m128i mask_start
|
||||
= _mm_sub_epi8(vramp, _mm_set1_epi8((char)skip_start));
|
||||
const __m128i mask_end
|
||||
= _mm_sub_epi8(vramp, _mm_set1_epi8((char)skip_end));
|
||||
|
||||
// Get the first 1-16 bytes into data0. If loading less than 16
|
||||
// bytes, the bytes are loaded to the high bits of the vector and
|
||||
// the least significant positions are filled with zeros.
|
||||
const __m128i data0 = _mm_blendv_epi8(_mm_load_si128(aligned_buf),
|
||||
_mm_setzero_si128(), mask_start);
|
||||
aligned_buf++;
|
||||
|
||||
__m128i v2, v3;
|
||||
|
||||
#ifndef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
if (size <= 16) {
|
||||
// Right-shift initial_crc by 1-16 bytes based on "size"
|
||||
// and store the result in v1 (high bytes) and v0 (low bytes).
|
||||
//
|
||||
// NOTE: The highest 8 bytes of initial_crc are zeros so
|
||||
// v1 will be filled with zeros if size >= 8. The highest
|
||||
// 8 bytes of v1 will always become zeros.
|
||||
//
|
||||
// [ v1 ][ v0 ]
|
||||
// [ initial_crc ] size == 1
|
||||
// [ initial_crc ] size == 2
|
||||
// [ initial_crc ] size == 15
|
||||
// [ initial_crc ] size == 16 (all in v0)
|
||||
const __m128i mask_low = _mm_add_epi8(
|
||||
vramp, _mm_set1_epi8((char)(size - 16)));
|
||||
MASK_LH(initial_crc, mask_low, *v0, *v1);
|
||||
|
||||
if (size2 <= 16) {
|
||||
// There are 1-16 bytes of input and it is all
|
||||
// in data0. Copy the input bytes to v3. If there
|
||||
// are fewer than 16 bytes, the low bytes in v3
|
||||
// will be filled with zeros. That is, the input
|
||||
// bytes are stored to the same position as
|
||||
// (part of) initial_crc is in v0.
|
||||
MASK_L(data0, mask_end, v3);
|
||||
} else {
|
||||
// There are 2-16 bytes of input but not all bytes
|
||||
// are in data0.
|
||||
const __m128i data1 = _mm_load_si128(aligned_buf);
|
||||
|
||||
// Collect the 2-16 input bytes from data0 and data1
|
||||
// to v2 and v3, and bitwise-xor them with the
|
||||
// low bits of initial_crc in v0. Note that the
|
||||
// the second xor is below this else-block as it
|
||||
// is shared with the other branch.
|
||||
MASK_H(data0, mask_end, v2);
|
||||
MASK_L(data1, mask_end, v3);
|
||||
*v0 = _mm_xor_si128(*v0, v2);
|
||||
}
|
||||
|
||||
*v0 = _mm_xor_si128(*v0, v3);
|
||||
*v1 = _mm_alignr_epi8(*v1, *v0, 8);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
// There is more than 16 bytes of input.
|
||||
const __m128i data1 = _mm_load_si128(aligned_buf);
|
||||
const __m128i *end = (const __m128i*)(
|
||||
(const char *)aligned_buf - 16 + size2);
|
||||
aligned_buf++;
|
||||
|
||||
MASK_LH(initial_crc, mask_start, *v0, *v1);
|
||||
*v0 = _mm_xor_si128(*v0, data0);
|
||||
*v1 = _mm_xor_si128(*v1, data1);
|
||||
|
||||
while (aligned_buf < end) {
|
||||
*v1 = _mm_xor_si128(*v1, _mm_clmulepi64_si128(
|
||||
*v0, vfold16, 0x00));
|
||||
*v0 = _mm_xor_si128(*v1, _mm_clmulepi64_si128(
|
||||
*v0, vfold16, 0x11));
|
||||
*v1 = _mm_load_si128(aligned_buf++);
|
||||
}
|
||||
|
||||
if (aligned_buf != end) {
|
||||
MASK_H(*v0, mask_end, v2);
|
||||
MASK_L(*v0, mask_end, *v0);
|
||||
MASK_L(*v1, mask_end, v3);
|
||||
*v1 = _mm_or_si128(v2, v3);
|
||||
}
|
||||
|
||||
*v1 = _mm_xor_si128(*v1, _mm_clmulepi64_si128(
|
||||
*v0, vfold16, 0x00));
|
||||
*v0 = _mm_xor_si128(*v1, _mm_clmulepi64_si128(
|
||||
*v0, vfold16, 0x11));
|
||||
*v1 = _mm_srli_si128(*v0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// x86 CLMUL CRC32 //
|
||||
/////////////////////
|
||||
|
||||
/*
|
||||
// These functions were used to generate the constants
|
||||
// at the top of crc32_arch_optimized().
|
||||
static uint64_t
|
||||
calc_lo(uint64_t p, uint64_t a, int n)
|
||||
{
|
||||
uint64_t b = 0; int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
b = b >> 1 | (a & 1) << (n - 1);
|
||||
a = (a >> 1) ^ ((0 - (a & 1)) & p);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// same as ~crc(&a, sizeof(a), ~0)
|
||||
static uint64_t
|
||||
calc_hi(uint64_t p, uint64_t a, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
a = (a >> 1) ^ ((0 - (a & 1)) & p);
|
||||
return a;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef BUILDING_CRC32_CLMUL
|
||||
|
||||
crc_attr_target
|
||||
crc_attr_no_sanitize_address
|
||||
static uint32_t
|
||||
crc32_arch_optimized(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
{
|
||||
#ifndef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
// The code assumes that there is at least one byte of input.
|
||||
if (size == 0)
|
||||
return crc;
|
||||
#endif
|
||||
|
||||
// uint32_t poly = 0xedb88320;
|
||||
const int64_t p = 0x1db710640; // p << 1
|
||||
const int64_t mu = 0x1f7011641; // calc_lo(p, p, 32) << 1 | 1
|
||||
const int64_t k5 = 0x163cd6124; // calc_hi(p, p, 32) << 1
|
||||
const int64_t k4 = 0x0ccaa009e; // calc_hi(p, p, 64) << 1
|
||||
const int64_t k3 = 0x1751997d0; // calc_hi(p, p, 128) << 1
|
||||
|
||||
const __m128i vfold4 = _mm_set_epi64x(mu, p);
|
||||
const __m128i vfold8 = _mm_set_epi64x(0, k5);
|
||||
const __m128i vfold16 = _mm_set_epi64x(k4, k3);
|
||||
|
||||
__m128i v0, v1, v2;
|
||||
|
||||
crc_simd_body(buf, size, &v0, &v1, vfold16,
|
||||
_mm_cvtsi32_si128((int32_t)~crc));
|
||||
|
||||
v1 = _mm_xor_si128(
|
||||
_mm_clmulepi64_si128(v0, vfold16, 0x10), v1); // xxx0
|
||||
v2 = _mm_shuffle_epi32(v1, 0xe7); // 0xx0
|
||||
v0 = _mm_slli_epi64(v1, 32); // [0]
|
||||
v0 = _mm_clmulepi64_si128(v0, vfold8, 0x00);
|
||||
v0 = _mm_xor_si128(v0, v2); // [1] [2]
|
||||
v2 = _mm_clmulepi64_si128(v0, vfold4, 0x10);
|
||||
v2 = _mm_clmulepi64_si128(v2, vfold4, 0x00);
|
||||
v0 = _mm_xor_si128(v0, v2); // [2]
|
||||
return ~(uint32_t)_mm_extract_epi32(v0, 2);
|
||||
}
|
||||
#endif // BUILDING_CRC32_CLMUL
|
||||
|
||||
|
||||
/////////////////////
|
||||
// x86 CLMUL CRC64 //
|
||||
/////////////////////
|
||||
|
||||
/*
|
||||
// These functions were used to generate the constants
|
||||
// at the top of crc64_arch_optimized().
|
||||
static uint64_t
|
||||
calc_lo(uint64_t poly)
|
||||
{
|
||||
uint64_t a = poly;
|
||||
uint64_t b = 0;
|
||||
|
||||
for (unsigned i = 0; i < 64; ++i) {
|
||||
b = (b >> 1) | (a << 63);
|
||||
a = (a >> 1) ^ (a & 1 ? poly : 0);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
calc_hi(uint64_t poly, uint64_t a)
|
||||
{
|
||||
for (unsigned i = 0; i < 64; ++i)
|
||||
a = (a >> 1) ^ (a & 1 ? poly : 0);
|
||||
|
||||
return a;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef BUILDING_CRC64_CLMUL
|
||||
|
||||
// MSVC (VS2015 - VS2022) produces bad 32-bit x86 code from the CLMUL CRC
|
||||
// code when optimizations are enabled (release build). According to the bug
|
||||
// report, the ebx register is corrupted and the calculated result is wrong.
|
||||
// Trying to workaround the problem with "__asm mov ebx, ebx" didn't help.
|
||||
// The following pragma works and performance is still good. x86-64 builds
|
||||
// and CRC32 CLMUL aren't affected by this problem. The problem does not
|
||||
// happen in crc_simd_body() either (which is shared with CRC32 CLMUL anyway).
|
||||
//
|
||||
// NOTE: Another pragma after crc64_arch_optimized() restores
|
||||
// the optimizations. If the #if condition here is updated,
|
||||
// the other one must be updated too.
|
||||
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) \
|
||||
&& defined(_M_IX86)
|
||||
# pragma optimize("g", off)
|
||||
#endif
|
||||
|
||||
crc_attr_target
|
||||
crc_attr_no_sanitize_address
|
||||
static uint64_t
|
||||
crc64_arch_optimized(const uint8_t *buf, size_t size, uint64_t crc)
|
||||
{
|
||||
#ifndef CRC_USE_GENERIC_FOR_SMALL_INPUTS
|
||||
// The code assumes that there is at least one byte of input.
|
||||
if (size == 0)
|
||||
return crc;
|
||||
#endif
|
||||
|
||||
// const uint64_t poly = 0xc96c5795d7870f42; // CRC polynomial
|
||||
const uint64_t p = 0x92d8af2baf0e1e85; // (poly << 1) | 1
|
||||
const uint64_t mu = 0x9c3e466c172963d5; // (calc_lo(poly) << 1) | 1
|
||||
const uint64_t k2 = 0xdabe95afc7875f40; // calc_hi(poly, 1)
|
||||
const uint64_t k1 = 0xe05dd497ca393ae4; // calc_hi(poly, k2)
|
||||
|
||||
const __m128i vfold8 = _mm_set_epi64x((int64_t)p, (int64_t)mu);
|
||||
const __m128i vfold16 = _mm_set_epi64x((int64_t)k2, (int64_t)k1);
|
||||
|
||||
__m128i v0, v1, v2;
|
||||
|
||||
#if defined(__i386__) || defined(_M_IX86)
|
||||
crc_simd_body(buf, size, &v0, &v1, vfold16,
|
||||
_mm_set_epi64x(0, (int64_t)~crc));
|
||||
#else
|
||||
// GCC and Clang would produce good code with _mm_set_epi64x
|
||||
// but MSVC needs _mm_cvtsi64_si128 on x86-64.
|
||||
crc_simd_body(buf, size, &v0, &v1, vfold16,
|
||||
_mm_cvtsi64_si128((int64_t)~crc));
|
||||
#endif
|
||||
|
||||
v1 = _mm_xor_si128(_mm_clmulepi64_si128(v0, vfold16, 0x10), v1);
|
||||
v0 = _mm_clmulepi64_si128(v1, vfold8, 0x00);
|
||||
v2 = _mm_clmulepi64_si128(v0, vfold8, 0x10);
|
||||
v0 = _mm_xor_si128(_mm_xor_si128(v1, _mm_slli_si128(v0, 8)), v2);
|
||||
|
||||
#if defined(__i386__) || defined(_M_IX86)
|
||||
return ~(((uint64_t)(uint32_t)_mm_extract_epi32(v0, 3) << 32) |
|
||||
(uint64_t)(uint32_t)_mm_extract_epi32(v0, 2));
|
||||
#else
|
||||
return ~(uint64_t)_mm_extract_epi64(v0, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) \
|
||||
&& defined(_M_IX86)
|
||||
# pragma optimize("", on)
|
||||
#endif
|
||||
|
||||
#endif // BUILDING_CRC64_CLMUL
|
||||
|
||||
|
||||
// Inlining this function duplicates the function body in crc32_resolve() and
|
||||
// crc64_resolve(), but this is acceptable because this is a tiny function.
|
||||
static inline bool
|
||||
is_arch_extension_supported(void)
|
||||
{
|
||||
int success = 1;
|
||||
uint32_t r[4]; // eax, ebx, ecx, edx
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// This needs <intrin.h> with MSVC. ICC has it as a built-in
|
||||
// on all platforms.
|
||||
__cpuid(r, 1);
|
||||
#elif defined(HAVE_CPUID_H)
|
||||
// Compared to just using __asm__ to run CPUID, this also checks
|
||||
// that CPUID is supported and saves and restores ebx as that is
|
||||
// needed with GCC < 5 with position-independent code (PIC).
|
||||
success = __get_cpuid(1, &r[0], &r[1], &r[2], &r[3]);
|
||||
#else
|
||||
// Just a fallback that shouldn't be needed.
|
||||
__asm__("cpuid\n\t"
|
||||
: "=a"(r[0]), "=b"(r[1]), "=c"(r[2]), "=d"(r[3])
|
||||
: "a"(1), "c"(0));
|
||||
#endif
|
||||
|
||||
// Returns true if these are supported:
|
||||
// CLMUL (bit 1 in ecx)
|
||||
// SSSE3 (bit 9 in ecx)
|
||||
// SSE4.1 (bit 19 in ecx)
|
||||
const uint32_t ecx_mask = (1 << 1) | (1 << 9) | (1 << 19);
|
||||
return success && (r[2] & ecx_mask) == ecx_mask;
|
||||
|
||||
// Alternative methods that weren't used:
|
||||
// - ICC's _may_i_use_cpu_feature: the other methods should work too.
|
||||
// - GCC >= 6 / Clang / ICX __builtin_cpu_supports("pclmul")
|
||||
//
|
||||
// CPUID decding is needed with MSVC anyway and older GCC. This keeps
|
||||
// the feature checks in the build system simpler too. The nice thing
|
||||
// about __builtin_cpu_supports would be that it generates very short
|
||||
// code as is it only reads a variable set at startup but a few bytes
|
||||
// doesn't matter here.
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file alone_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "alone_decoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file alone_decoder.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_ALONE_DECODER_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file alone_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file auto_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stream_decoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_buffer_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "block_decoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_buffer_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "block_buffer_encoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_buffer_encoder.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_BLOCK_BUFFER_ENCODER_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "block_decoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_decoder.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_BLOCK_DECODER_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "block_encoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_encoder.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_BLOCK_ENCODER_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_header_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_header_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file block_util.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file common.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file common.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_COMMON_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file easy_buffer_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "easy_preset.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file easy_decoder_memusage.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "easy_preset.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file easy_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "easy_preset.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file easy_encoder_memusage.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "easy_preset.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file easy_preset.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "easy_preset.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file easy_preset.h
|
||||
@ -5,11 +7,11 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_EASY_PRESET_H
|
||||
#define LZMA_EASY_PRESET_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
@ -30,3 +32,5 @@ typedef struct {
|
||||
/// Set *easy to the settings given by the preset. Returns true on error,
|
||||
/// false on success.
|
||||
extern bool lzma_easy_preset(lzma_options_easy *easy, uint32_t preset);
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file file_info.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "index_decoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_buffer_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "filter_decoder.h"
|
||||
@ -24,7 +23,7 @@ lzma_raw_buffer_decode(
|
||||
|| out_pos == NULL || *out_pos > out_size)
|
||||
return LZMA_PROG_ERROR;
|
||||
|
||||
// Initialize the decoer.
|
||||
// Initialize the decoder.
|
||||
lzma_next_coder next = LZMA_NEXT_CODER_INIT;
|
||||
return_if_error(lzma_raw_decoder_init(&next, allocator, filters));
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_buffer_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "filter_encoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_common.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "filter_common.h"
|
||||
@ -122,6 +121,15 @@ static const struct {
|
||||
.changes_size = false,
|
||||
},
|
||||
#endif
|
||||
#if defined(HAVE_ENCODER_RISCV) || defined(HAVE_DECODER_RISCV)
|
||||
{
|
||||
.id = LZMA_FILTER_RISCV,
|
||||
.options_size = sizeof(lzma_options_bcj),
|
||||
.non_last_ok = true,
|
||||
.last_ok = false,
|
||||
.changes_size = false,
|
||||
},
|
||||
#endif
|
||||
#if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
|
||||
{
|
||||
.id = LZMA_FILTER_DELTA,
|
||||
@ -145,7 +153,7 @@ lzma_filters_copy(const lzma_filter *src, lzma_filter *real_dest,
|
||||
return LZMA_PROG_ERROR;
|
||||
|
||||
// Use a temporary destination so that the real destination
|
||||
// will never be modied if an error occurs.
|
||||
// will never be modified if an error occurs.
|
||||
lzma_filter dest[LZMA_FILTERS_MAX + 1];
|
||||
|
||||
lzma_ret ret;
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_common.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_FILTER_COMMON_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "filter_decoder.h"
|
||||
@ -121,6 +120,14 @@ static const lzma_filter_decoder decoders[] = {
|
||||
.props_decode = &lzma_simple_props_decode,
|
||||
},
|
||||
#endif
|
||||
#ifdef HAVE_DECODER_RISCV
|
||||
{
|
||||
.id = LZMA_FILTER_RISCV,
|
||||
.init = &lzma_simple_riscv_decoder_init,
|
||||
.memusage = NULL,
|
||||
.props_decode = &lzma_simple_props_decode,
|
||||
},
|
||||
#endif
|
||||
#ifdef HAVE_DECODER_DELTA
|
||||
{
|
||||
.id = LZMA_FILTER_DELTA,
|
||||
@ -143,6 +150,16 @@ decoder_find(lzma_vli id)
|
||||
}
|
||||
|
||||
|
||||
// lzma_filter_coder begins with the same members as lzma_filter_decoder.
|
||||
// This function is a wrapper with a type that is compatible with the
|
||||
// typedef of lzma_filter_find in filter_common.h.
|
||||
static const lzma_filter_coder *
|
||||
coder_find(lzma_vli id)
|
||||
{
|
||||
return (const lzma_filter_coder *)decoder_find(id);
|
||||
}
|
||||
|
||||
|
||||
extern LZMA_API(lzma_bool)
|
||||
lzma_filter_decoder_is_supported(lzma_vli id)
|
||||
{
|
||||
@ -155,7 +172,7 @@ lzma_raw_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
const lzma_filter *options)
|
||||
{
|
||||
return lzma_raw_coder_init(next, allocator,
|
||||
options, (lzma_filter_find)(&decoder_find), false);
|
||||
options, &coder_find, false);
|
||||
}
|
||||
|
||||
|
||||
@ -174,8 +191,7 @@ lzma_raw_decoder(lzma_stream *strm, const lzma_filter *options)
|
||||
extern LZMA_API(uint64_t)
|
||||
lzma_raw_decoder_memusage(const lzma_filter *filters)
|
||||
{
|
||||
return lzma_raw_coder_memusage(
|
||||
(lzma_filter_find)(&decoder_find), filters);
|
||||
return lzma_raw_coder_memusage(&coder_find, filters);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_decoder.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_FILTER_DECODER_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "filter_encoder.h"
|
||||
@ -159,6 +158,16 @@ static const lzma_filter_encoder encoders[] = {
|
||||
.props_encode = &lzma_simple_props_encode,
|
||||
},
|
||||
#endif
|
||||
#ifdef HAVE_ENCODER_RISCV
|
||||
{
|
||||
.id = LZMA_FILTER_RISCV,
|
||||
.init = &lzma_simple_riscv_encoder_init,
|
||||
.memusage = NULL,
|
||||
.block_size = NULL,
|
||||
.props_size_get = &lzma_simple_props_size,
|
||||
.props_encode = &lzma_simple_props_encode,
|
||||
},
|
||||
#endif
|
||||
#ifdef HAVE_ENCODER_DELTA
|
||||
{
|
||||
.id = LZMA_FILTER_DELTA,
|
||||
@ -184,6 +193,16 @@ encoder_find(lzma_vli id)
|
||||
}
|
||||
|
||||
|
||||
// lzma_filter_coder begins with the same members as lzma_filter_encoder.
|
||||
// This function is a wrapper with a type that is compatible with the
|
||||
// typedef of lzma_filter_find in filter_common.h.
|
||||
static const lzma_filter_coder *
|
||||
coder_find(lzma_vli id)
|
||||
{
|
||||
return (const lzma_filter_coder *)encoder_find(id);
|
||||
}
|
||||
|
||||
|
||||
extern LZMA_API(lzma_bool)
|
||||
lzma_filter_encoder_is_supported(lzma_vli id)
|
||||
{
|
||||
@ -220,18 +239,18 @@ lzma_filters_update(lzma_stream *strm, const lzma_filter *filters)
|
||||
|
||||
extern lzma_ret
|
||||
lzma_raw_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
const lzma_filter *options)
|
||||
const lzma_filter *filters)
|
||||
{
|
||||
return lzma_raw_coder_init(next, allocator,
|
||||
options, (lzma_filter_find)(&encoder_find), true);
|
||||
filters, &coder_find, true);
|
||||
}
|
||||
|
||||
|
||||
extern LZMA_API(lzma_ret)
|
||||
lzma_raw_encoder(lzma_stream *strm, const lzma_filter *options)
|
||||
lzma_raw_encoder(lzma_stream *strm, const lzma_filter *filters)
|
||||
{
|
||||
lzma_next_strm_init(lzma_raw_coder_init, strm, options,
|
||||
(lzma_filter_find)(&encoder_find), true);
|
||||
lzma_next_strm_init(lzma_raw_coder_init, strm, filters,
|
||||
&coder_find, true);
|
||||
|
||||
strm->internal->supported_actions[LZMA_RUN] = true;
|
||||
strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
|
||||
@ -244,8 +263,7 @@ lzma_raw_encoder(lzma_stream *strm, const lzma_filter *options)
|
||||
extern LZMA_API(uint64_t)
|
||||
lzma_raw_encoder_memusage(const lzma_filter *filters)
|
||||
{
|
||||
return lzma_raw_coder_memusage(
|
||||
(lzma_filter_find)(&encoder_find), filters);
|
||||
return lzma_raw_coder_memusage(&coder_find, filters);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_encoder.h
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_FILTER_ENCODER_H
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_flags_decoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "filter_decoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file filter_flags_encoder.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "filter_encoder.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file hardware_cputhreads.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file hardware_physmem.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Jonathan Nieder
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file index.c
|
||||
@ -5,9 +7,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// SPDX-License-Identifier: 0BSD
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file index.h
|
||||
@ -12,9 +14,6 @@
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_INDEX_H
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user