home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / libsrc / m / src / exp.s < prev    next >
Encoding:
Text File  |  1993-06-28  |  2.0 KB  |  130 lines

  1. /* This is file EXP.S */
  2. /*
  3. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** Modified O.ROBERT 24, Avenue de Verdun 92170 VANVES, FRANCE
  6. **
  7. ** E-mail: roberto@germinal.ibp.fr
  8. **
  9. ** This file is distributed under the terms listed in the document
  10. ** "copying.dj", available from DJ Delorie at the address above.
  11. ** A copy of "copying.dj" should accompany this file; if not, a copy
  12. ** should be available from where this file was obtained.  This file
  13. ** may not be distributed without a verbatim copy of "copying.dj".
  14. **
  15. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  16. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. **
  18. ** or    03-Apr-1991    corrected bug about argument zero to pow
  19. **            fyl2x didn't like it
  20. **
  21. ** 17-08-92: modified to fix pow(-2,3) bug by kunst@prl.philips.nl
  22. **           pow(x,y)  x^y.  A domain error occurs if x=0 and y<=0,
  23. **                         or if x<0 and y is not an integer.
  24. **
  25. */
  26.  
  27. /* History:15,24 */
  28.     .data
  29. yint: 
  30.     .word   0,0
  31. LCW1:
  32.     .word    0
  33. LCW2:
  34.     .word    0
  35.  
  36.     .text
  37. LC0:
  38.     .double    0d1.0e+00
  39.  
  40. frac:
  41.     fstcww    LCW1
  42.     fstcww    LCW2
  43.     fwait
  44.     andw    $0xf3ff,LCW2
  45.     orw    $0x0400,LCW2
  46.     fldcww    LCW2
  47.     fldl    %st(0)
  48.     frndint
  49.     fldcww    LCW1
  50.     fxch    %st(1)
  51.     fsub    %st(1),%st
  52.     ret
  53.  
  54.     .globl    _pow2
  55. _pow2:
  56.     fldl    4(%esp)
  57. Lpow2:
  58.     call    frac
  59.     f2xm1
  60.     faddl    LC0
  61.     fscale
  62.     fstp    %st(1)
  63.     ret
  64.  
  65.     .globl    _exp
  66. _exp:
  67.     fldl    4(%esp)
  68.     fldl2e
  69.     fmulp
  70.     jmp    Lpow2
  71.  
  72.     .globl    _pow10
  73. _pow10:
  74.     fldl    4(%esp)
  75.     fldl2t
  76.     fmulp
  77.     jmp    Lpow2
  78.  
  79.     .globl    _pow
  80. _pow:
  81.     fldl    12(%esp)
  82.     fldl    4(%esp)
  83.     ftst    
  84.     fnstsww    %ax
  85.     sahf
  86.     jbe    xltez
  87.     fyl2x
  88.     jmp    Lpow2
  89. xltez:
  90.     jb    xltz
  91.     fstp    %st(0)
  92.     ftst
  93.     fnstsww    %ax
  94.     sahf
  95.     ja    ygtz
  96.     jb    error
  97.     fstp    %st(0) 
  98.     fld1l
  99.     fchs
  100. error:
  101.     fsqrt
  102.     ret
  103. ygtz:
  104.     fstp    %st(0)
  105.     fldzl
  106.     ret
  107. xltz:
  108.     fabs
  109.     fxch    %st(1)
  110.     call    frac
  111.     ftst
  112.     fnstsww    %ax
  113.     fstp    %st(0)
  114.     sahf
  115.     je    yisint
  116.     fstp    %st(0)
  117.     fchs
  118.     jmp    error
  119. yisint:
  120.     fistl    yint
  121.     fxch    %st(1)
  122.     fyl2x
  123.     call    Lpow2
  124.     andl    $1,yint
  125.     jz    yeven
  126.     fchs
  127. yeven:
  128.     ret
  129.  
  130.