xref: /titanic_41/usr/src/lib/libc/sparc/gen/memset.s (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27	.file	"memset.s"
28
29/*
30 * char *memset(sp, c, n)
31 *
32 * Set an array of n chars starting at sp to the character c.
33 * Return sp.
34 *
35 * Fast assembler language version of the following C-program for memset
36 * which represents the `standard' for the C-library.
37 *
38 *	void *
39 *	memset(void *sp1, int c, size_t n)
40 *	{
41 *	    if (n != 0) {
42 *		char *sp = sp1;
43 *		do {
44 *		    *sp++ = (char)c;
45 *		} while (--n != 0);
46 *	    }
47 *	    return (sp1);
48 *	}
49 */
50
51#include <sys/asm_linkage.h>
52
53	ANSI_PRAGMA_WEAK(memset,function)
54
55	ENTRY(memset)
56	mov	%o0, %o5		! copy sp before using it
57	cmp	%o2, 7			! if small counts, just write bytes
58	blu	.wrchar
59	.empty				! following lable is ok in delay slot
60
61.walign:btst	3, %o5			! if bigger, align to 4 bytes
62	bz	.wrword
63	andn	%o2, 3, %o3		! create word sized count in %o3
64	dec	%o2			! decrement count
65	stb	%o1, [%o5]		! clear a byte
66	b	.walign
67	inc	%o5			! next byte
68
69.wrword:and	%o1, 0xff, %o1		! generate a word filled with c
70	sll	%o1, 8, %o4
71	or 	%o1, %o4, %o1
72	sll	%o1, 16, %o4
73	or	%o1, %o4, %o1
741:	st	%o1, [%o5]		! word writing loop
75	subcc	%o3, 4, %o3
76	bnz	1b
77	inc	4, %o5
78
79	and	%o2, 3, %o2		! leftover count, if any
80.wrchar:deccc	%o2			! byte clearing loop
81	inc	%o5
82	bgeu,a	.wrchar
83	stb	%o1, [%o5 + -1]		! we've already incremented the address
84
85	retl
86	nop
87
88	SET_SIZE(memset)
89