aboutsummaryrefslogtreecommitdiff
path: root/newlib
AgeCommit message (Collapse)AuthorFilesLines
2025-06-02RISC-V: strcmp: refactor labels for improved readabilitypuranikvinit1-13/+18
Renames labels in strcmp.S to use descriptive .L prefixes (e.g., .Lcompare, .Lreturn_diff) instead of numeric labels (e.g., 1f, 2f). This improves maintainability and aligns with modern assembly conventions without affecting functionality. Signed-off-by: puranikvinit <kvp933.vinit@gmail.com> Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
2025-06-02RISC-V: setjmp: reduce code size for register load/store with Zilsdpuranikvinit1-25/+49
This patch optimizes the RISC-V setjmp implementation in newlib/libc/machine/riscv/setjmp.S for 32-bit targets. It reduces code size by using doubleword store/load instructions (sd/ld) when the Zilsd or Zclsd extensions are available for saving and restoring s0-s11 registers, while preserving the original single-word instructions (REG_S/REG_L) for compatibility with other configurations. Signed-off-by: puranikvinit <kvp933.vinit@gmail.com> Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> RISC-V: setjmp: reduce code size for register load/store with Zilsd
2025-06-02newlib: riscv: Remove undefined behavior in strlen()Eric Salem1-1/+4
Pointer arithmetic overflow is undefined behavior, so use a signed type to avoid it. Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-05-28newlib: riscv: Align whitespace of size optimized memset()Eric Salem1-4/+4
Align the whitespace of the size optimized implementation of memset() to match the speed optimized version. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
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-21libm: riscv: Reduce sqrt and sqrtf function for code sizezhusonghe2-0/+2
The merged below patch modifies the __ieee754_sqrtf and __ieee754_sqrt functions to use a shared implementation, replacing the original fsqrt.d[s] instruction usage. patch:https://sourceware.org/git/?p=newlib-cygwin.git;a=commit;h=d572c4482b473d7725be0f9380d4f5d8342e4390 Signed-off-by: Songhe Zhu <zhusonghe@eswincomputing.com>
2025-05-21newlib: Regenerate configuration fileEric Salem1-2/+39
Two new C files were added to the RISC-V build, so regenerate the relevant configuration file. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
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-14Remove Marcus Shawcroft from MAINTAINERSRichard Earnshaw1-1/+0
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-28makedocbook: Avoid python deprecation warningsJon Turney1-2/+2
Avoid some deprecation warnings with recent python: > .../newlib/doc/makedocbook.py:201: DeprecationWarning: 'count' is passed as positional argument > .../newlib/doc/makedocbook.py:566: DeprecationWarning: 'count' is passed as positional argument
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-25Fix GCN SIMD libm bugAndrew Stubbs1-2/+15
Since January, GCC has been miscompiling Newlib libm on AMD GCN due to undefined behaviour in the RESIZE_VECTOR macro. It was "working" but expanding the size of a vector would no longer zero the additional lanes, as it expected. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119325
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: regenerate Makefile.inCorinna Vinschen1-1/+20
A new C file was added to the RISC-V build
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(-)