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