xref: /titanic_52/usr/src/lib/libc/amd64/gen/wsncmp.s (revision eb0cc229f19c437a6b538d3ac0d0443268290b7e)
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)		/* (wchar *ws1, wchar_t *ws2, size_t n) */
47	cmpq	%rdi,%rsi	/ same string?
48	je	.equal
49	incq	%rdx		/ will later predecrement this uint
50.loop:
51	decq	%rdx
52	je	.equal		/ Used all n chars?
53	movl	(%rdi),%eax	/ slodb ; scab
54	cmpl	(%rsi),%eax
55	jne	.notequal_0	/ Are the bytes equal?
56	testl	%eax,%eax
57	je	.equal		/ End of string?
58
59	decq	%rdx
60	je	.equal		/ Used all n chars?
61	movl	4(%rdi),%eax	/ slodb ; scab
62	cmpl	4(%rsi),%eax
63	jne	.notequal_1	/ Are the bytes equal?
64	testl	%eax,%eax
65	je	.equal		/ End of string?
66
67	decq	%rdx
68	je	.equal		/ Used all n chars?
69	movl	8(%rdi),%eax	/ slodb ; scab
70	cmpl	8(%rsi),%eax
71	jne	.notequal_2	/ Are the bytes equal?
72	testl	%eax,%eax
73	je	.equal		/ End of string?
74
75	decq	%rdx
76	je	.equal		/ Used all n chars?
77	movl	12(%rdi),%eax	/ slodb ; scab
78	cmpl	12(%rsi),%eax
79	jne	.notequal_3	/ Are the bytes equal?
80	addq	$16,%rdi
81	addq	$16,%rsi
82	testl	%eax,%eax
83	jne	.loop		/ End of string?
84
85.equal:
86	xorl	%eax,%eax	/ return 0
87	ret
88
89	.align	4
90.notequal_3:
91	addq	$4,%rsi
92.notequal_2:
93	addq	$4,%rsi
94.notequal_1:
95	addq	$4,%rsi
96.notequal_0:
97	subl	(%rsi),%eax	/ return value is (*s1 - *--s2)
98	ret
99	SET_SIZE(_wcsncmp)
100
101	ENTRY(_wsncmp)
102	jmp	_wcsncmp	/ tail call into _wcsncmp
103	SET_SIZE(_wsncmp)
104