summaryrefslogtreecommitdiff
path: root/src/math/i386
AgeCommit message (Collapse)AuthorLines
2012-03-23asm for hypot and hypotfRich Felker-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.
2012-03-22acos.s fix: use the formula acos(x) = atan2(sqrt(1-x),sqrt(1+x))nsz-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.
2012-03-20optimize scalbn familyRich Felker-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.)
2012-03-19remquo asm: return quotient mod 8, as intended by the specRich Felker-17/+26
this is a lot more efficient and also what is generally wanted. perhaps the bit shuffling could be more efficient...
2012-03-19use alternate formula for acos asm to avoid loss of precisionRich Felker-3/+11
2012-03-19fix exp asmRich Felker-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.
2012-03-19bug fix: wrong opcode for writing long longRich Felker-2/+2
2012-03-19asm for log1pRich Felker-0/+45
2012-03-19asm for log2Rich Felker-0/+21
2012-03-19asm for remquoRich Felker-0/+43
this could perhaps use some additional testing for corner cases, but it seems to be correct.
2012-03-19optimize exponential asm for i386Rich Felker-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).
2012-03-19fix broken modf family functionsRich Felker-27/+66
2012-03-19asm for modf functionsRich Felker-0/+45
2012-03-19asm for floor/ceil/truncRich Felker-0/+75
2012-03-19asm for scalbn familyRich Felker-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.
2012-03-19asm for inverse trig functionsRich Felker-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.
2012-03-18asm for log functionsRich Felker-0/+42
2012-03-18fix broken exponential asmRich Felker-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.
2012-03-18asm for lrint family on i386Rich Felker-0/+46
2012-03-18asm exponential functions for i386Rich Felker-0/+89
2012-03-18assembly optimizations for fmod/remainder functionsRich Felker-0/+66
2012-03-18asm versions of some simple math functions for i386 and x86_64Rich Felker-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.
2012-03-15remove special nan handling from x86 sqrt asmRich Felker-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.
2012-03-15simplify nan check in sqrt (x86 asm); result of sqrt is never negativeRich Felker-4/+3
2012-03-15avoid changing NaNs in sqrt (x86 asm) to satisfy c99 f.9 recommendationRich Felker-0/+4
2012-03-15correctly rounded sqrt() asm for x86 (i387)Rich Felker-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.
2012-03-13correct rounding for i387 sqrtf functionRich Felker-0/+2
2012-03-13first commit of the new libm!Rich Felker-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.
2011-06-26use .type directives for math asm (needed for dynamic linking to work)Rich Felker-0/+26
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+163