2007-04-28 00:05:35 +08:00
|
|
|
/* a-memcpy.s -- memcpy, optimised for m68k asm
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 mocom software GmbH & Co KG)
|
|
|
|
*
|
|
|
|
* The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
* and license this software and its documentation for any purpose, provided
|
|
|
|
* that existing copyright notices are retained in all copies and that this
|
|
|
|
* notice is included verbatim in any distributions. No written agreement,
|
|
|
|
* license, or royalty fee is required for any of the authorized uses.
|
|
|
|
* Modifications to this software may be copyrighted by their authors
|
|
|
|
* and need not follow the licensing terms described here, provided that
|
|
|
|
* the new terms are clearly indicated on the first page of each file where
|
|
|
|
* they apply.
|
|
|
|
*/
|
|
|
|
|
2008-01-08 02:59:45 +08:00
|
|
|
#include "m68kasm.h"
|
|
|
|
|
2007-04-28 00:05:35 +08:00
|
|
|
.text
|
|
|
|
.align 4
|
|
|
|
|
2008-01-08 02:59:45 +08:00
|
|
|
.globl SYM(memcpy)
|
|
|
|
.type SYM(memcpy), @function
|
2007-04-28 00:05:35 +08:00
|
|
|
|
|
|
|
/* memcpy, optimised
|
|
|
|
*
|
|
|
|
* strategy:
|
|
|
|
* - no argument testing (the original memcpy from the GNU lib does
|
|
|
|
* no checking either)
|
|
|
|
* - make sure the destination pointer (the write pointer) is long word
|
|
|
|
* aligned. This is the best you can do, because writing to unaligned
|
|
|
|
* addresses can be the most costfull thing you could do.
|
|
|
|
* - Once you have figured that out, we do a little loop unrolling
|
|
|
|
* to further improve speed.
|
|
|
|
*/
|
|
|
|
|
2008-01-08 02:59:45 +08:00
|
|
|
SYM(memcpy):
|
2008-01-09 05:48:06 +08:00
|
|
|
move.l 4(sp),a0 | dest ptr
|
|
|
|
move.l 8(sp),a1 | src ptr
|
|
|
|
move.l 12(sp),d1 | len
|
|
|
|
cmp.l #8,d1 | if fewer than 8 bytes to transfer,
|
2007-04-28 00:05:35 +08:00
|
|
|
blo .Lresidue | do not optimise
|
|
|
|
|
|
|
|
/* align dest */
|
2008-01-09 05:48:06 +08:00
|
|
|
move.l a0,d0 | copy of dest
|
|
|
|
neg.l d0
|
|
|
|
and.l #3,d0 | look for the lower two only
|
2007-04-28 00:05:35 +08:00
|
|
|
beq 2f | is aligned?
|
2008-01-09 05:48:06 +08:00
|
|
|
sub.l d0,d1
|
|
|
|
lsr.l #1,d0 | word align needed?
|
2007-04-28 00:05:35 +08:00
|
|
|
bcc 1f
|
2008-01-09 05:48:06 +08:00
|
|
|
move.b (a1)+,(a0)+
|
2007-04-28 00:05:35 +08:00
|
|
|
1:
|
2008-01-09 05:48:06 +08:00
|
|
|
lsr.l #1,d0 | long align needed?
|
2007-04-28 00:05:35 +08:00
|
|
|
bcc 2f
|
2008-01-09 05:48:06 +08:00
|
|
|
move.w (a1)+,(a0)+
|
2007-04-28 00:05:35 +08:00
|
|
|
2:
|
|
|
|
|
|
|
|
/* long word transfers */
|
2008-01-09 05:48:06 +08:00
|
|
|
move.l d1,d0
|
|
|
|
and.l #3,d1 | byte residue
|
|
|
|
lsr.l #3,d0
|
2007-04-28 00:05:35 +08:00
|
|
|
bcc 1f | carry set for 4-byte residue
|
2008-01-09 05:48:06 +08:00
|
|
|
move.l (a1)+,(a0)+
|
2007-04-28 00:05:35 +08:00
|
|
|
1:
|
2008-01-09 05:48:06 +08:00
|
|
|
lsr.l #1,d0 | number of 16-byte transfers
|
2007-04-28 00:05:35 +08:00
|
|
|
bcc .Lcopy | carry set for 8-byte residue
|
|
|
|
bra .Lcopy8
|
|
|
|
|
|
|
|
1:
|
2008-01-09 05:48:06 +08:00
|
|
|
move.l (a1)+,(a0)+
|
|
|
|
move.l (a1)+,(a0)+
|
2007-04-28 00:05:35 +08:00
|
|
|
.Lcopy8:
|
2008-01-09 05:48:06 +08:00
|
|
|
move.l (a1)+,(a0)+
|
|
|
|
move.l (a1)+,(a0)+
|
2007-04-28 00:05:35 +08:00
|
|
|
.Lcopy:
|
|
|
|
#if !defined (__mcoldfire__)
|
2008-01-09 05:48:06 +08:00
|
|
|
dbra d0,1b
|
|
|
|
sub.l #0x10000,d0
|
2007-04-28 00:05:35 +08:00
|
|
|
#else
|
2008-01-09 05:48:06 +08:00
|
|
|
subq.l #1,d0
|
2007-04-28 00:05:35 +08:00
|
|
|
#endif
|
2007-05-04 03:45:26 +08:00
|
|
|
bpl 1b
|
2007-04-28 00:05:35 +08:00
|
|
|
bra .Lresidue
|
|
|
|
|
|
|
|
1:
|
2008-01-09 05:48:06 +08:00
|
|
|
move.b (a1)+,(a0)+ | move residue bytes
|
2007-04-28 00:05:35 +08:00
|
|
|
|
|
|
|
.Lresidue:
|
|
|
|
#if !defined (__mcoldfire__)
|
2008-01-09 05:48:06 +08:00
|
|
|
dbra d1,1b | loop until done
|
2007-04-28 00:05:35 +08:00
|
|
|
#else
|
2008-01-09 05:48:06 +08:00
|
|
|
subq.l #1,d1
|
2007-04-28 00:05:35 +08:00
|
|
|
bpl 1b
|
|
|
|
#endif
|
2008-01-09 05:48:06 +08:00
|
|
|
move.l 4(sp),d0 | return value
|
2007-04-28 00:05:35 +08:00
|
|
|
rts
|