xref: /dragonfly/lib/libc/x86_64/string/memcmp.S (revision ab23c864)
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 * $NetBSD: memcmp.S,v 1.2 2003/07/26 19:24:39 salo Exp $
7 * $FreeBSD: src/lib/libc/amd64/string/memcmp.S,v 1.2 2008/11/02 01:10:54 peter Exp $
8 */
9
10#include <machine/asm.h>
11
12#ifdef BCMP
13ENTRY(bcmp)
14#else
15ENTRY(memcmp)
16#endif
17	cld				/* set compare direction forward */
18	movq	%rdx,%rcx		/* compare by longs */
19	shrq	$3,%rcx
20	repe
21	cmpsq
22	jne	L5			/* do we match so far? */
23
24	movq	%rdx,%rcx		/* compare remainder by bytes */
25	andq	$7,%rcx
26	repe
27	cmpsb
28	jne	L6			/* do we match? */
29
30	xorl	%eax,%eax		/* we match, return zero	*/
31	ret
32
33L5:	movl	$8,%ecx			/* We know that one of the next	*/
34	subq	%rcx,%rdi		/* eight pairs of bytes do not	*/
35	subq	%rcx,%rsi		/* match.			*/
36	repe
37	cmpsb
38L6:	xorl	%eax,%eax		/* Perform unsigned comparison	*/
39	movb	-1(%rdi),%al
40	xorl	%edx,%edx
41	movb	-1(%rsi),%dl
42	subl	%edx,%eax
43	ret
44#ifdef BCMP
45END(bcmp)
46#else
47END(memcmp)
48#endif
49
50	.section .note.GNU-stack,"",%progbits
51