Commit Graph

946 Commits

Author SHA1 Message Date
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
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 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
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
nsz 03c52e137a Merge branch 'master' of git://git.etalabs.net/musl 2012-03-20 10:25:02 +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
nsz c879a9592f Merge branch 'master' of git://git.etalabs.net/musl 2012-03-20 04:09:14 +01:00
Rich Felker 804fbf0b8c use alternate formula for acos asm to avoid loss of precision 2012-03-19 23:08:49 -04:00
nsz 0b0735af45 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-20 03:13:26 +01: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 634c3a6302 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 23:55:06 +01: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