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

  1. | single 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. | Created single float version for 68000
  12. |
  13. | Revision 1.0:
  14. | original 8088 code from P.S.Housel for double floats
  15.  
  16. BIAS4    =    0x7F-1
  17.  
  18.     .text
  19.     .even
  20.     .globl    __divsf3, ___divsf3
  21.     .globl    __infinitysf
  22.  
  23. __divsf3:
  24. ___divsf3:
  25.     lea    sp@(4),a0    | pointer to parameters u and v
  26.     moveml    d2-d5,sp@-    | save registers
  27.     moveml    a0@,d4/d5    | d4 = u, d5 = v
  28.  
  29.     movel    d4,d0        | d0 = u.exp
  30.     swap    d0
  31.     movew    d0,d2        | d2 = u.sign
  32.     lsrw    #7,d0
  33.     andw    #0xff,d0    | kill sign bit
  34.  
  35.     movel    d5,d1        | d1 = v.exp
  36.     swap    d1
  37.     eorw    d1,d2        | d2 = u.sign ^ v.sign (in bit 31)
  38.     lsrw    #7,d1
  39.     andw    #0xff,d1    | kill sign bit
  40.  
  41.     andl    #0x7fffff,d4    | remove exponent from u.mantissa
  42.     tstw    d0        | check for zero exponent - no leading "1"
  43.     beq    0f
  44.     orl    #0x800000,d4    | restore implied leading "1"
  45.     bra    1f
  46. 0:    addw    #1,d0        | "normalize" exponent
  47. 1:    tstl    d4
  48.     beq    retz        | dividing zero
  49.  
  50.     andl    #0x7fffff,d5    | remove exponent from v.mantissa
  51.     tstw    d1        | check for zero exponent - no leading "1"
  52.     beq    0f
  53.     orl    #0x800000,d5    | restore implied leading "1"
  54.     bra    1f
  55. 0:    addw    #1,d1        | "normalize" exponent
  56. 1:    tstl    d5
  57.     beq    divz        | divide by zero
  58.  
  59.     subw    d1,d0        | subtract exponents,
  60.     addw    #BIAS4-8+1,d0    |  add bias back in, account for shift
  61.     addw    #34,d0        |  add loop offset, +2 for extra rounding bits
  62.                 |   for denormalized numbers (2 implied by dbra)
  63.     movew    #27,d1        | bit number for "implied" pos (+4 for rounding)
  64.     movel    #-1,d3        |  zero quotient (for speed a one's complement)
  65.     subl    d5,d4        | initial subtraction, u = u - v
  66. 2:
  67.     btst    d1,d3        | divide until 1 in implied position
  68.     beq    5f
  69.  
  70.     addl    d4,d4
  71.     bcs    4f        | if carry is set, add, else subtract
  72.  
  73.     addxl    d3,d3        | shift quotient and set bit zero
  74.     subl    d5,d4        | subtract, u = u - v
  75.     dbra    d0,2b        | give up if result is denormalized
  76.     bra    5f
  77. 4:
  78.     addxl    d3,d3        | shift quotient and clear bit zero
  79.     addl    d5,d4        | add (restore), u = u + v
  80.     dbra    d0,2b        | give up if result is denormalized
  81. 5:    subw    #2,d0        | remove rounding offset for denormalized nums
  82.     notl    d3        | invert quotient to get it right
  83.  
  84.     movel    d3,d4        | save quotient mantissa
  85.     clrw    d1        | zero rounding bits
  86.     jmp    norm_sf        | (registers on stack removed by norm_sf)
  87.  
  88. retz:    clrl    d0        | zero destination
  89.     moveml    sp@+,d2-d5
  90.     rts            | no normalization needed
  91.  
  92. divz:    movel    __infinitysf,d0    | return infinty value
  93.     moveml    sp@+,d2-d5    | should really cause trap ?!?
  94.     rts
  95.