xref: /titanic_52/usr/src/lib/libc/amd64/gen/wslen.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/*
32 * Wide character wcslen() implementation
33 *
34 * size_t
35 * wcslen(const wchar_t *s)
36 *{
37 *	const wchar_t *s0 = s + 1;
38 *	while (*s++)
39 *		;
40 *	return (s - s0);
41 *}
42 */
43
44#include <sys/asm_linkage.h>
45
46	ANSI_PRAGMA_WEAK(wcslen,function)
47	ANSI_PRAGMA_WEAK(wslen,function)
48
49	ENTRY(wcslen)		/* (wchar_t *) */
50	xorl	%eax,%eax
51
52	.align	8
53.loop:
54	cmpl	$0,(%rdi)
55	je	.out0
56	cmpl	$0,4(%rdi)
57	je	.out1
58	cmpl	$0,8(%rdi)
59	je	.out2
60	cmpl	$0,12(%rdi)
61	je	.out3
62	addq	$4,%rax
63	addq	$16,%rdi
64	jmp	.loop
65
66	.align	4
67.out1:
68	incq	%rax
69.out0:
70	ret
71
72	.align	4
73.out2:
74	addq	$2,%rax
75	ret
76
77	.align	4
78.out3:
79	addq	$3, %rax
80	ret
81	SET_SIZE(wcslen)
82
83	ENTRY(wslen)
84	jmp	wcslen		/ tail call into wcslen
85	SET_SIZE(wslen)
86