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