xref: /minix3/common/lib/libc/arch/m68k/string/memset.S (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc/*	$NetBSD: memset.S,v 1.7 2013/09/07 19:06:29 chs Exp $	*/
2b6cbf720SGianluca Guida
3b6cbf720SGianluca Guida/*-
4b6cbf720SGianluca Guida * Copyright (c) 1997 The NetBSD Foundation, Inc.
5b6cbf720SGianluca Guida * All rights reserved.
6b6cbf720SGianluca Guida *
7b6cbf720SGianluca Guida * This code is derived from software contributed to The NetBSD Foundation
8b6cbf720SGianluca Guida * by J.T. Conklin.
9b6cbf720SGianluca Guida *
10b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without
11b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions
12b6cbf720SGianluca Guida * are met:
13b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright
14b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer.
15b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright
16b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer in the
17b6cbf720SGianluca Guida *    documentation and/or other materials provided with the distribution.
18b6cbf720SGianluca Guida *
19b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20b6cbf720SGianluca Guida * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21b6cbf720SGianluca Guida * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22b6cbf720SGianluca Guida * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23b6cbf720SGianluca Guida * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24b6cbf720SGianluca Guida * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25b6cbf720SGianluca Guida * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26b6cbf720SGianluca Guida * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27b6cbf720SGianluca Guida * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28b6cbf720SGianluca Guida * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29b6cbf720SGianluca Guida * POSSIBILITY OF SUCH DAMAGE.
30b6cbf720SGianluca Guida */
31b6cbf720SGianluca Guida
32b6cbf720SGianluca Guida/*-
33b6cbf720SGianluca Guida * Copyright (c) 1990 The Regents of the University of California.
34b6cbf720SGianluca Guida * All rights reserved.
35b6cbf720SGianluca Guida *
36b6cbf720SGianluca Guida * This code is derived from software contributed to Berkeley by
37b6cbf720SGianluca Guida * the Systems Programming Group of the University of Utah Computer
38b6cbf720SGianluca Guida * Science Department.
39b6cbf720SGianluca Guida *
40b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without
41b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions
42b6cbf720SGianluca Guida * are met:
43b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright
44b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer.
45b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright
46b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer in the
47b6cbf720SGianluca Guida *    documentation and/or other materials provided with the distribution.
48b6cbf720SGianluca Guida * 3. Neither the name of the University nor the names of its contributors
49b6cbf720SGianluca Guida *    may be used to endorse or promote products derived from this software
50b6cbf720SGianluca Guida *    without specific prior written permission.
51b6cbf720SGianluca Guida *
52b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53b6cbf720SGianluca Guida * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54b6cbf720SGianluca Guida * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55b6cbf720SGianluca Guida * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56b6cbf720SGianluca Guida * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57b6cbf720SGianluca Guida * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58b6cbf720SGianluca Guida * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59b6cbf720SGianluca Guida * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60b6cbf720SGianluca Guida * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61b6cbf720SGianluca Guida * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62b6cbf720SGianluca Guida * SUCH DAMAGE.
63b6cbf720SGianluca Guida */
64b6cbf720SGianluca Guida
65b6cbf720SGianluca Guida#include <machine/asm.h>
66b6cbf720SGianluca Guida
67b6cbf720SGianluca Guida#if defined(LIBC_SCCS) && !defined(lint)
68b6cbf720SGianluca Guida#if 0
69b6cbf720SGianluca Guida	RCSID("from: @(#)bzero.s	5.1 (Berkeley) 5/12/90")
70b6cbf720SGianluca Guida#else
71*84d9c625SLionel Sambuc	RCSID("$NetBSD: memset.S,v 1.7 2013/09/07 19:06:29 chs Exp $")
72b6cbf720SGianluca Guida#endif
73b6cbf720SGianluca Guida#endif /* LIBC_SCCS and not lint */
74b6cbf720SGianluca Guida
75b6cbf720SGianluca GuidaENTRY(memset)
76*84d9c625SLionel Sambuc	movl	%d2,-(%sp)
77*84d9c625SLionel Sambuc	movl	8(%sp),%a0		| destination
78*84d9c625SLionel Sambuc	movl	16(%sp),%d1		| count
79*84d9c625SLionel Sambuc	movb	15(%sp),%d2		| get fill character
80b6cbf720SGianluca Guida
81b6cbf720SGianluca Guida	/*
82b6cbf720SGianluca Guida	 * It isn't worth the overhead of aligning to {long}word boundries
83b6cbf720SGianluca Guida	 * if the string is too short.
84b6cbf720SGianluca Guida	 */
85b6cbf720SGianluca Guida	cmpl	#15,%d1
86*84d9c625SLionel Sambuc	jlt	.Lbzbyte
87b6cbf720SGianluca Guida
88*84d9c625SLionel Sambuc	clrl %d0
89*84d9c625SLionel Sambuc	moveb	%d2,%d0
90*84d9c625SLionel Sambuc	movel	%d0,%d2
91b6cbf720SGianluca Guida	lsll	#8,%d0
92b6cbf720SGianluca Guida	orl	%d0,%d2
93b6cbf720SGianluca Guida	lsll	#8,%d0
94b6cbf720SGianluca Guida	orl	%d0,%d2
95b6cbf720SGianluca Guida	lsll	#8,%d0
96b6cbf720SGianluca Guida	orl	%d0,%d2
97b6cbf720SGianluca Guida
98b6cbf720SGianluca Guida	/* word align */
99b6cbf720SGianluca Guida	movl	%a0,%d0
100b6cbf720SGianluca Guida	btst	#0,%d0			| if (dst & 1)
101*84d9c625SLionel Sambuc	jeq	.Lbzalgndw		|
102*84d9c625SLionel Sambuc	movb	%d2,(%a0)+		|	*(char *)dst++ = X
103b6cbf720SGianluca Guida	subql	#1,%d1			|	len--
104b6cbf720SGianluca Guida	addql	#1,%d0
105*84d9c625SLionel Sambuc.Lbzalgndw:
106b6cbf720SGianluca Guida#ifndef	__mc68010__
107b6cbf720SGianluca Guida	/* long word align */
108b6cbf720SGianluca Guida	btst	#1,%d0			| if (dst & 2)
109*84d9c625SLionel Sambuc	jeq	.Lbzalgndl		|
110*84d9c625SLionel Sambuc	movw	%d2,(%a0)+		|	*(short *)dst++ = X
111b6cbf720SGianluca Guida	subql	#2,%d1			|	len -= 2
112*84d9c625SLionel Sambuc.Lbzalgndl:
113b6cbf720SGianluca Guida	/* set by 8 longwords */
114b6cbf720SGianluca Guida	movel	%d1,%d0
115b6cbf720SGianluca Guida	lsrl	#5,%d0			| cnt = len / 32
116*84d9c625SLionel Sambuc	jeq	.Lbzlong			| if (cnt)
117b6cbf720SGianluca Guida	andl	#31,%d1			|	len %= 32
118b6cbf720SGianluca Guida	subql	#1,%d0			|	set up for dbf
119*84d9c625SLionel Sambuc.Lbz32loop:
120*84d9c625SLionel Sambuc	movl	%d2,(%a0)+		|	set 8 long words
121*84d9c625SLionel Sambuc	movl	%d2,(%a0)+
122*84d9c625SLionel Sambuc	movl	%d2,(%a0)+
123*84d9c625SLionel Sambuc	movl	%d2,(%a0)+
124*84d9c625SLionel Sambuc	movl	%d2,(%a0)+
125*84d9c625SLionel Sambuc	movl	%d2,(%a0)+
126*84d9c625SLionel Sambuc	movl	%d2,(%a0)+
127*84d9c625SLionel Sambuc	movl	%d2,(%a0)+
128*84d9c625SLionel Sambuc#ifndef __mcoldfire__
129*84d9c625SLionel Sambuc	dbf	%d0,.Lbz32loop		|	till done
130b6cbf720SGianluca Guida	clrw	%d0
131*84d9c625SLionel Sambuc#endif
132b6cbf720SGianluca Guida	subql	#1,%d0
133*84d9c625SLionel Sambuc	jcc	.Lbz32loop
134b6cbf720SGianluca Guida#endif	/* !__mc68010__ */
135b6cbf720SGianluca Guida
136*84d9c625SLionel Sambuc.Lbzlong:
137b6cbf720SGianluca Guida	/* set by longwords */
138b6cbf720SGianluca Guida	movel	%d1,%d0
139b6cbf720SGianluca Guida	lsrl	#2,%d0			| cnt = len / 4
140*84d9c625SLionel Sambuc	jeq	.Lbzbyte			| if (cnt)
141b6cbf720SGianluca Guida	subql	#1,%d0			|	set up for dbf
142*84d9c625SLionel Sambuc.Lbzlloop:
143*84d9c625SLionel Sambuc	movl	%d2,(%a0)+		|	clear longwords
144*84d9c625SLionel Sambuc#ifndef __mcoldfire__
145*84d9c625SLionel Sambuc	dbf	%d0,.Lbzlloop		|	till done
146*84d9c625SLionel Sambuc#endif
147b6cbf720SGianluca Guida#ifdef	__mc68010__
148b6cbf720SGianluca Guida	clrw	%d0
149b6cbf720SGianluca Guida#endif	/* __mc68010__ */
150*84d9c625SLionel Sambuc#if defined(__m68010) || defined(__mcoldfire__)
151*84d9c625SLionel Sambuc	subql	#1,%d0
152*84d9c625SLionel Sambuc	jcc	.Lbzlloop
153*84d9c625SLionel Sambuc#endif	/* __mc68010__ || __mcoldfire__ */
154b6cbf720SGianluca Guida	andl	#3,%d1			|	len %= 4
155*84d9c625SLionel Sambuc	jeq	.Lbzdone
156b6cbf720SGianluca Guida
157b6cbf720SGianluca Guida	subql	#1,%d1			| set up for dbf
158*84d9c625SLionel Sambuc.Lbzbloop:
159*84d9c625SLionel Sambuc	movb	%d2,(%a0)+		| set bytes
160*84d9c625SLionel Sambuc.Lbzbyte:
161*84d9c625SLionel Sambuc#ifdef __mcoldfire__
162*84d9c625SLionel Sambuc	subql	#1,%d1			| decrement
163*84d9c625SLionel Sambuc	jcc	.Lbzbloop		| till done
164*84d9c625SLionel Sambuc#else
165*84d9c625SLionel Sambuc	dbf	%d1,.Lbzbloop		| till done
166*84d9c625SLionel Sambuc#endif
167*84d9c625SLionel Sambuc.Lbzdone:
168*84d9c625SLionel Sambuc	movl	8(%sp),%d0		| return destination
169b6cbf720SGianluca Guida#ifdef __SVR4_ABI__
170b6cbf720SGianluca Guida	moveal	%d0,%a0
171b6cbf720SGianluca Guida#endif
172*84d9c625SLionel Sambuc	movl	(%sp)+,%d2
173b6cbf720SGianluca Guida	rts
174*84d9c625SLionel SambucEND(memset)
175