newlib-cygwin/newlib/libc/string
Wilco Dijkstra 353ebae304 Improve performance of memmem
This patch significantly improves performance of memmem using a novel
modified Horspool algorithm.  Needles up to size 256 use a bad-character
table indexed by hashed pairs of characters to quickly skip past mismatches.
Long needles use a self-adapting filtering step to avoid comparing the whole
needle repeatedly.

By limiting the needle length to 256, the shift table only requires 8 bits
per entry, lowering preprocessing overhead and minimizing cache effects.
This limit also implies worst-case performance is linear.

Small needles up to size 2 use a dedicated linear search.  Very long needles
use the Two-Way algorithm (to avoid increasing stack size inlining is now disabled).

The performance gain is 6.6 times on English text on AArch64 using random
needles with average size 8 (this is even faster than the recently improved strstr
algorithm, so I'll update that in the near future).

The size-optimized memmem has also been rewritten from scratch to get a
2.7x performance gain.

Tested against GLIBC testsuite and randomized tests.

Message-Id: <DB5PR08MB1030649D051FA8532A4512C883B20@DB5PR08MB1030.eurprd08.prod.outlook.com>
2019-01-01 09:44:59 -06:00
..
Makefile.am string: add wmempcpy 2017-11-30 04:06:49 -06:00
Makefile.in makedoc: make errors visible 2017-12-07 11:54:11 +00:00
WIDTH-A width data generation 2018-03-12 10:17:20 +01:00
ambiguous.t generated width data, Unicode 10.0 2018-03-12 10:17:20 +01:00
bcmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
bcopy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
bzero.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
combining.t generated width data, Unicode 10.0 2018-03-12 10:17:20 +01:00
explicit_bzero.c Add explicit_bzero() 2016-03-18 12:33:40 +01:00
ffsl.c Add ffsl(), ffsll(), fls(), flsl(), flsll() 2017-07-05 13:49:48 +02:00
ffsll.c Add ffsl(), ffsll(), fls(), flsl(), flsll() 2017-07-05 13:49:48 +02:00
fls.c Add ffsl(), ffsll(), fls(), flsl(), flsll() 2017-07-05 13:49:48 +02:00
flsl.c Add ffsl(), ffsll(), fls(), flsl(), flsll() 2017-07-05 13:49:48 +02:00
flsll.c Add ffsl(), ffsll(), fls(), flsl(), flsll() 2017-07-05 13:49:48 +02:00
gnu_basename.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
index.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
local.h ansification: remove _EXFUN, _EXFUN_NOTHROW 2018-01-17 11:47:29 -06:00
memccpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
memchr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
memcmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
memcpy.c Use __inhibit_loop_to_libcall in all memset/memcpy implementations 2018-08-29 16:05:37 +02:00
memmem.c Improve performance of memmem 2019-01-01 09:44:59 -06:00
memmove.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mempcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
memrchr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
memset.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
mkunidata fix/enhance Unicode table generation scripts 2018-03-14 10:44:32 +01:00
mkwide width data generation 2018-03-12 10:17:20 +01:00
mkwidthA width data generation 2018-03-12 10:17:20 +01:00
rawmemchr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
rindex.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
stpcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
stpncpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
str-two-way.h Improve performance of memmem 2019-01-01 09:44:59 -06:00
strcasecmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strcasecmp_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
strcasestr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strcat.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strchr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strchrnul.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strcmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strcoll.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strcoll_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
strcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strcspn.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strdup.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strdup_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strerror.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strerror_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strings.tex Add man page entry for strnstr.c. 2017-08-30 15:10:07 +02:00
strlcat.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strlcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strlen.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strlwr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strncasecmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strncasecmp_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
strncat.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strncmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strncpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strndup.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strndup_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strnlen.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strnstr.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
strpbrk.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strrchr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strsep.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strsignal.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strspn.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strstr.c Improve performance of strstr 2018-10-18 19:51:39 +02:00
strtok.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strtok_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strupr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strverscmp.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
strxfrm.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
strxfrm_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
swab.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
timingsafe_bcmp.c Add timingsafe_bcmp() 2016-03-18 12:33:40 +01:00
timingsafe_memcmp.c Add timingsafe_memcmp() 2016-03-18 12:33:40 +01:00
u_strerr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
uniset width data generation 2018-03-12 10:17:20 +01:00
wcpcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcpncpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcscasecmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcscasecmp_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
wcscat.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcschr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcscmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcscoll.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcscoll_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
wcscpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcscspn.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsdup.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
wcslcat.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcslcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcslen.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsncasecmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsncasecmp_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
wcsncat.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsncmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsncpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsnlen.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcspbrk.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsrchr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsspn.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsstr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstok.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcstrings.tex string: add wmempcpy 2017-11-30 04:06:49 -06:00
wcswidth.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsxfrm.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wcsxfrm_l.c string: remove TRAD_SYNOPSIS 2017-12-01 03:41:52 -06:00
wcwidth.c use generated width data 2018-03-12 10:17:20 +01:00
wide.t generated width data, Unicode 10.0 2018-03-12 10:17:20 +01:00
wmemchr.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wmemcmp.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wmemcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wmemmove.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wmempcpy.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
wmemset.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00
xpg_strerror_r.c ansification: remove _DEFUN 2018-01-17 11:47:26 -06:00