home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 213a.lha / Sozobon-C / libfp / fpadd.s < prev    next >
Text File  |  1996-02-14  |  2KB  |  145 lines

  1. * Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  2. *
  3. * Permission is granted to anyone to use this software for any purpose
  4. * on any computer system, and to redistribute it freely, with the
  5. * following restrictions:
  6. * 1) No charge may be made other than reasonable charges for reproduction.
  7. * 2) Modified versions must be clearly marked as such.
  8. * 3) The authors are not responsible for any harmful consequences
  9. *    of using this software, even if they result from defects in it.
  10. *
  11. *    fpsub
  12. *
  13.     .globl    fpsub
  14.     .globl    _fpsub
  15. fpsub:
  16. _fpsub:
  17.     eor.b    #$80,11(sp)    * negate B, fall through
  18. *
  19. *    fpadd
  20. *
  21.     .globl    fpadd
  22.     .globl    _fpadd
  23. fpadd:
  24. _fpadd:
  25.     move.l    d3,a1        * save d3
  26.     move.l    4(sp),d0    * A
  27.     move.l    8(sp),d1    * B
  28.     move.b    #$7f,d3
  29.  
  30.     move.b    d0,d2
  31.     eor.b    d1,d2
  32.     bpl    same_sign
  33. * different signs
  34.     and.b    d3,d0
  35.     and.b    d3,d1
  36.  
  37.     cmp.b    d0,d1
  38.     bne    sk1
  39.     cmp.l    d0,d1
  40. sk1:
  41.     ble    norev1
  42.     move.l    d0,d2
  43.     move.l    d1,d0
  44.     move.l    d2,d1
  45.     eor.b    #$80,7(sp)
  46. norev1:
  47.     bsr    u_sub_
  48.  
  49.     tst.b    7(sp)
  50.     bpl    notneg1
  51.     tst.b    d0
  52.     beq    notneg1
  53.     or.b    #$80,d0
  54. notneg1:
  55.     move.l    a1,d3        * restore d3
  56.     rts
  57. * same signs
  58. same_sign:
  59.     and.b    d3,d0
  60.     and.b    d3,d1
  61.  
  62.     cmp.b    d0,d1
  63.     bne    sk2
  64.     cmp.l    d0,d1
  65. sk2:
  66.     ble    norev2
  67.     move.l    d0,d2
  68.     move.l    d1,d0
  69.     move.l    d2,d1
  70. norev2:
  71.     bsr    u_add_
  72.  
  73.     tst.b    7(sp)
  74.     bpl    notneg2
  75.     tst.b    d0
  76.     beq    notneg2
  77.     or.b    #$80,d0
  78. notneg2:
  79.     move.l    a1,d3        * restore d3
  80.     rts
  81. *
  82. *    unsigned fp add (d0+d1), d0 >= d1
  83. *
  84. u_add_:
  85.     move.l    d3,a2    * save d3
  86.     move.b    d0,d2    * result exp
  87.     sub.b    d1,d0
  88.     clr.l    d3
  89.     move.b    d0,d3    * diff of exps
  90.  
  91.     clr.b    d0
  92.     clr.b    d1
  93.  
  94.     cmp.b    #24,d3
  95.     bge    out1
  96.     lsr.l    d3,d1
  97.     add.l    d1,d0
  98.     bcc    out1
  99.     roxr.l    #1,d0
  100.     addq.b    #1,d2
  101.     bmi    overflow
  102. out1:
  103.     move.l    a2,d3    * restore d3
  104.     move.b    d2,d0
  105.     rts
  106. overflow:
  107.     move.l    a2,d3    * restore d3
  108.     move.l    #$ffffff7f,d0
  109.     rts
  110. *
  111. *    unsigned fp sub (d0-d1), d0 >= d1
  112. *
  113. u_sub_:
  114.     move.l    d3,a2    * save d3
  115.     move.b    d0,d2    * result exp
  116.     sub.b    d1,d0
  117.     clr.l    d3
  118.     move.b    d0,d3    * diff of exps
  119.  
  120.     clr.b    d0
  121.     clr.b    d1
  122.  
  123.     cmp.b    #24,d3
  124.     bgt    out2
  125.     lsr.l    d3,d1
  126.     clr.b    d1
  127.     sub.l    d1,d0
  128.     beq    underfl
  129. * normalize
  130. nloop:
  131.     tst.l    d0
  132.     bmi    out2
  133.     asl.l    #1,d0
  134.     subq.b    #1,d2
  135.     bne    nloop
  136. * underflow
  137. underfl:
  138.     move.l    a2,d3    * restore d3
  139.     clr.l    d0
  140.     rts
  141. out2:
  142.     move.l    a2,d3    * restore d3
  143.     move.b    d2,d0
  144.     rts
  145.