Home | History | Annotate | Line # | Download | only in string
strncmp.S revision 1.5
      1 /*
      2  * Copyright (c) 1993 Winning Strategies, Inc.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *      This product includes software developed by Winning Strategies, Inc.
     16  * 4. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  *
     30  *	$Id: strncmp.S,v 1.5 1994/01/28 20:34:55 jtc Exp $
     31  */
     32 
     33 #if defined(LIBC_SCCS)
     34 	.text
     35 	.asciz "$Id: strncmp.S,v 1.5 1994/01/28 20:34:55 jtc Exp $"
     36 #endif
     37 
     38 #include "DEFS.h"
     39 
     40 /*
     41  * strncmp(s1, s2, n)
     42  *	return an integer greater than, equal to, or less than 0,
     43  *	according as the first n characters of string s1 is greater
     44  *	than, equal to, or less than the string s2.
     45  *
     46  * %eax - pointer to s1
     47  * %ecx - pointer to s2
     48  * %edx - length
     49  *
     50  * Written by:
     51  *	J.T. Conklin (jtc (at) wimsey.com), Winning Strategies, Inc.
     52  */
     53 
     54 /*
     55  * I've unrolled the loop eight times: large enough to make a
     56  * significant difference, and small enough not to totally trash the
     57  * cashe.
     58  */
     59 
     60 ENTRY(strncmp)
     61 	pushl	%ebx
     62 	movl	8(%esp),%eax
     63 	movl	12(%esp),%ecx
     64 	movl	16(%esp),%edx
     65 	jmp	L2			/* Jump into the loop! */
     66 
     67 	.align 2,0x90
     68 L1:	incl	%eax
     69 	incl	%ecx
     70 	decl	%edx
     71 L2:	testl	%edx,%edx		/* Have we compared n chars yet? */
     72 	jle	L4			/* Yes, strings are equal */
     73 	movb	(%eax),%bl
     74 	testb	%bl,%bl
     75 	je	L3
     76 	cmpb	%bl,(%ecx)
     77 	jne	L3
     78 	incl	%eax
     79 	incl	%ecx
     80 	decl	%edx
     81 	testl	%edx,%edx
     82 	jle	L4
     83 	movb	(%eax),%bl
     84 	testb	%bl,%bl
     85 	je	L3
     86 	cmpb	%bl,(%ecx)
     87 	jne	L3
     88 	incl	%eax
     89 	incl	%ecx
     90 	decl	%edx
     91 	testl	%edx,%edx
     92 	jle	L4
     93 	movb	(%eax),%bl
     94 	testb	%bl,%bl
     95 	je	L3
     96 	cmpb	%bl,(%ecx)
     97 	jne	L3
     98 	incl	%eax
     99 	incl	%ecx
    100 	decl	%edx
    101 	testl	%edx,%edx
    102 	jle	L4
    103 	movb	(%eax),%bl
    104 	testb	%bl,%bl
    105 	je	L3
    106 	cmpb	%bl,(%ecx)
    107 	jne	L3
    108 	incl	%eax
    109 	incl	%ecx
    110 	decl	%edx
    111 	testl	%edx,%edx
    112 	jle	L4
    113 	movb	(%eax),%bl
    114 	testb	%bl,%bl
    115 	je	L3
    116 	cmpb	%bl,(%ecx)
    117 	jne	L3
    118 	incl	%eax
    119 	incl	%ecx
    120 	decl	%edx
    121 	testl	%edx,%edx
    122 	jle	L4
    123 	movb	(%eax),%bl
    124 	testb	%bl,%bl
    125 	je	L3
    126 	cmpb	%bl,(%ecx)
    127 	jne	L3
    128 	incl	%eax
    129 	incl	%ecx
    130 	decl	%edx
    131 	testl	%edx,%edx
    132 	jle	L4
    133 	movb	(%eax),%bl
    134 	testb	%bl,%bl
    135 	je	L3
    136 	cmpb	%bl,(%ecx)
    137 	jne	L3
    138 	incl	%eax
    139 	incl	%ecx
    140 	decl	%edx
    141 	testl	%edx,%edx
    142 	jle	L4
    143 	movb	(%eax),%bl
    144 	testb	%bl,%bl
    145 	je	L3
    146 	cmpb	%bl,(%ecx)
    147 	je	L1
    148 	.align 2,0x90
    149 L3:	movsbl	(%eax),%eax		/* unsigned comparision */
    150 	movsbl	(%ecx),%ecx
    151 	subl	%ecx,%eax
    152 	popl	%ebx
    153 	ret
    154 	.align 2,0x90
    155 L4:	xorl	%eax,%eax
    156 	popl	%ebx
    157 	ret
    158