/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* memcmp(s1, s2, len)
*
* Compare n bytes: s1>s2: >0 s1==s2: 0 s1<s2: <0
*
* Fast assembler language version of the following C-program for memcmp
* which represents the `standard' for the C-library.
*
* int
* memcmp(const void *s1, const void *s2, size_t n)
* {
* if (s1 != s2 && n != 0) {
* const char *ps1 = s1;
* const char *ps2 = s2;
* do {
* if (*ps1++ != *ps2++)
* return (ps1[-1] - ps2[-1]);
* } while (--n != 0);
* }
* return (NULL);
* }
*/
#include <sys/asm_linkage.h>
b,a .noteq
be,a 1f
b .noteq
b,a .noteq
b,a .noteq
srl %o4, 24, %o1 ! first byte
srl %o5, 24, %o2
cmp %o1, %o2
bne 1f
sll %o4, 8, %o4
sll %o5, 8, %o5
srl %o4, 24, %o1
srl %o5, 24, %o2
cmp %o1, %o2
bne 1f
sll %o4, 8, %o4
sll %o5, 8, %o5
srl %o4, 24, %o1
srl %o5, 24, %o2
cmp %o1, %o2
bne 1f
sll %o4, 8, %o4
sll %o5, 8, %o5
srl %o4, 24, %o1
srl %o5, 24, %o2
1:
ld [%sp + 68], %g2
retl
sub %o1, %o2, %o0 ! delay slot
.noteq:
ld [%sp + 68], %g2
retl ! strings aren't equal
.w3cmp:
bnz 2b
b .bytcmp
.w1cmp:
bnz 3b
b .bytcmp
.w2cmp:
bnz 4b
b .bytcmp
.w4cmp:
bnz,a 5b