1/*	$OpenBSD: strncmp.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain.
5 */
6
7#include <machine/asm.h>
8
9/*
10 * NOTE: I've unrolled the loop eight times: large enough to make a
11 * significant difference, and small enough not to totally trash the
12 * cache.
13 */
14
15ENTRY(strncmp)
16	pushl	%ebx
17	movl	8(%esp),%eax
18	movl	12(%esp),%ecx
19	movl	16(%esp),%edx
20	testl	%edx,%edx
21	jmp	L2			/* Jump into the loop! */
22
23	.align 2,0x90
24L1:	incl	%eax
25	incl	%ecx
26	decl	%edx
27L2:	jz	L4			/* strings are equal */
28	movb	(%eax),%bl
29	testb	%bl,%bl
30	jz	L3
31	cmpb	%bl,(%ecx)
32	jne	L3
33
34	incl	%eax
35	incl	%ecx
36	decl	%edx
37	jz	L4
38	movb	(%eax),%bl
39	testb	%bl,%bl
40	jz	L3
41	cmpb	%bl,(%ecx)
42	jne	L3
43
44	incl	%eax
45	incl	%ecx
46	decl	%edx
47	jz	L4
48	movb	(%eax),%bl
49	testb	%bl,%bl
50	jz	L3
51	cmpb	%bl,(%ecx)
52	jne	L3
53
54	incl	%eax
55	incl	%ecx
56	decl	%edx
57	jz	L4
58	movb	(%eax),%bl
59	testb	%bl,%bl
60	jz	L3
61	cmpb	%bl,(%ecx)
62	jne	L3
63
64	incl	%eax
65	incl	%ecx
66	decl	%edx
67	jz	L4
68	movb	(%eax),%bl
69	testb	%bl,%bl
70	jz	L3
71	cmpb	%bl,(%ecx)
72	jne	L3
73
74	incl	%eax
75	incl	%ecx
76	decl	%edx
77	jz	L4
78	movb	(%eax),%bl
79	testb	%bl,%bl
80	jz	L3
81	cmpb	%bl,(%ecx)
82	jne	L3
83
84	incl	%eax
85	incl	%ecx
86	decl	%edx
87	jz	L4
88	movb	(%eax),%bl
89	testb	%bl,%bl
90	jz	L3
91	cmpb	%bl,(%ecx)
92	jne	L3
93
94	incl	%eax
95	incl	%ecx
96	decl	%edx
97	jz	L4
98	movb	(%eax),%bl
99	testb	%bl,%bl
100	jz	L3
101	cmpb	%bl,(%ecx)
102	je	L1
103
104	.align 2,0x90
105L3:	movzbl	(%eax),%eax		/* unsigned comparision */
106	movzbl	(%ecx),%ecx
107	subl	%ecx,%eax
108	popl	%ebx
109	ret
110	.align 2,0x90
111L4:	xorl	%eax,%eax
112	popl	%ebx
113	ret
114END(strncmp)
115