aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/string
AgeCommit message (Collapse)AuthorFilesLines
2021-09-03strstr: avoid warningsCorinna Vinschen2-7/+7
unused function warning for two_way_short_needle, different char type warnings for standard string functions Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-06fix and amend scripts and makefile rules to generate Unicode dataThomas Wolff2-16/+19
2021-07-06update to Unicode 13.0Thomas Wolff2-51/+55
2021-04-13Add build mechanism to share common header files between machinesCorinna Vinschen1-0/+1
So far the build mechanism in newlib only allowed to either define machine-specific headers, or headers shared between all machines. In some cases, architectures are sufficiently alike to share header files between them, but not with other architectures. A good example is ix86 vs. x86_64, which share certain traits with each other, but not with other architectures. Introduce a new configure variable called "shared_machine_dir". This dir can then be used for headers shared between architectures. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-02-18Locale modifier "@cjksingle" to enforce single-width CJK width.Thomas Wolff1-2/+6
This option follows a proposal in the Terminals Working Group Specifications (https://gitlab.freedesktop.org/terminal-wg/specifications/issues/9#note_406682). It makes locale width consistent with the corresponding mintty feature.
2019-08-14memmem.c and strstr.c: do not require -std=c99Giacomo Tesio2-5/+10
2019-01-13update to Unicode 11.0Thomas Wolff2-57/+62
2019-01-01Improve performance of memmemWilco Dijkstra2-51/+137
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>
2018-10-18Improve performance of strstrWilco Dijkstra1-96/+127
v3: Add support for read ahead using strnlen, giving an additional 25% speedup on large inputs (both short and long needles). This patch significantly improves performance of strstr by using Sunday's Quick-Search algorithm. Due to its simplicity it has the best average performance of string matching algorithms on almost all inputs. It uses a bad-character shift table to skip past mismatches. The needle length is limited to 254 - this reduces the shift table memory 4 to 8 times, lowering preprocessing overhead and minimizing cache effects. The limit also implies its worst-case performance is linear. Larger needles are processed by the Two-Way algorithm. The macro AVAILABLE has been improved to use strnlen to read the input in chunks. This results in a 2.5 times speedup for large needles, reducing the performance drop when the Quick-Search algorithm can't be used. The code for 1-4 byte needles has been simplified and now uses unsigned char. Since the optimized code relies on 8-bit chars, we defer to the size-optimized implementation if CHAR_BIT > 8. The performance gain of finding a set of randomly chosen words of size 8 in 256 bytes of English text is 14 times on AArch64. For longer haystacks the gain is well over 20 times. The size-optimized strstr has also been rewritten from scratch to improve performance. On the same test the performance gain is 69%. Tested against GLIBC testsuite, randomized tests and the GNULIB strstr test (https://git.savannah.gnu.org/cgit/gnulib.git/tree/tests/test-strstr.c). --
2018-09-05Improve strstr performance of short needlesWilco Dijkstra1-10/+65
Improve strstr performance for the common case of short needles. For a single character strchr is best, for 2-4 characters a small loop is fastest. For these the speedup over the Two-Way algorithm is ~10 times on large strings. Newlib builds, the new code passes GLIBC testsuite. OK for commit?
2018-08-29Use __inhibit_loop_to_libcall in all memset/memcpy implementationsKeith Packard1-0/+2
This macro selects a compiler option that disables recognition of common memset/memcpy patterns and converting those to direct memset/memcpy calls. Signed-off-by: Keith Packard <keithp@keithp.com>
2018-03-14fix/enhance Unicode table generation scriptsThomas Wolff1-10/+27
Scripts do not try to acquire Unicode data by best-effort magic anymore. Options supported: -h for help -i to copy Unicode data from /usr/share/unicode/ucd first -u to download Unicode data from unicode.org first If (despite of -i or -u if given) the necessary Unicode files are not available locally, table generation is skipped, but no error code is returned, so not to obstruct the build process if called from a Makefile.
2018-03-12width data generationThomas Wolff5-0/+1388
2018-03-12use generated width dataThomas Wolff1-126/+24
2018-03-12generated width data, Unicode 10.0Thomas Wolff3-0/+201
These tables provide character width properties for use by the wcwidth/wcswidth functions. They are generated from Unicode.
2018-01-17ansification: remove _EXFUN, _EXFUN_NOTHROWYaakov Selkowitz1-1/+1
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _DEFUNYaakov Selkowitz85-175/+88
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _CAST_VOIDYaakov Selkowitz1-3/+3
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _PTRYaakov Selkowitz9-25/+25
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _PARAMSYaakov Selkowitz1-1/+1
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _CONSTYaakov Selkowitz70-144/+144
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _ANDYaakov Selkowitz77-124/+124
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-07makedoc: make errors visibleJon Turney1-3/+3
Discard QUICKREF sections, rather than writing them to stderr Discard MATHREF sections, rather than discarding as an error Pass NOTES sections through to texinfo, rather than discarding as an error Don't redirect makedoc stderr to .ref file Remove makedoc output on error Remove .ref files from CLEANFILES Regenerate Makefile.ins Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2017-12-01string: remove TRAD_SYNOPSISYaakov Selkowitz85-546/+85
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-11-30string: add wmempcpyYaakov Selkowitz4-38/+81
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-09-19Fix warnings and documentation in strnstr.cSebastian Huber1-4/+3
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-08-30newlib: string/Makefile.am (CHEWOUT_FILES): Add strnstr.defCorinna Vinschen2-2/+2
Regenerate strings/Makefile.in Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-08-30newlib: strnstr: drop traditional synopisisCorinna Vinschen1-7/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-08-30Add man page entry for strnstr.c.Sichen Zhao2-0/+43
2017-08-30Modify strnstr.c.Sichen Zhao1-55/+10
2017-08-25newlib: rebuild string/Makefile.inCorinna Vinschen1-27/+49
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-08-25Port strnstr.c to newlib.Sichen Zhao1-0/+1
2017-08-25Import strnstr.c from FreeBSD.Sichen Zhao1-0/+65
2017-07-05Add ffsl(), ffsll(), fls(), flsl(), flsll()Sebastian Huber7-13/+238
Use compiler builtin for ffs(). Remove duplicate implementation from Cygwin. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-07-05Implement bzero() via memset()Sebastian Huber1-8/+5
Use memset() to implement bzero() to profit from machine-specific memset() optimizations. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-19string: fix strverscmp doc inclusionYaakov Selkowitz1-0/+3
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-06-19string: add strverscmpYaakov Selkowitz4-2/+114
The actual implementation is from musl (MIT license). Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-03-15libc/string/strsignal.c: Use of || not && lead to dead code.Joel Sherrill1-4/+2
Coverity Id: 175333
2017-01-16Add missing headers to fix implicit function defnsPat Pannuto2-0/+2
A few files were missing headers for memset/malloc, likely missed because the files don't directly call the functions, rather they come in via macros in libc/include/sys/reent.h: #define _REENT_CHECK(var, what, type, size, init) do { \ struct _reent *_r = (var); \ if (_r->what == NULL) { \ _r->what = (type)malloc(size); \ #define _REENT_CHECK_ASCTIME_BUF(var) \ _REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \ memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE)) Without these fixes, implicit function signatures are provided, which gcc warns could cause aliasing issues down the line: ../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'memset' does not match original declaration [-Wlto-type-mismatch] /Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: return value type mismatch _PTR _EXFUN(memset,(_PTR, int, size_t)); ^ /Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: 'memset' was previously declared here /Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: code may be misoptimized unless -fno-strict-aliasing is used ../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch] /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch extern _PTR malloc _PARAMS ((size_t)); ^ /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used ../../../../../../../newlib-2.5.0/newlib/libc/time/lcltime.c:58:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch] /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch extern _PTR malloc _PARAMS ((size_t)); ^ /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used ../../../../../../../newlib-2.5.0/newlib/libc/string/strsignal.c:70:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch] /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch extern _PTR malloc _PARAMS ((size_t)); ^ /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here /Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used Including the proper headers elminates the implicit function signatures and these warnings.
2016-12-22Bump release to 2.5.0 for yearly snapshot.newlib-2_5_0Jeff Johnston1-32/+18
2016-08-31Fix typo in strerror doccygwin-2_6_0-releaseCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-23strerror_l: Fix copy-and-paste typoEric Blake1-1/+1
Signed-off-by: Eric Blake <eblake@redhat.com>
2016-08-23Mention strerror_l in libc/string/strings.texCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-23Implement missing POSIX-1.2008 function strerror_lCorinna Vinschen1-1/+18
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-21Remove extern declaration of __locale_cjk_lang in string/local.hCorinna Vinschen1-4/+0
Now that __locale_cjk_lang is an inline function in setlocale.h and setlocale.h is included, the declaration doesn't make sense. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-15Implement per-locale string functionsCorinna Vinschen18-52/+576
strcasecmp_l, strcoll_l, strncasecmp_l, strxfrm_l, wcscasecmp_l, wcscoll_l, wcstrncasecmp_l, wcstrxfrm_l, strftime_l. Add missing CHEWOUT_FILES from previous patch. TODO: strfmon_l. Signed-off by: Corinna Vinschen <corinna@vinschen.de>
2016-07-04Regenerate newlib MakefilesJon Turney1-3/+16
2016-03-18Add timingsafe_memcmp()Sebastian Huber3-18/+73
This function is used by LibreSSL and OpenSSH and is provided by the OpenBSD libc. * libc/include/string.h (timingsafe_memcmp): Declare. * libc/string/timingsafe_memcmp.c: New file. * libc/string/Makefile.am: Add new file. * libc/string/Makefile.in: Regenerate.
2016-03-18Add timingsafe_bcmp()Sebastian Huber3-21/+58
This function is used by LibreSSL and OpenSSH and is provided by the OpenBSD libc. * libc/include/string.h (timingsafe_bcmp): Declare. * libc/string/timingsafe_bcmp.c: New file. * libc/string/Makefile.am: Add new file. * libc/string/Makefile.in: Regenerate.
2016-03-18Add explicit_bzero()Sebastian Huber3-46/+72
This function is used by LibreSSL and OpenSSH and is provided by the OpenBSD libc. * libc/include/string.h (explicit_bzero): Declare. * libc/string/explicit_bzero.c: New file. * libc/string/Makefile.am: Add new file. * libc/string/Makefile.in: Regenerate.