home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / libsrc87 / _divdf3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-30  |  5.3 KB  |  253 lines

  1. |
  2. | double floating point divide routine
  3. |
  4. #ifndef __M68881__
  5.     .text
  6.     .even
  7.     .globl    __divdf3, ___divdf3
  8. #ifdef    ERROR_CHECK
  9. #include "errbase.h"
  10.     .globl    __infinitydf
  11. LC0:
  12.     .ascii "floating point division by 0\12\15\0"
  13.     .even
  14. #endif    ERROR_CHECK
  15.  
  16. __divdf3:
  17. ___divdf3:
  18. #ifdef    ERROR_CHECK
  19.     tstl    a7@(12)            | check if divisor is 0
  20.     bne    continue
  21.     tstl    a7@(16)
  22.     bne    continue
  23.  
  24.     pea    pc@(LC0)
  25.     pea    Stderr
  26.     jbsr    _fprintf    |
  27.     addql    #8,a7        |
  28.                     | set _errno to ERANGE
  29.     moveq    #ERANGE,d0
  30.     Emove    d0,Errno
  31.     moveml    __infinitydf,d0-d1    | return signed infinity 
  32.     btst    #31,a7@(4)        | transfer sign of dividend
  33.     beq    clear            | (mjr++)
  34.     bset    #31,d0            |
  35.     rts                |
  36. clear:                    |
  37.     bclr    #31,d0            |
  38.     rts
  39. continue:
  40.  
  41. #endif    /* ERROR_CHECK */
  42. #ifndef sfp004
  43. |
  44. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  45. | Based on a 80x86 floating point packet from comp.os.minix, written by P.Housel
  46. |
  47. | patched by Olaf Flebbe (flebbe@tat.physik.uni-tuebingen.de)
  48. |
  49. | Revision 1.2.2 olaf 12-92
  50. |   + added support for NaN and Infinites
  51. |   + added support for -0
  52. |
  53. | Revision 1.2.1 olaf 11-92
  54. |   + prevent the tie rounding case if dividing is not exact.
  55. |      > paranoia now says: "Division appears to round correctly"
  56. |      ** requires _normdf Version 1.6.1 or later
  57. |
  58. | Revision 1.2, kub 01-90 :
  59. | added support for denormalized numbers
  60. |
  61. | Revision 1.1, kub 12-89 :
  62. | Ported over to 68k assembler
  63. |
  64. | Revision 1.0:
  65. | original 8088 code from P.S.Housel
  66.  
  67. BIAS8    =    0x3FF-1
  68.  
  69.     lea    sp@(4),a0    | pointer to parameters u and v
  70.     moveml    d2-d7,sp@-    | save registers
  71.     moveml    a0@,d4-d5/d6-d7    | d4-d5 = u, d6-d7 = v
  72.  
  73.     movel    d4,d0        | d0 = u.exp
  74.     swap    d0
  75.     movew    d0,d2        | d2 = u.sign
  76.     lsrw    #4,d0
  77.     andw    #0x07ff,d0    | kill sign bit
  78.  
  79.     movel    d6,d1        | d1 = v.exp
  80.     swap    d1
  81.     eorw    d1,d2        | d2 = u.sign ^ v.sign (in bit 31)
  82.     lsrw    #4,d1
  83.     andw    #0x07ff,d1    | kill sign bit
  84.  
  85.     andl    #0x0fffff,d4    | remove exponent from u.mantissa
  86.     andl    #0x0fffff,d6    | remove exponent from v.mantissa
  87. |
  88. |
  89. |
  90.     cmpw    #0x7ff,d0
  91.     beq    0f        |u == NaN || u== Inf
  92.     cmpw    #0x7ff,d1
  93.     beq    1f        | v == NaN || v == Inf
  94.     tstw    d0
  95.     bne    3f        | u not zero nor denorm
  96.     movel    d5,d3
  97.     orl    d4,d3
  98.     beq    2f        | 0/ ?
  99.  
  100. 3:    tstw    d1
  101.     bne    nospec
  102.  
  103.     movel    d7,d3
  104.     orl    d6,d3
  105.     bne    nospec
  106.     bra    retinf        | x/0 -> +/- Inf
  107.     
  108. 0:    orl    d5,d4        | u == NaN ?
  109.     bne    retnan        | NaN/ x
  110.     cmpw    #0x7ff,d1    
  111.     beq    retnan        | Inf/Inf or Inf/NaN 
  112.     bra    retinf        | Inf/x | x != Inf && x != NaN
  113.  
  114. 1:    orl    d7,d6
  115.     bne    retnan        | x/NaN
  116.     bra    retzero        | x/Inf -> +/- 0
  117.  
  118. 2:    tstw    d1
  119.     bne    retzero        | 0/x ->+/- 0
  120.     orl    d5,d4
  121.     bne    retzero        | 0/x 
  122.     bra    retnan        | 0/0
  123. |
  124. |    Return Infinity with correct sign
  125. |    
  126. retinf:    clrl    d1
  127.     tstl    d2
  128.     bpl    0f
  129.     movel    #0xfff00000,d0
  130. return:    moveml    sp@+,d2-d7
  131.     rts
  132.  
  133. 0:    movel    #0x7ff00000,d0
  134.     bra    return    
  135. |
  136. |    Return NaN
  137. |
  138. retnan: movel    #0x7fffffff,d0
  139.     moveql    #-1,d1
  140.     bra    return
  141. |
  142. |    Return correct signed zero
  143. |
  144. retzero:clrl    d0        | zero destination
  145.     clrl    d1
  146.     tstl    d2
  147.     bmi    return
  148.     bset    #31,d0
  149.     bra    return
  150. |
  151. |    End of special handling
  152. |    
  153. nospec:    tstw    d0        | check for zero exponent - no leading "1"
  154.     beq    0f
  155.     orl    #0x100000,d4    | restore implied leading "1"
  156.     bra    1f
  157. 0:    addw    #1,d0        | "normalize" exponent
  158.  
  159. 1:    tstw    d1        | check for zero exponent - no leading "1"
  160.     beq    0f
  161.     orl    #0x100000,d6    | restore implied leading "1"
  162.     bra    1f
  163. 0:    addw    #1,d1        | "normalize" exponent
  164.  
  165. 1:    movew    d2,a0        | save sign
  166.  
  167.     subw    d1,d0        | subtract exponents,
  168.     addw    #BIAS8-11+1,d0    |  add bias back in, account for shift
  169.     addw    #66,d0        |  add loop offset, +2 for extra rounding bits
  170.                 |   for denormalized numbers (2 implied by dbra)
  171.     movew    #24,d1        | bit number for "implied" pos (+4 for rounding)
  172.     movel    #-1,d2        | zero the quotient
  173.     movel    #-1,d3        |  (for speed it is a one''s complement)
  174.     subl    d7,d5        | initial subtraction,
  175.     subxl    d6,d4        | u = u - v
  176. 2:
  177.     btst    d1,d2        | divide until 1 in implied position
  178.     beq    5f
  179.  
  180.     addl    d5,d5
  181.     addxl    d4,d4
  182.     bcs    4f        | if carry is set, add, else subtract
  183.  
  184.     addxl    d3,d3        | shift quotient and set bit zero
  185.     addxl    d2,d2
  186.     subl    d7,d5        | subtract
  187.     subxl    d6,d4        | u = u - v
  188.     dbra    d0,2b        | give up if result is denormalized
  189.     bra    5f
  190. 4:
  191.     addxl    d3,d3        | shift quotient and clear bit zero
  192.     addxl    d2,d2
  193.     addl    d7,d5        | add (restore)
  194.     addxl    d6,d4        | u = u + v
  195.     dbra    d0,2b        | give up if result is denormalized
  196. 5:    subw    #2,d0        | remove rounding offset for denormalized nums
  197.     notl    d2        | invert quotient to get it right
  198.     notl    d3
  199.  
  200.     movel    d5,d1
  201.     orl    d4,d1        | check for exact result
  202.     beq    1f
  203.     moveql    #-1,d1        | Set rounding bits for tie case
  204. 1:    movel    d2,d4        | save quotient mantissa
  205.     movel    d3,d5
  206.     movew    a0,d2        | get sign back
  207.     jmp    norm_df        | (registers on stack removed by norm_df)
  208.  
  209. #else
  210.  
  211. | double precision floating point stuff for Atari-gcc using the SFP004
  212. | developed with gas
  213. |
  214. | double precision division
  215. |
  216. | M. Ritzert (mjr at dmzrzu71)
  217. |
  218. | 4.10.1990
  219. |
  220. | no NAN checking implemented to gain compatibility with the TT-lib
  221. |
  222. | addresses of the 68881 data port. This choice is fastest when much data is
  223. | transferred between the two processors.
  224.  
  225. comm =     -6
  226. resp =    -16
  227. zahl =      0
  228.  
  229. | waiting loop ...
  230. |
  231. | wait:
  232. | ww:    cmpiw    #0x8900,a0@(resp)
  233. |     beq    ww
  234. | is coded directly by
  235. |    .long    0x0c688900, 0xfff067f8
  236.  
  237.     lea    0xfffffa50:w,a0
  238.     movew    #0x5400,a0@(comm)    | load first argument to fp0
  239.     cmpiw    #0x8900,a0@(resp)    | check
  240.     movel    a7@(4),a0@
  241.     movel    a7@(8),a0@
  242.     movew    #0x5420,a0@(comm)
  243.     .long    0x0c688900, 0xfff067f8
  244.     movel    a7@(12),a0@
  245.     movel    a7@(16),a0@
  246.     movew    #0x7400,a0@(comm)    | result to d0
  247.     .long    0x0c688900, 0xfff067f8
  248.     movel    a0@,d0
  249.     movel    a0@,d1
  250.      rts
  251. #endif    sfp004
  252. #endif /* !__M68881__ */
  253.