]> git.ipfire.org Git - thirdparty/coreutils.git/commit
wc: use avx2 optimization when counting only lines
authorKristoffer Brånemyr <ztion1@yahoo.se>
Sat, 20 Feb 2021 11:27:17 +0000 (12:27 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 2 May 2021 19:51:37 +0000 (20:51 +0100)
commit4064c57380621399b54217a64c2c2bed1d0dccd1
treefd79abf11f263fdde4bf53eb4fc8a0f3cb4f241e
parentd435cfc0bc554b8baef2e690e138e27ac1b4d5b1
wc: use avx2 optimization when counting only lines

Use cpuid to detect CPU support for avx2 instructions.
Performance was seen to improve by 5x for a file with only newlines,
while the performance for a file with no such characters is unchanged.

* configure.ac [USE_AVX2_WC_LINECOUNT]: A new conditional,
set when __get_cpuid_count() and avx2 compiler intrinsics are supported.
* src/wc.c (avx2_supported): A new function using __get_cpuid_count()
to determine if avx2 instructions are supported.
(wc_lines): A new function refactored from wc(),
which implements the standard line counting logic,
and provides the fallback implementation for when avx2 is not supported.
* src/wc_avx2.c: A new module to implement using avx2 intrinsics.
* src/local.mk: Reference the new module.  Note we build as a separate
lib so that it can be portably built with separate -mavx2 etc. flags.
configure.ac
src/local.mk
src/wc.c
src/wc_avx2.c [new file with mode: 0644]