memcmp.S revision 1.6
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	RETGUARD_SETUP(memcmp, r11)
11	movq	%rdx,%rcx		/* compare by longs */
12	shrq	$3,%rcx
13	repe
14	cmpsq
15	jne	5f			/* do we match so far? */
16
17	movq	%rdx,%rcx		/* compare remainder by bytes */
18	andq	$7,%rcx
19	repe
20	cmpsb
21	jne	6f			/* do we match? */
22
23	xorl	%eax,%eax		/* we match, return zero	*/
24	jmp	7f
25
265:	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
316:	xorl	%eax,%eax		/* Perform unsigned comparison	*/
32	movb	-1(%rdi),%al
33	xorl	%edx,%edx
34	movb	-1(%rsi),%dl
35	subl    %edx,%eax
367:	RETGUARD_CHECK(memcmp, r11)
37	ret
38	lfence
39END(memcmp)
40