xref: /titanic_44/usr/src/lib/libc/amd64/gen/wsncmp.s (revision 8de5c4f463386063e184a851437d58080c6c626c)
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	.file	"wsncmp.s"
28
29/
30/ Wide character wcsncpy() implementation
31/
32/ Algorithm based on Solaris 2.6 gen/strncpy.s implementation
33/
34
35#include <sys/asm_linkage.h>
36
37	ANSI_PRAGMA_WEAK(wcsncmp,function)
38	ANSI_PRAGMA_WEAK(wsncmp,function)
39
40	ENTRY(wcsncmp)		/* (wchar *ws1, wchar_t *ws2, size_t n) */
41	cmpq	%rdi,%rsi	/ same string?
42	je	.equal
43	incq	%rdx		/ will later predecrement this uint
44.loop:
45	decq	%rdx
46	je	.equal		/ Used all n chars?
47	movl	(%rdi),%eax	/ slodb ; scab
48	cmpl	(%rsi),%eax
49	jne	.notequal_0	/ Are the bytes equal?
50	testl	%eax,%eax
51	je	.equal		/ End of string?
52
53	decq	%rdx
54	je	.equal		/ Used all n chars?
55	movl	4(%rdi),%eax	/ slodb ; scab
56	cmpl	4(%rsi),%eax
57	jne	.notequal_1	/ Are the bytes equal?
58	testl	%eax,%eax
59	je	.equal		/ End of string?
60
61	decq	%rdx
62	je	.equal		/ Used all n chars?
63	movl	8(%rdi),%eax	/ slodb ; scab
64	cmpl	8(%rsi),%eax
65	jne	.notequal_2	/ Are the bytes equal?
66	testl	%eax,%eax
67	je	.equal		/ End of string?
68
69	decq	%rdx
70	je	.equal		/ Used all n chars?
71	movl	12(%rdi),%eax	/ slodb ; scab
72	cmpl	12(%rsi),%eax
73	jne	.notequal_3	/ Are the bytes equal?
74	addq	$16,%rdi
75	addq	$16,%rsi
76	testl	%eax,%eax
77	jne	.loop		/ End of string?
78
79.equal:
80	xorl	%eax,%eax	/ return 0
81	ret
82
83	.align	4
84.notequal_3:
85	addq	$4,%rsi
86.notequal_2:
87	addq	$4,%rsi
88.notequal_1:
89	addq	$4,%rsi
90.notequal_0:
91	subl	(%rsi),%eax	/ return value is (*s1 - *--s2)
92	ret
93	SET_SIZE(wcsncmp)
94
95	ENTRY(wsncmp)
96	jmp	wcsncmp		/ tail call into wcsncmp
97	SET_SIZE(wsncmp)
98