Home | History | Annotate | Download | only in string
      1 /*	$OpenBSD: memcmp.S,v 1.4 2005/08/07 11:30:38 espie Exp $ */
      2 /*
      3  * Written by J.T. Conklin <jtc (at) netbsd.org>.
      4  * Public domain.
      5  */
      6 
      7 #include <machine/asm.h>
      8 
      9 ENTRY(memcmp)
     10 	pushl	%edi
     11 	pushl	%esi
     12 	movl	12(%esp),%edi
     13 	movl	16(%esp),%esi
     14 	cld				/* set compare direction forward */
     15 
     16 	movl	20(%esp),%ecx		/* compare by words */
     17 	shrl	$2,%ecx
     18 	repe
     19 	cmpsl
     20 	jne	L5			/* do we match so far? */
     21 
     22 	movl	20(%esp),%ecx		/* compare remainder by bytes */
     23 	andl	$3,%ecx
     24 	repe
     25 	cmpsb
     26 	jne	L6			/* do we match? */
     27 
     28 	xorl	%eax,%eax		/* we match, return zero	*/
     29 	popl	%esi
     30 	popl	%edi
     31 	ret
     32 
     33 L5:	movl	$4,%ecx			/* We know that one of the next	*/
     34 	subl	%ecx,%edi		/* four pairs of bytes do not	*/
     35 	subl	%ecx,%esi		/* match.			*/
     36 	repe
     37 	cmpsb
     38 L6:	movzbl  -1(%edi),%eax		/* Perform unsigned comparison	*/
     39 	movzbl	-1(%esi),%edx
     40 	subl	%edx,%eax
     41 	popl	%esi
     42 	popl	%edi
     43 	ret
     44