summaryrefslogtreecommitdiff
path: root/src/math/i386
AgeCommit message (Collapse)AuthorLines
2020-03-24math: move x87-family fmod functions to C with inline asmAlexander Monakov-33/+29
2020-03-24math: move x87-family remainder functions to C with inline asmAlexander Monakov-39/+33
2020-03-24math: move x87-family rint functions to C with inline asmAlexander Monakov-18/+21
2020-03-24math: move x87-family lrint functions to C with inline asmAlexander Monakov-46/+48
2020-03-24math: move i386 sqrt to C with inline asmAlexander Monakov-21/+15
2020-03-24math: move i386 sqrtf to C with inline asmAlexander Monakov-7/+12
2020-03-24math: move trivial x86-family sqrt functions to C with inline asmAlexander Monakov-5/+7
2020-03-24math: move x87-family fabs functions to C with inline asmAlexander Monakov-18/+21
2020-02-06remove i386 asm for single and double precision exp-family functionsRich Felker-62/+3
these did not truncate excess precision in the return value. fixing them looks like considerable work, and the current C code seems to outperform them significantly anyway. long double functions are left in place because they are not subject to excess precision issues and probably better than the C code.
2020-02-06rename i386 exp.s to exp_ld.sRich Felker-0/+1
this commit is for the sake of reviewable history.
2020-02-06fix excess precision in return value of i386 log-family functionsRich Felker-0/+20
2020-02-06fix excess precision in return value of i386 acos[f] and asin[f]Rich Felker-42/+75
analogous to commit 1c9afd69051a64cf085c6fb3674a444ff9a43857 for atan[2][f].
2020-02-06fix excess precision in return value of i386 atan[2][f]Rich Felker-2/+8
for functions implemented in C, this is a requirement of C11 (F.6); strictly speaking that text does not apply to standard library functions, but it seems to be intended to apply to them, and C2x is expected to make it a requirement. failure to drop excess precision is particularly bad for inverse trig functions, where a value with excess precision can be outside the range of the function (entire range, or range for a particular subdomain), breaking reasonable invariants a caller may expect.
2019-08-05fix build regression in i386 asm for atan2, atan2fRich Felker-2/+2
commit f3ed8bfe8a82af1870ddc8696ed4cc1d5aa6b441 inadvertently removed labels that were still needed.
2019-08-05fix x87 stack imbalance in corner cases of i386 math asmRich Felker-44/+14
commit 31c5fb80b9eae86f801be4f46025bc6532a554c5 introduced underflow code paths for the i386 math asm, along with checks on the fpu status word to skip the underflow-generation instructions if the underflow flag was already raised. unfortunately, at least one such path, in log1p, returned with 2 items on the x87 stack rather than just 1 item for the return value. this is a violation of the ABI's calling convention, and could cause subsequent floating point code to produce NANs due to x87 stack overflow. if floating point results are used in flow control, this can lead to runaway wrong code execution. rather than reviewing each "underflow already raised" code path for correctness, remove them all. they're likely slower than just performing the underflow code unconditionally, and significantly more complex. all of this code should be ripped out and replaced by C source files with inline asm. doing so would preclude this kind of error by having the compiler perform all x87 stack register allocation and stack manipulation, and would produce comparable or better code. however such a change is a much larger project.
2015-04-18remove the last of possible-textrels from i386 asmRich Felker-1/+5
none of these are actual textrels because of ld-time binding performed by -Bsymbolic-functions, but I'm changing them with the goal of making ld-time binding purely an optimization rather than relying on it for semantic purposes. in the case of memmove's call to memcpy, making it explicit that the memmove asm is assuming the forward-copying behavior of the memcpy asm is desirable anyway; in case memcpy is ever changed, the semantic mismatch would be apparent while editing memmcpy.s.
2014-11-05math: use fnstsw consistently instead of fstsw in x87 asmSzabolcs Nagy-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.
2014-01-08math: add drem and dremf weak aliases to i386 remainder asmSzabolcs Nagy-0/+6
weak_alias was only in the c code, so drem was missing on platforms where remainder is implemented in asm.
2013-09-05math: fix exp2l asm on x86 (raise underflow correctly)Szabolcs Nagy-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
2013-08-15math: fix i386 atan2.s to raise underflow for subnormal resultsSzabolcs Nagy-2/+24
2013-08-15math: fix x86 asin, atan, exp, log1p to raise underflowSzabolcs Nagy-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
2013-08-15math: fix x86 expl.s to raise underflow and clean up special case handlingSzabolcs Nagy-23/+16
2012-12-16math: x86_64 version of expl, fixed some comments in the i386 versionSzabolcs Nagy-4/+4
2012-12-14math: fix i386/expl.s with more precise x*log2eSzabolcs Nagy-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
2012-12-12math: add empty __invtrigl.s to i386 and x86_64Szabolcs Nagy-0/+0
__invtrigl is not needed when acosl, asinl, atanl have asm implementations
2012-08-08math: fix exp.s on i386 and x86_64 so the exception flags are correctnsz-21/+18
exp(inf), exp(-inf), exp(nan) used to raise wrong flags
2012-05-07some assemblers don't like fistpq; use the alt. mnemonic fistpllRich Felker-3/+3
2012-05-05math: change the formula used for acos.snsz-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)
2012-04-04math: fix x86 asin accuracynsz-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
2012-03-29math: remove x86 modf asmnsz-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
2012-03-27math: fix typo in i386 remquof and remquol asmnsz-5/+5
(fldl instruction was used instead of flds and fldt)
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