Home | History | Annotate | Line # | Download | only in string
strncmp.S revision 1.3
      1  1.1  cgd /*
      2  1.1  cgd  * Copyright (c) 1993 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.1  cgd  *    derived from this software withough 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.3  jtc  *	$Id: strncmp.S,v 1.3 1993/10/21 01:40:42 jtc Exp $
     31  1.1  cgd  */
     32  1.1  cgd 
     33  1.3  jtc #if defined(LIBC_SCCS)
     34  1.1  cgd 	.text
     35  1.3  jtc 	.asciz "$Id: strncmp.S,v 1.3 1993/10/21 01:40:42 jtc Exp $"
     36  1.3  jtc #endif
     37  1.1  cgd 
     38  1.1  cgd #include "DEFS.h"
     39  1.1  cgd 
     40  1.1  cgd /*
     41  1.1  cgd  * strncmp(s1, s2, n)
     42  1.1  cgd  *	return an integer greater than, equal to, or less than 0,
     43  1.1  cgd  *	according as the first n characters of string s1 is greater
     44  1.1  cgd  *	than, equal to, or less than the string s2.
     45  1.1  cgd  *
     46  1.1  cgd  * %eax - pointer to s1
     47  1.1  cgd  * %ecx - pointer to s2
     48  1.1  cgd  * %edx - length
     49  1.1  cgd  *
     50  1.1  cgd  * Written by:
     51  1.1  cgd  *	J.T. Conklin (jtc (at) wimsey.com), Winning Strategies, Inc.
     52  1.1  cgd  */
     53  1.1  cgd 
     54  1.1  cgd /*
     55  1.1  cgd  * I've unrolled the loop eight times: large enough to make a
     56  1.1  cgd  * significant difference, and small enough not to totally trash the
     57  1.1  cgd  * cashe.
     58  1.1  cgd  */
     59  1.1  cgd 
     60  1.1  cgd ENTRY(strncmp)
     61  1.1  cgd 	pushl	%ebx
     62  1.1  cgd 	movl	8(%esp),%eax
     63  1.1  cgd 	movl	12(%esp),%ecx
     64  1.1  cgd 	movl	16(%esp),%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.1  cgd L2:	testl	%edx,%edx		/* Have we compared n chars yet? */
     72  1.1  cgd 	jle	L4			/* Yes, strings are equal */
     73  1.1  cgd 	movb	(%eax),%bl
     74  1.2  jtc 	testb	%bl,%bl
     75  1.1  cgd 	je	L3
     76  1.1  cgd 	cmpb	%bl,(%ecx)
     77  1.1  cgd 	jne	L3
     78  1.1  cgd 	incl	%eax
     79  1.1  cgd 	incl	%ecx
     80  1.1  cgd 	decl	%edx
     81  1.1  cgd 	testl	%edx,%edx
     82  1.1  cgd 	jle	L4
     83  1.1  cgd 	movb	(%eax),%bl
     84  1.2  jtc 	testb	%bl,%bl
     85  1.1  cgd 	je	L3
     86  1.1  cgd 	cmpb	%bl,(%ecx)
     87  1.1  cgd 	jne	L3
     88  1.1  cgd 	incl	%eax
     89  1.1  cgd 	incl	%ecx
     90  1.1  cgd 	decl	%edx
     91  1.1  cgd 	testl	%edx,%edx
     92  1.1  cgd 	jle	L4
     93  1.1  cgd 	movb	(%eax),%bl
     94  1.2  jtc 	testb	%bl,%bl
     95  1.1  cgd 	je	L3
     96  1.1  cgd 	cmpb	%bl,(%ecx)
     97  1.1  cgd 	jne	L3
     98  1.1  cgd 	incl	%eax
     99  1.1  cgd 	incl	%ecx
    100  1.1  cgd 	decl	%edx
    101  1.1  cgd 	testl	%edx,%edx
    102  1.1  cgd 	jle	L4
    103  1.1  cgd 	movb	(%eax),%bl
    104  1.2  jtc 	testb	%bl,%bl
    105  1.1  cgd 	je	L3
    106  1.1  cgd 	cmpb	%bl,(%ecx)
    107  1.1  cgd 	jne	L3
    108  1.1  cgd 	incl	%eax
    109  1.1  cgd 	incl	%ecx
    110  1.1  cgd 	decl	%edx
    111  1.1  cgd 	testl	%edx,%edx
    112  1.1  cgd 	jle	L4
    113  1.1  cgd 	movb	(%eax),%bl
    114  1.2  jtc 	testb	%bl,%bl
    115  1.1  cgd 	je	L3
    116  1.1  cgd 	cmpb	%bl,(%ecx)
    117  1.1  cgd 	jne	L3
    118  1.1  cgd 	incl	%eax
    119  1.1  cgd 	incl	%ecx
    120  1.1  cgd 	decl	%edx
    121  1.1  cgd 	testl	%edx,%edx
    122  1.1  cgd 	jle	L4
    123  1.1  cgd 	movb	(%eax),%bl
    124  1.2  jtc 	testb	%bl,%bl
    125  1.1  cgd 	je	L3
    126  1.1  cgd 	cmpb	%bl,(%ecx)
    127  1.1  cgd 	jne	L3
    128  1.1  cgd 	incl	%eax
    129  1.1  cgd 	incl	%ecx
    130  1.1  cgd 	decl	%edx
    131  1.1  cgd 	testl	%edx,%edx
    132  1.1  cgd 	jle	L4
    133  1.1  cgd 	movb	(%eax),%bl
    134  1.2  jtc 	testb	%bl,%bl
    135  1.1  cgd 	je	L3
    136  1.1  cgd 	cmpb	%bl,(%ecx)
    137  1.1  cgd 	jne	L3
    138  1.1  cgd 	incl	%eax
    139  1.1  cgd 	incl	%ecx
    140  1.1  cgd 	decl	%edx
    141  1.1  cgd 	testl	%edx,%edx
    142  1.1  cgd 	jle	L4
    143  1.1  cgd 	movb	(%eax),%bl
    144  1.2  jtc 	testb	%bl,%bl
    145  1.1  cgd 	je	L3
    146  1.1  cgd 	cmpb	%bl,(%ecx)
    147  1.1  cgd 	je	L1
    148  1.1  cgd 	.align 2,0x90
    149  1.1  cgd L3:	movsbl	(%eax),%eax		/* unsigned comparision */
    150  1.1  cgd 	movsbl	(%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