xref: /titanic_50/usr/src/lib/libc/amd64/gen/wschr.s (revision 79659ce54ea319c9c890f6dd5dbeb1146d725cb9)
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/
32/ Wide character wcschr() implementation
33/
34/ Algorithm based on Solaris 2.6 gen/strchr.s implementation
35/
36
37#include <sys/asm_linkage.h>
38
39	ANSI_PRAGMA_WEAK(wcschr,function)
40	ANSI_PRAGMA_WEAK(wschr,function)
41
42	.align	8		/ accounts for .loop alignment and prolog
43
44	ENTRY(wcschr)		/* (wchar_t *s, wchar_t wc) */
45	movq	%rdi,%rax
46.loop:
47	movl	(%rax),%edx	/ %edx = wchar of string
48	cmpl	%esi,%edx	/ find it?
49	je	.found		/ yes
50	testl	%edx,%edx	/ is it null?
51	je	.notfound
52
53	movl	4(%rax),%edx	/ %edx = wchar of string
54	cmpl	%esi,%edx	/ find it?
55	je	.found1		/ yes
56	testl	%edx,%edx	/ is it null?
57	je	.notfound
58
59	movl	8(%rax),%edx	/ %edx = wchar of string
60	cmpl	%esi,%edx	/ find it?
61	je	.found2		/ yes
62	testl	%edx,%edx	/ is it null?
63	je	.notfound
64
65	movl	12(%rax),%edx	/ %edx = wchar of string
66	cmpl	%esi,%edx	/ find it?
67	je	.found3		/ yes
68	addq	$16,%rax
69	testl	%edx,%edx	/ is it null?
70	jne	.loop
71
72.notfound:
73	xorl	%eax,%eax	/ %rax = NULL
74	ret
75
76.found3:
77	addq	$12,%rax
78	ret
79.found2:
80	addq	$8,%rax
81	ret
82.found1:
83	addq	$4,%rax
84.found:
85	ret
86	SET_SIZE(wcschr)
87
88	ENTRY(wschr)
89	jmp	wcschr		/ tail call into wcschr
90	SET_SIZE(wschr)
91