aboutsummaryrefslogtreecommitdiff
path: root/newlib
AgeCommit message (Collapse)AuthorFilesLines
2018-07-30ctype: Avoid GCC note in towctrans_l.cSebastian Huber1-2/+2
The previous version genenerated the following GCC note: towctrans_l.c:44:1: note: offset of packed bit-field 'diff' has changed in GCC 4.4 caseconv_table [] = { ^~~~~~~~~~~~~~ Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30ctype: Fix integer type for caseconv_entry::deltaSebastian Huber1-1/+1
The commit 46ba1675c457324b0eeef4670a09101ef3f34c50 accidently changed a bit-field from signed to unsigned. The caseconv_entry::delta must be a signed integer, see also "newlib/libc/ctype/caseconv.t". Unfortunately, a standard GCC/Newlib build is done without -Wsign-conversion. Using this warning option would have helped to avoid this bug: caseconv.t:2:22: warning: unsigned conversion from 'int' to 'unsigned int:17' changes value from '-32' to '131040' [-Wsign-conversion] {0x0061, 25, TOUP, -32}, Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-30Fix comparison between two character arraysJordi Sanfeliu1-1/+1
Hello, The member 'id' in the 'utmp' struct is not a numeric but a character array, hence the strncmp() function is needed to compare two members.
2018-07-25Cygwin: define _POSIX_ASYNCHRONOUS_IOYaakov Selkowitz1-1/+1
This feature is now available as of the recent AIO commits. Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-07-20ctype: Fix bitfield types on 16-bit targetsnewlib-snapshot-20180720Sebastian Huber2-6/+8
This prevents errors like this: newlib/libc/ctype/categories.c:6:3: error: width of 'first' exceeds its type unsigned int first: 24; ^ Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-20RTEMS: Unconditionally define _off_t to int64_tSebastian Huber1-4/+0
Exotic RTEMS targets can define this back to int32_t as an exception if there are good reasons. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-07-19Remove myself from MAINTAINERSDJ Delorie1-4/+1
Stepping down from target-specific maintainerships.
2018-07-17Print sign of NaN values to nano-vfprintf.Kumar Gala1-0/+2
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-13Fix to stop a fall-through in a switch statementJordi Sanfeliu1-0/+1
The following fixes a fall-through that prevented from reading the next entry in the UTMP file and terminated the program with an abort().
2018-07-13strcmp.S: Improve performance for misaligned stringsSiddhesh Poyarekar1-11/+40
Replace the simple byte-wise compare in the misaligned case with a dword compare with page boundary checks in place. For simplicity I've chosen a 4K page boundary so that we don't have to query the actual page size on the system. This results in up to 3x improvement in performance in the unaligned case on falkor and about 2.5x improvement on mustang as measured using bench-strcmp in glibc.
2018-07-13memcmp.S: optimize for medium to large sizesSiddhesh Poyarekar1-44/+100
This improved memcmp provides a fast path for compares up to 16 bytes and then compares 16 bytes at a time, thus optimizing loads from both sources. The glibc memcmp microbenchmark retains performance (with an error of ~1ns) for smaller compare sizes and reduces up to 31% of execution time for compares up to 4K on the APM Mustang. On Qualcomm Falkor this improves to almost 48%, i.e. it is almost 2x improvement for sizes of 2K and above.
2018-07-13Improve strncmp for mutually misaligned inputsSiddhesh Poyarekar1-17/+79
The mutually misaligned inputs on aarch64 are compared with a simple byte copy, which is not very efficient. Enhance the comparison similar to strcmp by loading a double-word at a time. The peak performance improvement (i.e. 4k maxlen comparisons) due to this on the strncmp microbenchmark in glibc is as follows: falkor: 3.5x (up to 72% time reduction) cortex-a73: 3.5x (up to 71% time reduction) cortex-a53: 3.5x (up to 71% time reduction) All mutually misaligned inputs from 16 bytes maxlen onwards show upwards of 15% improvement and there is no measurable effect on the performance of aligned/mutually aligned inputs.
2018-07-11Remove float compare option from sincosfSzabolcs Nagy1-10/+1
PREFER_FLOAT_COMPARISON setting was not correct as it could raise spurious exceptions. Fixing it is easy: just use ISLESS(x, y) instead of abstop12(x) < abstop12(y) with appropriate non-signaling definition for ISLESS. However it seems this setting is not very useful (there is only minor performance difference on various architectures), so remove this option for now.
2018-07-11Fix the documentation comments for log_inline in powSzabolcs Nagy1-3/+3
There was a typo and the arguments were not explained clearly.
2018-07-06Fix namespace issues in sinf, cosf and sincosfSzabolcs Nagy5-18/+19
Use const sincos_t for clarity instead of making the typedef const. Use __inv_pi4 and __sincosf_table to avoid namespace issues with static linking.
2018-07-06Fix large ulp error in pow without fma very near 1.0Szabolcs Nagy1-2/+4
The !HAVE_FAST_FMA code path split r = z/c - 1 into r = rhi + rlo such that when z = 1-tiny and c = 1 then rlo and rhi could have much larger magnitude than r which later caused large rounding errors. So do a nearest rounding instead of truncation at the split. In newlib with default settings this was observable on some arm targets that enable the new math code but has no fma.
2018-07-06Change the return type of converttoint and document the semanticsSzabolcs Nagy1-1/+9
The roundtoint and converttoint internal functions are only called with small values, so 32 bit result is enough for converttoint and it is a signed int conversion so the natural return type is int32_t. The original idea was to help the compiler keeping the result in uint64_t, then it's clear that no sign extension is needed and there is no accidental undefined or implementation defined signed int arithmetics. But it turns out gcc does a good job with inlining so changing the type has no overhead and the semantics of the conversion is less surprising this way. Since we want to allow the asuint64 (x + 0x1.8p52) style conversion, the top bits were never usable and the existing code ensures that only the bottom 32 bits of the conversion result are used. In newlib with default settings only aarch64 is affected and there is no significant code generation change with gcc after the patch.
2018-07-06Remove unused TOINT_RINT and TOINT_SHIFT macrosSzabolcs Nagy2-10/+1
Only have separate code paths for TOINT_INTRINSICS and !TOINT_INTRINSICS.
2018-07-06Move __HAVE_FAST_FMA to math_config.hSzabolcs Nagy7-35/+21
Define it consistently with other HAVE_* macros that only affect code using math_config.h. This is also closer to the Arm Optimized Routines code.
2018-07-06Fix code style and comments of new math codeSzabolcs Nagy8-74/+134
Synchronize code style and comments with Arm Optimized Routines, there are no code changes in this patch. This ensures different projects using the same code have consistent code style so bug fix patches can be applied more easily.
2018-07-05Fix newlib functions perror()/psignal() not to use writev().Takashi Yano2-37/+39
This fix is for some platforms which do not have writev(). *perror.c: Use _write_r() instead of writev(). *psignal.c: Use write() insetad of writev(). Revise commit: d4f4e7ae1be1bcf8c021f2b0865aafc16b338aa3
2018-07-04Fix a bug of perror()/psignal() that changes the orientation of stderr.Takashi Yano2-8/+54
* perror.c: Fix the problem that perror() changes the orientation of stderr to byte-oriented mode if stderr is not oriented yet. * psignal.c: Ditto.
2018-06-27newlib: enable new math functions on CygwinCorinna Vinschen1-0/+4
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-27New pow implementationSzabolcs Nagy8-5/+607
The new implementation is provided under !__OBSOLETE_MATH, it uses ISO C99 code. With default settings the worst case error in nearest rounding mode is 0.54 ULP with inlined fma and fma contraction. It uses a 4 KB lookup table in addition to the table in exp_data.c, on aarch64 .text+.rodata size of libm.a is increased by 2295 bytes. Improvements on Cortex-A72: latency: 3.3x thruput: 4.9x
2018-06-27New log2 implementationSzabolcs Nagy6-4/+399
The new implementation is provided under !__OBSOLETE_MATH, it uses ISO C99 code. With default settings the worst case error in nearest rounding mode is 0.547 ULP with inlined fma and fma contraction. It uses a 1 KB lookup table, on aarch64 .text+.rodata size of libm.a is increased by 1584 bytes. Note that the math.h header defines log2(x) to be log(x)/Ln2, this is not changed, so the new code is only used if that macro is suppressed. Improvements on Cortex-A72: latency: 2.0x thruput: 2.2x
2018-06-27New log implementationSzabolcs Nagy9-4/+744
The new implementations are provided under !__OBSOLETE_MATH, it uses ISO C99 code. With default settings the worst case error in nearest rounding mode is 0.519 ULP with inlined fma and fma contraction. It uses a 2 KB lookup table, on aarch64 .text+.rodata size of libm.a is increased by 1703 bytes. The w_log.c wrapper is disabled since error handling is inline in the new code. New __HAVE_FAST_FMA and __HAVE_FAST_FMA_DEFAULT feature macros were added to enable selecting between the code path that uses fma and the one that does not. Targets supposed to set __HAVE_FAST_FMA_DEFAULT if they have single instruction fma and the compiler can actually inline it (gcc has __FP_FAST_FMA macro but that does not guarantee inlining with -fno-builtin-fma). Improvements on Cortex-A72: latency: 1.9x thruput: 2.3x
2018-06-27New exp and exp2 implementationsSzabolcs Nagy11-5/+1138
The new implementations are provided under !__OBSOLETE_MATH, they use ISO C99 code. There are several settings, with the default one the worst case error in nearest rounding mode is 0.509 ULP for exp and 0.507 ULP for exp2 when a multiply and add is contracted into an fma. They use a shared 2 KB lookup table, on aarch64 .text+.rodata size of libm.a is increased by 1868 bytes. The w_*.c wrappers are disabled for the new code as it takes care of error handling inline. The old exp2(x) code used to be just pow(2,x) so the speedup there is more significant. The file name has no special prefix to avoid any name collision with existing files. Improvements on Cortex-A72: exp latency: 3.2x exp thruput: 4.1x exp2 latency: 7.8x exp2 thruput: 18.8x
2018-06-27Use uint32_t sign argument to math error functionsSzabolcs Nagy3-13/+13
This change is equivalent to the commit https://github.com/ARM-software/optimized-routines/commit/c65db17340782d647c49e17cbba244862dc38402 and only affects code that is from the Arm optimized-routines project. It does not affect the observable behaviour, but the code generation can be different on 64bit targets. The intention is to make the portable semantics of the code obvious by using a fixed size type.
2018-06-26Fix Unicode table.Takashi Yano2-26/+16
* (mkcategories): Fix a bug that outputs incorrect Unicode category table for code point ranges. * (categories.t): Rebuild it using the bug-fixed mkcategories. This fixes the problem reported in the following post. https://cygwin.com/ml/cygwin/2018-06/msg00248.html
2018-06-26Revert "Remove -fno-builtin to allow gcc to inline functions such as fabs, ↵Corinna Vinschen8-8/+8
floor, creal, imag." This reverts commit c077b9de99c6980a0c1631ec2938f6ff2cf0c289. Yet another accidental commit...
2018-06-25Remove -fno-builtin to allow gcc to inline functions such as fabs, floor, ↵Jon Beniston8-8/+8
creal, imag.
2018-06-21Improve performance of sinf/cosf/sincosfWilco Dijkstra11-6/+667
Here is the correct patch with both filenames and int cast fixed: This patch is a complete rewrite of sinf, cosf and sincosf. The new version is significantly faster, as well as simple and accurate. The worst-case ULP is 0.56072, maximum relative error is 0.5303p-23 over all 4 billion inputs. In non-nearest rounding modes the error is 1ULP. The algorithm uses 3 main cases: small inputs which don't need argument reduction, small inputs which need a simple range reduction and large inputs requiring complex range reduction. The code uses approximate integer comparisons to quickly decide between these cases - on some targets this may be slow, so this can be configured to use floating point comparisons. The small range reducer uses a single reduction step to handle values up to 120.0. It is fastest on targets which support inlined round instructions. The large range reducer uses integer arithmetic for simplicity. It does a 32x96 bit multiply to compute a 64-bit modulo result. This is more than accurate enough to handle the worst-case cancellation for values close to an integer multiple of PI/4. It could be further optimized, however it is already much faster than necessary. Simple benchmark showing speedup factor on AArch64 for various ranges: range 0.7853982 sinf 1.7 cosf 2.2 sincosf 2.8 range 1.570796 sinf 1.9 cosf 1.9 sincosf 2.7 range 3.141593 sinf 2.0 cosf 2.0 sincosf 3.5 range 6.283185 sinf 2.3 cosf 2.3 sincosf 4.2 range 125.6637 sinf 2.9 cosf 3.0 sincosf 5.1 range 1.1259e15 sinf 26.8 cosf 26.8 sincosf 45.2 ChangeLog: 2018-05-18 Wilco Dijkstra <wdijkstr@arm.com> * newlib/libm/common/Makefile.in: Regenerated. * newlib/libm/common/Makefile.am: Add sinf.c, cosf.c, sincosf.c sincosf.h, sincosf_data.c. Add -fbuiltin -fno-math-errno to CFLAGS. * newlib/libm/common/math_config.h: Add HAVE_FAST_ROUND, HAVE_FAST_LROUND, roundtoint, converttoint, force_eval_float, force_eval_double, eval_as_float, eval_as_double, likely, unlikely. * newlib/libm/common/cosf.c: New file. * newlib/libm/common/sinf.c: Likewise. * newlib/libm/common/sincosf.h: Likewise. * newlib/libm/common/sincosf.c: Likewise. * newlib/libm/common/sincosf_data.c: Likewise. * newlib/libm/math/sf_cos.c: Add #if to build conditionally. * newlib/libm/math/sf_sin.c: Likewise. * newlib/libm/math/wf_sincos.c: Likewise. --
2018-06-21Revert "Improve performance of sinf/cosf/sincosf"Corinna Vinschen11-667/+6
This reverts commit fca80a9d1b3fa6620cdaccec6b726eef1a6530a1. Accidentally pushed a preliminary version
2018-06-21libm/common/s_round.c (round): Add cast for 16-bit CPUsJon Beniston1-1/+1
2018-06-19Improve performance of sinf/cosf/sincosfWilco Dijkstra11-6/+667
This patch is a complete rewrite of sinf, cosf and sincosf. The new version is significantly faster, as well as simple and accurate. The worst-case ULP is 0.56072, maximum relative error is 0.5303p-23 over all 4 billion inputs. In non-nearest rounding modes the error is 1ULP. The algorithm uses 3 main cases: small inputs which don't need argument reduction, small inputs which need a simple range reduction and large inputs requiring complex range reduction. The code uses approximate integer comparisons to quickly decide between these cases - on some targets this may be slow, so this can be configured to use floating point comparisons. The small range reducer uses a single reduction step to handle values up to 120.0. It is fastest on targets which support inlined round instructions. The large range reducer uses integer arithmetic for simplicity. It does a 32x96 bit multiply to compute a 64-bit modulo result. This is more than accurate enough to handle the worst-case cancellation for values close to an integer multiple of PI/4. It could be further optimized, however it is already much faster than necessary. Simple benchmark showing speedup factor on AArch64 for various ranges: range 0.7853982 sinf 1.7 cosf 2.2 sincosf 2.8 range 1.570796 sinf 1.9 cosf 1.9 sincosf 2.7 range 3.141593 sinf 2.0 cosf 2.0 sincosf 3.5 range 6.283185 sinf 2.3 cosf 2.3 sincosf 4.2 range 125.6637 sinf 2.9 cosf 3.0 sincosf 5.1 range 1.1259e15 sinf 26.8 cosf 26.8 sincosf 45.2 ChangeLog: 2018-06-18 Wilco Dijkstra <wdijkstr@arm.com> * newlib/libm/common/Makefile.in: Regenerated. * newlib/libm/common/Makefile.am: Add sinf.c, cosf.c, sincosf.c sincosf.h, sincosf_data.c. Add -fbuiltin -fno-math-errno to CFLAGS. * newlib/libm/common/math_config.h: Add HAVE_FAST_ROUND, HAVE_FAST_LROUND, roundtoint, converttoint, force_eval_float, force_eval_double, eval_as_float, eval_as_double, likely, unlikely. * newlib/libm/common/cosf.c: New file. * newlib/libm/common/sinf.c: Likewise. * newlib/libm/common/sincosf.h: Likewise. * newlib/libm/common/sincosf.c: Likewise. * newlib/libm/common/sincosf_data.c: Likewise. * newlib/libm/math/sf_cos.c: Add #if to build conditionally. * newlib/libm/math/sf_sin.c: Likewise. * newlib/libm/math/wf_sincos.c: Likewise. --
2018-06-18newlib: getopt now permutes multi-flag options correctlyThomas Kindler2-13/+23
Previously, "test 1 2 3 -a -b -c" was permuted to "test -a -b -c 1 2 3", but "test 1 2 3 -abc" was left as "test 1 2 3 -abc". Signed-off-by: Thomas Kindler <mail+newlib@t-kindler.de>
2018-05-29Fix issue with malloc_extend_topJeff Johnston1-1/+6
- when calculating a correction to align next brk to page boundary, ensure that the correction is less than a page size - if allocating the correction fails, ensure that the top size is set to brk + sbrk_size (minus any front alignment made) Signed-off-by: Jeff Johnston <jjohnstn@redhat.com>
2018-05-29fix llrint and lrint for 52 <= exponent <= 62Matthias Kannwischer2-4/+4
2018-05-29Fix 32-bit overflow in mktime() when time_t is 64-bits longFreddie Chopin1-1/+1
When converting number of days since epoch (32-bits) to seconds, calculations using 32-bit `long` overflow for years above 2038. Solve this by casting number of days to `time_t` just before final multiplication. Signed-off-by: Freddie Chopin <freddie.chopin@gmail.com>
2018-05-07Use _LDBL_EQ_DBL in nexttowardf.cJeff Johnston1-2/+2
2018-05-07 Tom de Vries <tom@codesourcery.com> * libm/common/nexttowardf.c: Use _LDBL_EQ_DBL instead of _LDBL_EQ_DOUBLE.
2018-04-13Add nvptx port.Jeff Johnston132-113/+7504
- From: Cesar Philippidis <cesar@codesourcery.com> Date: Tue, 10 Apr 2018 14:43:42 -0700 Subject: [PATCH] nvptx port This port adds support for Nvidia GPU's, which are primarily used as offload accelerators in OpenACC and OpenMP.
2018-04-09strtod: Convert 64 bit double to 64 bit int during computationCorinna Vinschen1-0/+9
The gdtoa implementation uses the type long, defined as Long, in lots of code. For historical reason newlib defines Long as int32_t instead. This works fine, as long as floating point exceptions are not enabled. The conversion to 32 bit int can lead to a FE_INVALID situation. Example: const char *str = "121645100408832000.0"; char *ptr; feenableexcept (FE_INVALID); strtod (str, &ptr); This leads to the following situation in strtod double aadj; Long L; [...] L = (Long)aadj; For instance, on x86_64 the code here is cvttsd2si %xmm0,%eax At this point, aadj is 2529648000.0 in our example. The conversion to 32 bit %eax results in a negative int value, thus the conversion is invalid. With feenableexcept (FE_INVALID), a SIGFPE is raised. Fix this by always using 64 bit ints here if double is not a 32 bit type to avoid this type of FP exceptions. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-03-27newlib: fix iswupper_l in !_MB_CAPABLE caseCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-03-26comments to document struct caseconv_entryThomas Wolff1-3/+33
explain design of compact (packed) struct caseconv_entry, in case it needs to be modified for future Unicode versions
2018-03-26newlib: fix indentation in toulowerThomas Wolff1-10/+10
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-03-16Reduce qsort stack consumptionHakan Lindqvist1-6/+54
Classical function call recursion wastes a lot of stack space. Each recursion level requires a full stack frame comprising all local variables and additional space as dictated by the processor calling convention. This implementation instead stores the variables that are unique for each recursion level in a parameter stack array, and uses iteration to emulate recursion. Function call recursion is not used until the array is full. To ensure the stack consumption isn't worsened by this design, the size of the parameter stack array is chosen to be similar to the stack frame excluding the array. Each function call recursion level can handle 8 iterative recursion levels. Stack consumption will worsen when sorting tiny arrays that do not need recursion (of 6 elements or less). It will be about equal for up to 15 elements, and be an improvement for larger arrays. The best case improvement is a stack size reduction down to about one quarter of the stack consumption before the change. A design where the parameter stack array is large enough for the worst case recursion level was rejected because it would worsen the stack consumption when sorting arrays smaller than about 1500 elements. The worst case is 31 levels on a 32-bit system. A design with a dynamic parameter array size was rejected because of limitations in some compilers.
2018-03-16Ensure qsort recursion depth is boundedHakan Lindqvist1-12/+56
The qsort algorithm splits the input array in three parts. The left and right parts may need further sorting. One of them is sorted by recursion, the other by iteration. This update ensures that it is the smaller part that is chosen for recursion. By choosing the smaller part, each recursion level will handle less than half the array of the previous recursion level. Hence the recursion depth is bounded to be less than log2(n) i.e. 1 level per significant bit in the array size n. The update also includes code comments explaining the algorithm.
2018-03-15Correct prototypes of pthread_mutex_getprioceiling() and pthread_setschedparam()Joel Sherrill1-2/+2
2018-03-15[arm] Fix syscalls.c for newlib embedded syscalls buildsRichard Earnshaw1-119/+126
Newlib has a build configuration where syscalls can be directly embedded in the newlib library rather than relying on libgloss. This configuration was broken recently by an update to the libgloss support for Arm that was not propagated to the syscalls interface in newlib itself. This patch restores the build. It's essentially a copy of https://sourceware.org/ml/newlib/2018/msg00128.html but there are some other minor cleanups and changes that I've made at the same time. None of those cleanups affect functionality. The prototypes of the following functions have been updated: _link, _sbrk, _getpid, _write, _swiwrite, _lseek, _swilseek, _read and _swiread. Signed-off-by: Richard Earnshaw <Richard.Earnshaw@arm.com>
2018-03-14ssp: fix wchar.h with -std=c99Yaakov Selkowitz1-2/+2
https://sourceware.org/ml/newlib/2018/msg00261.html Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>