home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / mntlib16.lzh / MNTLIB16 / _DIVDF3.S < prev    next >
Text File  |  1993-07-29  |  3KB  |  110 lines

  1. | double floating point divide routine
  2. |
  3. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  4. | Based on a 80x86 floating point packet from comp.os.minix, written by P.Housel
  5. |
  6. |
  7. | Revision 1.2, kub 01-90 :
  8. | added support for denormalized numbers
  9. |
  10. | Revision 1.1, kub 12-89 :
  11. | Ported over to 68k assembler
  12. |
  13. | Revision 1.0:
  14. | original 8088 code from P.S.Housel
  15.  
  16. BIAS8    =    0x3FF-1
  17.  
  18.     .text
  19.     .even
  20.     .globl    __divdf3, ___divdf3
  21.     .globl    __infinitydf
  22.  
  23. __divdf3:
  24. ___divdf3:
  25.     lea    sp@(4),a0    | pointer to parameters u and v
  26.     moveml    d2-d7,sp@-    | save registers
  27.     moveml    a0@,d4-d5/d6-d7    | d4-d5 = u, d6-d7 = v
  28.  
  29.     movel    d4,d0        | d0 = u.exp
  30.     swap    d0
  31.     movew    d0,d2        | d2 = u.sign
  32.     lsrw    #4,d0
  33.     andw    #0x07ff,d0    | kill sign bit
  34.  
  35.     movel    d6,d1        | d1 = v.exp
  36.     swap    d1
  37.     eorw    d1,d2        | d2 = u.sign ^ v.sign (in bit 31)
  38.     lsrw    #4,d1
  39.     andw    #0x07ff,d1    | kill sign bit
  40.  
  41.     andl    #0x0fffff,d4    | remove exponent from u.mantissa
  42.     tstw    d0        | check for zero exponent - no leading "1"
  43.     beq    0f
  44.     orl    #0x100000,d4    | restore implied leading "1"
  45.     bra    1f
  46. 0:    addw    #1,d0        | "normalize" exponent
  47. 1:    movel    d4,d3
  48.     orl    d5,d3
  49.     beq    retz        | dividing zero
  50.  
  51.     andl    #0x0fffff,d6    | remove exponent from v.mantissa
  52.     tstw    d1        | check for zero exponent - no leading "1"
  53.     beq    0f
  54.     orl    #0x100000,d6    | restore implied leading "1"
  55.     bra    1f
  56. 0:    addw    #1,d1        | "normalize" exponent
  57. 1:    movel    d6,d3
  58.     orl    d7,d3
  59.     beq    divz        | divide by zero
  60.  
  61.     movew    d2,a0        | save sign
  62.  
  63.     subw    d1,d0        | subtract exponents,
  64.     addw    #BIAS8-11+1,d0    |  add bias back in, account for shift
  65.     addw    #66,d0        |  add loop offset, +2 for extra rounding bits
  66.                 |   for denormalized numbers (2 implied by dbra)
  67.     movew    #24,d1        | bit number for "implied" pos (+4 for rounding)
  68.     movel    #-1,d2        | zero the quotient
  69.     movel    #-1,d3        |  (for speed it is a one's complement)
  70.     subl    d7,d5        | initial subtraction,
  71.     subxl    d6,d4        | u = u - v
  72. 2:
  73.     btst    d1,d2        | divide until 1 in implied position
  74.     beq    5f
  75.  
  76.     addl    d5,d5
  77.     addxl    d4,d4
  78.     bcs    4f        | if carry is set, add, else subtract
  79.  
  80.     addxl    d3,d3        | shift quotient and set bit zero
  81.     addxl    d2,d2
  82.     subl    d7,d5        | subtract
  83.     subxl    d6,d4        | u = u - v
  84.     dbra    d0,2b        | give up if result is denormalized
  85.     bra    5f
  86. 4:
  87.     addxl    d3,d3        | shift quotient and clear bit zero
  88.     addxl    d2,d2
  89.     addl    d7,d5        | add (restore)
  90.     addxl    d6,d4        | u = u + v
  91.     dbra    d0,2b        | give up if result is denormalized
  92. 5:    subw    #2,d0        | remove rounding offset for denormalized nums
  93.     notl    d2        | invert quotient to get it right
  94.     notl    d3
  95.  
  96.     movel    d2,d4        | save quotient mantissa
  97.     movel    d3,d5
  98.     movew    a0,d2        | get sign back
  99.     clrw    d1        | zero rounding bits
  100.     jmp    norm_df        | (registers on stack removed by norm_df)
  101.  
  102. retz:    clrl    d0        | zero destination
  103.     clrl    d1
  104.     moveml    sp@+,d2-d7
  105.     rts            | no normalization needed
  106.  
  107. divz:    moveml    __infinitydf,d0-d1 | return infinty value
  108.     moveml    sp@+,d2-d7    | should really cause trap ?!?
  109.     rts
  110.