Commit Graph
100 Commits
Author SHA1 Message Date
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 df82f8f2dc update COPYRIGHT status of TRE regex code 2012-03-24 17:46:42 -04:00
Rich Felker db0da51b5c update README to remove information no longer relevant as of 0.8.7 2012-03-24 17:43:07 -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
Rich Felker 494ba80e9a simplify creal and cimag macros 2012-03-22 20:00:58 -04: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
Rich Felker 132f0a0083 tgmath.h: suppress any existing macro definitions before defining macros
this is necessary so that we can freely add macro versions of some of
the math/complex functions without worrying about breaking tgmath.
2012-03-22 15:36:56 -04:00
Rich Felker 2e0c1fed36 sysconf support for dynamic limits (open files and processes) 2012-03-22 01:00:35 -04:00
Rich Felker 47db8903f6 fix DECIMAL_DIG definitions
DECIMAL_DIG is not the same as LDBL_DIG

type_DIG is the maximimum number of decimal digits that can survive a
round trip from decimal to type and back to decimal.

DECIMAL_DIG is the minimum number of decimal digits required in order
for any floating point type to survive the round trip to decimal and
back, and it is generally larger than LDBL_DIG. since the exact
formula is non-trivial, and defining it larger than necessary may be
legal but wasteful, just define the right value in bits/float.h.
2012-03-21 12:42:48 -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 80949ccdc6 limits.h: support gcc's -funsigned-char
some software apparently uses this and breaks with musl due to
mismatching definitions...
2012-03-20 21:10:06 -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
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
Rich Felker 0108420281 Merge remote branch 'nsz/master' 2012-03-19 18:30:35 -04:00
Rich Felker d9c1d72cdc bug fix: wrong opcode for writing long long 2012-03-19 13:58:47 -04: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
Rich Felker 0b70a1e9a9 asm for floor/ceil/trunc 2012-03-19 05:42:04 -04: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
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
Rich Felker 6f26cf3dac asm exponential functions for i386 2012-03-18 21:43:43 -04: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
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 8e092217dd move nonstandard gamma() etc. to _GNU_SOURCE only
it's not even provided in the library at the moment, but could easily
be provided with weak aliases if desired.
2012-03-17 21:48:48 -04:00
Rich Felker 65db6bf5ea c++ seems to want some casts in the float representation-access macros 2012-03-17 21:40:10 -04:00
Rich Felker da0acc32ef release notes for 0.8.7 2012-03-17 20:35:25 -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
Rich Felker 0b337e04aa Merge remote branch 'nsz/master' 2012-03-17 17:34:30 -04:00
Rich Felker 523a3ab1a2 don't fail on inability to install dynamic linker (e.g. if not root) 2012-03-17 00:48:55 -04: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 a43c3a337f revert COPYRIGHT file changes in preparation to merge nsz's math branch 2012-03-16 20:52:00 -04:00
Rich Felker 6f21da618f update copyright status (math library and new year) 2012-03-16 19:18:00 -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
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
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
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 d46cf2e14c add .gitignore file
I've had this around for a long time but somehow it never got
committed.
2012-03-09 03:39:28 -05:00
Rich Felker 405ce58dcf fix nan/infinity macros in math.h, etc.
the previous version not only failed to work in c++, but also failed
to produce constant expressions, making the macros useless as
initializers for objects of static storage duration.

gcc 3.3 and later have builtins for these, which sadly seem to be the
most "portable" solution. the alternative definitions produce
exceptions (for NAN) and compiler warnings (for INFINITY) on newer
versions of gcc.
2012-03-02 22:35:37 -05: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 9fcecd7b34 typo in math.h c version check 2012-03-02 11:38:39 -05:00
Rich Felker db3e78cee5 make math.h compatibe with c89 2012-03-02 00:36:26 -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 051175d4fe add memory.h, bogus legacy alias for string.h 2012-03-01 01:34:58 -05:00
Rich Felker 15d143b547 search internal headers first
this is necessitated by the ugly <syscall.h> just added
2012-03-01 00:21:20 -05:00
Rich Felker d36751943a use c++-friendly initializers for pthread initializer definitions
these will also avoid obnoxious warnings with gcc -Wbraces.
2012-02-29 22:55:08 -05:00
Rich Felker 4ce6766a32 add <syscall.h> as an alias for <sys/syscall.h>
apparently some broken stuff (libstdc++) needs this.
2012-02-29 22:36:06 -05:00
Rich Felker 95b930ad26 implement wcsftime function 2012-02-28 15:59:01 -05:00
Rich Felker b1a8e0d454 release notes for 0.8.6 2012-02-28 11:56:13 -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 aab33ec0a3 update release notes for 0.8.5 2012-02-27 20:12:06 -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 834255a3ff use __attribute__((const)) on arm __pthread_self function 2012-02-25 02:52:18 -05:00
Rich Felker 06aec8d715 replace prototype for basename in string.h with non-prototype declaration
GNU programs may expect the GNU version of basename, which has a
different prototype (argument is const-qualified) and prototype it
themselves too. of course if they're expecting the GNU behavior for
the function, they'll still run into problems, but at least this
eliminates some compile-time failures.
2012-02-24 23:23:47 -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 61c2cf877b remove -std=gnu99 from musl-gcc wrapper
while probably desirable, changing the default language variant is
outside the scope of the wrapper's responsibility.
2012-02-17 23:51:23 -05:00
Rich Felker 3c870263c5 two fixes for "make install" handling of shared libs
1. don't try to install (and thus build) shared libs when they were
disabled in config.mak

2. ensure that the path for the dynamic linker exists before
attempting to install it.
2012-02-17 23:17:48 -05:00
Rich Felker 1611ab0d9b add get_current_dir_name function 2012-02-17 23:10:00 -05:00
Rich Felker 414a4cdebc add float_t and double_t to math.h 2012-02-15 21:47:55 -05:00
Rich Felker 88d84b7cc8 fix default nameserver when resolv.conf doesn't exist 2012-02-11 00:06:32 -05:00