aboutsummaryrefslogtreecommitdiff
path: root/newlib/libm
AgeCommit message (Collapse)AuthorFilesLines
2025-08-27amdgcn, libm: fix vector ilogb bugs (bug 33272)Andrew Stubbs5-97/+99
The vector ilogb routines, including the ones inlined into fmod, had a bug in which the conditional masks were not properly applied, causing the value of one lane to be affected by conditional choices of another lane. The problem was not immediately obviously because all values were calculated correctly when no lane contained a subnormal input. The problem is fixed by proper use of VECTOR_COND_MOVE and VECTOR_WHILE.
2025-08-08amdgcn, libm: fix infinite loopAndrew Stubbs1-2/+5
The end condition on this loop, unlike all the other similar loops, is "i >= 0", which is a problem because "i <<= 1" can go negative and then zero if you continue shifting, and so back to true, again. This isn't a problem for the loop in the scalar implementation, but it means we need to mask the shift in the vector implementation. This fixes GCC PR#121392.
2025-07-21newlib: add dummy implementations of fe{get,set}prec for Aarch64 CygwinRadek Bartoň3-0/+41
This patch introduces dummy implementation of fegetprec and fsetprec for Cygwin build as those symbols are being exported by cygwin1.dll and AArch64 do not support changing floating point precision at runtime. Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
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-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
2024-12-31Changes for 4.5.0 snapshotnewlib-4.5.0Jeff Johnston1-2/+2
- bump up release to 4.5.0
2024-12-05libm/common: Fix nextafter and nextafterf when x == yKito Cheng2-2/+2
That according to C99/POSIX, nextafter(x,y) should return y if x==y. [1] NetBSD fix for this: https://github.com/IIJ-NetBSD/netbsd-src/commit/3bc685224189d2b7dfb68da52d9725a256a667bd [2] glibc fix for this: https://github.com/bminor/glibc/commit/bc9f6000f6752153e5e1902259d5f491a88a1ae5#diff-bcc0628a39c3c2003047dcb5a40a8b50c00f01a74b1c8c1100d770a8e48b1ce2 [3] Linux man page: https://man7.org/linux/man-pages/man3/nextafter.3.html
2024-09-19powf: Fixed another precision bug in powf() (FreeBSD)Fabian Schriever1-1/+1
Fixed another precision bug in powf(). This one is in the computation [t=p_l+p_h High]. We multiply t by lg2_h, and want the result to be exact. For the bogus float case of the high-low decomposition trick, we normally discard the lowest 12 bits of the fraction for the high part, keeping 12 bits of precision. That was used for t here, but it doesnt't work because for some reason we only discard the lowest 9 bits in the fraction for lg2_h. Discard another 3 bits of the fraction for t to compensate. This bug gave wrong results like: powf(0.9999999, -2.9999995) = 1.0000002 (should be 1.0000001) hex values: 3F7FFFFF C03FFFFE 3F800002 3F800001 As explained in the log for the previous commit, the bug is normally masked by doing float calculations in extra precision on i386's, but is easily detected by ucbtest on systems that don't have accidental extra precision. Reference: https://github.com/freebsd/freebsd-src/commit/5f20e5ce7f396ad064bfc1f45b8075ea1c0580f9 Original Author: Bruce Evans
2024-09-19powf: Fixed 2 bugs in the computation /* t_h=ax+bp[k] High */. (FreeBSD)Fabian Schriever1-1/+2
(1) The bit for the 1.0 part of bp[k] was right shifted by 4. This seems to have been caused by a typo in converting e_pow.c to e_powf.c. (2) The lower 12 bits of ax+bp[k] were not discarded, so t_h was actually plain ax+bp[k]. This seems to have been caused by a logic error in the conversion. These bugs gave wrong results like: powf(-1.1, 101.0) = -15158.703 (should be -15158.707) hex values: BF8CCCCD 42CA0000 C66CDAD0 C66CDAD4 Fixing (1) gives a result wrong in the opposite direction (hex C66CDAD8), and fixing (2) gives the correct result. ucbtest has been reporting this particular wrong result on i386 systems with unpatched libraries for 9 years. I finally figured out the extent of the bugs. On i386's they are normally hidden by extra precision. We use the trick of representing floats as a sum of 2 floats (one much smaller) to get extra precision in intermediate calculations without explicitly using more than float precision. This trick is just a pessimization when extra precision is available naturally (as it always is when dealing with IEEE single precision, so the float precision part of the library is mostly misimplemented). (1) and (2) break the trick in different ways, except on i386's it turns out that the intermediate calculations are done in enough precision to mask both the bugs and the limited precision of the float variables (as far as ucbtest can check). ucbtest detects the bugs because it forces float precision, but this is not a normal mode of operation so the bug normally has little effect on i386's. On systems that do float arithmetic in float precision, e.g., amd64's, there is no accidental extra precision and the bugs just give wrong results. Reference: https://github.com/freebsd/freebsd-src/commit/12be4e0d5a54a6750913aee2564d164baa71f0dc Original Author: Bruce Evans
2024-09-19powf: Fix the hi+lo decomposition for 2/(3ln2) (FreeBSD)Fabian Schriever1-2/+2
The decomposition needs to be into 12+24 bits of precision for extra- precision multiplication, but was into 13+24 bits. On i386 with -O1 the bug was hidden by accidental extra precision, but on amd64, in 2^32 trials the bug caused about 200000 errors of more than 1 ulp, with a maximum error of about 80 ulps. Now the maximum error in 2^32 trials on amd64 is 0.8573 ulps. It is still 0.8316 ulps on i386 with -O1. The nearby decomposition of 1/ln2 and the decomposition of 2/(3ln2) in the double precision version seem to be sub-optimal but not broken. Reference: https://github.com/freebsd/freebsd-src/commit/b4437c3d322a0f6d23d12b6f76d2fc72d2ff0ec2 Original Author: Bruce Evans
2024-09-02newlib: xtensa: remove sys/xtensa. use machine/xtensaAlexey Lapshin1-1/+1
Remove sys/xtensa that is actually duplicate newlib's code. Move used code to machine/xtensa or to libgloss
2024-07-16newlib: Add more FreeBSD files for non LDBL_EQ_DBL supportKito Cheng9-3/+593
For RISC-V, AArch64, i386, and x86_64 - k_tanl.c is required for tanl; the linker will report `__kernel_tanl` not found when tanl is called. - s_cospil.c and s_sinpil.c are added for cospil and sinpil, which are already available for ld80 but not for ld128.
2024-07-01arm: Fix fma & fmaf implementationsMickaël Thomas2-2/+2
The vfma.f32|64 z, x, y instruction performs the operation z += x * y without intermediate rounding. The register used for z is both read and written by the instruction. The inline assembly must therefore use the "+" constraint modifier.
2024-06-06newlib: libm: skip "long double" complex functions if long double != doublePietro Monteiro14-6/+47
The rest of "long double" functions aren't compiled with long double and double are not the same. Do the same for all complex functions. Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
2024-01-22newlib: docs: add "Function " to every function nodeMike Frysinger4-129/+129
When creating a split manual with one-node-per-page, the main index.html ends up getting clobbered by the page for the index() function because it uses "@node index" which, for html, also creates an index.html page. To remedy this, add "Function " to every function node so now we output "Function-index.html" and avoid clobbering. It also namespaces every other function and helps make sure we don't clobber anything else. Otherwise, there isn't really much rendering difference as @node text is mostly internal. Node title text comes from @section instead.
2024-01-22newlib: docs: print the function indexMike Frysinger1-0/+6
The generated function documentation makes sure to include entries for every function in the function index via @findex, but then the manuals forget to actually print the index.
2023-12-31Changes for newlib 4.4.0 snapshotnewlib-4.4.0Jeff Johnston1-2/+2
- bump up version to 4.4.0
2023-12-20newlib: Fix long double for unsupported rounding modes and exceptionsCraig Blackmore3-2/+16
RISC-V newlib fails to build for soft float multilibs since long double support was enabled in: commit 04798b7bb69571452d2cfc7e0b052a9bbd3b619d Author: Kito Cheng <kito.cheng@sifive.com> Date: Mon Dec 4 15:41:39 2023 +0800 RISC-V: Support long double math Long double for RISC-V is using 128 bit IEEE 754 format like Aarch64, so we reference AArch64 to support that. The RISC-V soft floating point environment only supports the FE_TONEAREST rounding mode and does not support exceptions. Guard long double rounding and exception support with ifdefs based on the presence of the relevant rounding modes and exceptions. Tested on gcc/g++ testsuite using RISC-V GNU Newlib Toolchain built by riscv-gnu-toolchain with multilibs: riscv-sim/-march=rv32i/-mabi=ilp32/-mcmodel=medlow riscv-sim/-march=rv32iac/-mabi=ilp32/-mcmodel=medlow riscv-sim/-march=rv32im/-mabi=ilp32/-mcmodel=medlow riscv-sim/-march=rv32imac/-mabi=ilp32/-mcmodel=medlow riscv-sim/-march=rv32imafc/-mabi=ilp32f/-mcmodel=medlow riscv-sim/-march=rv64imac/-mabi=lp64/-mcmodel=medlow Co-authored-by: Simon Cook <simon.cook@embecosm.com>
2023-12-19Remove curly braces in `@author` tag in .texi filesFreddie Chopin1-4/+4
Curly braces cause documentation build failure with texinfo 7.1 (works fine up to 7.0.3):
2023-12-04pru: libm: Fix incorrect function nameDimitar Dimitrov1-1/+1
Upstream GCC changed -Wimplicit-function-declaration warning into an error. The build break about missing fpclassifyf function prototype exposed a bug in the PRU port of libm. The fix is to use the fpclassify macro for both double and float types. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2023-12-04RISC-V: Support long double mathKito Cheng1-0/+1
Long double for RISC-V is using 128 bit IEEE 754 format like Aarch64, so we reference AArch64 to support that.
2023-10-10Delete check in catan, catanf, and catanl functions.Joseph Faulls3-6/+0
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-08-17newlib: add Xtensa portAlexey Lapshin14-1/+508
2023-07-27Fix rounding results in lrint() & llrint() when close to 0Jesse Huang via Newlib4-48/+26
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-26RISC-V: Support Zfinx/Zdinx extension.Kito Cheng via Newlib39-48/+85
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-05-16newlib: Add non LDBL_EQ_DBL math support for aarch64, i386, and x86_64Jennifer Averett40-52/+257
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-16newlib: Add FreeBSD files for non LDBL_EQ_DBL supportJennifer Averett79-0/+12804
FreeBSD files to add long double support for i386, aarch64 and x86_64.
2023-05-05Move signgm.c from libc/reent to libm/mathJennifer Averett2-0/+17
2023-04-13Replace always true if with elseAndoni Arregi1-2/+5
2023-04-13Compare j as unsignedAndoni Arregi1-1/+1
j is int32_t and thus j<<31 is undefined if j==1. Taken from FreeBSD commit bdd8abc6d6a93ce3ab8ad5db716222ee3110c4a3
2023-04-13Fix x close to 1, y between 2^31 and 2^64Andoni Arregi1-2/+2
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-13Fix missing sign for overflow/underflow where x is negative and y is large ↵Andoni Arregi1-19/+18
odd integer
2023-03-30Bump newlib version in the manual to 4.3.0Tobias Burnus1-2/+2
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-01-18amdgcn: Add vectorized math routinesKwok Cheung Yeung93-1/+8155
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-16Fix 3 other instances of Reme typo (should be Remez)Jeff Johnston3-3/+3
2022-12-16Revert "amdgcn: Add vectorized math routines"Jeff Johnston92-6239/+1
This reverts commit 125e39bfea1a39341a60348c93a65cf4894e0f2a.
2022-12-16Fix a typo in the comment.Nadav Rotem1-1/+1
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-16amdgcn: Add vectorized math routinesKwok Cheung Yeung92-1/+6239
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-07-13Add --enable-newlib-reent-thread-local optionMatt Joyce1-0/+4
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-05-04Silence xsltproc when writing manpagesJon Turney1-1/+1
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-04Add build avoidance for 'make man'Jon Turney1-4/+5
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-04Simplify rules for creating man pagesJon Turney1-5/+3
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-03-16newlib: libm: integrate tests subdirMike Frysinger6-209/+91
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-02-17newlib: libm: merge build up a directoryMike Frysinger52-15005/+431
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-16newlib: fix mips fenv.o handlingMike Frysinger2-3/+3
Commit 8fa73a9f8414a4926365324c2fe32a237c2eb91d 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-15newlib/libgloss: drop unused $(CROSS_CFLAGS)Mike Frysinger32-62/+32
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-14Improve lgammaf range for very small casesAndoni Arregi1-1/+1
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-11newlib: remove unused fenv flagsMike Frysinger2-4/+2
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-10Fix expf overflow limitAndoni Arregi1-2/+2
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-10newlib: libm: fix rebase conflictsMike Frysinger1-5/+1
I missed this cleanup when rebasing on top of the latest branch.