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