346 Commits

Author SHA1 Message Date
Eric Biggers
29dfcfd866 lib/matchfinder: support dynamic dispatch for init and rebase
Currently the optimized implementations of matchfinder_init() and
matchfinder_rebase() are chosen via static dispatch.  That means that
the AVX-2 implementations usually aren't used.

Fix this by using dynamic dispatch, like what libdeflate does for the
Adler-32 and CRC-32 checksums and for DEFLATE decompression.

Based on work by Andrew Steinborn <git@steinborn.me>
(https://github.com/ebiggers/libdeflate/pull/77).  He wrote:

"The main impact is on x86: the AVX2 matchfinder can now be properly
dynamically dispatched at runtime and if -mavx2 is included in CFLAGS
(or -march set to any platform with AVX2 support). On my Ryzen 9 3900X,
I got an approximately 1% boost in deflate time (measured with a
uncompressed tarball of the Silesia corpus) using just the changes in
this PR and the regular CFLAGS, and a 2.7% boost when specifying -mavx2
as CFLAGS. (I also tested with an Intel Xeon Skylake c5.large EC2
instance, and did not see any performance regression)."
2020-10-28 19:20:53 -07:00
Eric Biggers
f8057e8805 lib/matchfinder: document matchfinder_rebase() preconditions 2020-10-28 19:20:30 -07:00
Eric Biggers
6d66819651 scripts/run_tests.sh: show ldd output if binary isn't dynamically linked 2020-10-28 19:19:48 -07:00
Eric Biggers
952329aeb9 scripts/run_tests.sh: silence some build output 2020-10-26 00:05:30 -07:00
Eric Biggers
ff8634427b lib/matchfinder: simplify init and rebase
Remove the ability of matchfinder_init() and matchfinder_rebase() to
fail due to the matchfinder memory size being misaligned.  Instead,
require that the size always be 128-byte aligned -- which is already the
case.  Also, make the matchfinder memory always be 32-byte aligned --
which doesn't really have any downside.
2020-10-25 22:42:25 -07:00
Eric Biggers
f2f6a6e396 Makefile: support linking programs to shared library
Most Linux distributions want dynamic linking rather than static
linking, so support this via 'make USE_SHARED_LIB=1'.
2020-10-25 22:03:08 -07:00
Eric Biggers
2bfee0204c Makefile: add missing settings to rebuild logic
The Makefile didn't trigger a rebuild if some settings changed, e.g.
LDFLAGS or DECOMPRESSION_ONLY.  Fix this.

Also simplify the rebuild logic by not handling the library and programs
separately, as this optimization doesn't seem to be worthwhile.
2020-10-25 21:36:19 -07:00
Eric Biggers
7ba3155c17 programs: rename program_invocation_name to prog_invocation_name
Avoid confusion with the GNU extension 'program_invocation_name', which
is described by 'man 3 program_invocation_name'.  The GNU version isn't
supposed to be exposed without defining _GNU_SOURCE, which we don't in
any of the relevant files, but it's best to avoid any confusion.
2020-10-25 20:49:27 -07:00
Eric Biggers
25a591b94e libdeflate.h: fix adler parameter name
This is supposed to be just 'adler', not 'adler32'.
2020-10-18 23:07:03 -07:00
Eric Biggers
166084acaa lib/deflate_compress: select min_size_to_compress based on level
The cutoff for outputting uncompressed data is currently < 16 bytes for
all compression levels.  That isn't ideal, since the higher the
compression level, the more we should bother with very small inputs; and
the lower the compression level, the less we should bother.

Use a formula that produces the following cutoffs:

        Level  Cutoff
        -----  ------
        0      56
        1      52
        2      48
        3      44
        4      40
        5      36
        6      32
        7      28
        8      24
        9      20
        10     16
        11     12
        12     8

Update https://github.com/ebiggers/libdeflate/issues/67
2020-10-18 18:37:51 -07:00
Eric Biggers
a2d92667b5 scripts/run_tests.sh: add CFI tests 2020-10-18 15:14:15 -07:00
Eric Biggers
3b4a590f10 scripts/run_tests.sh: add ASAN tests 2020-10-18 15:14:15 -07:00
Eric Biggers
3b12acdf32 scripts/run_tests.sh: test for correct symbol prefixes 2020-10-18 15:14:15 -07:00
Eric Biggers
3a378845c4 scripts/run_tests.sh: test 'make install' and 'make uninstall' 2020-10-18 15:14:15 -07:00
Eric Biggers
ef5a23a65f travis.yml: add shellcheck job 2020-10-18 15:14:15 -07:00
Eric Biggers
5c06c57435 Makefile: add shellcheck target 2020-10-18 15:14:15 -07:00
Eric Biggers
6eb61145a0 travis.yml: improve job specifications
Improve the list of Travis CI jobs by using the build matrix feature to
test all combinations of compilers and architectures on the latest
version of Ubuntu, and by adding more jobs for older versions of Ubuntu.
2020-10-18 15:14:15 -07:00
Eric Biggers
0a9254fb49 scripts/run_tests.sh: refactor and allow specifying CC and CFLAGS
Don't try to detect and use different compilers, since it's better to
specify this via the environment (e.g. via the Travis CI build matrix).

While doing this, also deduplicate the logic for testing with valgrind
and UBSAN, improve the log messages, and add a test with -O3.
2020-10-18 15:14:15 -07:00
Eric Biggers
0a32a34da5 scripts/run_tests.sh: fix a shellcheck warning 2020-10-18 15:14:15 -07:00
Eric Biggers
fb3bbaad0b scripts/run_tests.sh: define $MAKE variable
... so that we don't have to remember to add -j everytime.  Also switch
to a better way of getting the number of processors.
2020-10-18 15:14:15 -07:00
Eric Biggers
de4f3f4bb7 scripts/run_tests.sh: remove concept of skipping tests
Just require that the needed programs have been installed.
2020-10-18 15:14:15 -07:00
Eric Biggers
634291abd6 scripts/run_tests.sh: remove concept of test groups
Now that run_tests.sh has been cleaned up to remove (or move) test
groups that weren't very useful, remove the concept of test groups and
just run all the tests.
2020-10-18 15:14:15 -07:00
Eric Biggers
63efed8dee scripts/run_tests.sh: remove windows_tests
To further trim down run_tests.sh, move the functionality of
windows_tests() directly into .travis.yml.
2020-10-18 15:14:15 -07:00
Eric Biggers
416fea5fad scripts/run_tests.sh: remove checksum_benchmarks
The reason that run_tests.sh supported running checksum_benchmarks.sh is
that as a side effect, checksum_benchmarks.sh runs the 'test_checksums'
program with all combinations of CPU features.

However, commit ec60cb48d11c ("tools/run_tests.sh: test different
combinations of CPU features") made run_tests.sh handle this elsewhere.

So having run_tests.sh run checksum_benchmarks.sh is no longer useful.

Keep checksum_benchmarks.sh around for manual benchmark runs, however.
2020-10-18 15:14:15 -07:00
Eric Biggers
cdd71f52f0 scripts/run_tests.sh: stop auto-logging to run_tests.log
This isn't useful for CI testing, which collects stdout instead.
Just remove the automatic log file for now.
2020-10-18 15:14:15 -07:00
Eric Biggers
c583b0a70c scripts, Makefile: move static_analysis_tests to a Makefile target
To further trim down run_tests.sh, move the code that runs the clang
static analyzer into a 'make' target.
2020-10-18 15:14:15 -07:00
Eric Biggers
14a5617b70 scripts: move android_tests into a new script
android_tests is only useful for local testing, and it wasn't being run
in Travis CI.  Move it into a separate script to avoid complicating
run_tests.sh.
2020-10-18 15:14:15 -07:00
Eric Biggers
6bc4596108 scripts: rename SMOKEDATA to TESTDATA
Use a more obvious name.
2020-10-18 15:14:15 -07:00
Eric Biggers
a89aba54b7 scripts: move litrunlen overflow test into a C test program
This removes the ad-hoc "edge_case" group of tests, and it removes the
dependency on Python.
2020-10-18 15:14:15 -07:00
Eric Biggers
f7138d6172 scripts: remove mips_tests
This was only useful for me to do local testing, I don't have the needed
MIPS router available anymore, and its main purpose was test a big
endian system but that's now covered by testing s390x with Travis CI.
2020-10-18 15:14:15 -07:00
Eric Biggers
50fa75455b scripts: remove windows_build.sh
This script only worked for me to do local testing and wasn't otherwise
used.  In particular, the Windows build tests in Travis CI don't use
this script, nor does the make-windows-releases script use it.
2020-10-18 15:14:15 -07:00
Eric Biggers
ca42459cd7 scripts/run_tests.sh: be compatible with old bash versions
Prior to bash 4.4, using an empty array with 'set -u' produced an error.
Work around it.
2020-10-18 15:14:15 -07:00
Eric Biggers
68a5b89a1b scripts/produce_gzip_benchmark_table.sh: clean up
Address all shellcheck warnings, avoid hardcoded path, and add
'-u -o pipefail'.
2020-10-18 15:14:15 -07:00
Eric Biggers
61583588cd scripts/make-window-releases.sh: address all shellcheck warnings
Also add '-o pipefail'.
2020-10-18 15:14:15 -07:00
Eric Biggers
44980854d3 scripts/gzip_tests.sh: address all shellcheck warnings 2020-10-18 15:14:15 -07:00
Eric Biggers
ea4d0c9919 scripts/gzip_tests.sh: remove test for decreasing size as level increases
Compression is based on heuristics, so we can't guarantee in every
circumstance that the compression ratio will improve as the compression
level increases.  The tests need to be 100% reliable though, so drop
this part of the test.
2020-10-18 15:14:15 -07:00
Eric Biggers
ddb3db2050 scripts/gzip_tests.sh: skip if GNU gzip/gunzip is too old 2020-10-18 15:14:15 -07:00
Eric Biggers
455e9c2c3e scripts/gzip_tests.sh: work around broken timestamps in Travis CI 2020-10-18 15:14:15 -07:00
Eric Biggers
b6f9462708 scripts/gzip_tests.sh: be compatible with old coreutils versions
Very old versions of coreutils don't have 'realpath'.
Use the more portable 'readlink -f' instead.
2020-10-18 15:14:15 -07:00
Eric Biggers
57ddb0571c scripts/exec_tests.sh: address shellcheck warnings 2020-10-18 15:14:15 -07:00
Eric Biggers
c509497a54 scripts/detect.sh: clean up
Remove the need to use a temporary file, fix all the shellcheck
warnings, and add 'set -eu'.
2020-10-18 15:14:15 -07:00
Eric Biggers
b87bd659fd scripts/checksum_benchmarks.sh: address all shellcheck warnings 2020-10-18 15:14:15 -07:00
Eric Biggers
fe04c9e60f scripts/android_build.sh: address shellcheck warnings 2020-10-18 15:14:15 -07:00
Eric Biggers
2c0223afc8 scripts: add .sh suffix to make-windows-releases
All the other shell scripts have it.
2020-10-18 15:14:15 -07:00
Eric Biggers
2cb8c2142d scripts: move detect.sh into scripts directory
This is a shell script, so move it into the scripts directory.
2020-10-18 15:14:15 -07:00
Eric Biggers
bf50c64e86 scripts: rename tools/ directory to scripts/
"scripts" is a more descriptive name than "tools", which sounds too
similar to "programs".
2020-10-18 15:14:15 -07:00
Eric Biggers
eb54d9e257 programs/test_util.c: don't be noisy about skipping perf tests 2020-10-18 15:14:15 -07:00
Eric Biggers
cda4447098 programs/test_*: remove unnecessary 'tests passed' messages 2020-10-18 15:14:15 -07:00
Eric Biggers
303bb42c52 Makefile: allow disabling compiler warnings
Move the user-specified CFLAGS to the end of the CFLAGS definition, so
that warnings the Makefile enables can be disabled using -Wno-$foo.
This is useful when old compilers give false positive warnings.
2020-10-18 15:14:15 -07:00
Eric Biggers
ef936b6521 lib/x86/adler32: use unsigned vector types
This is needed to avoid the following error when using
-fsanitize=undefined with gcc:

    lib/x86/adler32_impl.h:214:2: runtime error: signed integer overflow:
    1951294680 + 1956941400 cannot be represented in type 'int'

Note that this isn't seen when using -fsanitize=undefined with clang.

Old compilers don't have unsigned vector types, so work around that.
2020-10-18 15:14:15 -07:00