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