xref: /openbsd-src/lib/libc/arch/i386/string/memcmp.S (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#include <machine/asm.h>
7
8#if defined(LIBC_SCCS)
9	.text
10	.asciz "$OpenBSD: memcmp.S,v 1.3 1997/07/23 20:55:21 kstailey Exp $"
11#endif
12
13ENTRY(memcmp)
14	pushl	%edi
15	pushl	%esi
16	movl	12(%esp),%edi
17	movl	16(%esp),%esi
18	cld				/* set compare direction forward */
19
20	movl	20(%esp),%ecx		/* compare by words */
21	shrl	$2,%ecx
22	repe
23	cmpsl
24	jne	L5			/* do we match so far? */
25
26	movl	20(%esp),%ecx		/* compare remainder by bytes */
27	andl	$3,%ecx
28	repe
29	cmpsb
30	jne	L6			/* do we match? */
31
32	xorl	%eax,%eax		/* we match, return zero	*/
33	popl	%esi
34	popl	%edi
35	ret
36
37L5:	movl	$4,%ecx			/* We know that one of the next	*/
38	subl	%ecx,%edi		/* four pairs of bytes do not	*/
39	subl	%ecx,%esi		/* match.			*/
40	repe
41	cmpsb
42L6:	movzbl  -1(%edi),%eax		/* Perform unsigned comparison	*/
43	movzbl	-1(%esi),%edx
44	subl	%edx,%eax
45	popl	%esi
46	popl	%edi
47	ret
48