aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc
AgeCommit message (Collapse)AuthorFilesLines
2025-05-28newlib: riscv: Optimize memset() for speedEric Salem1-71/+262
The RISC-V Zba, Zbkb, and Zilsd/Zclsd extensions provide instructions optimized for bit and load/store operations. Use them when available for the RISC-V port. Also increase loop unrolling for faster performance. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-05-27RISC-V: memcpy() align dest when misaligned access is prohibitedMahmoud Abumandour1-12/+60
Add a code path for when source and dest are differently aligned. If misaligned access is slow or prohibited, and the alignments of the source and destination are different, we align the destination to do XLEN stores. This uses only one aligned store for every four (or eight for XLEN == 64) bytes of data. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
2025-05-27RISC-V: memcpy() Use inline functions instead of macros and gotosMahmoud Abumandour1-18/+24
Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
2025-05-27RISC-V: memcpy() Use uintxlen_t for xlen-sized copyMahmoud Abumandour1-35/+36
Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
2025-05-22glob: Fix old style function declarations warningsSebastian Huber1-64/+22
2025-05-22glob: Fix incompatible pointer types errorSebastian Huber1-2/+2
This fixes a compile error with GCC 15.
2025-05-22ftw: Fix incompatible pointer types errorSebastian Huber1-1/+3
This fixes a compile error with GCC 15.
2025-05-21newlib: riscv: Optimize memchr() and memrchr()Eric Salem4-83/+249
The RISC-V Zbb, Zbkb, and Zilsd extensions provide instructions optimized for bit and load/store operations. Use them when available for the RISC-V port. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-05-21newlib: riscv: Add memchr() and memrchr() implementationsEric Salem3-1/+199
Copy stock implementations of memchr() and memrchr() to the RISC-V port. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-05-02newlib: riscv: Remove unnecessary byte load for strlen()Eric Salem1-7/+7
For architectures where XLEN is 32 bits, when detecting a null byte, a word is read at a time. Once a null is found in the word, its precise location is then determined. Make clear to the compiler that if the first three bytes are not null, the last byte must be null, and does not need to be read from the string, since its value is always zero. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-05-02Newlib: Update search.h functions for POSIX.1-2024Mark Geisert5-9/+11
Add type posix_tnode. Change certain uses of "void" to "posix_tnode" in both the prototypes and definitions of functions associated with <search.h>. (Necessary changes to Cygwin's /usr/include/search.h will follow in a separate patch to be sent to cygwin-patches.) Reported-by: Collin Funk <collin.funk1@gmail.com> Addresses: https://cygwin.com/pipermail/cygwin/2025-April/258032.html Signed-off-by: Mark Geisert <mark@maxrnd.com> Fixes: ec98d19a08c2 "* wininfo.h (wininfo::timer_active): Delete."
2025-04-23newlib: riscv: Fix build for rv64eEric Salem1-2/+2
Update the macro check so that rv64e builds successfully. Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-04-15newlib: riscv: Remove unnecessary byte load/store for stpcpy()/strcpy()Eric Salem1-3/+3
For architectures where XLEN is 32 bits, when detecting a null byte, a word is read at a time. Once a null is found in the word, its precise location is then determined. Make clear to the compiler that if the first three bytes are not null, the last byte must be null, and does not need to be read from the source string, since its value is always zero. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-04-11RISC-V: Size optimized versions: Replace add with addim fally4-8/+8
Replace add instructions with addi where applicable in the size optimized versions of memmove(), memset(), memcpy(), and strcmp(). This change does not affect the functions themselves and is only done to improve syntactic accuracy. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11RISC-V: memset() size optimized version: Rename local labelsm fally1-4/+4
Rename local labels to improve readability. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11RISC-V: memset() size optimized version: Use compressed registersEric Salem1-3/+3
Swap register t1 with a3, so that the affected instructions can be compressed. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Reviewed-by: m fally <marlene.fally@gmail.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-04-11RISC-V: memcpy() size optimized version: Use compressed registersMahmoud Abumandour1-4/+4
Replace registers t1 and t2 with registers a3 and a4 respectively, so that the affected instructions can be compressed. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
2025-04-11RISC-V: memcpy() size optimized version: Replace lb with lbuMahmoud Abumandour1-1/+1
Replace lb with lbu to avoid unnecessary sign extension. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
2025-04-11RISC-V: memmove() size optimized version: Relax RAW dependencym fally1-2/+2
Move the instruction that increments the remaining number of bytes to be copied inbetween the load and store instructions. This is done in order to relax the RAW dependency between the load and store instructions. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11RISC-V: memmove() size optimized version: Replace lb with lbum fally1-3/+3
Replace lb with lbu to avoid unnecessary sign extension. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11RISC-V: memmove() size optimized version: Add commentsm fally1-8/+8
Since the algorithm in this version of memmove() is different from the original version, add comments to give a description. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Reviewed-by: Eric Salem <ericsalem@gmail.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11RISC-V: memmove() size optimized version: Rename local labelsm fally1-6/+6
Rename local lables so that the structure of the function is clearer. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11RISC-V: memmove() size optimized version: Use compressed registers onlym fally1-8/+8
Change register t1 to register a4, so that the affected instructions can be compressed. Since now we have less registers available, the following changes need to be made: In the previous version of this function, a4 was used to hold the offset that needs to be added to source and destination addresses before copying any data in the case of source address > destination address. Since a4 now holds the destination address, this offset is not calculated anymore. Instead, the value in a2 (the number of bytes to be copied) is added to the source and destination addresses. Therefore, in the case of source address > destination adress, a value of 1 needs to be subtracted from both addresses before starting the copying process. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11RISC-V: memmove() size optimized version: Use compressed registerm fally1-2/+2
Replace register t2 with register a5, so that lb/sb instructions can be compressed. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-04-11newlib: sys/unistd.h: Change inline to __inlineTakashi Yano1-1/+1
Addresses: https://sourceware.org/pipermail/cygwin-patches/2025q2/013644.html Fixes: 3e8a7eb1a868 ("sys/unistd.h: fix definition of setproctitle_init") Reported-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> Co-authored-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-04-02newlib: riscv: Fix build and reorganize header filesEric Salem6-11/+21
The sys/asm.h header file is included for certain assembly files, so move the typedef to a separate header file due to the build breaking on some systems. Also include the port's string header file (and move and rename) instead of the system's version. Addresses: https://sourceware.org/pipermail/newlib/2025/021591.html Fixes: c3b9bb173c8c ("newlib: riscv: Add XLEN typedef and clean up types") Reported-by: Jeff Law <jlaw@ventanamicro.com> Suggested-by: Kito Cheng <kito.cheng@gmail.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-04-01RISC-V: Fix the asm code for large code modelKito Cheng1-1/+8
The large code model assume the data may far away from the code, so we must put the address of the target data wihin the `.text` section, normally we will just put within the function or nearby the function to prevent it out-of-range. Report from riscv-gnu-toolchain: https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1699 Verified with riscv-gnu-toolchain with rv64gc.
2025-03-24getlocalename_l: allow LC_ALL categoryCorinna Vinschen2-3/+17
Following the changes from Austin Group bug https://www.austingroupbugs.net/view.php?id=1741, getlocalename_l() now allows to specify LC_ALL and returns a setlocale-conmpatible LC_ALL locale string. Consequentially we have to raise the size of _reent::_getlocalename_l_buf so there's enough space for the LC_ALL locale string. Guard all different definitions and usages of _getlocalename_l_buf in reent.h with _MB_CAPABLE. Link: https://www.austingroupbugs.net/view.php?id=1741 Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24locale: drop global_locale_string, add locale_string to locale_tCorinna Vinschen2-22/+29
After 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") the Austin Group changed the definition of getlocalename_l() to return setlocale-compatible strings if LC_ALL has been specified. In contrast to the former definition which disallowed LC_ALL as category. In preparation, add a locale_string to every locale_t, and drop the static global_locale_string. This in turn requires to change currentlocale() to work locale-agnostic. Rename to __currentlocale and take two parameters, the locale object and a target string to store the locale string. The latter is required to allow specifiying a target string not in the current locale. Link: https://www.austingroupbugs.net/view.php?id=1741 Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24getlocalename_l: fix commentCorinna Vinschen1-1/+1
Fix name of the defining POSIX standard. Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24getlocalename_l: fix return value in LC_GLOBAL_LOCALE caseCorinna Vinschen1-2/+2
The data was written to the per-reent getlocalename buffer, but the value wasn't returned. Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24newlib: riscv: Add stpcpy() portEric Salem4-45/+75
Add implementation of stpcpy() to the RISC-V port. Also refactor shared code between strcpy() and stpcpy() to a common function. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-03-24newlib: riscv: Optimize strlen()Eric Salem2-12/+57
The RISC-V Zbb extension provides instructions optimized for bit operations. Use them when available for the RISC-V port. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-03-24newlib: riscv: Add XLEN typedef and clean up typesEric Salem4-44/+45
The size of the long data type isn't precisely defined in the C standard, so create a new typedef that uses either uint32_t or uint64_t based on XLEN. The fixed width types are more robust against any ABI changes and fit the data types of the intrinsic functions. Use the new uintxlen_t type instead of long and uintptr_t. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-03-14newlib: fix uninitialized character count being used when printing float ↵Igor Petrov2-0/+2
without "_printf_float" being linked Patch fixes wrong number of written characters being returend from 'printf' family of functionsx when '_printf_float' is not linked (nano.specs). If user tries to print a floating point number anyway, returned number of written characters is not correct. For example in printf("%d%f", 1, 1.0); should return 1, but actaully returns 2.
2025-03-12posix_spawn: skip SIGKILL & SIGSTOPYuyi Wang1-0/+2
sigaction() returns EINVAL on SIGKILL & SIGSTOP. We need to skip them. Fixes: c7c1a1ca1b33 ("* libc/posix/posix_spawn.c: New file.")
2025-03-05sys/unistd.h: fix definition of setproctitle_initCorinna Vinschen1-1/+1
setproctitle_init is defined in c2x manner, omitting names for the unused parameters. This can result in warnings or errors on certain compiler versions: clang 8: error: parameter name omitted clang 15: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions] gcc -Wsystem-headers -pedantic -std=c17: warning: ISO C does not support omitting parameter names in function definitions before C2X [-Wpedantic] Add parameters to avoid above warning and errors. Fixes: 2e7f7b96e5f1 ("Cygwin: implement setproctitle") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-03Silence -Woverflow warning in arc4random.cJan Dubiec1-3/+3
This patch fixes "integer overflow" warning in arc4random.c. It explicitly casts REKEY_BASE macro to size_t. The existing code relies on an implicit conversion to int and assumes that sizeof(int)=sizeof(size_t), which is not always true. 2025-03-02 Jan Dubiec <jdx@o2.pl> newlib/ChangeLog: * libc/stdlib/arc4random.c (REKEY_BASE): Explicitly cast the macro to size_t. newlib/libc/stdlib/arc4random.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
2025-03-03Silence -Wshift-count-overflow warningsJan Dubiec3-5/+6
This patch fixes a few "left shift count >= width of type [-Wshift-count-overflow]" warnings. Before shifting a char 16 (or more) bits left first it explicitly casts the char to uint32_t. The existing code relies on implicit casts to int and assumes that ints are 32-bit. This is not always true because the C standard does not require int to be 32-bit and there are targets (e.g. H8/300) where by default int is indeed 16-bit. 2025-03-02 Jan Dubiec <jdx@o2.pl> newlib/ChangeLog: * libc/stdlib/gdtoa-gdtoa.c (gdtoa): Cast to __ULong before left shift. * libc/string/memmem.c (memmem): Cast to uint32_t before left shift. * libc/string/strstr.c (strstr2): Ditto. (strstr3): Ditto. (strstr4): Ditto. newlib/libc/stdlib/gdtoa-gdtoa.c | 2 +- newlib/libc/string/memmem.c | 3 ++- newlib/libc/string/strstr.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-)
2025-03-03H8/300: Silence -Wold-style-definition warningsJan Dubiec2-6/+3
2025-03-02 Jan Dubiec <jdx@o2.pl> newlib/ChangeLog: * libc/sys/h8300hms/sbrk.c: Replace the K&R definition with the standard one. * libc/sys/h8300hms/syscalls.c (_isatty): Ditto. (_unlink): Ditto. newlib/libc/sys/h8300hms/sbrk.c | 3 +-- newlib/libc/sys/h8300hms/syscalls.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-)
2025-02-21Add check for clang to avoid unnecessary FPU directivesVolodymyr Turanskyy1-2/+2
This improves compatibility with clang that does not support vfpxd and does not need these extra directives. Change-Id: Id2027e622aef8457ac9c7e1d6715a9240ce8e3f0
2025-02-21Use .p2align 2 instead of .align 0Volodymyr Turanskyy2-2/+2
This is to improve compatibility with LLVM clang: .align 0 is a special case for GCC that is not handled by clang. Change-Id: I855939a32294c74813ecce7275a362265dbc3b1a
2025-02-17strcasecmp family: cast character to unsigned when calling tolowerCorinna Vinschen4-10/+10
The strcasecmp family of functions (strcasecmp, strncasecmp, strcasecmp_l, strncasecmp_l) call tolower on the incoming character before comparison. tolower takes an int as parameter. All four strcasecmp functions neglect to cast the character to unsigned before using it as parameter to tolower. This tolower is called with negative values if the incoming character is not in the ASCII range. This breaks case-insensitive comparison in other singlebyte codesets like ISO-8859-1 with native characters. Adding casts to unsigned char when calling tolower fixes it. Reported-by: Bruno Haible <bruno@clisp.org> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-14unistd.h: enable SEEK_DATA and SEEK_HOLE also for POSIX-1.2024Christian Franke1-1/+1
https://pubs.opengroup.org/onlinepubs/9799919799/functions/lseek.html Signed-off-by: Christian Franke <christian.franke@t-online.de>
2025-02-12Protect strcat from accessing an unaligend long pointerAlexey Lapshin1-9/+12
- related to Bug libc/32679
2025-02-11Protect strncat from accessing an unaligend long pointerJeff Johnston1-9/+12
- fixes Bug libc/32679
2025-02-10newlib: introduce --enable-newlib-hw-misaligned-access optionAlexey Lapshin4-2/+20
Some hardware may perform better when copying unaligned word-sized memory compared to byte-by-byte copying. In case not defined explicitly by --enable-newlib-hw-misaligned-access config option or variable $default_newlib_hw_misaligned_access in configure.host file the compiler check will be performed to detect if __riscv_misaligned_fast or __riscv_misaligned_slow is defined. This commit introduces autodetection for RISC-V. Additionally, checking for __ARM_FEATURE_UNALIGNED could be checked for ARM architecture. However, this was not implemented in the commit, as changes in newlib/libc/machine/[arm|aarch64] need to be performed.
2025-02-10newlib: str[n]cat: optimize skipping of the destination stringAlexey Lapshin2-17/+18
Prepare pointer to be aligned and than use word-size iterator on aligned memory.
2025-02-10newlib: memmove: improve performance for overlapping buffersAlexey Lapshin1-3/+21
This change provides word-sized copy for overlapping buffers, that could increase performance significantly. Performance measurement for RISCV: uint8_t buf[1024]; memmove (buf + 4, buf, sizeof(buf) - 4); CPU cycles: 12255 -> 2076
2025-02-10newlib: mem[p]cpy/memmove improve performance for optimized versionsAlexey Lapshin3-3/+3
This change improves performance on memory blocks with sizes in range [4..15]. Performance measurements made for RISCV machine (memset): size 4, CPU cycles change: 50 -> 37 size 5, CPU cycles change: 57 -> 40 size 6, CPU cycles change: 64 -> 47 size 7, CPU cycles change: 71 -> 54 size 8, CPU cycles change: 78 -> 44 size 9, CPU cycles change: 85 -> 47 size 10, CPU cycles change: 92 -> 54 size 11, CPU cycles change: 99 -> 61 size 12, CPU cycles change: 106 -> 51 size 13, CPU cycles change: 113 -> 54 size 14, CPU cycles change: 120 -> 61 size 15, CPU cycles change: 127 -> 68