4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-02 04:20:28 +08:00

363 Commits

Author SHA1 Message Date
Eshan dhawan
7c5a0c04ae Removed Soft float from MIPS
This Patch removes Soft Float code from MIPS.
Instead It adds the soft float code from RISCV

The code came from FreeBSD and assumes the FreeBSD softfp
implementation not the one with GCC. That was an overlooked and
fixed in the other fenv code already.

Signed-off-by: Eshan Dhawan <eshandhawan51@gmail.com>
2021-03-03 17:57:31 -05:00
Jeff Johnston
f24ce1da03 Bump up newlib version to 4.1.0 2020-12-23 11:59:36 -05:00
Paul Zimmermann
8169276058 fixes to make compilation succeeds 2020-12-18 16:53:19 -05:00
Jeff Johnston
dad02bce3a Update gamma functions from code in picolibc
- fixes issue with inf sign when x is -0
2020-12-18 16:53:19 -05:00
Jeff Johnston
333317dedb Add declarations for __ieee754_tgamma functions to fdlibm.h 2020-12-18 16:53:18 -05:00
Fabian Schriever
39f2545591 Fix error in powf for x close to 1 and large y
This patch fixes the error found by Paul Zimmermann (see
https://homepages.loria.fr/PZimmermann/papers/#accuracy) regarding x
close to 1 and rather large y (specifically he found the case
powf(0x1.ffffeep-1,-0x1.000002p+27) which returns +Inf instead of the
correct value). We found 2 more values for x which show the same faulty
behaviour, and all 3 are fixed with this patch. We have tested all
combinations for x in [+1.fffdfp-1, +1.00020p+0] and y in
[-1.000007p+27, -1.000002p+27] and [1.000002p+27,1.000007p+27].
2020-12-11 17:41:05 -05:00
Jeff Johnston
90400463f3 Bump newlib release to 4.0.0 2020-12-11 17:41:05 -05:00
Kito Cheng
a005d8e7ff RISC-V: Add machine-specific implementation for lrint[f], lround[f], llrint[f] and llround[f]. 2020-11-18 14:18:28 -05:00
Kito Cheng
cc8a2d577d RISC-V: Add machine-specific implementation for isnan[f] and copysign[f] 2020-11-18 14:18:28 -05:00
Kito Cheng
ffa6fd6352 RISC-V: Add missing compile rule for s_finite.c, sf_finite.c, s_isinf.c and sf_isinf.c 2020-11-18 14:18:28 -05:00
Kito Cheng
ac8ef88787 RISC-V: Fix wrong including file in s_isinf.c 2020-10-29 12:28:59 -04:00
Kito Cheng
906849c4f9 RISC-V: NaN should return 0 for finite[f] 2020-10-29 12:28:59 -04:00
Kito Cheng
f685416883 RISC-V: Implment finite and fpclassify 2020-10-27 10:50:46 -04:00
Kito Cheng
245b6f20d5 RISC-V: Add fabs[f], fmax[f] and fmin[f]. 2020-10-27 10:50:46 -04:00
Keith Packard
2bd71cbf91 libm: Make tgamma(-small) = -INFINITY
Need to copy the argument sign to the output for tgamma(finite)
overflow case.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-14 10:54:31 -04:00
Keith Packard via Newlib
63c71d3ae4 libm: Fix 'gamma' and 'gammaf' functions. Clean up other gamma code. [v2]
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
2020-10-14 10:54:30 -04:00
Keith Packard via Newlib
2d9bb96b51 libm/riscv: Use common fma code when necessary
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>
2020-10-14 10:54:30 -04:00
Keith Packard via Newlib
f9c1c0a860 libm/riscv: Fix machine-specific sqrt build process
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>
2020-10-14 10:54:30 -04:00
Keith Packard via Newlib
844fe09301 libm/machine/arm: Rename s*_fma.c -> s*_fma_arm.c
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>
2020-10-14 10:54:30 -04:00
Keith Packard via Newlib
89536c0234 libm/machine/riscv: Add custom fma/sqrt functions when supported [v2]
Check for HW FMA and SQRT support and use those instructions in place
of software implementations.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-14 10:54:27 -04:00
Keith Packard via Newlib
82e91123e9 libm/machine/arm: Add optimized fmaf and fma when available
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>
2020-10-14 10:54:27 -04:00
Keith Packard via Newlib
bf65b24d00 libm: Detect fast fmaf support
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>
2020-10-14 10:54:27 -04:00
Keith Packard via Newlib
7e690708b4 libm: ARM without HW double does not have fast FMA
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>
2020-10-14 10:54:27 -04:00
Keith Packard via Newlib
cf3c0c19b3 libm/math: ensure that expf(-huge) sets FE_UNDERFLOW exception
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>
2020-10-14 10:54:27 -04:00
Keith Packard via Newlib
9bc79893be libm: Control errno support with _IEEE_LIBM configuration parameter
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>
2020-10-14 10:54:26 -04:00
Keith Packard via Newlib
0f9f9849ab libm/math: Don't modify __ieee754_pow return values in pow
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>
2020-10-14 10:54:26 -04:00
Keith Packard via Newlib
e39f26c0ba libm/math: Set errno to ERANGE for pow(0, -y)
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>
2020-10-14 10:54:26 -04:00
Keith Packard via Newlib
bd14299346 libm/math: Make yx functions set errno=ERANGE for x=0
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>
2020-10-14 10:54:26 -04:00
Keith Packard via Newlib
2daeea8884 libm/math: set errno to ERANGE at gamma poles
For POSIX, gamma(i) (i non-positive integer) should set errno to
ERANGE instead of EDOM.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-14 10:54:26 -04:00
Keith Packard via Newlib
325de9664e libm/common: Set WANT_ERRNO based on _IEEE_LIBM value
_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>
2020-10-14 10:54:26 -04:00
Keith Packard
d128bb40be libm/math: Use __math_xflow in obsolete math code [v2]
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
2020-10-14 10:54:25 -04:00
Sebastian Huber
9cc139b9fe arm: Fix include to avoid undefined reference
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>
2020-10-14 10:54:25 -04:00
Eshan dhawan
8eb046d24f arm: Split fenv.c into multiple files
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>
2020-10-14 10:54:25 -04:00
Eshan dhawan
89f87b85eb arm: Fix fenv support
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>
2020-10-14 10:54:25 -04:00
Corinna Vinschen
1d0b1e9bd5 libm: machine: Add missing sparc and mips configuration
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-10-14 10:54:22 -04:00
Eshan dhawan via Newlib
011d459484 mips fenv support
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-10-14 10:54:22 -04:00
Eshan dhawan via Newlib
09f5b05014 SPARC fenv support
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-10-14 10:54:22 -04:00
Eshan dhawan via Newlib
9fc5eb7747 fenv aarch64 support
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-10-14 10:54:22 -04:00
Eshan dhawan via Newlib
c5bb4fc899 fenv support arm
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-10-14 10:54:21 -04:00
Jeff Johnston
db57a46672 Regenerate libm/machine configuration files for powerpc 2020-10-14 10:54:21 -04:00
Eshan dhawan via Newlib
3ef3750910 hard float support for PowerPC taken from FreeBSD
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-10-14 10:54:21 -04:00
Keith Packard via Newlib
7c84adcc2e newlib/libm/math: Make pow/powf return qnan for snan arg
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>
2020-10-14 10:54:16 -04:00
Keith Packard via Newlib
87edc8c912 newlib/libm/common: Don't re-convert float to bits in modf/modff
These functions shared a pattern of re-converting the argument to bits
when returning +/-0. Skip that as the initial conversion still has the
sign bit.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-14 10:54:16 -04:00
Keith Packard via Newlib
e7aa772fe7 newlib/libm/common: Fix modf/modff returning snan
Recent GCC appears to elide multiplication by 1, which causes snan
parameters to be returned unchanged through *iptr. Use the existing
conversion of snan to qnan to also set the correct result in *iptr
instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-14 10:54:16 -04:00
Joseph S. Myers
6ed0615e25 Fix spurious underflow exceptions for Bessel functions for double(from glibc bug 14155)
This fix comes from glibc, from files which originated from
	the same place as the newlib files. Those files in glibc carry
	the same license as the newlib files.

Bug 14155 is spurious underflow exceptions from Bessel functions for
large arguments.  (The correct results for large x are roughly
constant * sin or cos (x + constant) / sqrt (x), so no underflow
exceptions should occur based on the final result.)

There are various places underflows may occur in the intermediate
calculations that cause the failures listed in that bug.  This patch
fixes problems for the double version where underflows occur in
calculating the intermediate functions P and Q (in particular, x**-12
gets computed while calculating Q).  Appropriate approximations are
used for P and Q for arguments at least 0x1p28 and above to avoid the
underflows.

For sufficiently large x - 0x1p129 and above - the code already has a
cut-off to avoid calculating P and Q at all, which means the
approximations -0.125 / x and 0.375 / x can't themselves cause
underflows calculating Q.  This cut-off is heuristically reasonable
for the point beyond which Q can be neglected (based on expecting
around 0x1p-64 to be the least absolute value of sin or cos for large
arguments representable in double).

The float versions use a cut-off 0x1p17, which is less heuristically
justifiable but should still only affect values near zeroes of the
Bessel functions where these implementations are intrinsically
inaccurate anyway (bugs 14469-14472), and should serve to avoid
underflows (the float underflow for jn in bug 14155 probably comes
from the recurrence to compute jn).  ldbl-96 uses 0x1p129, which may
not really be enough heuristically (0x1p143 or so might be safer - 143
= 64 + 79, number of mantissa bits plus total number of significant
bits in representation) but again should avoid underflows and only
affect values where the code is substantially inaccurate anyway.
ldbl-128 and ldbl-128ibm share a completely different implementation
with no such cut-off, which I propose to fix separately.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-10-14 10:54:16 -04:00
Fabian Schriever
0c6275cc93 Fix hypotf missing mask in hi+lo decomposition
Add the missing mask for the decomposition of hi+lo which caused some
errors of 1-2 ULP.

This change is taken over from FreeBSD:
95436ce20d

Additionally I've removed some variable assignments which were never
read before being overwritten again in the next 2 lines.
2020-10-14 10:54:15 -04:00
Fabian Schriever
1895f91f95 Fix modf/f for NaN input
For NaN input the modf/f procedures should return NaN instead of zero
with the sign of the input.
2020-10-14 10:54:15 -04:00
Fabian Schriever
fa8465ff48 Fix for k_tan.c specific inputs
This fix for k_tan.c is a copy from fdlibm version 5.3 (see also
http://www.netlib.org/fdlibm/readme), adjusted to use the macros
available in newlib (SET_LOW_WORD).

This fix reduces the ULP error of the value shown in the fdlibm readme
(tan(1.7765241907548024E+269)) to 0.45 (thereby reducing the error by
1).

This issue only happens for large numbers that get reduced by the range
reduction to a value smaller in magnitude than 2^-28, that is also
reduced an uneven number of times. This seems rather unlikely given that
one ULP is (much) larger than 2^-28 for the values that may cause an
issue.  Although given the sheer number of values a double can
represent, it is still possible that there are more affected values,
finding them however will be quite hard, if not impossible.

We also took a look at how another library (libm in FreeBSD) handles the
issue: In FreeBSD the complete if branch which checks for values smaller
than 2^-28 (or rather 2^-27, another change done by FreeBSD) is moved
out of the kernel function and into the external function. This means
that the value that gets checked for this condition is the unreduced
value. Therefore the input value which caused a problem in the
fdlibm/newlib kernel tan will run through the full polynomial, including
the careful calculation of -1/(x+r). So the difference is really whether
r or y is used. r = y + p with p being the result of the polynomial with
1/3*x^3 being the largest (and magnitude defining) value. With x being
<2^-27 we therefore know that p is smaller than y (y has to be at least
the size of the value of x last mantissa bit divided by 2, which is at
least x*2^-51 for doubles) by enough to warrant saying that r ~ y.  So
we can conclude that the general implementation of this special case is
the same, FreeBSD simply has a different philosophy on when to handle
especially small numbers.
2020-10-14 10:54:15 -04:00
Fabian Schriever
83aabb816f Fix truncf for sNaN input
Make line 47 in sf_trunc.c reachable. While converting the double
precision function trunc to the single precision version truncf an error
was introduced into the special case. This special case is meant to
catch both NaNs and infinities, however qNaNs and infinities work just
fine with the simple return of x (line 51). The only error occurs for
sNaNs where the same sNaN is returned and no invalid exception is
raised.
2020-10-14 10:54:14 -04:00
Joel Sherrill
3af9fe92bb i386/fenv.c: Include fenv.c implementation shared with x86_64, not stub 2020-10-14 10:54:14 -04:00