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