diff options
author | Kristoffer Brånemyr <ztion1@yahoo.se> | 2021-02-20 12:27:17 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2021-05-02 20:51:37 +0100 |
commit | 4064c57380621399b54217a64c2c2bed1d0dccd1 (patch) | |
tree | fd79abf11f263fdde4bf53eb4fc8a0f3cb4f241e /src/local.mk | |
parent | d435cfc0bc554b8baef2e690e138e27ac1b4d5b1 (diff) | |
download | coreutils-4064c57380621399b54217a64c2c2bed1d0dccd1.tar.gz |
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.
Diffstat (limited to 'src/local.mk')
-rw-r--r-- | src/local.mk | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/local.mk b/src/local.mk index 8c8479a53..c6555dafb 100644 --- a/src/local.mk +++ b/src/local.mk @@ -427,6 +427,15 @@ src_basenc_CPPFLAGS = -DBASE_TYPE=42 $(AM_CPPFLAGS) src_expand_SOURCES = src/expand.c src/expand-common.c src_unexpand_SOURCES = src/unexpand.c src/expand-common.c +src_wc_SOURCES = src/wc.c +if USE_AVX2_WC_LINECOUNT +noinst_LIBRARIES += src/libwc_avx2.a +src_libwc_avx2_a_SOURCES = src/wc_avx2.c +wc_avx2_ldadd = src/libwc_avx2.a +src_wc_LDADD += $(wc_avx2_ldadd) +src_libwc_avx2_a_CFLAGS = -mavx2 $(AM_CFLAGS) +endif + # Ensure we don't link against libcoreutils.a as that lib is # not compiled with -fPIC which causes issues on 64 bit at least src_libstdbuf_so_LDADD = $(LIBINTL) |