2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 #include <ppc/proc_reg.h>
26 ; int bcmp(const void *LHS, const void *RHS, size_t len);
28 ; Because bcmp returns zero if equal and nonzero otherwise, it is slightly
29 ; faster than memcmp, which returns the difference between the first different
39 cmpwi cr1,r5,6 ; six chars long?
40 mr r6,r3 ; copy LHS ptr so we can use r3 as result
41 mr. r3,r5 ; test length and move to r3
42 bgt cr1,Llong ; more than 6 chars long
43 blt cr1,Lshort ; less than 6
45 ; most common operand length is 6 chars (enet addrs)
47 lwz r8,0(r6) ; first 4 bytes of LHS
48 lwz r7,0(r4) ; and RHS
49 lhz r9,4(r6) ; next 2 of LHS
50 sub. r3,r8,r7 ; compare first 4
51 bnelr ; first 4 differed (r3!=0)
52 lhz r10,4(r4) ; next 2 of RHS
53 sub r3,r9,r10 ; compare last 2
54 blr ; done, result in r3
58 srwi r0,r5,2 ; r0 = word len
59 mtctr r0 ; set up for loop
61 lwz r8,0(r6) ; next 4 bytes from LHS
63 lwz r7,0(r4) ; next 4 from RHS
65 sub. r3,r8,r7 ; compare next 4 bytes
66 bdnzt+ eq,Llongloop ; loop if ctr!=0 and cr0_eq
67 bnelr ; done if not equal (r3!=0)
69 andi. r5,r5,3 ; more to go?
71 ; compare short strings (0-5 bytes long)
72 ; r5 = length remaining
74 ; r3 = zero if length is zero
79 lbz r8,0(r6) ; get next byte from LHS
81 lbz r7,0(r4) ; and next byte from RHS
83 sub. r3,r8,r7 ; compare
84 bdnzt+ eq,Lshortloop ; loop if ctr!=0 and cr0_eq
85 blr ; done, r3 set correctly by the subtract