Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. format ELF
  3. include 'proc32.inc'
  4. section '.text' executable
  5.            
  6. public exp_     as "exp"
  7. public exp2_    as "exp2"
  8.  
  9. SaveCW          dw ?
  10. MaskedCW        dw ?
  11.  
  12. ;               2**x = 2**int(x) * 2**frac(x).
  13. ;               We can easily compute 2**int(x) with fscale and
  14. ;               2**frac(x) using f2xm1.
  15. exp2_int:
  16.                 fstcw   [SaveCW]
  17.  
  18. ; Modify the control word to truncate when rounding.
  19.  
  20.                 fstcw   [MaskedCW]
  21.                 or      byte ptr MaskedCW + 1, 1100b
  22.                 fldcw   [MaskedCW]
  23.  
  24.                 fld     st0           ;Duplicate tos.
  25.                 fld     st0
  26.                 frndint                 ;Compute integer portion.
  27.  
  28.                 fxch                    ;Swap whole and int values.
  29.                 fsub    st0, st1    ;Compute fractional part.
  30.  
  31.                 f2xm1                   ;Compute 2**frac(x)-1.
  32.                 fld1
  33.                 faddp    st1, st0       ;Compute 2**frac(x).
  34.  
  35.                 fxch                    ;Get integer portion.
  36.                 fld1                    ;Compute 1*2**int(x).
  37.                 fscale
  38.                 fstp    st1           ;Remove st(1) (which is 1).
  39.  
  40.                 fmulp  st1, st0         ;Compute 2**int(x) * 2**frac(x).
  41.                 fstp    st1           ;Remove st1
  42.  
  43.                 fldcw   [SaveCW]     ;Restore rounding mode.
  44.                 ret
  45.  
  46. exp_:
  47. ;       exp(x) = 2**(x * lg(e))
  48.  
  49.                 fld     qword[esp+4]
  50.         fldl2e          ;Put lg(e) onto the stack.
  51.         fmulp st1, st0  ;Compute x*lg(e).
  52.         call    exp2_int;Compute 2**(x * lg(e))
  53.         ret
  54.  
  55. exp2_:          
  56.                 fld     qword[esp+4]
  57.         call    exp2_int;Compute 2 ** x
  58.         ret
  59.  
  60.  
  61.