memcmp.S revision 1.2
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
5 */
6
7#include <machine/asm.h>
8
9ENTRY(memcmp)
10	cld				/* set compare direction forward */
11	movq	%rdx,%rcx		/* compare by longs */
12	shrq	$3,%rcx
13	repe
14	cmpsq
15	jne	L5			/* do we match so far? */
16
17	movq	%rdx,%rcx		/* compare remainder by bytes */
18	andq	$7,%rcx
19	repe
20	cmpsb
21	jne	L6			/* do we match? */
22
23	xorl	%eax,%eax		/* we match, return zero	*/
24	ret
25
26L5:	movl	$8,%ecx			/* We know that one of the next	*/
27	subq	%rcx,%rdi		/* eight pairs of bytes do not	*/
28	subq	%rcx,%rsi		/* match.			*/
29	repe
30	cmpsb
31L6:	xorl	%eax,%eax		/* Perform unsigned comparison	*/
32	movb	-1(%rdi),%al
33	xorl	%edx,%edx
34	movb	-1(%rsi),%dl
35	subl    %edx,%eax
36	ret
37