Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Written by J.T. Conklin <jtc@netbsd.org>.
  3.  * Public domain.
  4.  */
  5.  
  6. /* e^x = 2^(x * log2(e)) */
  7.  
  8.   .file "exp.s"
  9.         .text
  10.         .p2align 4,,15
  11.  
  12. .globl _exp
  13. .def   _exp;  .scl  2;  .type 32; .endef
  14.  
  15. _exp:
  16.  
  17.       fldl  4(%esp)
  18. /* I added the following ugly construct because exp(+-Inf) resulted
  19.    in NaN.  The ugliness results from the bright minds at Intel.
  20.    For the i686 the code can be written better.
  21.    -- drepper@cygnus.com.  */
  22.     fxam        /* Is NaN or +-Inf?  */
  23.     fstsw %ax
  24.     movb  $0x45, %dh
  25.     andb  %ah, %dh
  26.     cmpb  $0x05, %dh
  27.     je  1f      /* Is +-Inf, jump.  */
  28.  
  29.     fldl2e
  30.     fmulp       /* x * log2(e) */
  31.     fld %st
  32.     frndint       /* int(x * log2(e)) */
  33.     fsubr %st,%st(1)    /* fract(x * log2(e)) */
  34.     fxch
  35.     f2xm1       /* 2^(fract(x * log2(e))) - 1 */
  36.     fld1
  37.     faddp       /* 2^(fract(x * log2(e))) */
  38.     fscale        /* e^x */
  39.     fstp  %st(1)
  40.     ret
  41.  
  42. 1:
  43.     testl $0x200, %eax    /* Test sign.  */
  44.     jz  2f      /* If positive, jump.  */
  45.  
  46.     fstp  %st
  47.     fldz        /* Set result to 0.  */
  48. 2:
  49.     ret
  50.