xref: /titanic_41/usr/src/lib/libc/amd64/gen/wslen.s (revision 6185db853e024a486ff8837e6784dd290d866112)
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/*
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#include "SYS.h"
50
51	ENTRY(_wcslen)		/* (wchar_t *) */
52	xorl	%eax,%eax
53
54	.align	8
55.loop:
56	cmpl	$0,(%rdi)
57	je	.out0
58	cmpl	$0,4(%rdi)
59	je	.out1
60	cmpl	$0,8(%rdi)
61	je	.out2
62	cmpl	$0,12(%rdi)
63	je	.out3
64	addq	$4,%rax
65	addq	$16,%rdi
66	jmp	.loop
67
68	.align	4
69.out1:
70	incq	%rax
71.out0:
72	ret
73
74	.align	4
75.out2:
76	addq	$2,%rax
77	ret
78
79	.align	4
80.out3:
81	addq	$3, %rax
82	ret
83	SET_SIZE(_wcslen)
84
85	ENTRY(_wslen)
86	jmp	_wcslen		/ tail call into _wcslen
87	SET_SIZE(_wslen)
88