xref: /titanic_44/usr/src/lib/libc/amd64/gen/memccpy.s (revision fb3fb4f3d76d55b64440afd0af72775dfad3bd1d)
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)	/* (void *dst, void *src, uchar_t c, size_t) */
38.loop:
39	decq	%rcx		/ decrement bytes to go
40	jl	.notfound
41	movb	(%rsi),%dh
42	movb	%dh,(%rdi)	/ move byte
43	cmpb	%dh,%dl		/ is it the byte sought?
44	je	.found		/ yes
45
46	decq	%rcx		/ decrement bytes to go
47	jl	.notfound
48	movb	1(%rsi),%dh
49	movb	%dh,1(%rdi)	/ move byte
50	cmpb	%dh,%dl		/ is it the byte sought?
51	je	.found1		/ yes
52
53	decq	%rcx		/ decrement bytes to go
54	jl	.notfound
55	movb	2(%rsi),%dh
56	movb	%dh,2(%rdi)	/ move byte
57	cmpb	%dh,%dl		/ is it the byte sought?
58	je	.found2		/ yes
59
60	decq	%rcx		/ decrement bytes to go
61	jl	.notfound
62	movb	3(%rsi),%dh
63	movb	%dh,3(%rdi)	/ move byte
64	addq	$4,%rsi
65	addq	$4,%rdi
66	cmpb	%dh,%dl		/ is it the byte sought?
67	jne	.loop		/ no
68	decq	%rdi
69
70.found:
71	incq	%rdi		/ return pointer to next byte in dest
72	movq	%rdi,%rax
73	ret
74
75	.align	4
76.found2:
77	incq	%rdi
78.found1:
79	addq	$2,%rdi		/ return pointer to next byte in dest
80	movq	%rdi,%rax
81	ret
82
83	.align	4
84.notfound:
85	xorl	%eax,%eax	/ search fails
86	ret
87	SET_SIZE(memccpy)
88