1 /* $NetBSD: memset.S,v 1.1 2014/09/03 19:34:25 matt Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <machine/asm.h>
35 #if defined(LIBC_SCCS) && !defined(lint)
36 __RCSID("$NetBSD: memset.S,v 1.1 2014/09/03 19:34:25 matt Exp $")
37 #endif /* LIBC_SCCS && !lint */
39 /*----------------------------------------------------------------------*/
41 void bzero(void *b r3, size_t len r4);
42 void * memset(void *b r3, int c r4, size_t len r5);
44 /*----------------------------------------------------------------------*/
58 l.or r11, r3, r0 /* move start to return value */
60 l.sfeqi r5, 0 /* anything to do? */
61 l.bf .Lret /* no, just return */
64 l.sfgeui r5, 7 /* small buffer? */
65 l.add r5, r5, r3 /* r5 is end pointer */
66 l.bnf .Lbyte_fill /* yes. just byte fill */
70 // Let's see the fill type
71 l.sfeqi r4, 0 /* filling with 0? */
72 l.bf .Lalignment_check /* don't to replicate */
74 l.extbz r4, r4 /* truncate to 8 bits */
75 l.slli r13, r4, 8 /* shift left 8 bits */
76 l.or r4, r4, r13 /* merge the two bytes */
77 l.slli r13, r4, 16 /* shift left 16 bits */
78 l.or r4, r4, r13 /* merge the two halves */
82 l.andi r13, r3, 3 /* get low bits of start */
83 l.sfeqi r13, 0 /* word aligned? */
84 l.bf .Lword_fill /* yes, start setting */
87 l.add r5, r5, r13 /* increase length */
88 l.sub r3, r3, r13 /* mask word aligned */
89 l.slli r13, r13, 3 /* bytes to bits */
90 l.addi r15, r13, -8 /* minus one byte */
92 l.lwz r6, 0(r3) /* get first word */
93 l.movhi r7, 0xff00 /* 0xff000000 */
94 l.sra r7, r7, r13 /* shift right align bytes */
95 l.and r6, r6, r7 /* clear bytes to be filled */
97 l.srl r7, r_fill, r13 /* clear bytes to preserve */
98 l.or r6, r6, r7 /* merge existing with new */
100 l.sw 0(r3), r6 /* store first word */
101 l.addi r3, r3, 4 /* advance to next word */
102 l.addi r5, r5, -4 /* one less word to do */
105 l.srli r6, r5, 2 /* clear low two bits of len */
106 l.srli r6, r6, 2 /* ... */
107 l.sfgeu r3, r6 /* any more full words? */
108 l.bf .Lend_fill /* no, handle the last bytes */
112 l.sw 0(r3), r_fill /* store a word */
113 l.addi r3, r3, 4 /* advance */
114 l.sfgeu r3, r6 /* any more full words? */
115 l.bnf .Lword_fill /* yes, fill next word */
117 l.j .Lend_fill /* fill any leftover bytes */
121 l.sb 0(r3), r_fill /* store a byte */
122 l.addi r3, r3, 1 /* advance */
124 l.sfeq r3, r5 /* at the end? */
125 l.bnf .Lbyte_fill /* no, fill next byte */