Home | History | Annotate | Line # | Download | only in string
strcmp.S revision 1.1.56.1
      1       1.1  christos /*
      2       1.1  christos  * Written by J.T. Conklin <jtc (at) acorntoolworks.com>
      3       1.1  christos  * Public domain.
      4       1.1  christos  */
      5       1.1  christos 
      6       1.1  christos #include <machine/asm.h>
      7       1.1  christos 
      8       1.1  christos #if defined(LIBC_SCCS)
      9  1.1.56.1       tls 	RCSID("$NetBSD: strcmp.S,v 1.1.56.1 2014/08/19 23:45:13 tls Exp $")
     10       1.1  christos #endif
     11       1.1  christos 
     12       1.1  christos ENTRY(strcmp)
     13       1.1  christos 	pushl	%esi
     14       1.1  christos 	pushl	%ebx
     15       1.1  christos 	movl	12(%esp),%ebx
     16       1.1  christos 	movl	16(%esp),%esi
     17       1.1  christos 
     18       1.1  christos 	/*
     19       1.1  christos 	 * Align s1 to word boundary.
     20       1.1  christos 	 * Consider unrolling loop?
     21       1.1  christos 	 */
     22       1.1  christos .Ls1align:
     23       1.1  christos 	testb	$3,%bl
     24       1.1  christos 	je	.Ls1aligned
     25       1.1  christos 	movb	(%ebx),%al
     26       1.1  christos 	incl	%ebx
     27       1.1  christos 	movb	(%esi),%dl
     28       1.1  christos 	incl	%esi
     29       1.1  christos 	testb	%al,%al
     30       1.1  christos 	je	.Ldone
     31       1.1  christos 	cmpb	%al,%dl
     32       1.1  christos 	je	.Ls1align
     33       1.1  christos 	jmp	.Ldone
     34       1.1  christos 
     35       1.1  christos 	/*
     36       1.1  christos 	 * Check whether s2 is aligned to a word boundary.  If it is, we
     37       1.1  christos 	 * can compare by words.  Otherwise we have to compare by bytes.
     38       1.1  christos 	 */
     39       1.1  christos .Ls1aligned:
     40       1.1  christos 	testl	$3,%esi
     41       1.1  christos 	jne	.Lbyte_loop
     42       1.1  christos 
     43       1.1  christos 	subl	$4,%ebx
     44       1.1  christos 	subl	$4,%esi
     45       1.1  christos 
     46       1.1  christos 	_ALIGN_TEXT
     47       1.1  christos .Lword_loop:
     48       1.1  christos 	movl	4(%ebx),%eax
     49       1.1  christos 	addl	$4,%ebx
     50       1.1  christos 	movl	4(%esi),%edx
     51       1.1  christos 	addl	$4,%esi
     52       1.1  christos 	cmpl	%eax,%edx
     53       1.1  christos 	jne	.Lbyte_loop
     54       1.1  christos 	subl	$0x01010101,%edx
     55       1.1  christos 	notl	%eax
     56       1.1  christos 	andl	%eax,%edx
     57       1.1  christos 	testl	$0x80808080,%edx
     58       1.1  christos 	je	.Lword_loop
     59       1.1  christos 
     60       1.1  christos 	_ALIGN_TEXT
     61       1.1  christos .Lbyte_loop:
     62       1.1  christos 	movb	(%ebx),%al
     63       1.1  christos 	incl	%ebx
     64       1.1  christos 	movb	(%esi),%dl
     65       1.1  christos 	incl	%esi
     66       1.1  christos 	testb	%al,%al
     67       1.1  christos 	je	.Ldone
     68       1.1  christos 	cmpb	%al,%dl
     69       1.1  christos 	je	.Lbyte_loop
     70       1.1  christos 
     71       1.1  christos .Ldone:
     72       1.1  christos 	movzbl	%al,%eax
     73       1.1  christos 	movzbl	%dl,%edx
     74       1.1  christos 	subl	%edx,%eax
     75       1.1  christos 	popl	%ebx
     76       1.1  christos 	popl	%esi
     77       1.1  christos 	ret
     78  1.1.56.1       tls END(strcmp)
     79