/*ProfiPacket - packet radio terminal program
  Copyright (C) 1999  Alexander Feigl

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  Author:

  Alexander Feigl
  Burachstraße 51

  D-88250 Weingarten

  Mail : Alexander.Feigl@gmx.de
*/


.text
.even
.globl _memcpyfast

_memcpyfast:	move.l 4(sp),a0
		move.l 8(sp),a1
		move.l 12(sp),d0
		movem.l d2-d7/a2-a6,-(sp)
		tst.l d0
		beq .Exit
		cmpa.l a1,a0
		blt .Reverse_Copy
		beq .Exit

.Even_Forward:	cmp.l #12*4,d0
		blt .Long_Forward
		movem.l (a0),d1-d7/a2-a6
		movem.l d1-d7/a2-a6,(a1)
		add.l #12*4,a0
		add.l #12*4,a1
		sub.l #12*4,d0
		bra .Even_Forward
.Long_Forward:	cmp.l #4,d0
		blt .Rest_Forward
		move.l (a0)+,(a1)+
		subq.l #4,d0
		bra .Long_Forward
.Rest_Forward:	tst.l d0
		beq .Exit
.Rest_Forward_L:move.b (a0)+,(a1)+
		subq.l #1,d0
		bne .Rest_Forward_L
		bra .Exit


.Reverse_Copy:	add.l d0,a0
		add.l d0,a1
.Even_Reverse:  cmp.l #12*4,d0
		blt .Long_Reverse
		sub.l #12*4,d0
		sub.l #12*4,a0
		sub.l #12*4,a1
		movem.l (a0),d1-d7/a2-a6
		movem.l d1-d7/a2-a6,(a1)
		bra .Even_Reverse
.Long_Reverse:	cmp.l #4,d0
		blt .Rest_Reverse
		move.l -(a0),-(a1)
		subq.l #4,d0
		bra .Long_Reverse
.Rest_Reverse:	tst.l d0
		beq .Exit
.Rest_Reverse_L:move.b -(a0),-(a1)
		subq.l #1,d0
		bne .Rest_Reverse_L
.Exit:		movem.l (sp)+,d2-d7/a2-a6
		rts



