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