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