Home | History | Annotate | Line # | Download | only in powerpc
memset.S revision 1.1
      1  1.1  matt /*	$NetBSD: memset.S,v 1.1 2003/08/10 21:17:09 matt Exp $ */
      2  1.1  matt 
      3  1.1  matt /*-
      4  1.1  matt  * Copyright (C) 2003	Matt Thomas <matt (at) 3am-software.com>
      5  1.1  matt  * Copyright (C) 2001	Martin J. Laubach <mjl (at) netbsd.org>
      6  1.1  matt  * All rights reserved.
      7  1.1  matt  *
      8  1.1  matt  * Redistribution and use in source and binary forms, with or without
      9  1.1  matt  * modification, are permitted provided that the following conditions
     10  1.1  matt  * are met:
     11  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     12  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     13  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  matt  *    documentation and/or other materials provided with the distribution.
     16  1.1  matt  * 3. The name of the author may not be used to endorse or promote products
     17  1.1  matt  *    derived from this software without specific prior written permission.
     18  1.1  matt  *
     19  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  1.1  matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  1.1  matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  1.1  matt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  1.1  matt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  1.1  matt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  1.1  matt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  1.1  matt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  1.1  matt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  1.1  matt  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  1.1  matt  */
     30  1.1  matt /*----------------------------------------------------------------------*/
     31  1.1  matt 
     32  1.1  matt #define _NOREGNAMES
     33  1.1  matt #include <machine/asm.h>
     34  1.1  matt 
     35  1.1  matt /*----------------------------------------------------------------------*/
     36  1.1  matt /*
     37  1.1  matt      void bzero(void *b r3, size_t len r4);
     38  1.1  matt      void * memset(void *b r3, int c r4, size_t len r5);
     39  1.1  matt */
     40  1.1  matt /*----------------------------------------------------------------------*/
     41  1.1  matt 
     42  1.1  matt #define r_dst	%r4
     43  1.1  matt #define r_len	%r5
     44  1.1  matt #define r_tmp	%r6
     45  1.1  matt #define r_val	%r0
     46  1.1  matt 
     47  1.1  matt ENTRY(bzero)
     48  1.1  matt 		li	r_val, 0		/* Value to fill with */
     49  1.1  matt 		mr	r_len, %r4
     50  1.1  matt 		b	cb_memset
     51  1.1  matt 
     52  1.1  matt ENTRY(memset)
     53  1.1  matt 		mr	r_val, %r4		/* Value to fill with */
     54  1.1  matt 
     55  1.1  matt cb_memset:
     56  1.1  matt 		cmplwi	r_len, 0		/* is the length 0? */
     57  1.1  matt 		beqlr-				/*    nothing to do */
     58  1.1  matt 		mr	r_dst, %r3
     59  1.1  matt 		/*
     60  1.1  matt 		 * r3=start, r4=dstptr, r5=length, r0=fill-val
     61  1.1  matt 		 */
     62  1.1  matt 		cmplwi	r_len, 6		/* more than 6 bytes? */
     63  1.1  matt 		bgt	complex_fill		/*    do it the complex way */
     64  1.1  matt 		subi	r_dst, r_dst, 1		/* presubtract for stbu */
     65  1.1  matt simple_fill:	mtctr	r_len			/* set CTR */
     66  1.1  matt 1:		stbu	r_val, 1(r_dst)		/* update memory */
     67  1.1  matt 		bdnz+	1b			/*    until CTR is 0 */
     68  1.1  matt 		blr				/* return */
     69  1.1  matt 
     70  1.1  matt complex_fill:
     71  1.1  matt 		rlwimi	r_val, r_val, 8, 16, 23	/* word extend fill value */
     72  1.1  matt 		rlwimi	r_val, r_val, 16, 0, 15
     73  1.1  matt 		andi.	r_tmp, r_dst, 0x03
     74  1.1  matt 		beq+	word_fill		/* already aligned to word? */
     75  1.1  matt 		andi.	r_tmp, r_dst, 0x01
     76  1.1  matt 		beq	half_fill		/* aligned to halfword? */
     77  1.1  matt 		stb	r_val, 0(r_dst)
     78  1.1  matt 		addi	r_dst, r_dst, 1
     79  1.1  matt 		subi	r_len, r_len, 1		/* subtract byte */
     80  1.1  matt 		andi.	r_tmp, r_dst, 0x02
     81  1.1  matt 		beq	word_fill		/* aligned to word? */
     82  1.1  matt half_fill:
     83  1.1  matt 		stw	r_val, 0(r_dst)
     84  1.1  matt 		addi	r_dst, r_dst, 2
     85  1.1  matt 		subi	r_len, r_len, 2		/* subtract halfword */
     86  1.1  matt 
     87  1.1  matt word_fill:
     88  1.1  matt 		cmplwi	r_len, 4		/* we have more than 4 bytes? */
     89  1.1  matt 		blt-	trailing_bytes		/* no?  finish writing */
     90  1.1  matt 		srwi	r_tmp, r_len, 2		/* get word count */
     91  1.1  matt 		mtctr	r_tmp
     92  1.1  matt 		subi	r_dst, r_dst, 4
     93  1.1  matt 1:		stwu	r_val, 4(r_dst)
     94  1.1  matt 		bdnz+	1b
     95  1.1  matt 
     96  1.1  matt trailing_bytes:
     97  1.1  matt 		andi.	r_len, r_len, 0x03	/* how much left? */
     98  1.1  matt 		beqlr+				/* nothing? return */
     99  1.1  matt 		addi	r_dst, r_dst, 3
    100  1.1  matt 		b	simple_fill
    101