home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / mint / mntlib16 / _fixdfsi.s < prev    next >
Encoding:
Text File  |  1993-08-03  |  1.9 KB  |  90 lines

  1. | double float to long conversion 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.3, kub 01-90 :
  8. | added support for denormalized numbers
  9. |
  10. | Revision 1.2, kub 01-90 :
  11. | replace far shifts by swaps to gain speed
  12. |
  13. | Revision 1.1, kub 12-89 :
  14. | Ported over to 68k assembler
  15. |
  16. | Revision 1.0:
  17. | original 8088 code from P.S.Housel
  18.  
  19. BIAS8    =    0x3FF-1
  20.  
  21.     .text
  22.     .even
  23.     .globl    __fixdfsi, ___fixdfsi
  24.  
  25. __fixdfsi:
  26. ___fixdfsi:
  27.     lea    sp@(4),a0    | pointer to parameters
  28.     moveml    d2/d4/d5,sp@-    | save registers
  29.     moveml    a0@,d4-d5    | get the number
  30.     movew    a0@,d0        | extract exp
  31.     movew    d0,d2        | extract sign
  32.     lsrw    #4,d0
  33.     andw    #0x07ff,d0    | kill sign bit
  34.  
  35.     andl    #0x0fffff,d4    | remove exponent from mantissa
  36.     orl    #0x100000,d4    | restore implied leading "1"
  37.  
  38.     cmpw    #BIAS8,d0    | check exponent
  39.     blt    zero        | strictly factional, no integer part ?
  40.     cmpw    #BIAS8+32,d0    | is it too big to fit in a 32-bit integer ?
  41.     bgt    toobig
  42.  
  43.     subw    #BIAS8+21,d0    | adjust exponent
  44.     bgt    2f        | shift up
  45.     beq    3f        | no shift
  46.  
  47.     cmpw    #-8,d0        | replace far shifts by swap
  48.     bgt    1f
  49.     movew    d4,d5        | shift fast, 16 bits
  50.     swap    d5
  51.     clrw    d4
  52.     swap    d4
  53.     addw    #16,d0        | account for swap
  54.     bgt    2f
  55.     beq    3f
  56.  
  57. 1:    lsrl    #1,d4        | shift down to align radix point;
  58.     addw    #1,d0        | extra bits fall off the end (no rounding)
  59.     blt    1b        | shifted all the way down yet ?
  60.     bra    3f
  61.  
  62. 2:    addl    d5,d5        | shift up to align radix point
  63.     addxl    d4,d4
  64.     subw    #1,d0
  65.     bgt    2b
  66.  
  67. 3:    movel    d4,d0        | put integer into result register
  68.     cmpl    #0x80000000,d0    | -2147483648 is a nasty evil special case
  69.     bne    6f
  70.     tstw    d2        | this had better be -2^31 and not 2^31
  71.     bpl    toobig
  72.     bra    8f
  73. 6:    tstl    d0        | sign bit set ? (i.e. too big)
  74.     bmi    toobig
  75. 7:
  76.     tstw    d2        | is it negative ?
  77.     bpl    8f
  78.     negl    d0        | negate
  79. 8:
  80.     moveml    sp@+,d2/d4/d5
  81.     rts
  82.  
  83. zero:
  84.     clrl    d0        | make the whole thing zero
  85.     bra    7b
  86.  
  87. toobig:
  88.     movel    #0x7fffffff,d0    | ugh. Should cause a trap here.
  89.     bra    7b
  90.