Commit Graph

453 Commits

Author SHA1 Message Date
Joseph Faulls dcb2b7d7b8 Delete check in catan, catanf, and catanl functions.
The check incorrectly results in catan returning nan + inf i when real part is +/- 1 and
imaginary part is 0.  The same occurs for real 0.8 and imaginary 0.6.

The change ends up matching glibc behaviour.
2023-10-10 15:18:54 -04:00
Alexey Lapshin 7ba103eb1a newlib: add Xtensa port 2023-08-17 18:14:15 -04:00
Jesse Huang via Newlib 9e329b544a Fix rounding results in lrint() & llrint() when close to 0
soft-fp should round floating pointer numbers according to the current
rounding mode. However, in the current code of lrint() and llrint(),
there are if statements before the actual rounding computation

      if(j0 < -1)
        return 0;

Where j0 is the exponent of the floating point number.

It means any number having a exponent less than -1
(i.e. interval (-0.5, 0.5)) will be rounded to 0 regardeless of the
rounding mode.

The bug already fixed in glibc in 2006 by moving the check afterwards
the rounding computation, but still persists in newlib.

This patch fixed it in a similar way to glibc
Ref Commit in glibc: 6624dbc07b5a9fb316ed188ef01f65b8eea8b47c
2023-07-27 11:14:12 +02:00
Kito Cheng via Newlib d572c4482b RISC-V: Support Zfinx/Zdinx extension.
Zfinx/Zdinx are new extensions ratified in 2022, it similar to F/D extensions,
support hard float operation for single/double precision, but the difference
between Zfinx/Zdinx and F/D is Zfinx/Zdinx is operating under general purpose
registers rather than dedicated floating-point registers.

This patch improve the hard float support detection for RISC-V port, so
that Zfinx/Zdinx can have better/right performance.

Co-authored-by: Jesse Huang <jesse.huang@sifive.com>
2023-07-26 15:21:35 +02:00
Jennifer Averett 048ebea981 newlib: Add non LDBL_EQ_DBL math support for aarch64, i386, and x86_64
Rename s_nearbyint.c, s_fdim.c and s_scalbln.c to remove conflicts
    Remove functions that are not needed from above files
    Modify include paths
    Add includes missing in cygwin build
    Add missing types
    Create Makefiles
    Create header files to resolve dependencies between directories
    Modify some instances of unsigned long to uint64_t for 32 bit platforms
    Add HAVE_FPMATH_H
2023-05-16 09:05:36 -05:00
Jennifer Averett c630a6a837 newlib: Add FreeBSD files for non LDBL_EQ_DBL support
FreeBSD files to add long double support for i386,
aarch64 and x86_64.
2023-05-16 09:05:36 -05:00
Jennifer Averett 742b8db95d Move signgm.c from libc/reent to libm/math 2023-05-05 14:49:48 -04:00
Andoni Arregi ef75abddc7 Replace always true if with else 2023-04-13 13:36:11 -04:00
Andoni Arregi 9e89e66729 Compare j as unsigned
j is int32_t and thus j<<31 is undefined if j==1.

Taken from FreeBSD commit bdd8abc6d6a93ce3ab8ad5db716222ee3110c4a3
2023-04-13 13:34:57 -04:00
Andoni Arregi e5a36e6af7 Fix x close to 1, y between 2^31 and 2^64
E.g. known errors:
x = 0x1.000002c5e2e99p+0, y = 0x1.c9eee35374af6p+31 had an error of 639
ULP and is now correctly rounded.
x = 0x1.fffffd2e3e669p-1, y = 0x1.344c9823eb66cp+32 had an error of 428
ULP and is now correctly rounded.
2023-04-13 13:33:46 -04:00
Andoni Arregi 5a961061de Fix missing sign for overflow/underflow where x is negative and y is large odd integer 2023-04-13 13:32:47 -04:00
Tobias Burnus 544aa97f86 Bump newlib version in the manual to 4.3.0
While commit 9e09d6ed8 (tag: newlib-4.3.0) bumped the newlib version to 4.3.0,
this commit updates the version/date in the libc/libm manuals to match.
2023-03-30 14:09:30 +02:00
Kwok Cheung Yeung e18743072b amdgcn: Add vectorized math routines
This implements a set of vectorized math routines to be used by the
compiler auto-vectorizer.  Versions for vectors with 2 lanes up to
64 lanes (in powers of 2) are provided.

These routines are based on the scalar versions of the math routines in
libm/common, libm/math and libm/mathfp.  They make extensive use of the GCC
C vector extensions and GCN-specific builtins in GCC.
2023-01-18 13:22:58 -05:00
Jeff Johnston c8130c3fe8 Fix 3 other instances of Reme typo (should be Remez) 2022-12-16 14:18:56 -05:00
Jeff Johnston c04c01524d Revert "amdgcn: Add vectorized math routines"
This reverts commit 125e39bfea.
2022-12-16 12:28:48 -05:00
Nadav Rotem abf672604b Fix a typo in the comment.
The implementation of expf() explains how approximation in the range [0 - 0.34] is done. The comment describes the "Reme" algorithm for constructing the polynomial. This is a typo and should be the "Remez" algorithm. The remez algorithm (or minimax) is used to calculate the coefficients of polynomials in other implementations of exp(0 and log().

See more:
https://en.wikipedia.org/wiki/Remez_algorithm
2022-12-16 12:18:28 -05:00
Kwok Cheung Yeung 125e39bfea amdgcn: Add vectorized math routines
This implements a set of vectorized math routines to be used by the
compiler auto-vectorizer.  Versions for vectors with 2 lanes up to
64 lanes (in powers of 2) are provided.

These routines are based on the scalar versions of the math routines in
libm/common, libm/math and libm/mathfp.  They make extensive use of the GCC
C vector extensions and GCN-specific builtins in GCC.
2022-12-16 12:18:14 -05:00
Matt Joyce ea99f21ce6 Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data.  This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.

The reentrancy structure contains for example errno and the standard input,
output, and error file streams.  This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it.  This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).

If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member.  The thread-local objects are defined in translation units which use
the corresponding object.
2022-07-13 06:55:46 +02:00
Jon Turney 81b7cf09fa Silence xsltproc when writing manpages
Unless make is invoked with V=1, have xmlto pass the parameter
'man.output.quietly=1' to xsltproc to suppress "Note: Writing foo.N"
output from the manpages stylesheet.

(This doesn't quite do what it says: The output is not silenced if V has
any value, including 0.  You could consider that either a bug or a
feature.)
2022-05-04 17:05:52 -04:00
Jon Turney d51aab2abd Add build avoidance for 'make man'
This will generate multiple manpage files as an output, but we don't
know what they will be called, so use a timestamp for build avoidance.
2022-05-04 17:05:41 -04:00
Jon Turney 3d64a500f1 Simplify rules for creating man pages
Simplify rules for creating docbook XML used to create manpages:
Updating the output using move-if-change and then unconditionally
touching the .stamp file doesn't make much sense.
2022-05-04 17:05:24 -04:00
Mike Frysinger fb42151a18 newlib: libm: integrate tests subdir
Integrate the old libm/test/ subdir into the main build.  It hasn't
been used in a long time causing the code to rot a bit.  I've fixed
some of those, but it still fails for many ports, so it's disabled
by default.  People who want to take a closer look can run:
$ make libm/test/test
2022-03-16 22:01:19 -04:00
Mike Frysinger ac9f8c46b1 newlib: libm: merge build up a directory
Convert all the libm/ subdir makes into the top-level Makefile.  This
allows us to build all of libm from the top Makefile without using any
recursive make calls.  This is faster and avoids the funky lib.a logic
where we unpack subdir archives to repack into a single libm.a.  The
machine override logic is maintained though by way of Makefile include
ordering, and source file accumulation in libm_a_SOURCES.

One thing to note is that this will require GNU Make because of:
	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
This was the only way I could find to supporting per-dir compiler
settings, and I couldn't find a POSIX compatible way of transforming
the variable content.  I don't think this is a big deal as other
Makefiles in the tree are using GNU Make-specific syntax, but I call
this out as it's the only one so far in the new automake code that
I've been writing.

Automake doesn't provide precise control over the output object names
(by design).  This is fine by default as we get consistent names in all
the subdirs: libm_a-<source>.o.  But this relies on using the same set
of compiler flags for all objects.  We currently compile libm/common/
with different optimizations than the rest.

If we want to compile objects differently, we can create an intermediate
archive with the subset of objects with unique flags, and then add those
objects to the main archive.  But Automake will use a different prefix
for the objects, and thus we can't rely on ordering to override.

But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
since $@ contains /, Automake complains it's an invalid name.  While
GNU Make supports this, it's a POSIX extension, so Automake flags it.
Using $(subst) avoids the Automake warning to get a POSIX compliant
name, albeit with a GNU Make extension.
2022-02-17 20:56:32 -05:00
Mike Frysinger beadbdfc04 newlib: fix mips fenv.o handling
Commit 8fa73a9f84 changed how fenv.c is
compiled wrt mips16 targets used the wrong variable to add fenv.o to
libm.a.  Fix that thinko so it's included in the build again.
2022-02-16 20:40:53 -05:00
Mike Frysinger 907764ebec newlib/libgloss: drop unused $(CROSS_CFLAGS)
This is used in a bunch of places, but nowhere is it ever set, and
nowhere can I find any documentation, nor can I find any other project
using it.  So delete the flags to simplify.
2022-02-15 20:02:51 -05:00
Andoni Arregi ec69debcb9 Improve lgammaf range for very small cases
The original cut for small arguments at |x|<2**-70 (copied from the
double version) produces that when computing nadj we get a subnormal
number for t*x and thus, the division of pi/subnormal will be INF and
the logarithm of it too, which is wrong as a result for lgammaf in this
range.
The proposed new limit seems to be safe and has been tested to
produce accurate results.
(Courtesy of Andreas Jung, ESA)
2022-02-14 14:44:11 +01:00
Mike Frysinger bf167aade1 newlib: remove unused fenv flags
These look like they were just copied & pasted from common/Makefile.am.
The funcs in this dir are all stubs that don't actually call any math
or builtin functions, and a simple compile shows they produce identical
object code.  So delete to simplify the build rules.
2022-02-11 06:26:01 -05:00
Andoni Arregi 8f2bd6f046 Fix expf overflow limit
Correct the overflow limit in the variable o_threshold to be consistent
with the FLT_UWORD_LOG_MAX variable used by the internal implementation
of the expf algorithm itself.
The u_threshold variable has also been modified to be written in the
same format.

Note that this fix improves the situation but does not completely
correct the inconsistencies regarding the overflow and underflow limits
between the expf wrapper (wf_exp.c) and the expf algorithm itself
(ef_exp.c).

Currently these limits are different for the
_FLT_LARGEST_EXPONENT_IS_NORMAL and _FLT_NO_DENORMALS cases as well as
for the case where __OBSOLETE_MATH is not defined (only for the
underflow limit in this case).
2022-02-10 15:59:14 +01:00
Mike Frysinger e95c80b6d8 newlib: libm: fix rebase conflicts
I missed this cleanup when rebasing on top of the latest branch.
2022-02-10 00:36:34 -05:00
Mike Frysinger e114cbc6e1 newlib: libm: move configure into top-level
This kills off the last configure script under libm/ and folds it
into the top newlib configure script.  The vast majority of logic
was already in the top configure script, so move the little that
is left into a libm/acinclude.m4 file.
2022-02-10 00:28:05 -05:00
Mike Frysinger 5b9c4cf23e newlib: drop support for $oext
This was needed only to support libtool in case objects ended in .lo
instead of .o, but we dropped libtool, so drop this too.
2022-02-09 23:35:23 -05:00
Mike Frysinger f034d8ad19 newlib: drop support for $aext
This was needed only to support libtool in case the library ended in
.la instead of .a, but we dropped libtool, so drop this too.
2022-02-09 23:34:17 -05:00
Mike Frysinger 5c21b37214 newlib: fix mkdoc dependencies
Make sure we depend on the right name of mkdoc all the time, and that
the rules that need it (e.g. .def files) depend on it.

Reported-by: Jon Turney <jon.turney@dronecode.org.uk>
2022-02-09 23:26:19 -05:00
Mike Frysinger 006da84337 newlib: drop libtool support
This was only ever used for i?86-pc-linux-gnu targets, but that's been
broken for years, and has since been dropped.  So clean this up too.

This also deletes the funky objectlist logic since it only existed for
the libtool libraries.  Since it was the only thing left in the small
Makefile.shared file, we can punt that too.
2022-02-09 20:27:37 -05:00
Mike Frysinger 985c8f3592 newlib: drop autoconf-2.13 hack
We require autoconf-2.69 now, so we don't need this old install hack.
2022-02-08 22:18:06 -05:00
Mike Frysinger b63a4bb49a newlib: drop cygnus EXEEXT hack
Now that we rely on AC_NO_EXECUTABLES to disable link tests, we don't
need this hack to disable exeext probing.
2022-02-08 22:18:05 -05:00
Mike Frysinger e7ad3f5aa8 newlib: switch to AM_PROG_AR
Now that we require automake-1.15, we can use this macro rather than
do the tool search ourselves.
2022-02-08 21:24:59 -05:00
Mike Frysinger 34af195290 newlib: switch to standard AM_PROG_AS
Now that we require a recent automake version, rely on it to provide AS
and CCAS and CCASFLAGS for us.
2022-02-08 20:19:18 -05:00
Mike Frysinger b9346cee1a newlib: switch to standard AC_PROG_CC
Now that we use AC_NO_EXECUTABLES, and we require a recent version of
autoconf, we don't need to define our own copies of these macros.  So
switch to the standard AC_PROG_CC.
2022-02-08 19:09:26 -05:00
Mike Frysinger 9b50254377 newlib: move AC_NO_EXECUTABLES logic up to common code
This logic was added to libc & libm to get it working again after some
reworks in the CPP handling, but now that that's settled, let's move
this to the common newlib configure logic.  This will make it easier
to consolidate all the configure calls into the top-level newlib dir.

This does create a lot of noise in the generate scripts, but that's
because of the ordering of the calls, not because of correctness. We
will try to draw that back down in follow up commits as we modernize
the toolchain calls in here.
2022-02-08 19:09:26 -05:00
Mike Frysinger 953ba1e6d1 newlib: simplify nds32 automake checks
This code is a bit more convoluted than it needs to be.  GPR_SOURCES
is never set to anything, and the automake checks use negative logic
to add the SP & DP source files to dedicated variables that are only
expanded once.  Get rid of the unused variable, use normal boolean
logic, and collapse the source settings into a single variable.
2022-02-08 19:06:15 -05:00
Mike Frysinger 24b1e4b942 newlib: drop shared documentation rules
Now that the top-level makefile handles these, don't need to copy
these into every single subdir.
2022-02-05 00:18:01 -05:00
Mike Frysinger 6026ef29d8 newlib: move man page generation into top-level build
This allows building the libc & libm pages in parallel, and drops
the duplication in the subdirs with the chew/chapter settings.

The unused rules in Makefile.shared are left in place to minimize
noise in the change.
2022-02-05 00:17:54 -05:00
Mike Frysinger 3365bd2f7a newlib: libm: move manual into top-level build
This doesn't migrate all the docs, just the libm's manual (pdf/info).
This is to show the basic form of migrating the chew files.
2022-02-04 19:39:05 -05:00
Mike Frysinger 041dd7ff26 newlib: add AC_CACHE_CHECK sugar around preprocessor checks
This isn't strictly necessary, but it makes for much clearer logs as
to what the target is doing, and provides cache vars for anyone who
wants to force the test a different way, and it lets the build cache
its own results when rerunning config.status.
2022-02-01 18:15:51 -05:00
Mike Frysinger 4b0e66093c newlib: fix preprocessor checks
Restore the call to AC_NO_EXECUTABLES -- I naively assumed in commit
2e9aa5f56c ("newlib: update preprocessor
configure checks") that checking for a preprocessor would not involve
linking code.  Unfortunately, autoconf will implicitly check that the
compiler "works" before allowing it to be used, and that involves a
link test, and that fails because newlib provides the C library which
is needed to pass a link test.

There is some code in NEWLIB_CONFIGURE specifically to help mitigate
these, but it's not kicking in here for some reason, so let's just add
the AC_NO_EXECUTABLES call back until we can unwind that custom logic.

Additionally, we have to call AC_PROG_CPP explicitly.  This was being
invoked later on, but only in the use_libtool=yes codepath, and that
is almost never enabled.
2022-01-31 22:21:17 -05:00
Mike Frysinger fc0bd2eb03 newlib: use abs_newlib_basedir for -I paths
When we had configure scripts in subdirs, the newlib_basedir value
was computed relative to that, and it'd be the same when used in the
Makefile in the same dir.  With many subdir configure scripts removed,
the top-level configure & Makefile can't use the same relative path.
So switch the subdir Makefiles over to abs_newlib_basedir when they
use -I to find source headers.

Do this for all subdirs, even ones with configure scripts and where
newlib_basedir works.  This makes the code consistent, and avoids
surprises if the configure script is ever removed in the future as
part of merging to the higher level.

Some of the subdirs were using -I$(newlib_basedir)/../newlib/ for
some reason.  Collapse those too since newlib_basedir points to the
newlib source tree already.
2022-01-29 01:35:30 -05:00
Mike Frysinger 6444f108d9 newlib: export abs_newlib_basedir for all subdirs
When using the top-level configure script but subdir Makefiles, the
newlib_basedir value gets a bit out of sync: it's relative to where
configure lives, not where the Makefile lives.  Move the abs setting
from the top-level configure script into acinclude.m4 so we can rely
on it being available everywhere.  Although this commit doesn't use
it anywhere, just lays the groundwork.
2022-01-29 01:35:30 -05:00
Mike Frysinger 2339979934 newlib: libm: merge machine/ configure scripts up a level
The machine configure scripts are all effectively stub scripts that
pass the higher level options to its own makefile.  The only one doing
any custom tests was nds32.  The rest were all effectively the same as
the libm/ configure script.

So instead of recursively running configure in all of these subdirs,
generate their makefiles from the top-level configure.  For nds32,
deploy a pattern of including subdir logic via m4:
	m4_include([machine/nds32/acinclude.m4])

Even its set of checks are very small -- it does 2 preprocessor tests
and sets up 2 makefile conditionals.

Some of the generated machine makefiles have a bunch of extra stuff
added to them, but that's because they were inconsistent in their
configure libtool calls.  The top-level has it, so it exports some
new vars to the ones that weren't already.
2022-01-26 03:11:20 -05:00
Mike Frysinger 6ac043b192 newlib: libm: merge machine/ trampoline up a level
The machine/{configure,Makefile} files exist only to fan out to the
specific machine/$arch/ subdir.  We already have all that same info
in the libm/ dir itself, so by moving the recursive configure and
make calls into it, we can cut off this logic entirely and save the
overhead.

For arches that don't have a machine subdir, it means they can skip
the logic entirely.
2022-01-26 03:11:20 -05:00