home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff362.lzh / MemRoutines / memcpy.asm < prev    next >
Assembly Source File  |  1990-08-11  |  2KB  |  80 lines

  1. ;---------------------------------------------------------------------
  2. ; memcpy() -- a faster version
  3. ;---------------------------------------------------------------------
  4. ; toaddr = memcpy( to,from,count)
  5.  
  6. ; This routine copies "count" bytes from the "from" address to the "to"
  7. ; address. It attempts to move data in longwords whenever possible. The
  8. ; "to" address is returned.
  9.  
  10. ;                            Robert Broughton
  11. ;                            328-1027 Davie St.
  12. ;                            Vancouver, BC V6E 4L2
  13. ;                            Canada
  14. ;                            USENet: a1040@mindlink.UUCP
  15. ;
  16. MANX    SET        1
  17.         IFND        MANX
  18.         IDNT        _memcpy
  19.         CSECT        _memcpy
  20.         ENDC
  21.         XDEF        _memcpy
  22. _memcpy:
  23.         link        a5,#.127
  24.         move.l    8(a5),a1            ;* out
  25.       move.l   12(a5),a0   ;* in
  26.         move.l    16(a5),d0    ;* count
  27.  
  28.         cmp.l        #7,d0
  29.         ble        finish       ;* too small, don't bother with optimization
  30.  
  31.         move.l    a0,d1
  32.         btst        #0,d1            ;*  even or odd
  33.         beq        ineven      ;*  it's even already
  34.         move.b    (a0)+,(a1)+ ;*  now it's even
  35.         subq.l    #1,d0
  36. ineven:
  37.         move.l    a1,d1
  38.         btst        #0,d1            ;*  how about output
  39.         beq        outeven
  40.  
  41. outodd:
  42. ;     unfortunately, the output address is not word-aligned, so we will
  43. ;     load a long word, and store it as four bytes
  44.         cmp.l        #3,d0
  45.         ble        finish
  46.  
  47.         move.l    (a0)+,d1
  48.         move.b    d1,3(a1)
  49.         lsr.w        #8,d1
  50.         move.b    d1,2(a1)        
  51.         swap        d1
  52.         move.b    d1,1(a1)
  53.         lsr.w        #8,d1
  54.         move.b    d1,(a1)        
  55.         addq.l    #4,a1
  56.         subq.l    #4,d0
  57.         bra        outodd
  58.  
  59. outeven:
  60. ;        ideal situation; we can load and store longwords
  61.         cmp.l        #3,d0
  62.         ble        finish
  63.  
  64.         move.l    (a0)+,(a1)+
  65.         subq.l    #4,d0
  66.         bra        outeven
  67.  
  68. finish:
  69.         cmp.b        #0,d0
  70.         ble      really
  71.         move.b    (a0)+,(a1)+
  72.         dbf        d0,finish
  73.  
  74. really:
  75.         move.l    8(a5),d0        ;* Lattice memcpy does this
  76.         unlk        a5
  77.         rts
  78. .127    equ        0
  79.  
  80.