xref: /titanic_50/usr/src/lib/libc/i386/gen/strncmp.s (revision c51cb4bc539e1650eb5bb4f805cc779bfce99c06)
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 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26	.file	"strncmp.s"
27
28#include "SYS.h"
29
30	ENTRY(strncmp)
31	pushl	%esi		/ save register variables
32	movl	8(%esp),%esi	/ %esi = first string
33	movl	%edi,%edx
34	movl	12(%esp),%edi	/ %edi = second string
35	cmpl	%esi,%edi	/ same string?
36	je	.equal
37	movl	16(%esp),%ecx	/ %ecx = length
38	incl	%ecx		/ will later predecrement this uint
39.loop:
40	decl	%ecx
41	je	.equal		/ Used all n chars?
42	movb	(%esi),%al	/ slodb ; scab
43	cmpb	(%edi),%al
44	jne	.notequal_0	/ Are the bytes equal?
45	testb	%al,%al
46	je	.equal		/ End of string?
47
48	decl	%ecx
49	je	.equal		/ Used all n chars?
50	movb	1(%esi),%al	/ slodb ; scab
51	cmpb	1(%edi),%al
52	jne	.notequal_1	/ Are the bytes equal?
53	testb	%al,%al
54	je	.equal		/ End of string?
55
56	decl	%ecx
57	je	.equal		/ Used all n chars?
58	movb	2(%esi),%al	/ slodb ; scab
59	cmpb	2(%edi),%al
60	jne	.notequal_2	/ Are the bytes equal?
61	testb	%al,%al
62	je	.equal		/ End of string?
63
64	decl	%ecx
65	je	.equal		/ Used all n chars?
66	movb	3(%esi),%al	/ slodb ; scab
67	cmpb	3(%edi),%al
68	jne	.notequal_3	/ Are the bytes equal?
69	addl	$4,%esi
70	addl	$4,%edi
71	testb	%al,%al
72	jne	.loop		/ End of string?
73
74.equal:
75	popl	%esi		/ restore registers
76	xorl	%eax,%eax	/ return 0
77	movl	%edx,%edi
78	ret
79
80	.align	4
81.notequal_3:
82	incl	%edi
83.notequal_2:
84	incl	%edi
85.notequal_1:
86	incl	%edi
87.notequal_0:
88	popl	%esi		/ restore registers
89	clc			/ clear carry bit
90	subb	(%edi),%al
91	movl	%edx,%edi
92	movl	$-1, %eax	/ possibly wasted instr
93	jc	.neg		/ did we overflow in the sub
94	movl	$1, %eax	/ if not a > b
95.neg:
96	ret
97	SET_SIZE(strncmp)
98