xref: /dragonfly/sys/platform/pc64/x86_64/memcmp.s (revision 88ed2a5c)
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#include <machine/asmacros.h>
10#include <machine/pmap.h>
11
12#include "assym.s"
13
14	ALIGN_DATA
15
16	.text
17
18#ifdef BCMP
19ENTRY(bcmp)
20#else
21ENTRY(memcmp)
22#endif
23	cld				/* set compare direction forward */
24	movq	%rdx,%rcx		/* compare by longs */
25	shrq	$3,%rcx
26	repe
27	cmpsq
28	jne	L5			/* do we match so far? */
29
30	movq	%rdx,%rcx		/* compare remainder by bytes */
31	andq	$7,%rcx
32	repe
33	cmpsb
34	jne	L6			/* do we match? */
35
36	xorl	%eax,%eax		/* we match, return zero	*/
37	ret
38
39L5:	movl	$8,%ecx			/* We know that one of the next	*/
40	subq	%rcx,%rdi		/* eight pairs of bytes do not	*/
41	subq	%rcx,%rsi		/* match.			*/
42	repe
43	cmpsb
44L6:	xorl	%eax,%eax		/* Perform unsigned comparison	*/
45	movb	-1(%rdi),%al
46	xorl	%edx,%edx
47	movb	-1(%rsi),%dl
48	subl	%edx,%eax
49	ret
50#ifdef BCMP
51END(bcmp)
52#else
53END(memcmp)
54#endif
55