home *** CD-ROM | disk | FTP | other *** search
- #APP
-
- | void *memcpy(void *dest, const void *src, size_t cnt);
- | This function is allowed to play fast and loose...
- |
- | Michal Jaegermann ntomczak@vm.ucs.ualberta.ca
- | pared down version of bcopy.s
- |
- |
- .text
- .even
- .globl _memcpy
- _memcpy:
- movl sp@(4),a1 | dst -> a1
- movl sp@(8),a0 | src -> a0
- movl sp@(12),d0 | cnt -> d0
- jeq return | cnt == 0, nothing to do
- cmpl a0,a1
- jeq return | src dst same
- moveml d2-d3/a1,sp@- | save d2,d3,a1(dst)
-
- | check for odd src or dst
- movw a0,d1
- movw a1,d2
- eorb d1,d2
- btst #0,d2
- jne oddeven
- btst #0,d1
- jeq setup
- movb a0@+,a1@+ | odd odd
- subql #1,d0 | move it
-
- setup:
- | if we are here we can unroll a copy loop
- movl d0,d2
- lsrl #5,d2 | how many times through a copy loop
- movl d2,d3 | get upper 16 bits of d2 into
- swap d3 | lower word of d3
-
- movw d0,d1
- andw #0x1c,d1 | 4 bytes/copy 32 bytes max/iter
- lsrw #1,d1 | calc index into loop (each movl == 2bytes)
- negw d1 |
- addw #18,d1 | 16 + 2 bytes for jmp ext word - d1 == index
-
- eveneven: | may want long alignment for 020/030 etc
- jmp pc@(0,d1:w) | dive into loop at appro spot
- loop1:
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
-
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
-
- dbra d2,loop1
- dbra d3,loop1
-
- btst #1,d0
- jeq L4
- movw a0@+,a1@+ | residual word
- L4: btst #0,d0
- jeq ret
- movb a0@,a1@ | residual byte
- ret:
- moveml sp@+,d2-d3/a1
- movl a1,d0 | return destination
- return: rts
-
- oddeven:
- movw d0,d1
- swap d1
- jra upbra
- upcopy: | byte-by-byte forward
- movb a0@+,a1@+
- upbra:
- dbra d0,upcopy
- dbra d1,upcopy
- jra ret
-