xref: /titanic_41/usr/src/lib/libc/i386/gen/memccpy.s (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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 2004 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#include <sys/asm_linkage.h>
32
33	ANSI_PRAGMA_WEAK(memccpy,function)
34
35#include "SYS.h"
36
37	ENTRY(memccpy)
38	pushl	%esi		/ save register variable
39	movl	8(%esp),%eax	/ %eax = address of dest string
40	movl	12(%esp),%esi	/ %esi = address of source string
41	movb	16(%esp),%dh	/ %dh = character to search for
42	movl	20(%esp),%ecx	/ %ecx = length to go still
43.loop:
44	decl	%ecx		/ decrement bytes to go
45	jl	.notfound
46	movb	(%esi),%dl
47	movb	%dl,(%eax)	/ move byte
48	cmpb	%dh,%dl		/ is it the byte sought?
49	je	.found		/ yes
50
51	decl	%ecx		/ decrement bytes to go
52	jl	.notfound
53	movb	1(%esi),%dl
54	movb	%dl,1(%eax)	/ move byte
55	cmpb	%dh,%dl		/ is it the byte sought?
56	je	.found1		/ yes
57
58	decl	%ecx		/ decrement bytes to go
59	jl	.notfound
60	movb	2(%esi),%dl
61	movb	%dl,2(%eax)	/ move byte
62	cmpb	%dh,%dl		/ is it the byte sought?
63	je	.found2		/ yes
64
65	decl	%ecx		/ decrement bytes to go
66	jl	.notfound
67	movb	3(%esi),%dl
68	movb	%dl,3(%eax)	/ move byte
69	addl	$4,%esi
70	addl	$4,%eax
71	cmpb	%dh,%dl		/ is it the byte sought?
72	jne	.loop		/ no
73	decl	%eax
74
75.found:
76	popl	%esi		/ restore register variable
77	incl	%eax		/ return pointer to next byte in dest
78	ret
79
80	.align	4
81.found2:
82	incl	%eax
83.found1:
84	popl	%esi		/ restore register variable
85	addl	$2,%eax		/ return pointer to next byte in dest
86	ret
87
88	.align	4
89.notfound:
90	popl	%esi		/ restore register variable
91	xorl	%eax,%eax	/ search fails
92	ret
93	SET_SIZE(memccpy)
94