 *
 * Mesa 3-D graphics library
 * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *

* misc assembler implementations       28.1.98 by Sam Jordan


		XDEF    _q_memcpy
		XDEF    _q_memset

******************************************************************************
*
*       void q_memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) );
*
*       fast memcopy operation
*
******************************************************************************

_q_memcpy

		rsreset
		rs.l    1
.dest           rs.l    1
.source         rs.l    1
.count          rs.l    1

		move.l  .dest(sp),a1
		move.l  .source(sp),a0
		move.l  a0,d1
		move.l  a1,d0
		and.b   #$3,d0
		and.b   #$3,d1
		cmp.b   d0,d1
		bne.b   .bytecopy
		move.l  .count(sp),d1
		move.l  a1,d0
		neg.l   d0
		and.l   #$3,d0
		beq     .main
		cmp.l   d0,d1
		blt     .main
		sub.l   d0,d1
		subq    #1,d0
.first
		move.b  (a0)+,(a1)+
		dbra    d0,.first
.main
		move.l  d1,d0
		beq     .end
		asr.l   #2,d1
		beq     .cont
.loop
		move.l  (a0)+,(a1)+
		subq.l  #1,d1
		bne.b   .loop
.cont
		and.l   #$3,d0
		beq     .end
		subq    #1,d0
.loop2
		move.b  (a0)+,(a1)+
		dbra    d0,.loop2
		bra.b   .end
.bytecopy
		move.l  .count(sp),d0
.loop3
		move.b  (a0)+,(a1)+
		subq.l  #1,d0
		bne.b   .loop3
.end
		rts


******************************************************************************
*
*       void q_memset( (void *) (DST), (int) (VAL), (size_t) (N) );
*
*       fast memset operation
*
******************************************************************************

_q_memset

		rsreset
.regs           rs.l    1
		rs.l    1
.dest           rs.l    1
.value          rs.l    1
.count          rs.l    1

		move.l  d2,-(sp)
		move.l  .dest(sp),a1
		move.l  .value(sp),d0
		move.l  d0,d1
		lsl.l   #8,d0
		move.b  d1,d0
		move.l  d0,d1
		swap    d0
		move    d1,d0
		move.l  .count(sp),d1
		move.l  a1,d2
		neg.l   d2
		and.l   #$3,d2
		beq     .main
		cmp.l   d2,d1
		blt     .main
		sub.l   d2,d1
		subq    #1,d2
.first
		move.b  d0,(a1)+
		dbra    d2,.first
.main
		move.l  d1,d2
		beq     .end
		asr.l   #2,d1
		beq     .cont
.loop
		move.l  d0,(a1)+
		subq.l  #1,d1
		bne.b   .loop
.cont
		and.l   #$3,d2
		beq     .end
		subq    #1,d2
.loop2
		move.b  d0,(a1)+
		dbra    d2,.loop2
.end
		move.l  (sp)+,d2
		rts
