]> git.ipfire.org Git - thirdparty/coreutils.git/commit
wc: improve aarch64 Neon optimization for 'wc -l'
authorCollin Funk <collin.funk1@gmail.com>
Tue, 10 Mar 2026 02:32:27 +0000 (19:32 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Tue, 10 Mar 2026 03:06:07 +0000 (20:06 -0700)
commite0190a9d1b208136bcd757f5f687d2451e5430d7
tree1d5b71d1fbefbfdacdfde9b96e1fa110202493e5
parenta4cf72f5a798edcbe9502a53e6e9a042d9a1163d
wc: improve aarch64 Neon optimization for 'wc -l'

    $ yes abcdefghijklmnopqrstuvwxyz | head -n 200000000 > input
    $ time ./src/wc-prev -l input
    200000000 input

    real 0m1.240s
    user 0m0.456s
    sys 0m0.784s
    $ time ./src/wc -l input
    200000000 input

    real 0m0.936s
    user 0m0.141s
    sys 0m0.795s

* configure.ac: Use unsigned char for the buffer to avoid potential
compiler warnings. Check for the functions being used in src/wc_neon.c
after this patch.
* src/wc_neon.c (wc_lines_neon): Use vreinterpretq_s8_u8 to convert 0xff
into -1 instead of bitwise AND instructions into convert it into 1.
Perform the pairwise addition and lane extraction once every 8192 bytes
instead of once every 64 bytes.
Thanks to Lasse Collin for spotting this and reviewing a draft of this
patch.
configure.ac
src/wc_neon.c