about summary refs log tree commit diff
path: root/src/math/i386
Commit message (Collapse)AuthorAgeFilesLines
* math: use fnstsw consistently instead of fstsw in x87 asmSzabolcs Nagy2014-11-057-7/+7
| | | | | | fnstsw does not wait for pending unmasked x87 floating-point exceptions and it is the same as fstsw when all exceptions are masked which is the only environment libc supports.
* math: add drem and dremf weak aliases to i386 remainder asmSzabolcs Nagy2014-01-082-0/+6
| | | | | weak_alias was only in the c code, so drem was missing on platforms where remainder is implemented in asm.
* math: fix exp2l asm on x86 (raise underflow correctly)Szabolcs Nagy2013-09-051-32/+38
| | | | | | | | | | | | | | | | there were two problems: * omitted underflow on subnormal results: exp2l(-16383.5) was calculated as sqrt(2)*2^-16384, the last bits of sqrt(2) are zero so the down scaling does not underflow eventhough the result is in subnormal range * spurious underflow for subnormal inputs: exp2l(0x1p-16400) was evaluated as f2xm1(x)+1 and f2xm1 raised underflow (because inexact subnormal result) the first issue is fixed by raising underflow manually if x is in (-32768,-16382] and not integer (x-0x1p63+0x1p63 != x) the second issue is fixed by treating x in (-0x1p64,0x1p64) specially for these fixes the special case handling was completely rewritten
* math: fix i386 atan2.s to raise underflow for subnormal resultsSzabolcs Nagy2013-08-152-2/+24
|
* math: fix x86 asin, atan, exp, log1p to raise underflowSzabolcs Nagy2013-08-156-3/+98
| | | | | | underflow is raised by an inexact subnormal float store, since subnormal operations are slow, check the underflow flag and skip the store if it's already raised
* math: fix x86 expl.s to raise underflow and clean up special case handlingSzabolcs Nagy2013-08-151-23/+16
|
* math: x86_64 version of expl, fixed some comments in the i386 versionSzabolcs Nagy2012-12-163-4/+4
|
* math: fix i386/expl.s with more precise x*log2eSzabolcs Nagy2012-12-142-7/+107
| | | | | | | | | with naive exp2l(x*log2e) the last 12bits of the result was incorrect for x with large absolute value with hi + lo = x*log2e is caluclated to 128 bits precision and then expl(x) = exp2l(hi) + exp2l(hi) * f2xm1(lo) this gives <1.5ulp measured error everywhere in nearest rounding mode
* math: add empty __invtrigl.s to i386 and x86_64Szabolcs Nagy2012-12-121-0/+0
| | | | | __invtrigl is not needed when acosl, asinl, atanl have asm implementations
* math: fix exp.s on i386 and x86_64 so the exception flags are correctnsz2012-08-081-21/+18
| | | | exp(inf), exp(-inf), exp(nan) used to raise wrong flags
* some assemblers don't like fistpq; use the alt. mnemonic fistpllRich Felker2012-05-073-3/+3
|
* math: change the formula used for acos.snsz2012-05-051-10/+8
| | | | | | | | | | old: 2*atan2(sqrt(1-x),sqrt(1+x)) new: atan2(fabs(sqrt((1-x)*(1+x))),x) improvements: * all edge cases are fixed (sign of zero in downward rounding) * a bit faster (here a single call is about 131ns vs 162ns) * a bit more precise (at most 1ulp error on 1M uniform random samples in [0,1), the old formula gave some 2ulp errors as well)
* math: fix x86 asin accuracynsz2012-04-041-2/+3
| | | | | 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
* math: remove x86 modf asmnsz2012-03-293-84/+0
| | | | | 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
* math: fix typo in i386 remquof and remquol asmnsz2012-03-271-5/+5
| | | | (fldl instruction was used instead of flds and fldt)
* asm for hypot and hypotfRich Felker2012-03-232-0/+87
| | | | | | | | | 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.
* acos.s fix: use the formula acos(x) = atan2(sqrt(1-x),sqrt(1+x))nsz2012-03-221-3/+1
| | | | | | | 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.
* optimize scalbn familyRich Felker2012-03-203-7/+46
| | | | | | | | | | | | | | | | | | 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.)
* remquo asm: return quotient mod 8, as intended by the specRich Felker2012-03-191-17/+26
| | | | | this is a lot more efficient and also what is generally wanted. perhaps the bit shuffling could be more efficient...
* use alternate formula for acos asm to avoid loss of precisionRich Felker2012-03-191-3/+11
|
* fix exp asmRich Felker2012-03-191-23/+22
| | | | | | | | | | | | 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.
* bug fix: wrong opcode for writing long longRich Felker2012-03-192-2/+2
|
* asm for log1pRich Felker2012-03-193-0/+45
|
* asm for log2Rich Felker2012-03-193-0/+21
|
* asm for remquoRich Felker2012-03-193-0/+43
| | | | | this could perhaps use some additional testing for corner cases, but it seems to be correct.
* optimize exponential asm for i386Rich Felker2012-03-192-58/+77
| | | | | | 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).
* fix broken modf family functionsRich Felker2012-03-193-27/+66
|
* asm for modf functionsRich Felker2012-03-193-0/+45
|
* asm for floor/ceil/truncRich Felker2012-03-199-0/+75
|
* asm for scalbn familyRich Felker2012-03-199-0/+64
| | | | | | | 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.
* asm for inverse trig functionsRich Felker2012-03-1912-0/+93
| | | | | | | 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.
* asm for log functionsRich Felker2012-03-186-0/+42
|
* fix broken exponential asmRich Felker2012-03-182-1/+21
| | | | | | | | | 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.
* asm for lrint family on i386Rich Felker2012-03-186-0/+46
|
* asm exponential functions for i386Rich Felker2012-03-189-0/+89
|
* assembly optimizations for fmod/remainder functionsRich Felker2012-03-186-0/+66
|
* asm versions of some simple math functions for i386 and x86_64Rich Felker2012-03-186-0/+36
| | | | | | | 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.
* remove special nan handling from x86 sqrt asmRich Felker2012-03-151-3/+0
| | | | | | | 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.
* simplify nan check in sqrt (x86 asm); result of sqrt is never negativeRich Felker2012-03-151-4/+3
|
* avoid changing NaNs in sqrt (x86 asm) to satisfy c99 f.9 recommendationRich Felker2012-03-151-0/+4
|
* correctly rounded sqrt() asm for x86 (i387)Rich Felker2012-03-151-0/+16
| | | | | | | | | | | | | | | | 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.
* correct rounding for i387 sqrtf functionRich Felker2012-03-131-0/+2
|
* first commit of the new libm!Rich Felker2012-03-1325-179/+5
| | | | | | | | | | | | | | | | 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.
* use .type directives for math asm (needed for dynamic linking to work)Rich Felker2011-06-2615-0/+26
|
* initial check-in, version 0.5.0 v0.5.0Rich Felker2011-02-1224-0/+163