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