1e017c78wollman/*
2e017c78wollman * Copyright (c) 1993 Winning Strategies, Inc.
3e017c78wollman * All rights reserved.
4e017c78wollman *
5e017c78wollman * Redistribution and use in source and binary forms, with or without
6e017c78wollman * modification, are permitted provided that the following conditions
7e017c78wollman * are met:
8e017c78wollman * 1. Redistributions of source code must retain the above copyright
9e017c78wollman *    notice, this list of conditions and the following disclaimer.
10e017c78wollman * 2. Redistributions in binary form must reproduce the above copyright
11e017c78wollman *    notice, this list of conditions and the following disclaimer in the
12e017c78wollman *    documentation and/or other materials provided with the distribution.
13e017c78wollman * 3. All advertising materials mentioning features or use of this software
14e017c78wollman *    must display the following acknowledgement:
15e017c78wollman *      This product includes software developed by Winning Strategies, Inc.
16e017c78wollman * 4. The name of the author may not be used to endorse or promote products
17e017c78wollman *    derived from this software without specific prior written permission
18e017c78wollman *
19e017c78wollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20e017c78wollman * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21e017c78wollman * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22e017c78wollman * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23e017c78wollman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24e017c78wollman * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25e017c78wollman * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26e017c78wollman * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27e017c78wollman * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28e017c78wollman * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29e017c78wollman */
30e017c78wollman
31314a1d3peter#include <machine/asm.h>
32e6788c9obrien__FBSDID("$FreeBSD$");
33e017c78wollman
34e017c78wollman/*
35e017c78wollman * memcmp (void *b1, void *b2, size_t len)
36e017c78wollman *
37e017c78wollman * Written by:
38e017c78wollman *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
39e017c78wollman */
40e017c78wollman
41e017c78wollmanENTRY(memcmp)
42e017c78wollman	pushl	%edi
43e017c78wollman	pushl	%esi
44e017c78wollman	movl	12(%esp),%edi
45e017c78wollman	movl	16(%esp),%esi
46e017c78wollman	cld				/* set compare direction forward */
47e017c78wollman
48e017c78wollman	movl	20(%esp),%ecx		/* compare by words */
49e017c78wollman	shrl	$2,%ecx
50e017c78wollman	repe
51e017c78wollman	cmpsl
52e017c78wollman	jne	L5			/* do we match so far? */
53e017c78wollman
54e017c78wollman	movl	20(%esp),%ecx		/* compare remainder by bytes */
55e017c78wollman	andl	$3,%ecx
56e017c78wollman	repe
57e017c78wollman	cmpsb
58e017c78wollman	jne	L6			/* do we match? */
59e017c78wollman
60e017c78wollman	xorl	%eax,%eax		/* we match, return zero	*/
61e017c78wollman	popl	%esi
62e017c78wollman	popl	%edi
63e017c78wollman	ret
64e017c78wollman
65e017c78wollmanL5:	movl	$4,%ecx			/* We know that one of the next	*/
66e017c78wollman	subl	%ecx,%edi		/* four pairs of bytes do not	*/
67e017c78wollman	subl	%ecx,%esi		/* match.			*/
68e017c78wollman	repe
69e017c78wollman	cmpsb
70e017c78wollmanL6:	movzbl  -1(%edi),%eax		/* Perform unsigned comparison	*/
71e017c78wollman        movzbl  -1(%esi),%edx
72e017c78wollman        subl    %edx,%eax
73e017c78wollman	popl	%esi
74e017c78wollman	popl	%edi
75e017c78wollman	ret
763375b83peterEND(memcmp)
77a5e01ackib
78a5e01ackib	.section .note.GNU-stack,"",%progbits
79