xref: /netbsd-src/common/lib/libc/arch/i386/string/strcmp.S (revision 2c56941e163201dcb781df7fdeec6bd093647c91)
137c9f0a6Schristos/*
237c9f0a6Schristos * Written by J.T. Conklin <jtc@acorntoolworks.com>
337c9f0a6Schristos * Public domain.
437c9f0a6Schristos */
537c9f0a6Schristos
637c9f0a6Schristos#include <machine/asm.h>
737c9f0a6Schristos
837c9f0a6Schristos#if defined(LIBC_SCCS)
9*2c56941eSjakllsch	RCSID("$NetBSD: strcmp.S,v 1.2 2014/03/22 19:38:46 jakllsch Exp $")
1037c9f0a6Schristos#endif
1137c9f0a6Schristos
1237c9f0a6SchristosENTRY(strcmp)
1337c9f0a6Schristos	pushl	%esi
1437c9f0a6Schristos	pushl	%ebx
1537c9f0a6Schristos	movl	12(%esp),%ebx
1637c9f0a6Schristos	movl	16(%esp),%esi
1737c9f0a6Schristos
1837c9f0a6Schristos	/*
1937c9f0a6Schristos	 * Align s1 to word boundary.
2037c9f0a6Schristos	 * Consider unrolling loop?
2137c9f0a6Schristos	 */
2237c9f0a6Schristos.Ls1align:
2337c9f0a6Schristos	testb	$3,%bl
2437c9f0a6Schristos	je	.Ls1aligned
2537c9f0a6Schristos	movb	(%ebx),%al
2637c9f0a6Schristos	incl	%ebx
2737c9f0a6Schristos	movb	(%esi),%dl
2837c9f0a6Schristos	incl	%esi
2937c9f0a6Schristos	testb	%al,%al
3037c9f0a6Schristos	je	.Ldone
3137c9f0a6Schristos	cmpb	%al,%dl
3237c9f0a6Schristos	je	.Ls1align
3337c9f0a6Schristos	jmp	.Ldone
3437c9f0a6Schristos
3537c9f0a6Schristos	/*
3637c9f0a6Schristos	 * Check whether s2 is aligned to a word boundary.  If it is, we
3737c9f0a6Schristos	 * can compare by words.  Otherwise we have to compare by bytes.
3837c9f0a6Schristos	 */
3937c9f0a6Schristos.Ls1aligned:
4037c9f0a6Schristos	testl	$3,%esi
4137c9f0a6Schristos	jne	.Lbyte_loop
4237c9f0a6Schristos
4337c9f0a6Schristos	subl	$4,%ebx
4437c9f0a6Schristos	subl	$4,%esi
4537c9f0a6Schristos
4637c9f0a6Schristos	_ALIGN_TEXT
4737c9f0a6Schristos.Lword_loop:
4837c9f0a6Schristos	movl	4(%ebx),%eax
4937c9f0a6Schristos	addl	$4,%ebx
5037c9f0a6Schristos	movl	4(%esi),%edx
5137c9f0a6Schristos	addl	$4,%esi
5237c9f0a6Schristos	cmpl	%eax,%edx
5337c9f0a6Schristos	jne	.Lbyte_loop
5437c9f0a6Schristos	subl	$0x01010101,%edx
5537c9f0a6Schristos	notl	%eax
5637c9f0a6Schristos	andl	%eax,%edx
5737c9f0a6Schristos	testl	$0x80808080,%edx
5837c9f0a6Schristos	je	.Lword_loop
5937c9f0a6Schristos
6037c9f0a6Schristos	_ALIGN_TEXT
6137c9f0a6Schristos.Lbyte_loop:
6237c9f0a6Schristos	movb	(%ebx),%al
6337c9f0a6Schristos	incl	%ebx
6437c9f0a6Schristos	movb	(%esi),%dl
6537c9f0a6Schristos	incl	%esi
6637c9f0a6Schristos	testb	%al,%al
6737c9f0a6Schristos	je	.Ldone
6837c9f0a6Schristos	cmpb	%al,%dl
6937c9f0a6Schristos	je	.Lbyte_loop
7037c9f0a6Schristos
7137c9f0a6Schristos.Ldone:
7237c9f0a6Schristos	movzbl	%al,%eax
7337c9f0a6Schristos	movzbl	%dl,%edx
7437c9f0a6Schristos	subl	%edx,%eax
7537c9f0a6Schristos	popl	%ebx
7637c9f0a6Schristos	popl	%esi
7737c9f0a6Schristos	ret
78*2c56941eSjakllschEND(strcmp)
79