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