memcmp.S revision 1.3
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	movq	%rdx,%rcx		/* compare by longs */
11	shrq	$3,%rcx
12	repe
13	cmpsq
14	jne	L5			/* do we match so far? */
15
16	movq	%rdx,%rcx		/* compare remainder by bytes */
17	andq	$7,%rcx
18	repe
19	cmpsb
20	jne	L6			/* do we match? */
21
22	xorl	%eax,%eax		/* we match, return zero	*/
23	ret
24
25L5:	movl	$8,%ecx			/* We know that one of the next	*/
26	subq	%rcx,%rdi		/* eight pairs of bytes do not	*/
27	subq	%rcx,%rsi		/* match.			*/
28	repe
29	cmpsb
30L6:	xorl	%eax,%eax		/* Perform unsigned comparison	*/
31	movb	-1(%rdi),%al
32	xorl	%edx,%edx
33	movb	-1(%rsi),%dl
34	subl    %edx,%eax
35	ret
36