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