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