1651 Commits

Author SHA1 Message Date
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