 *
 * 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
		XDEF    _getLibBase
		XDEF    _getTBL
		vea

_getLibBase
		mr      r3,r2
		blr

_getTBL
		mftbl   r3
		blr

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

_q_memcpy
		prolog
		andi.   r6,r3,$3
		andi.   r7,r4,$3
		cmpw    r6,r7
		bne     .bytecopy
		neg     r6,r3
		andi.   r6,r6,$3
		beq     .main
		cmpw    r5,r6
		blt     .main
		subf    r5,r6,r5
		mtctr   r6
.first
		lbz     r0,0(r4)
		addi    r4,r4,1
		stb     r0,0(r3)
		addi    r3,r3,1
		bdnz    .first
.main
		mr.     r6,r5
		beq     .end
		srawi.  r5,r5,2
		beq     .cont
		mtctr   r5
		subi    r3,r3,4
		subi    r4,r4,4
.loop
		lwzu    r0,4(r4)
		stwu    r0,4(r3)
		bdnz    .loop
		addi    r4,r4,4
		addi    r3,r3,4
.cont
		andi.   r6,r6,$3
		beq     .end
		mtctr   r6
.loop2
		lbz     r0,0(r4)
		addi    r4,r4,1
		stb     r0,0(r3)
		addi    r3,r3,1
		bdnz    .loop2
		b       .end
.bytecopy
		mtctr   r5
		subi    r4,r4,1
		subi    r3,r3,1
.loop3
		lbzu    r0,1(r4)
		stbu    r0,1(r3)
		bdnz    .loop3
.end
		epilog


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

_q_memset
		prolog
		insrwi  r4,r4,8,16
		insrwi  r4,r4,16,0
		neg     r6,r3
		andi.   r6,r6,$3
		beq     .main
		cmpw    r5,r6
		blt     .main
		subf    r5,r6,r5
		mtctr   r6
.first
		stb     r4,0(r3)
		addi    r3,r3,1
		bdnz    .first
.main
		mr.     r6,r5
		beq     .end
		srawi.  r5,r5,2
		beq     .cont
		mtctr   r5
		subi    r3,r3,4
.loop
		stwu    r4,4(r3)
		bdnz    .loop
		addi    r3,r3,4
.cont
		andi.   r6,r6,$3
		beq     .end
		mtctr   r6
.loop2
		stb     r4,0(r3)
		addi    r3,r3,1
		bdnz    .loop2
.end
		epilog


