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