home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / mint / mntlib24 / _divdf3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-03  |  4.6 KB  |  202 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. | Revision 1.2, kub 01-90 :
  48. | added support for denormalized numbers
  49. |
  50. | Revision 1.1, kub 12-89 :
  51. | Ported over to 68k assembler
  52. |
  53. | Revision 1.0:
  54. | original 8088 code from P.S.Housel
  55.  
  56. BIAS8    =    0x3FF-1
  57.  
  58.     lea    sp@(4),a0    | pointer to parameters u and v
  59.     moveml    d2-d7,sp@-    | save registers
  60.     moveml    a0@,d4-d5/d6-d7    | d4-d5 = u, d6-d7 = v
  61.  
  62.     movel    d4,d0        | d0 = u.exp
  63.     swap    d0
  64.     movew    d0,d2        | d2 = u.sign
  65.     lsrw    #4,d0
  66.     andw    #0x07ff,d0    | kill sign bit
  67.  
  68.     movel    d6,d1        | d1 = v.exp
  69.     swap    d1
  70.     eorw    d1,d2        | d2 = u.sign ^ v.sign (in bit 31)
  71.     lsrw    #4,d1
  72.     andw    #0x07ff,d1    | kill sign bit
  73.  
  74.     andl    #0x0fffff,d4    | remove exponent from u.mantissa
  75.     tstw    d0        | check for zero exponent - no leading "1"
  76.     beq    0f
  77.     orl    #0x100000,d4    | restore implied leading "1"
  78.     bra    1f
  79. 0:    addw    #1,d0        | "normalize" exponent
  80. 1:    movel    d4,d3
  81.     orl    d5,d3
  82.     beq    retz        | dividing zero
  83.  
  84.     andl    #0x0fffff,d6    | remove exponent from v.mantissa
  85.     tstw    d1        | check for zero exponent - no leading "1"
  86.     beq    0f
  87.     orl    #0x100000,d6    | restore implied leading "1"
  88.     bra    1f
  89. 0:    addw    #1,d1        | "normalize" exponent
  90. 1:    movel    d6,d3
  91.     orl    d7,d3
  92.  
  93. #ifndef    ERROR_CHECK
  94.     beq    divz        | divide by zero
  95. #endif    ERROR_CHECK
  96.  
  97.     movew    d2,a0        | save sign
  98.  
  99.     subw    d1,d0        | subtract exponents,
  100.     addw    #BIAS8-11+1,d0    |  add bias back in, account for shift
  101.     addw    #66,d0        |  add loop offset, +2 for extra rounding bits
  102.                 |   for denormalized numbers (2 implied by dbra)
  103.     movew    #24,d1        | bit number for "implied" pos (+4 for rounding)
  104.     movel    #-1,d2        | zero the quotient
  105.     movel    #-1,d3        |  (for speed it is a one''s complement)
  106.     subl    d7,d5        | initial subtraction,
  107.     subxl    d6,d4        | u = u - v
  108. 2:
  109.     btst    d1,d2        | divide until 1 in implied position
  110.     beq    5f
  111.  
  112.     addl    d5,d5
  113.     addxl    d4,d4
  114.     bcs    4f        | if carry is set, add, else subtract
  115.  
  116.     addxl    d3,d3        | shift quotient and set bit zero
  117.     addxl    d2,d2
  118.     subl    d7,d5        | subtract
  119.     subxl    d6,d4        | u = u - v
  120.     dbra    d0,2b        | give up if result is denormalized
  121.     bra    5f
  122. 4:
  123.     addxl    d3,d3        | shift quotient and clear bit zero
  124.     addxl    d2,d2
  125.     addl    d7,d5        | add (restore)
  126.     addxl    d6,d4        | u = u + v
  127.     dbra    d0,2b        | give up if result is denormalized
  128. 5:    subw    #2,d0        | remove rounding offset for denormalized nums
  129.     notl    d2        | invert quotient to get it right
  130.     notl    d3
  131.  
  132.     movel    d2,d4        | save quotient mantissa
  133.     movel    d3,d5
  134.     movew    a0,d2        | get sign back
  135.     clrw    d1        | zero rounding bits
  136.     jmp    norm_df        | (registers on stack removed by norm_df)
  137.  
  138. retz:    clrl    d0        | zero destination
  139.     clrl    d1
  140.     moveml    sp@+,d2-d7
  141.     rts            | no normalization needed
  142.  
  143. #ifndef    ERROR_CHECK
  144. | NOTE: __infinitydf is in the text segment
  145. divz:    moveml    __infinitydf,d0-d1 | return infinity value
  146.     moveml    sp@+,d2-d7    | should really cause trap ?!?
  147.  
  148.     btst    #31,a7@(4)        | transfer sign of dividend
  149.     beq    clear            | (mjr++)
  150.     bset    #31,d0            |
  151.     rts                |
  152. clear:                    |
  153.     bclr    #31,d0            |
  154.     rts
  155.  
  156. #endif    ERROR_CHECK
  157.  
  158. #else
  159.  
  160. | double precision floating point stuff for Atari-gcc using the SFP004
  161. | developed with gas
  162. |
  163. | double precision division
  164. |
  165. | M. Ritzert (mjr at dmzrzu71)
  166. |
  167. | 4.10.1990
  168. |
  169. | no NAN checking implemented to gain compatibility with the TT-lib
  170. |
  171. | addresses of the 68881 data port. This choice is fastest when much data is
  172. | transferred between the two processors.
  173.  
  174. comm =     -6
  175. resp =    -16
  176. zahl =      0
  177.  
  178. | waiting loop ...
  179. |
  180. | wait:
  181. | ww:    cmpiw    #0x8900,a0@(resp)
  182. |     beq    ww
  183. | is coded directly by
  184. |    .long    0x0c688900, 0xfff067f8
  185.  
  186.     lea    0xfffffa50:w,a0
  187.     movew    #0x5400,a0@(comm)    | load first argument to fp0
  188.     cmpiw    #0x8900,a0@(resp)    | check
  189.     movel    a7@(4),a0@
  190.     movel    a7@(8),a0@
  191.     movew    #0x5420,a0@(comm)
  192.     .long    0x0c688900, 0xfff067f8
  193.     movel    a7@(12),a0@
  194.     movel    a7@(16),a0@
  195.     movew    #0x7400,a0@(comm)    | result to d0
  196.     .long    0x0c688900, 0xfff067f8
  197.     movel    a0@,d0
  198.     movel    a0@,d1
  199.      rts
  200. #endif    sfp004
  201. #endif /* !__M68881__ */
  202.