summaryrefslogtreecommitdiffstats
path: root/newlib
Commit message (Collapse)AuthorAgeFilesLines
...
* libc/include/math.h: Remove parameter nameChristophe Lyon2020-09-251-8/+8
| | | | | | | | | | | | | | | | | | | | | As discussed in GCC bug 97088 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97088), parameters in prototypes of library functions should use reserved names, or no name at all. This patch removes the 'x' parameter name from extern int __isinff (float); extern int __isinfd (double); extern int __isnanf (float); extern int __isnand (double); extern int __fpclassifyf (float); extern int __fpclassifyd (double); extern int __signbitf (float); extern int __signbitd (double); to avoid possible clashes with user code in case someone uses before including Newlib's math.h (or uses some other conflicting definition)
* Port of C-SKY for newlibJojo R2020-09-2311-2/+6360
| | | | | | | | | Contributor list:   - Lifang Xia <lifang_xia@c-sky.com>   - Jojo R <jiejie_rong@c-sky.com>   - Xianmiao Qu <xianmiao_qu@c-sky.com>   - Yunhai Shang <yunhai_shang@c-sky.com>
* libm: Make tgamma(-small) = -INFINITYKeith Packard2020-09-181-1/+1
| | | | | | | Need to copy the argument sign to the output for tgamma(finite) overflow case. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm: Fix 'gamma' and 'gammaf' functions. Clean up other gamma code. [v2]Keith Packard via Newlib2020-09-0413-118/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current gamma, gamma_r, gammaf and gammaf_r functions return |gamma(x)| instead of ln(|gamma(x)|) due to a change made back in 2002 to the __ieee754_gamma_r implementation. This patch fixes that, making all of these functions map too their lgamma equivalents. To fix the underlying bug, the __ieee754_gamma functions have been changed to return gamma(x), removing the _r variants as those are no longer necessary. Their names have been changed to __ieee754_tgamma to avoid potential confusion from users. Now that the __ieee754_tgamma functions return the correctly signed value, the tgamma functions have been modified to use them. libm.a now exposes the following gamma functions: ln(|gamma(x)|): __ieee754_lgamma_r __ieee754_lgammaf_r lgamma lgamma_r gamma gamma_r lgammaf lgammaf_r gammaf gammaf_r lgammal (on machines where long double is double) gamma(x): __ieee754_tgamma __ieee754_tgammaf tgamma tgammaf tgammal (on machines where long double is double) Additional aliases for any of the above functions can be added if necessary; in particular, I'm not sure if we need to include __ieee754_gamma*_r functions (which would return ln(|(gamma(x)|). Signed-off-by: Keith Packard <keithp@keithp.com> ---- v2: Switch commit message to ASCII
* libm/riscv: Use common fma code when necessaryKeith Packard via Newlib2020-09-042-0/+4
| | | | | | | For RISC-V targets without hardware FMA support, include the common fma implementation to provide that API. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/riscv: Fix machine-specific sqrt build processKeith Packard via Newlib2020-09-044-20/+16
| | | | | | | | | | | | Like ARM, some RISC-V implementations have hardware sqrt. Support for that can be detected at compile time, which the code did. However, the filenames were incorrect so that both the risc-v specific and general code were getting included in the resulting library. Fix this by following the ARM model and #include'ing the general code when the architecture-specific support is not available. Signed-off-by: Keith Packard <keithp@keithp.com>
* loadlocale: don't casecmp digitsCorinna Vinschen2020-09-041-1/+1
| | | | | | strcmp is sufficient here Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Fix warnings when building for msp430-elfJozef Lawrynowicz2020-09-036-16/+24
| | | | | | | | The MSP430 target supports both 16-bit and 20-bit size_t and intptr_t. Some implicit casts in Newlib expect these types to be "long", (a 32-bit type on MSP430) which causes warnings during compilation such as: "cast from pointer to integer of different size"
* libm/machine/arm: Rename s*_fma.c -> s*_fma_arm.cKeith Packard via Newlib2020-09-024-14/+14
| | | | | | | | | | | This is required to avoid colliding with files built from libm/common that would end up with the same object name. When libm.a was constructed from the individual sub-libraries, the contents of the libm/common files would be replaced by that from libm/machine/arm with the same name. Signed-off-by: Keith Packard <keithp@keithp.com>
* doc: Also update shebang for chapter-texi2docbook.pyJon Turney2020-08-261-1/+1
|
* Enabled _CS* defines for RTEMSEshan dhawan via Newlib2020-08-251-1/+2
| | | | Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* doc: Various fixes to makedocbook for python3.8Jon Turney2020-08-241-4/+6
| | | | | Also update shebang to explicitly use python3, since python2 is EOL and (per PEP 0394) 'python' may not exist at all.
* libm/stdlib: Realloc when shrinking by 2* or moreKeith Packard via Newlib2020-08-171-3/+3
| | | | | | This reduces memory usage when reallocating objects much smaller. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/stdlib: don't read past source in nano_reallocKeith Packard via Newlib2020-08-171-2/+4
| | | | | | | Save the computed block size and use it to avoid reading past the end of the source block. Signed-off-by: Keith Packard <keithp@keithp.com>
* libc/stdlib: Fix build failure in nano_callocCraig Blackmore2020-08-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commit 588a5e1ddebdf6d74391c7409680ea20e050c0e1 added a non-reentrant call to nano_malloc which causes a build failure if INTERNAL_NEWLIB is defined. Here is a snippet of the error: In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38: .../newlib/newlib/libc/include/malloc.h:42:25: note: expected 'struct _reent *' but argument is of type 'ptrdiff_t' {aka 'int'} 42 | extern void *_malloc_r (struct _reent *, size_t); | ^~~~~~~~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:67:22: error: too few arguments to function '_malloc_r' 67 | #define nano_malloc _malloc_r | ^~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:456:11: note: in expansion of macro 'nano_malloc' 456 | mem = nano_malloc(bytes); | ^~~~~~~~~~~ In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38: .../newlib/newlib/libc/include/malloc.h:42:14: note: declared here 42 | extern void *_malloc_r (struct _reent *, size_t); | ^~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:43: warning: "assert" redefined 43 | #define assert(x) ((void)0) | This patch adds a missing RCALL to the args when calling nano_malloc from nano_calloc, so that if the call is reentrant, reent_ptr is passed as the first argument. The variable `bytes` (also added in 588a5e1d) has been changed from a `ptrdiff_t` to `malloc_size_t` as it does not need to be signed. It is used to store the product of two unsigned malloc_size_t variables and then iff there was no overflow is it passed to malloc and memset which both expect size_t which is unsigned. Signed-off-by: Craig Blackmore <craig.blackmore@embecosm.com>
* libc/stdlib: Use __builtin_mul_overflow for reallocarray and callocKeith Packard via Newlib2020-08-123-15/+22
| | | | | | | This built-in function (available in both gcc and clang) is more efficient and generates shorter code than open-coding the test. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/machine/riscv: Add custom fma/sqrt functions when supported [v2]Keith Packard via Newlib2020-08-127-5/+237
| | | | | | | Check for HW FMA and SQRT support and use those instructions in place of software implementations. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/machine/arm: Add optimized fmaf and fma when availableKeith Packard via Newlib2020-08-106-5/+125
| | | | | | | | | | | When HAVE_FAST_FMAF is set, use the vfma.f32 instruction, when HAVE_FAST_FMA is set, use the vfma.f64 instruction. Usually the compiler built-ins will already have inlined these instructions, but provide these symbols for cases where that doesn't work instead of falling back to the (inaccurate) common code versions. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm: Detect fast fmaf supportKeith Packard via Newlib2020-08-101-0/+8
| | | | | | | Anything with fast FMA is assumed to have fast FMAF, along with 32-bit arms that advertise 32-bit FP support and __ARM_FEATURE_FMA Signed-off-by: Keith Packard <keithp@keithp.com>
* libm: ARM without HW double does not have fast FMAKeith Packard via Newlib2020-08-101-1/+1
| | | | | | | | 32-bit ARM processors with HW float (but not HW double) may define __ARM_FEATURE_FMA, but that only means they have fast FMA for 32-bit floats. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/math: ensure that expf(-huge) sets FE_UNDERFLOW exceptionKeith Packard via Newlib2020-08-101-1/+1
| | | | | | | | It was calling __math_uflow(0) instead of __math_uflowf(0), which resulted in no exception being set on machines with exception support for float but not double. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm: Control errno support with _IEEE_LIBM configuration parameterKeith Packard via Newlib2020-08-056-73/+22
| | | | | | | | | | | | | | | | This removes the run-time configuration of errno support present in portions of the math library and unifies all of the compile-time errno configuration under a single parameter so that the whole library is consistent. The run-time support provided by _LIB_VERSION is no longer present in the public API, although it is still used internally to disable errno setting in some functions. Now that it is a constant, the compiler should remove that code when errno is not supported. This removes s_lib_ver.c as _LIB_VERSION is no longer variable. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/math: Don't modify __ieee754_pow return values in powKeith Packard via Newlib2020-08-052-26/+2
| | | | | | | | The __ieee754 functions already return the right value in exception cases, so don't modify those. Setting the library to _POSIX_/_IEEE_ mode now only affects whether errno is modified. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/math: Set errno to ERANGE for pow(0, -y)Keith Packard via Newlib2020-08-052-4/+2
| | | | | | | | | POSIX says that the errno for pow(0, -y) should be ERANGE instead of EDOM. https://pubs.opengroup.org/onlinepubs/9699919799/functions/pow.html Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/math: Make yx functions set errno=ERANGE for x=0Keith Packard via Newlib2020-08-056-42/+52
| | | | | | | | | | The y0, y1 and yn functions need separate conditions when x is zero as that returns ERANGE instead of EDOM. Also stop adjusting the return value from the __ieee754_y* functions as that is already correct and we were just breaking it. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/math: set errno to ERANGE at gamma polesKeith Packard via Newlib2020-08-054-39/+16
| | | | | | | For POSIX, gamma(i) (i non-positive integer) should set errno to ERANGE instead of EDOM. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm: Set math_errhandling to match library and hardware [v2]Keith Packard via Newlib2020-08-042-1/+22
| | | | | | | | | | | | | | | | math_errhandling is specified to contain two bits of information: 1. MATH_ERRNO -- Set when the library sets errno 2. MATH_ERREXCEPT -- Set when math operations report exceptions MATH_ERRNO should match whether the original math code is compiled in _IEEE_LIBM mode and the new math code has WANT_ERRNO == 1. MATH_ERREXCEPT should match whether the underlying hardware has exception support. This patch adds configurations of this value for RISC-V, ARM, Aarch64, x86 and x86_64 when using HW float. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/common: Set WANT_ERRNO based on _IEEE_LIBM valueKeith Packard via Newlib2020-08-041-1/+3
| | | | | | | | _IEEE_LIBM is the configuration value which controls whether the original libm functions modify errno. Use that in the new math code as well so that the resulting library is internally consistent. Signed-off-by: Keith Packard <keithp@keithp.com>
* libm/math: Use __math_xflow in obsolete math code [v2]Keith Packard2020-08-039-32/+34
| | | | | | | | | | | | | | | | | | C compilers may fold const values at compile time, so expressions which try to elicit underflow/overflow by performing simple arithemetic on suitable values will not generate the required exceptions. Work around this by replacing code which does these arithmetic operations with calls to the existing __math_xflow functions that are designed to do this correctly. Signed-off-by: Keith Packard <keithp@keithp.com> ---- v2: libm/math: Pass sign to __math_xflow instead of muliplying result
* select.h: update FD macros to latest FreeBSD, fix type conversion warningCorinna Vinschen2020-08-031-27/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Compiling #include <sys/select.h> void f(int X) {   fd_set set;   FD_ZERO(&set);   FD_SET(X,&set);   FD_CLR(X+1,&set);   (void)FD_ISSET(X+2,&set); } results in plenty of gcc warnings when compiled with -Wconversion -Wsign-conversion: fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may   FD_SET(X,&set);   ^~~~~~ [...] The unsigned NFDBITS macro combined with the signed 1L constant are causing lots of implicit signed/unsigned type conversions. Fix this by updating the FD_* macro code to the latest from FreeBSD and adding an (int) cast to _NFDBITS. As a side-effect, this fixes the visibility of NFDBITS and fds_bits (only if __BSD_VISIBLE). This also eliminates the old, outdated fd_set workaround. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Cygwin: posix_spawn: add Cygwin-specific code fixing process synchronisationCorinna Vinschen2020-08-031-0/+64
| | | | | | | | | | | | | | | | | | | | | | Newlib's posix_spawn has been taken from FreeBSD. The code relies on BSD-specific behaviour of vfork, namely the fact that vfork blocks the parent until the child exits or calls execve as well as the fact that the child shares parent memory in non-COW mode. This behaviour can't be emulated by Cygwin. Cygwin's vfork is equivalent to fork. This is POSIX-compliant, but it's lacking BSD's vfork ingrained synchronization of the parent to wait for the child calling execve, or the chance to just write a variable and the parent will see the result. So this requires a Cygwin-specific solution. The core function of posix_spawn, called do_posix_spawn is now implemented twice, once using the BSD method, and once for Cygwin using Windows synchronization under the hood waiting for the child to call execve and signalling errors upstream. The Windows specifics are hidden inside Cygwin, so newlib only calls internal Cygwin functions. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* arm: Fix include to avoid undefined referenceSebastian Huber2020-07-291-1/+1
| | | | | | | ld: libm.a(lib_a-fesetenv.o): in function `fesetenv': newlib/libm/machine/arm/fesetenv.c:38: undefined reference to `vmsr_fpscr' Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
* arm: Split fenv.c into multiple filesEshan dhawan2020-07-2919-282/+696
| | | | | | | | | Use the already existing stub files if possible. These files are necessary to override the stub implementation with the machine-specific implementation through the build system. Reviewed-by: Sebastian Huber <sebastian.huber@embedded-brains.de> Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* arm: Fix fenv supportEshan dhawan2020-07-299-772/+127
| | | | | | | | | | | | | | | | | | | The previous fenv support for ARM used the soft-float implementation of FreeBSD. Newlib uses the one from libgcc by default. They are not compatible. Having an GCC incompatible soft-float fenv support in Newlib makes no sense. A long-term solution could be to provide a libgcc compatible soft-float support. This likely requires changes in the GCC configuration. For now, provide a stub implementation for soft-float multilibs similar to RISC-V. Move implementation to one file and delete now unused files. Hide implementation details. Remove function parameter names from header file to avoid name conflicts. Provide VFP support if __SOFTFP__ is not defined like glibc. Reviewed-by: Sebastian Huber <sebastian.huber@embedded-brains.de> Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* riscv: fix integer wraparound in memcpyPkmX via Newlib2020-07-271-2/+2
| | | | | | | | This patch fixes a bug in RISC-V's memcpy implementation where an integer wraparound occurs when src + size < 8 * sizeof(long), causing the word-sized copy loop to be incorrectly entered. Signed-off-by: Chih-Mao Chen <cmchen@andestech.com>
* ctype.h: Fix unused variable warningsAschref Ben Thabet2020-07-161-4/+9
| | | | | | | | | | | | | | | | | | | | If __HAVE_LOCALE_INFO__ is not defined, then the locale in the locale-specific ctype functions is ignored. In the previous implementation this resulted in compiler warnings. For example: int main() { locale_t locale; locale = duplocale(uselocale((locale_t)0)); isspace_l('x', locale); return 0; } gcc -Wall main.c main.c: In function 'main': main.c:6:11: warning: variable 'locale' set but not used [-Wunused-but-set-variable] 6 | locale_t locale; | ^~~~~~
* testsuite: Fix iconv tests to use new encoding config definesKeith Packard via Newlib2020-07-103-48/+47
| | | | | | | | _ICONV_CONVERTER -> ICONV_FROM_ENCODING. It's not perfect, as the library can support different from/to encodings now, but at least in the default configurations the tests now work. Signed-off-by: Keith Packard <keithp@keithp.com>
* libc/iconv: find_alias was mis-computing remaining alias table lengthKeith Packard via Newlib2020-07-101-1/+1
| | | | | | | | This caused the strnstr to walk off the end of the alias array and fetch invalid data. Instead of attempting to update 'len', just re-compute it based on the table end pointer that is already known. Signed-off-by: Keith Packard <keithp@keithp.com>
* libc/iconv: Remove unneeded pointer var for _iconv_aliasesKeith Packard via Newlib2020-07-102-6/+3
| | | | | | | The pointer value for the iconv alias data never changes, so get rid of the pointer and make it an array instead. Signed-off-by: Keith Packard <keithp@keithp.com>
* libc/iconv: Detect CES handler loading failureKeith Packard via Newlib2020-07-101-1/+1
| | | | | | | Fix the code checking for character set loading failure so that it checks the return value from the init function. Signed-off-by: Keith Packard <keithp@keithp.com>
* Removed #ifndef _ARM_PCS_VFP_ from sys/fenv.h for armEshan dhawan via Newlib2020-07-061-2/+2
| | | | Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* libm: machine: Add missing sparc and mips configurationCorinna Vinschen2020-07-037-3/+12683
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* mips fenv supportEshan dhawan via Newlib2020-07-0319-0/+662
| | | | Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* SPARC fenv supportEshan dhawan via Newlib2020-07-0317-0/+546
| | | | Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* fenv aarch64 supportEshan dhawan via Newlib2020-07-0216-3/+515
| | | | Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* fenv support armEshan dhawan via Newlib2020-06-0922-3/+1339
| | | | Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* Regenerate libm/machine configuration files for powerpcJeff Johnston2020-06-094-3/+6342
|
* hard float support for PowerPC taken from FreeBSDEshan dhawan via Newlib2020-06-0318-0/+491
| | | | Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
* Reimplement aligned_allocSzabolcs Nagy2020-05-191-32/+30
| | | | | | | | | | | | | | | | | | | | The original implementation had multiple issues: - Only worked when posix_memalign was available (Linux, RTEMS). - Violated C11 link namespace rules by calling posix_memalign. - Failed to set errno on error. These can be fixed by essentially using the same implementation for aligned_alloc as for memalign, i.e. simply calling _memalign_r (which is always available and a "more reserved name" although technically still not in the reserved link namespace, at least code written in c cannot define a colliding symbol, newlib has plenty such namespace issues so this is fine). It is not clear what the right policy is when MALLOC_PROVIDED is set, currently that does not cover aligned_alloc so it is kept that way. Tested on aarch64-none-elf
* newlib/libm/math: Make pow/powf return qnan for snan argKeith Packard via Newlib2020-03-262-7/+16
| | | | | | | | The IEEE spec for pow only has special case for x**0 and 1**y when x/y are quiet NaN. For signaling NaN, the general case applies and these functions should signal the invalid exception and return a quiet NaN. Signed-off-by: Keith Packard <keithp@keithp.com>