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