home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / updates / update16.zoo / lib / memcpy.s < prev    next >
Encoding:
Text File  |  1992-03-06  |  1.6 KB  |  83 lines

  1. #APP
  2.  
  3. | void *memcpy(void *dest, const void *src, size_t cnt);
  4. |    This function is allowed to play fast and loose...
  5. |
  6. |    Michal Jaegermann ntomczak@vm.ucs.ualberta.ca
  7. |    pared down version of bcopy.s
  8. |
  9.     .text
  10.     .even
  11.     .globl _memcpy
  12. _memcpy:
  13.     movl    sp@(4),a1    | dst -> a1
  14.     movl    sp@(8),a0    | src -> a0
  15.     movl    sp@(12),d0    | cnt -> d0
  16.     jeq    return        | cnt == 0, nothing to do
  17.     cmpl    a0,a1
  18.     jeq    return        |  src dst same
  19.     moveml    d2-d3/a1,sp@-    | save d2,d3,a1(dst)
  20.  
  21.     | check for odd src or dst
  22.     movw    a0,d1
  23.     movw    a1,d2
  24.     eorb    d1,d2
  25.     btst    #0,d2
  26.     jne    oddeven
  27.     btst    #0,d1
  28.     jeq    setup
  29.     movb    a0@+,a1@+    | odd  odd
  30.     subql   #1,d0        | move it
  31.  
  32. setup:
  33.     | if we are here we can unroll a copy loop
  34.     movl    d0,d2
  35.     lsrl    #5,d2        | how many times through a copy loop
  36.     movl    d2,d3        | get upper 16 bits of d2 into 
  37.     swap    d3        | lower word of d3
  38.  
  39.     movw    d0,d1
  40.     andw    #0x1c,d1    | 4 bytes/copy  32 bytes max/iter
  41.     lsrw    #1,d1        | calc index into loop (each movl == 2bytes)
  42.     negw    d1        |  
  43.     addw    #18,d1        | 16 + 2 bytes for jmp ext word - d1 == index
  44.  
  45. eveneven:            | may want long alignment for 020/030 etc
  46.     jmp    pc@(0,d1:w)    |  dive into loop at appro spot
  47. loop1:
  48.     movl    a0@+,a1@+
  49.     movl    a0@+,a1@+
  50.     movl    a0@+,a1@+
  51.     movl    a0@+,a1@+
  52.  
  53.     movl    a0@+,a1@+
  54.     movl    a0@+,a1@+
  55.     movl    a0@+,a1@+
  56.     movl    a0@+,a1@+
  57.  
  58.     dbra    d2,loop1
  59.     dbra    d3,loop1
  60.  
  61.     btst    #1,d0
  62.     jeq    L4
  63.     movw    a0@+,a1@+    | residual word
  64. L4:    btst    #0,d0
  65.     jeq    ret
  66.     movb    a0@,a1@        | residual byte
  67. ret:
  68.     moveml    sp@+,d2-d3/a1
  69.     movl    a1,d0        | return destination
  70. return:    rts
  71.  
  72. oddeven:
  73.     movw    d0,d1
  74.     swap    d1
  75.     jra    upbra
  76. upcopy:                | byte-by-byte forward
  77.     movb    a0@+,a1@+
  78. upbra:
  79.     dbra    d0,upcopy
  80.     dbra    d1,upcopy
  81.     jra    ret
  82.