1. 05 9月, 2013 15 次提交
    • S
    • S
      math: remove *_WORD64 macros from libm.h · 63b9cc77
      Szabolcs Nagy 提交于
      only fma used these macros and the explicit union is clearer
      63b9cc77
    • S
      math: long double fix (use ldshape union) · aa0c4a20
      Szabolcs Nagy 提交于
      * use new ldshape union consistently
      * add ld128 support to frexpl
      * simplify sqrtl comment (ld64 is not just arm)
      aa0c4a20
    • S
      math: use float_t and double_t in scalbnf and scalbn · 2eaed464
      Szabolcs Nagy 提交于
      remove STRICT_ASSIGN (c99 semantics is assumed) and use the conventional
      union to prepare the scaling factor (so libm.h is no longer needed)
      2eaed464
    • S
      math: fix remaining old long double code (erfl, fmal, lgammal, scalbnl) · 34660d73
      Szabolcs Nagy 提交于
      in lgammal don't handle 1 and 2 specially, in fma use the new ldshape
      union instead of ld80 one.
      34660d73
    • S
      math: cbrt cleanup and long double fix · 535104ab
      Szabolcs Nagy 提交于
      * use float_t and double_t
      * cleanup subnormal handling
      * bithacks according to the new convention (ldshape for long double
      and explicit unions for float and double)
      535104ab
    • S
      math: fix underflow in exp*.c and long double handling in exp2l · 39c910fb
      Szabolcs Nagy 提交于
      * don't care about inexact flag
      * use double_t and float_t (faster, smaller, more precise on x86)
      * exp: underflow when result is zero or subnormal and not -inf
      * exp2: underflow when result is zero or subnormal and not exact
      * expm1: underflow when result is zero or subnormal
      * expl: don't underflow on -inf
      * exp2: fix incorrect comment
      * expm1: simplify special case handling and overflow properly
      * expm1: cleanup final scaling and fix negative left shift ub (twopk)
      39c910fb
    • S
      math: long double trigonometric cleanup (cosl, sinl, sincosl, tanl) · ea9bb95a
      Szabolcs Nagy 提交于
      ld128 support was added to internal kernel functions (__cosl, __sinl,
      __tanl, __rem_pio2l) from freebsd (not tested, but should be a good
      start for when ld128 arch arrives)
      
      __rem_pio2l had some code cleanup, the freebsd ld128 code seems to
      gather the results of a large reduction with precision loss (fixed
      the bug but a todo comment was added for later investigation)
      
      the old copyright was removed from the non-kernel wrapper functions
      (cosl, sinl, sincosl, tanl) since these are trivial and the interesting
      parts and comments had been already rewritten.
      ea9bb95a
    • S
      math: long double inverse trigonometric cleanup (acosl, asinl, atanl, atan2l) · bcd797a5
      Szabolcs Nagy 提交于
      * added ld128 support from freebsd fdlibm (untested)
      * using new ldshape union instead of IEEEl2bits
      * inexact status flag is not supported
      bcd797a5
    • S
      math: rewrite hypot · c2a0dfea
      Szabolcs Nagy 提交于
      method: if there is a large difference between the scale of x and y
      then the larger magnitude dominates, otherwise reduce x,y so the
      argument of sqrt (x*x+y*y) does not overflow or underflow and calculate
      the argument precisely using exact multiplication. If the argument
      has less error than 1/sqrt(2) ~ 0.7 ulp, then the result has less error
      than 1 ulp in nearest rounding mode.
      
      the original fdlibm method was the same, except it used bit hacks
      instead of dekker-veltkamp algorithm, which is problematic for long
      double where different representations are supported. (the new hypot
      and hypotl code should be smaller and faster on 32bit cpu archs with
      fast fpu), the new code behaves differently in non-nearest rounding,
      but the error should be still less than 2ulps.
      
      ld80 and ld128 are supported
      c2a0dfea
    • S
      math: rewrite remainder functions (remainder, remquo, fmod, modf) · ee2ee92d
      Szabolcs Nagy 提交于
      * results are exact
      * modfl follows truncl (raises inexact flag spuriously now)
      * modf and modff only had cosmetic cleanup
      * remainder is just a wrapper around remquo now
      * using iterative shift+subtract for remquo and fmod
      * ld80 and ld128 are supported as well
      ee2ee92d
    • S
      math: rewrite rounding functions (ceil, floor, trunc, round, rint) · d1a2ead8
      Szabolcs Nagy 提交于
      * faster, smaller, cleaner implementation than the bit hacks of fdlibm
      * use arithmetics like y=(double)(x+0x1p52)-0x1p52, which is an integer
      neighbor of x in all rounding modes (0<=x<0x1p52) and only use bithacks
      when that's faster and smaller (for float it usually is)
      * the code assumes standard excess precision handling for casts
      * long double code supports both ld80 and ld128
      * nearbyint is not changed (it is a wrapper around rint)
      d1a2ead8
    • S
      math: fix logb(-0.0) in downward rounding mode · 98be442e
      Szabolcs Nagy 提交于
      use -1/(x*x) instead of -1/(x+0) to return -inf, -0+0 is -0 in
      downward rounding mode
      98be442e
    • S
      math: ilogb cleanup · 4cec31fc
      Szabolcs Nagy 提交于
      * consistent code style
      * explicit union instead of typedef for double and float bit access
      * turn FENV_ACCESS ON to make 0/0.0f raise invalid flag
      * (untested) ld128 version of ilogbl (used by logbl which has ld128 support)
      4cec31fc
    • S
      long double cleanup, initial commit · af5f6d95
      Szabolcs Nagy 提交于
      new ldshape union, ld128 support is kept, code that used the old
      ldshape union was rewritten (IEEEl2bits union of freebsd libm is
      not touched yet)
      
      ld80 __fpclassifyl no longer tries to handle invalid representation
      af5f6d95
  2. 17 8月, 2013 1 次提交
  3. 16 8月, 2013 1 次提交
  4. 15 8月, 2013 9 次提交
  5. 28 7月, 2013 1 次提交
  6. 19 5月, 2013 2 次提交
    • S
      math: add fma TODO comments about the underflow issue · 1e5eb735
      Szabolcs Nagy 提交于
      The underflow exception is not raised correctly in some
      cornercases (see previous fma commit), added comments
      with examples for fmaf, fmal and non-x86 fma.
      
      In fmaf store the result before returning so it has the
      correct precision when FLT_EVAL_METHOD!=0
      1e5eb735
    • S
      math: fix two fma issues (only affects non-nearest rounding mode, x86) · ffd8ac2d
      Szabolcs Nagy 提交于
      1) in downward rounding fma(1,1,-1) should be -0 but it was 0 with
      gcc, the code was correct but gcc does not support FENV_ACCESS ON
      so it used common subexpression elimination where it shouldn't have.
      now volatile memory access is used as a barrier after fesetround.
      
      2) in directed rounding modes there is no double rounding issue
      so the complicated adjustments done for nearest rounding mode are
      not needed. the only exception to this rule is raising the underflow
      flag: assume "small" is an exactly representible subnormal value in
      double precision and "verysmall" is a much smaller value so that
      	(long double)(small plus verysmall) == small
      then
      	(double)(small plus verysmall)
      raises underflow because the result is an inexact subnormal, but
      	(double)(long double)(small plus verysmall)
      does not because small is not a subnormal in long double precision
      and it is exact in double precision.
      now this problem is fixed by checking inexact using fenv when the
      result is subnormal
      ffd8ac2d
  7. 18 5月, 2013 2 次提交
    • S
      math: sin cos cleanup · bfda3793
      Szabolcs Nagy 提交于
      * use unsigned arithmetics
      * use unsigned to store arg reduction quotient (so n&3 is understood)
      * remove z=0.0 variables, use literal 0
      * raise underflow and inexact exceptions properly when x is small
      * fix spurious underflow in tanl
      bfda3793
    • S
      math: tan cleanups · 1d5ba3bb
      Szabolcs Nagy 提交于
      * use unsigned arithmetics on the representation
      * store arg reduction quotient in unsigned (so n%2 would work like n&1)
      * use different convention to pass the arg reduction bit to __tan
        (this argument used to be 1 for even and -1 for odd reduction
        which meant obscure bithacks, the new n&1 is cleaner)
      * raise inexact and underflow flags correctly for small x
        (tanl(x) may still raise spurious underflow for small but normal x)
        (this exception raising code increases codesize a bit, similar fixes
        are needed in many other places, it may worth investigating at some
        point if the inexact and underflow flags are worth raising correctly
        as this is not strictly required by the standard)
      * tanf manual reduction optimization is kept for now
      * tanl code path is cleaned up to follow similar logic to tan and tanf
      1d5ba3bb
  8. 16 5月, 2013 1 次提交
    • S
      math: use double_t for temporaries to avoid stores on i386 · e216951f
      Szabolcs Nagy 提交于
      When FLT_EVAL_METHOD!=0 (only i386 with x87 fp) the excess
      precision of an expression must be removed in an assignment.
      (gcc needs -fexcess-precision=standard or -std=c99 for this)
      
      This is done by extra load/store instructions which adds code
      bloat when lot of temporaries are used and it makes the result
      less precise in many cases.
      Using double_t and float_t avoids these issues on i386 and
      it makes no difference on other archs.
      
      For now only a few functions are modified where the excess
      precision is clearly beneficial (mostly polynomial evaluations
      with temporaries).
      
      object size differences on i386, gcc-4.8:
                   old   new
      __cosdf.o    123    95
      __cos.o      199   169
      __sindf.o    131    95
      __sin.o      225   203
      __tandf.o    207   151
      __tan.o      605   499
      erff.o      1470  1416
      erf.o       1703  1649
      j0f.o       1779  1745
      j0.o        2308  2274
      j1f.o       1602  1568
      j1.o        2286  2252
      tgamma.o    1431  1424
      math/*.o   64164 63635
      e216951f
  9. 08 1月, 2013 1 次提交
    • S
      math: erf and erfc cleanup · 121e3a38
      Szabolcs Nagy 提交于
      common part of erf and erfc was put in a separate function which
      saved some space and the new code is using unsigned arithmetics
      
      erfcf had a bug: for some inputs in [7.95,8] the result had
      more than 60ulp error: in expf(-z*z - 0.5625f) the argument
      must be exact but not enough lowbits of z were zeroed,
      -SET_FLOAT_WORD(z, ix&0xfffff000);
      +SET_FLOAT_WORD(z, ix&0xffffe000);
      fixed the issue
      121e3a38
  10. 02 1月, 2013 3 次提交
    • S
      math: bessel cleanup (jn.c and jnf.c) · 5652d700
      Szabolcs Nagy 提交于
      both jn and yn functions had integer overflow issues for large
      and small n
      
      to handle these issues nm1 (== |n|-1) is used instead of n and -n
      in the code and some loops are changed to make sure the iteration
      counter does not overflow
      
      (another solution could be to use larger integer type or even double
      but that has more size and runtime cost, on x87 loading int64_t or
      even uint32_t into an fpu register is more than two times slower than
      loading int32_t, and using double for n slows down iteration logic)
      
      yn(-1,0) now returns inf
      
      posix2008 specifies that on overflow and at +-0 all y0,y1,yn functions
      return -inf, this is not consistent with math when n<0 odd integer in yn
      (eg. when x->0, yn(-1,x)->inf, but historically yn(-1,0) seems to be
      special cased and returned -inf)
      
      some threshold values in jnf and ynf were fixed that seems to be
      incorrectly copy-pasted from the double version
      5652d700
    • S
      math: bessel cleanup (j1.c and j1f.c) · 5bb6b249
      Szabolcs Nagy 提交于
      a common code path in j1 and y1 was factored out so the resulting
      object code is a bit smaller
      
      unsigned int arithmetics is used for bit manipulation
      
      j1(-inf) now returns 0 instead of -0
      
      an incorrect threshold in the common code of j1f and y1f got fixed
      (this caused spurious overflow and underflow exceptions)
      
      the else branch in pone and pzero functions are fixed
      (so code analyzers dont warn about uninitialized values)
      5bb6b249
    • S
      math: bessel cleanup (j0.c and j0f.c) · 697acde6
      Szabolcs Nagy 提交于
      a common code path in j0 and y0 was factored out so the resulting
      object code is smaller
      
      unsigned int arithmetics is used for bit manipulation
      
      the logic of j0 got a bit simplified (x < 1 case was handled
      separately with a bit higher precision than now, but there are large
      errors in other domains anyway so that branch has been removed)
      
      some threshold values were adjusted in j0f and y0f
      697acde6
  11. 17 12月, 2012 4 次提交
    • S
      math: use 0x1p-120f and 0x1p120f for tiny and huge values · c6383b7b
      Szabolcs Nagy 提交于
      previously 0x1p-1000 and 0x1p1000 was used for raising inexact
      exception like x+tiny (when x is big) or x+huge (when x is small)
      
      the rational is that these float consts are large enough
      (0x1p-120 + 1 raises inexact even on ld128 which has 113 mant bits)
      and float consts maybe smaller or easier to load on some platforms
      (on i386 this reduced the object file size by 4bytes in some cases)
      c6383b7b
    • S
      math: tgammal.c fixes · d8a7619e
      Szabolcs Nagy 提交于
      this is not a full rewrite just fixes to the special case logic:
      +-0 and non-integer x<INT_MIN inputs incorrectly raised invalid
      exception and for +-0 the return value was wrong
      
      so integer test and odd/even test for negative inputs are changed
      and a useless overflow test was removed
      d8a7619e
    • S
      math: tanh.c cleanup similar to sinh, cosh · e42a977f
      Szabolcs Nagy 提交于
      comments are kept in the double version of the function
      
      compared to fdlibm/freebsd we partition the domain into one
      more part and select different threshold points:
      now the [log(5/3)/2,log(3)/2] and [log(3)/2,inf] domains
      should have <1.5ulp error
      (so only the last bit may be wrong, assuming good exp, expm1)
      
      (note that log(3)/2 and log(5/3)/2 are the points where tanh
      changes resolution: tanh(log(3)/2)=0.5, tanh(log(5/3)/2)=0.25)
      
      for some x < log(5/3)/2 (~=0.2554) the error can be >1.5ulp
      but it should be <2ulp
      (the freebsd code had some >2ulp errors in [0.255,1])
      
      even with the extra logic the new code produces smaller
      object files
      e42a977f
    • S
      math: sinh.c cleanup similar to the cosh one · f1434582
      Szabolcs Nagy 提交于
      comments are kept in the double version of the function
      f1434582