xref: /titanic_50/usr/src/lib/libc/i386/gen/wsncmp.s (revision 7014882c6a3672fd0e5d60200af8643ae53c5928)
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.h"
36
37	ANSI_PRAGMA_WEAK(wcsncmp,function)
38	ANSI_PRAGMA_WEAK(wsncmp,function)
39
40	ENTRY(wcsncmp)
41	pushl	%esi		/ save register variables
42	movl	8(%esp),%esi	/ %esi = first string
43	movl	%edi,%edx
44	movl	12(%esp),%edi	/ %edi = second string
45	cmpl	%esi,%edi	/ same string?
46	je	.equal
47	movl	16(%esp),%ecx	/ %ecx = length
48	incl	%ecx		/ will later predecrement this uint
49.loop:
50	decl	%ecx
51	je	.equal		/ Used all n chars?
52	movl	(%esi),%eax	/ slodb ; scab
53	cmpl	(%edi),%eax
54	jne	.notequal_0	/ Are the bytes equal?
55	testl	%eax,%eax
56	je	.equal		/ End of string?
57
58	decl	%ecx
59	je	.equal		/ Used all n chars?
60	movl	4(%esi),%eax	/ slodb ; scab
61	cmpl	4(%edi),%eax
62	jne	.notequal_1	/ Are the bytes equal?
63	testl	%eax,%eax
64	je	.equal		/ End of string?
65
66	decl	%ecx
67	je	.equal		/ Used all n chars?
68	movl	8(%esi),%eax	/ slodb ; scab
69	cmpl	8(%edi),%eax
70	jne	.notequal_2	/ Are the bytes equal?
71	testl	%eax,%eax
72	je	.equal		/ End of string?
73
74	decl	%ecx
75	je	.equal		/ Used all n chars?
76	movl	12(%esi),%eax	/ slodb ; scab
77	cmpl	12(%edi),%eax
78	jne	.notequal_3	/ Are the bytes equal?
79	addl	$16,%esi
80	addl	$16,%edi
81	testl	%eax,%eax
82	jne	.loop		/ End of string?
83
84.equal:
85	popl	%esi		/ restore registers
86	xorl	%eax,%eax	/ return 0
87	movl	%edx,%edi
88	ret
89
90	.align	4
91.notequal_3:
92	addl	$4,%edi
93.notequal_2:
94	addl	$4,%edi
95.notequal_1:
96	addl	$4,%edi
97.notequal_0:
98	popl	%esi		/ restore registers
99	subl	(%edi),%eax	/ return value is (*s1 - *--s2)
100	movl	%edx,%edi
101	ret
102	SET_SIZE(wcsncmp)
103
104	ENTRY(wsncmp)
105	_prologue_
106	movl	_esp_(12),%ecx
107	movl	_esp_(8),%eax
108	movl	_esp_(4),%edx
109	pushl	%ecx
110	pushl	%eax
111	pushl	%edx
112	call	_fref_(wcsncmp)
113	addl	$12,%esp
114	_epilogue_
115	ret
116	SET_SIZE(wsncmp)
117