Commit Graph

847 Commits

Author SHA1 Message Date
Rich Felker
96e9773eb7 use the new integer parser (FILE/shgetc based) for strtol, wcstol, etc. 2012-04-16 16:55:24 -04:00
Rich Felker
18efeb320b new scanf implementation and corresponding integer parser/converter
advantages over the old code:
- correct results for floating point (old code was bogus)
- wide/regular scanf separated so scanf does not pull in wide code
- well-defined behavior on integers that overflow dest type
- support for %[a-b] ranges with %[ (impl-defined by widely used)
- no intermediate conversion of fmt string to wide string
- cleaner, easier to share code with strto* functions
- better standards conformance for corner cases

the old code remains in the source tree, as the wide versions of the
scanf-family functions are still using it. it will be removed when no
longer needed.
2012-04-16 16:03:45 -04:00
Rich Felker
cc762434d9 fix buggy limiter handling in shgetc
this is needed for upcoming new scanf
2012-04-16 15:36:18 -04:00
Rich Felker
0d5df2df4f wordexp must set the we_offs entries of we_wordv to null pointers 2012-04-16 13:25:05 -04:00
Rich Felker
bef7a85e45 fix crash in wordfree if we_offs is not initialized by the caller
I'm not sure if it's legal for wordexp to modify this field, but this
is the only easy/straightforward fix, and applications should not
care. if it's an issue, i can work out a different (but more complex)
solution later.
2012-04-16 13:03:22 -04:00
Rich Felker
f007bb854b fix broken shgetc limiter logic (wasn't working) 2012-04-16 01:55:37 -04:00
Rich Felker
2ac580fdfe floatscan: fix incorrect count of leading nonzero digits
this off-by-one error was causing values with just one digit past the
decimal point to be treated by the integer case. in many cases it
would yield the correct result, but if expressions are evaluated in
excess precision, double rounding may occur.
2012-04-16 01:53:52 -04:00
Rich Felker
b9dd43db04 fix signedness error handling invalid multibyte sequences in regexec
the "< 0" test was always false due to use of an unsigned type. this
resulted in infinite loops on 32-bit machines (adding -1U to a pointer
is the same as adding -1) and crashes on 64-bit machines (offsetting
the string pointer by 4gb-1b when an illegal sequence was hit).
2012-04-14 22:32:42 -04:00
Rich Felker
386b34a07b remove invalid code from TRE
TRE wants to treat + and ? after a +, ?, or * as special; ? means
ungreedy and + is reserved for future use. however, this is
non-conformant. although redundant, these redundant characters have
well-defined (no-op) meaning for POSIX ERE, and are actually _literal_
characters (which TRE is wrongly ignoring) in POSIX BRE mode.

the simplest fix is to simply remove the unneeded nonstandard
functionality. as a plus, this shaves off a small amount of bloat.
2012-04-13 19:50:58 -04:00
Rich Felker
b6dbdc69b6 fix broken regerror (typo) and missing message 2012-04-13 18:40:38 -04:00
Rich Felker
11f3e33f9b use fast version of the int reading code for the high-order digits too
this increases code size slightly, but it's considerably faster,
especially for power-of-2 bases.
2012-04-13 04:38:56 -04:00
Rich Felker
26832d045f use macros instead of inline functions in shgetc.h
at -Os optimization level, gcc refuses to inline these functions even
though the inlined code would roughly the same size as the function
call, and much faster. the easy solution is to make them into macros.
2012-04-13 03:59:36 -04:00
Rich Felker
54222d1efc fix spurious overflows in strtoull with small bases
whenever the base was small enough that more than one digit could
still fit after UINTMAX_MAX/36-1 was reached, only the first would be
allowed; subsequent digits would trigger spurious overflow, making it
impossible to read the largest values in low bases.
2012-04-13 03:26:59 -04:00
Rich Felker
3ddeedd8f7 remove magic numbers from floatscan 2012-04-12 00:25:52 -04:00
Rich Felker
fe514951af optimize more integer cases in floatscan; comment the whole procedure 2012-04-12 00:16:01 -04:00
Rich Felker
470fecdd3a revert invalid optimization in floatscan 2012-04-11 23:08:50 -04:00
Rich Felker
96acdae944 fix stupid typo in floatscan that caused excess rounding of some values 2012-04-11 21:29:12 -04:00
Rich Felker
cc00f05632 Merge remote branch 'nsz/master' 2012-04-11 14:59:36 -04:00
Rich Felker
4054da9ba0 optimize floatscan downscaler to skip results that won't be needed
when upscaling, even the very last digit is needed in cases where the
input is exact; no digits can be discarded. but when downscaling, any
digits less significant than the mantissa bits are destined for the
great bitbucket; the only influence they can have is their presence
(being nonzero). thus, we simply throw them away early. the result is
nearly a 4x performance improvement for processing huge values.

the particular threshold LD_B1B_DIG+3 is not chosen sharply; it's
simply a "safe" distance past the significant bits. it would be nice
to replace it with a sharp bound, but i suspect performance will be
comparable (within a few percent) anyway.
2012-04-11 14:51:08 -04:00
Rich Felker
5837a0bb6b simplify/debloat radix point alignment code in floatscan
now that this is the first operation, it can rely on the circular
buffer contents not being wrapped when it begins. we limit the number
of digits read slightly in the initial parsing loops too so that this
code does not have to consider the case where it might cause the
circular buffer to wrap; this is perfectly fine because KMAX is chosen
as a power of two for circular-buffer purposes and is much larger than
it otherwise needs to be, anyway.

these changes should not affect performance at all.
2012-04-11 14:20:45 -04:00
Rich Felker
1bdd5c8b98 optimize floatscan: avoid excessive upscaling
upscaling by even one step too much creates 3-29 extra iterations for
the next loop. this is still suboptimal since it always goes by 2^29
rather than using a smaller upscale factor when nearing the target,
but performance on common, small-magnitude, few-digit values has
already more than doubled with this change.

more optimizations on the way...
2012-04-11 14:11:47 -04:00
Rich Felker
7ef1a9bba5 fix incorrect initial count in shgetc when data is already buffered 2012-04-11 00:26:41 -04:00
Rich Felker
48bb81adf8 fix bug parsing lone zero followed by junk, and hex float over-reading 2012-04-11 00:18:57 -04:00
Rich Felker
38b3f1fea8 fix float scanning of certain values ending in zeros
for example, "1000000000" was being read as "1" due to this loop
exiting early. it's necessary to actually update z and zero the
entries so that the subsequent rounding code does not get confused;
before i did that, spurious inexact exceptions were being raised.
2012-04-10 23:41:54 -04:00
Rich Felker
633a26c1e6 fix potential overflow in exponent reading
note that there's no need for a precise cutoff, because exponents this
large will always result in overflow or underflow (it's impossible to
read enough digits to compensate for the exponent magnitude; even at a
few nanoseconds per digit it would take hundreds of years).
2012-04-10 23:05:16 -04:00
Rich Felker
c5ff29699c set errno properly when parsing floating point 2012-04-10 22:38:21 -04:00
Rich Felker
2162541f38 add "scan helper getc" and rework strtod, etc. to use it
the immediate benefit is a significant debloating of the float parsing
code by moving the responsibility for keeping track of the number of
characters read to a different module.

by linking shgetc with the stdio buffer logic, counting logic is
defered to buffer refill time, keeping the calls to shgetc fast and
light.

in the future, shgetc will also be useful for integrating the new
float code with scanf, which needs to not only count the characters
consumed, but also limit the number of characters read based on field
width specifiers.

shgetc may also become a useful tool for simplifying the integer
parsing code.
2012-04-10 21:47:37 -04:00
Rich Felker
4fb6aa02c8 unify strtof/strtod/strtold wrappers and fix initial whitespace issue 2012-04-10 20:25:06 -04:00
Rich Felker
415c4cd7fd new floating point parser/converter
this version is intended to be fully conformant to the ISO C, POSIX,
and IEEE standards for conversion of decimal/hex floating point
strings to float, double, and long double (ld64 or ld80 only at
present) values. in particular, all results are intended to be rounded
correctly according to the current rounding mode. further, this
implementation aims to set the floating point underflow, overflow, and
inexact flags to reflect the conversion performed.

a moderate amount of testing has been performed (by nsz and myself)
prior to integration of the code in musl, but it still may have bugs.

so far, only strto(d|ld|f) use the new code. scanf integration will be
done as a separate commit, and i will add implementations of the wide
character functions later.
2012-04-10 11:52:55 -04:00
nsz
37eaec3ad3 math: fix x86 asin accuracy
use (1-x)*(1+x) instead of (1-x*x) in asin.s
the later can be inaccurate with upward rounding when x is close to 1
2012-04-04 17:34:28 +02:00
Rich Felker
4f346b08b3 improve name lookup performance in corner cases
the buffer in getaddrinfo really only matters when /etc/hosts is huge,
but in that case, the huge number of syscalls resulting from a tiny
buffer would seriously impact the performance of every name lookup.

the buffer in __dns.c has also been enlarged a bit so that typical
resolv.conf files will fit fully in the buffer. there's no need to
make it so large as to dominate the syscall overhead for large files,
because resolv.conf should never be large.
2012-04-01 23:22:16 -04:00
nsz
7eabe8e690 math: minor cleanups in ceil and floor 2012-03-29 14:09:57 +02:00
nsz
d79ac8c38f math: remove x86 modf asm
the int part was wrong when -1 < x <= -0 (+0.0 instead of -0.0)
and the size and performace gain of the asm version was negligible
2012-03-29 14:05:16 +02:00
nsz
f6ceccd922 math: rewrite modf.c and clean up modff.c
cleaner implementation with unions and unsigned arithmetic
2012-03-29 14:03:18 +02:00
nsz
9f58d06007 math: fix modfl.c bug
modfl(+-inf) was wrong on ld80 because the explicit msb
was not taken into account during inf vs nan check
2012-03-28 23:51:09 +02:00
nsz
cf682072ce math: fix a regression in powl and do some cleanups
previously a division was accidentally turned into integer div
(w = -i/NXT;) instead of long double div (w = -i; w /= NXT;)
2012-03-27 22:49:37 +02:00
nsz
bbfbc7edaf math: add dummy tgamma and tgammaf implementations 2012-03-27 22:17:36 +02:00
nsz
1b229a2098 math: remove comment about aliasing lgamma as gamma
It is probably not worth supporting gamma.
(it was already deprecated in 4.3BSD)
2012-03-27 22:12:20 +02:00
nsz
ad23771c32 math: fix typo in i386 remquof and remquol asm
(fldl instruction was used instead of flds and fldt)
2012-03-27 22:01:21 +02:00
Rich Felker
a9014ac1b9 Merge remote branch 'nsz/master' 2012-03-25 00:42:51 -04:00
Rich Felker
bff650df9f add strfmon_l variant (still mostly incomplete) 2012-03-25 00:21:20 -04:00
Rich Felker
ad2d2b963a asm for hypot and hypotf
special care is made to avoid any inexact computations when either arg
is zero (in which case the exact absolute value of the other arg
should be returned) and to support the special condition that
hypot(±inf,nan) yields inf.

hypotl is not yet implemented since avoiding overflow is nontrivial.
2012-03-23 01:52:49 -04:00
Rich Felker
a9e85c0a5c make dlerror conform to posix
the error status is required to be sticky after failure of dlopen or
dlsym until cleared by dlerror. applications and especially libraries
should never rely on this since it is not thread-safe and subject to
race conditions, but glib does anyway.
2012-03-23 00:28:20 -04:00
nsz
6d8df2b972 minor rintl.c fix: remove unsupported ldbl format message 2012-03-23 01:26:04 +01:00
nsz
cb8fce4b4f fix tgammal: don't set the signgam global
(tgamma must be thread-safe, signgam is for lgamma* functions)
2012-03-23 01:18:12 +01:00
Rich Felker
13e400b355 add creal/cimag macros in complex.h (and use them in the functions defs) 2012-03-22 15:54:55 -04:00
nsz
a4a0c91275 acos.s fix: use the formula acos(x) = atan2(sqrt(1-x),sqrt(1+x))
the old formula atan2(1,sqrt((1+x)/(1-x))) was faster but
could give nan result at x=1 when the rounding mode is
FE_DOWNWARD (so 1-1 == -0 and 2/-0 == -inf), the new formula
gives -0 at x=+-1 with downward rounding.
2012-03-22 14:54:47 +01:00
Rich Felker
2e0c1fed36 sysconf support for dynamic limits (open files and processes) 2012-03-22 01:00:35 -04:00
Rich Felker
25501c1079 initial, very primitive strfmon 2012-03-21 00:47:37 -04:00
Rich Felker
30df206cb0 x86_64 math asm, long double functions only
this has not been tested heavily, but it's known to at least assemble
and run in basic usage cases. it's nearly identical to the
corresponding i386 code, and thus expected to be just as correct or
just as incorrect.
2012-03-20 23:29:24 -04:00
Rich Felker
58bf74850f Merge remote branch 'nsz/master' 2012-03-20 19:51:11 -04:00
Rich Felker
ad47d45e9d upgrade to latest upstream TRE regex code (0.8.0)
the main practical results of this change are
1. the regex code is no longer subject to LGPL; it's now 2-clause BSD
2. most (all?) popular nonstandard regex extensions are supported

I hesitate to call this a "sync" since both the old and new code are
heavily modified. in one sense, the old code was "more severely"
modified, in that it was actively hostile to non-strictly-conforming
expressions. on the other hand, the new code has eliminated the
useless translation of the entire regex string to wchar_t prior to
compiling, and now only converts multibyte character literals as
needed.

in the future i may use this modified TRE as a basis for writing the
long-planned new regex engine that will avoid multibyte-to-wide
character conversion entirely by compiling multibyte bracket
expressions specific to UTF-8.
2012-03-20 19:44:05 -04:00
nsz
91c28f61f4 nearbyint optimization (only clear inexact when necessary)
old code saved/restored the fenv (the new code is only as slow
as that when inexact is not set before the call, but some other
flag is set and the rounding is inexact, which is rare)

before:
bench_nearbyint_exact              5000000 N        261 ns/op
bench_nearbyint_inexact_set        5000000 N        262 ns/op
bench_nearbyint_inexact_unset      5000000 N        261 ns/op

after:
bench_nearbyint_exact             10000000 N         94.99 ns/op
bench_nearbyint_inexact_set       25000000 N         65.81 ns/op
bench_nearbyint_inexact_unset     10000000 N         94.97 ns/op
2012-03-20 22:49:19 +01:00
nsz
8c6fc860a9 remove a fixme comment 2012-03-20 20:08:35 +01:00
nsz
f1347a3a45 clean up pow.c and powf.c
fix comments about special cases
2012-03-20 20:04:53 +01:00
nsz
615bbd365f clean up powl.c
fix special cases, use multiplication instead of scalbnl
2012-03-20 19:59:50 +01:00
nsz
1e2fea632b fix a cbrtl.c regression and remove x87 precision setting 2012-03-20 15:17:15 +01:00
Rich Felker
baa43bca0a optimize scalbn family
the fscale instruction is slow everywhere, probably because it
involves a costly and unnecessary integer truncation operation that
ends up being a no-op in common usages. instead, construct a floating
point scale value with integer arithmetic and simply multiply by it,
when possible.

for float and double, this is always possible by going to the
next-larger type. we use some cheap but effective saturating
arithmetic tricks to make sure even very large-magnitude exponents
fit. for long double, if the scaling exponent is too large to fit in
the exponent of a long double value, we simply fallback to the
expensive fscale method.

on atom cpu, these changes speed up scalbn by over 30%. (min rdtsc
timing dropped from 110 cycles to 70 cycles.)
2012-03-20 00:51:32 -04:00
Rich Felker
7513d3ecab remquo asm: return quotient mod 8, as intended by the spec
this is a lot more efficient and also what is generally wanted.
perhaps the bit shuffling could be more efficient...
2012-03-19 23:53:52 -04:00
Rich Felker
804fbf0b8c use alternate formula for acos asm to avoid loss of precision 2012-03-19 23:08:49 -04:00
Rich Felker
97721a5508 Merge remote branch 'nsz/master' 2012-03-19 22:07:43 -04:00
Rich Felker
acb744921b fix exp asm
exponents (base 2) near 16383 were broken due to (1) wrong cutoff, and
(2) inability to fit the necessary range of scalings into a long
double value.

as a solution, we fall back to using frndint/fscale for insanely large
exponents, and also have to special-case infinities here to avoid
inf-inf generating nan.

thankfully the costly code never runs in normal usage cases.
2012-03-19 21:55:53 -04:00
nsz
0cbb654791 code cleanup of named constants
zero, one, two, half are replaced by const literals
The policy was to use the f suffix for float consts (1.0f),
but don't use suffix for long double consts (these consts
can be exactly represented as double).
2012-03-19 23:41:19 +01:00
nsz
b03255af77 fix remainder*.c: remove useless long double cast 2012-03-19 23:39:47 +01:00
nsz
4caa17b2a1 don't try to create non-standard denormalization signal
Underflow exception is only raised when the result is
invalid, but fmod is always exact. x87 has a denormalization
exception, but that's nonstandard. And the superflous *1.0
will be optimized away by any compiler that does not honor
signaling nans.
2012-03-19 23:30:45 +01:00
Rich Felker
0108420281 Merge remote branch 'nsz/master' 2012-03-19 18:30:35 -04:00
nsz
75483499da new modff.c code, fix nan handling in modfl 2012-03-19 23:27:45 +01:00
nsz
2786c7d216 use scalbn or *2.0 instead of ldexp, fix fmal
Some code assumed ldexp(x, 1) is faster than 2.0*x,
but ldexp is a wrapper around scalbn which uses
multiplications inside, so this optimization is
wrong.

This commit also fixes fmal which accidentally
used ldexp instead of ldexpl loosing precision.

There are various additional changes from the
work-in-progress const cleanups.
2012-03-19 22:57:58 +01:00
nsz
01fdfd491b fix long double const workaround in cbrtl 2012-03-19 22:49:03 +01:00
nsz
2e8c8fbe7d don't inline __rem_pio2l so the code size is smaller 2012-03-19 19:26:31 +01:00
nsz
c3587effe2 minor fix in __tanl (get sign properly) 2012-03-19 19:14:32 +01:00
Rich Felker
d9c1d72cdc bug fix: wrong opcode for writing long long 2012-03-19 13:58:47 -04:00
nsz
eca1c35e5b remove long double const workarounds
Some long double consts were stored in two doubles as a workaround
for x86_64 and i386 with the following comment:
/* Long double constants are slow on these arches, and broken on i386. */
This is most likely old gcc bug related to the default x87 fpu
precision setting (it's double instead of double extended on BSD).
2012-03-19 18:52:17 +01:00
nsz
9a810cb685 fix erfl wrapper for long double==double case 2012-03-19 18:06:06 +01:00
Rich Felker
b04b588791 asm for log1p 2012-03-19 10:59:41 -04:00
Rich Felker
9d82a15e15 asm for log2 2012-03-19 10:43:28 -04:00
Rich Felker
27deb53889 asm for remquo
this could perhaps use some additional testing for corner cases, but
it seems to be correct.
2012-03-19 09:42:51 -04:00
Rich Felker
02db27d9de optimize exponential asm for i386
up to 30% faster exp2 by avoiding slow frndint and fscale functions.
expm1 also takes a much more direct path for small arguments (the
expected usage case).
2012-03-19 09:00:30 -04:00
Rich Felker
da7458a602 Merge remote branch 'nsz/master' 2012-03-19 06:28:22 -04:00
Rich Felker
be5b01f855 fix broken modf family functions 2012-03-19 06:22:54 -04:00
Rich Felker
1bf4dad327 asm for modf functions 2012-03-19 05:56:41 -04:00
nsz
8051e08e10 simplify scalbn*.c implementations
The old scalbn.c was wrong and slow, the new one is just slow.
(scalbn(0x1p+1023,-2097) should give 0x1p-1074, but the old code gave 0)
2012-03-19 10:54:07 +01:00
nsz
f767aba8af Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 10:50:42 +01:00
Rich Felker
0b70a1e9a9 asm for floor/ceil/trunc 2012-03-19 05:42:04 -04:00
nsz
9322344fa4 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 10:20:24 +01:00
Rich Felker
58ff9e8eaf asm for scalbn family
unlike some implementations, these functions perform the equivalent of
gcc's -ffloat-store on the result before returning. this is necessary
to raise underflow/overflow/inexact exceptions, perform the correct
rounding with denormals, etc.
2012-03-19 05:15:30 -04:00
Rich Felker
bc33e61704 asm for inverse trig functions
unlike trig functions, these are easy to do in asm because they do not
involve (arbitrary-precision) argument reduction. fpatan automatically
takes care of domain issues, and in asin and acos, fsqrt takes care of
them for us.
2012-03-19 04:56:07 -04:00
nsz
0627e58af8 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 08:01:21 +01:00
Rich Felker
495a52ae7b asm for log functions 2012-03-18 23:50:54 -04:00
Rich Felker
aa1b4dff45 fix broken exponential asm
infinities were getting converted into nans. the new code simply tests
for infinity and replaces it with a large magnitude value of the same
sign.

also, the fcomi instruction is apparently not part of the i387
instruction set, so avoid using it.
2012-03-18 23:17:28 -04:00
Rich Felker
37eb14dd2b asm for lrint family on i386 2012-03-18 22:05:20 -04:00
nsz
dbdec9722e Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 02:55:31 +01:00
Rich Felker
6f26cf3dac asm exponential functions for i386 2012-03-18 21:43:43 -04:00
nsz
682e471400 remove unnecessary TODO comments from fma.c 2012-03-19 02:05:57 +01:00
nsz
d09a83f613 fmal bug fix: nan input should not raise exception 2012-03-19 00:59:16 +01:00
nsz
b1cbd70743 add fma implementation for x86
correctly rounded double precision fma using extended
precision arithmetics for ld80 systems (x87)
2012-03-19 00:36:55 +01:00
Rich Felker
b935147761 assembly optimizations for fmod/remainder functions 2012-03-18 17:09:34 -04:00
Rich Felker
8d9e948652 asm versions of some simple math functions for i386 and x86_64
these are functions that have direct fpu approaches to implementation
without problematic exception or rounding issues. x86_64 lacks
float/double versions because i'm unfamiliar with the necessary sse
code for performing these operations.
2012-03-18 16:43:54 -04:00
nsz
afad262440 simplify lround and llround functions
Simple wrappers around round is enough because
spurious inexact exception is allowed.
2012-03-18 20:52:33 +01:00
nsz
65db00983f make lrint and llrint functions work without fenv support 2012-03-18 20:40:43 +01:00
nsz
9b6899f2c5 faster lrint and llrint functions
A faster workaround for spurious inexact exceptions
when the result cannot be represented. The old code
actually could be wrong, because gcc reordered the
integer conversion and the exception check.
2012-03-18 19:27:39 +01:00
Rich Felker
9e2a895aaa fix loads of missing const in new libm, and some global vars (?!) in powl 2012-03-18 01:58:28 -04:00
Rich Felker
b60053e762 try fixing/optimizing x86_64 fenv exception code
untested; may need followup-fixes.
2012-03-17 20:10:02 -04:00
Rich Felker
316e024f63 optimize x86 feclearexcept
if all exception flags will be cleared, we can avoid the expensive
store/reload of the environment and just use the fnclex instruction.
2012-03-17 19:29:00 -04:00
Rich Felker
9cb6878e74 fix x86_64 fe[gs]etround, analogous to nsz's x86 changes 2012-03-17 18:02:20 -04:00
Rich Felker
d5e576c752 minor 387 fenv optimizations 2012-03-17 17:49:10 -04:00
nsz
88cfaf8a14 fix i386 fegetround and make fesetround faster
Note that the new fesetround has slightly different semantics:

Storing the floating-point environment with fnstenv makes the
next fldenv (or fldcw) "non-signaling", so unmasked and pending
exceptions does not invoke the exception handler.
(These are rare since exceptions are handled immediately and by
default all exceptions are masked anyway. But if one manually
unmasks an exception in the control word then either sets the
corresponding exception flag in the status word or the execution
of an exception raising floating-point operation gets interrupted
then it may happen).
So the old implementation did not trap in some rare cases
where the new implementation traps.

However POSIX does not specify anything like the x87 exception
handling traps and the fnstenv/fldenv pair is significantly slower
than the fnstcw/fldcw pair (new code is about 5x faster here and
it's dominated by the function call overhead).
2012-03-17 13:46:15 +01:00
Rich Felker
d3fc724759 one more fenv availability issue: lround 2012-03-17 00:02:36 -04:00
Rich Felker
2e77dc13f8 make fma and lrint functions build without full fenv support
this is necessary to support archs where fenv is incomplete or
unavailable (presently arm). fma, fmal, and the lrint family should
work perfectly fine with this change; fmaf is slightly broken with
respect to rounding as it depends on non-default rounding modes to do
its work.
2012-03-16 23:58:49 -04:00
Rich Felker
8c071f872b other side of the signgam namespace fix: use the internal name 2012-03-16 21:20:53 -04:00
Rich Felker
1a3dce4184 make signgam a weak alias for an internal symbol
otherwise, the standard C lgamma function will clobber a symbol in the
namespace reserved for the application.
2012-03-16 21:18:48 -04:00
Rich Felker
de7db6e927 fix namespace issues for lgamma, etc.
standard functions cannot depend on nonstandard symbols
2012-03-16 21:16:32 -04:00
Rich Felker
93a50a26cd Merge remote branch 'nsz/master' 2012-03-16 21:01:34 -04:00
Rich Felker
2cbb24bba3 remove junk sincos implementations in preparation to merge nsz's real ones 2012-03-16 20:53:05 -04:00
Rich Felker
9d507419db remove special nan handling from x86 sqrt asm
a double precision nan, when converted to extended (80-bit) precision,
will never end in 0x400, since the corresponding bits do not exist in
the original double precision value. thus there's no need to waste
time and code size on this check.
2012-03-15 19:56:36 -04:00
Rich Felker
1295848efb simplify nan check in sqrt (x86 asm); result of sqrt is never negative 2012-03-15 12:16:51 -04:00
nsz
40305f74bd in math.h make lgamma_r and non-double bessel _GNU_SOURCE only
long double and float bessel functions are no longer xsi extensions
2012-03-15 09:29:53 +01:00
nsz
0144b45b71 efficient sincos based on sin and cos 2012-03-15 08:17:28 +01:00
Rich Felker
5657cc58e5 implement sincosf and sincosl functions; add prototypes
presumably broken gcc may generate calls to these, and it's said that
ffmpeg makes use of sincosf.
2012-03-15 02:38:42 -04:00
Rich Felker
46702f68f9 avoid changing NaNs in sqrt (x86 asm) to satisfy c99 f.9 recommendation 2012-03-15 01:55:54 -04:00
Rich Felker
809556e60a correctly rounded sqrt() asm for x86 (i387)
the fsqrt opcode is correctly rounded, but only in the fpu's selected
precision mode, which is 80-bit extended precision. to get a correctly
rounded double precision output, we check for the only corner cases
where two-step rounding could give different results than one-step
(extended-precision mantissa ending in 0x400) and adjust the mantissa
slightly in the opposite direction of the rounding which the fpu
already did (reported in the c1 flag of the fpu status word).

this should have near-zero cost in the non-corner cases and at worst
very low cost.

note that in order for sqrt() to get used when compiling with gcc, the
broken, non-conformant builtin sqrt must be disabled.
2012-03-15 01:29:03 -04:00
Rich Felker
e0a54e6725 correct rounding for i387 sqrtf function 2012-03-13 22:15:52 -04:00
nsz
32ca5ef3ff math cleanup: use 1.0f instead of 1.0F 2012-03-13 21:11:46 +01:00
nsz
8d0a6f7a1c math cleanup: use 1.0f instead of (float)1.0 2012-03-13 20:24:23 +01:00
nsz
9560b6b152 remove libm.h includes when math.h and float.h are enough 2012-03-13 19:51:14 +01:00
Rich Felker
291f839a44 fix scanf handling of "0" (followed by immediate EOF) with "%x"
other cases with %x were probably broken too.

I would actually like to go ahead and replace this code in scanf with
calls to the new __intparse framework, but for now this calls for a
quick and unobtrusive fix without the risk of breaking other things.
2012-03-13 12:37:51 -04:00
nsz
df8b3e5aef clean up __expo2.c, use a slightly better k constant 2012-03-13 16:38:22 +01:00
Rich Felker
bf9d9dcaa6 implement nan, nanf, nanl 2012-03-13 01:55:25 -04:00
Rich Felker
b69f695ace first commit of the new libm!
thanks to the hard work of Szabolcs Nagy (nsz), identifying the best
(from correctness and license standpoint) implementations from freebsd
and openbsd and cleaning them up! musl should now fully support c99
float and long double math functions, and has near-complete complex
math support. tgmath should also work (fully on gcc-compatible
compilers, and mostly on any c99 compiler).

based largely on commit 0376d44a890fea261506f1fc63833e7a686dca19 from
nsz's libm git repo, with some additions (dummy versions of a few
missing long double complex functions, etc.) by me.

various cleanups still need to be made, including re-adding (if
they're correct) some asm functions that were dropped.
2012-03-13 01:17:53 -04:00
Rich Felker
b4a07bb469 fix obscure bug in strtoull reading the highest 16 possible values 2012-03-02 12:48:17 -05:00
Rich Felker
6cf51fe51a remove debug cruft that was left in getdate 2012-03-02 00:24:49 -05:00
Rich Felker
b93b7382d6 first try at implementing getdate function 2012-03-02 00:24:17 -05:00
Rich Felker
536db2b5ac fix bugs in strptime handling of string day/month names, literals 2012-03-02 00:23:43 -05:00
Rich Felker
ca19774c91 implement a64l and l64a (legacy xsi stuff) 2012-03-01 23:43:31 -05:00
Rich Felker
e0614f7cd4 add all missing wchar functions except floating point parsers
these are mostly untested and adapted directly from corresponding byte
string functions and similar.
2012-03-01 23:24:45 -05:00
Rich Felker
899b13cae7 support null buffer argument to getcwd, auto-allocating behavior
this is a popular extension some programs depend on, and by using a
temporary buffer and strdup rather than malloc prior to the syscall,
i've avoided the dependency on free and thus minimized the bloat cost
of supporting this feature.
2012-03-01 22:08:05 -05:00
Rich Felker
95b930ad26 implement wcsftime function 2012-02-28 15:59:01 -05:00
Rich Felker
e3234d0109 fix pthread_cleanup_pop(1) crash in non-thread-capable, static-linked programs 2012-02-28 10:13:35 -05:00
Rich Felker
dac084a4c5 work around "signal loses thread pointer" issue with "approach 2"
this was discussed on the mailing list and no consensus on the
preferred solution was reached, so in anticipation of a release, i'm
just committing a minimally-invasive solution that avoids the problem
by ensuring that multi-threaded-capable programs will always have
initialized the thread pointer before any signal handler can run.

in the long term we may switch to initializing the thread pointer at
program start time whenever the program has the potential to access
any per-thread data.
2012-02-27 18:51:02 -05:00
Rich Felker
78e79d9d50 new attempt at working around the gcc 3 visibility bug
since gcc is failing to generate the necessary ".hidden" directive in
the output asm, generate it explicitly with an __asm__ statement...
2012-02-24 20:07:21 -05:00
Rich Felker
7fa29920ed remove useless attribute visibility from definitions
this was a failed attempt at working around the gcc 3 visibility bug
affecting x86_64. subsequent patch will address it with an ugly but
working hack.
2012-02-24 20:02:42 -05:00
Rich Felker
bae2e52bfd cleanup and work around visibility bug in gcc 3 that affects x86_64
in gcc 3, the visibility attribute must be placed on both the
declaration and on the definition. if it's omitted from the
definition, the compiler fails to emit the ".hidden" directive in the
assembly, and the linker will either generate textrels (if supported,
such as on i386) or refuse to link (on targets where certain types of
textrels are forbidden or impossible without further assumptions about
memory layout, such as on x86_64).

this patch also unifies the decision about when to use visibility into
libc.h and makes the visibility in the utf-8 state machine tables
based on libc.h rather than a duplicate test.
2012-02-23 21:24:56 -05:00
Rich Felker
00b883a955 fix (hopefully) PTRACE_TRACEME (command 0) argument handling 2012-02-23 13:08:47 -05:00
Rich Felker
56ddcc7208 fix for previous incorrect fix of cancellation in dns lookups
uninitialized file descriptor was being closed on return, causing
stdin to be closed in many cases.
2012-02-23 13:07:20 -05:00
Rich Felker
f96eb335e1 fix get_current_dir_name behavior 2012-02-17 23:56:28 -05:00
Rich Felker
1611ab0d9b add get_current_dir_name function 2012-02-17 23:10:00 -05:00
Rich Felker
88d84b7cc8 fix default nameserver when resolv.conf doesn't exist 2012-02-11 00:06:32 -05:00
Rich Felker
f42bad9ccb fix illegal goto out of cleanup context in dns lookups 2012-02-11 00:05:58 -05:00
Rich Felker
2230218c28 small fix for new pthread cleanup stuff
even if pthread_create/exit code is not linked, run flag needs to be
checked and cleanup function potentially run on pop. thus, move the
code to the module that's always linked when pthread_cleanup_push/pop
is used.
2012-02-09 21:24:56 -05:00
Rich Felker
afc35d5efd replace bad cancellation cleanup abi with a sane one
the old abi was intended to duplicate glibc's abi at the expense of
being ugly and slow, but it turns out glib was not even using that abi
except on non-gcc-compatible compilers (which it doesn't even support)
and was instead using an exceptions-in-c/unwind-based approach whose
abi we could not duplicate anyway without nasty dwarf2/unwind
integration.

the new abi is copied from a very old glibc abi, which seems to still
be supported/present in current glibc. it avoids all unwinding,
whether by sjlj or exceptions, and merely maintains a linked list of
cleanup functions to be called from the context of pthread_exit. i've
made some care to ensure that longjmp out of a cleanup function should
work, even though it is not required to.

this change breaks abi compatibility with programs which were using
pthread cancellation, which is unfortunate, but that's why i'm making
the change now rather than later. considering that most pthread
features have not been usable until recently anyway, i don't see it as
a major issue at this point.
2012-02-09 02:33:08 -05:00