]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. | |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
22 | * | |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | ; | |
26 | #include <ppc/asm.h> | |
27 | #include <ppc/proc_reg.h> | |
28 | ; | |
29 | ; int bcmp(const void *LHS, const void *RHS, size_t len); | |
30 | ; | |
31 | ; Because bcmp returns zero if equal and nonzero otherwise, it is slightly | |
32 | ; faster than memcmp, which returns the difference between the first different | |
33 | ; bytes. | |
34 | ; r3 - LHS | |
35 | ; r4 - RHS | |
36 | ; r5 - len | |
37 | ||
38 | .align 5 | |
39 | .globl EXT(bcmp) | |
40 | LEXT(bcmp) | |
41 | ||
42 | cmpwi cr1,r5,6 ; six chars long? | |
43 | mr r6,r3 ; copy LHS ptr so we can use r3 as result | |
44 | mr. r3,r5 ; test length and move to r3 | |
45 | bgt cr1,Llong ; more than 6 chars long | |
46 | blt cr1,Lshort ; less than 6 | |
47 | ||
48 | ; most common operand length is 6 chars (enet addrs) | |
49 | ||
50 | lwz r8,0(r6) ; first 4 bytes of LHS | |
51 | lwz r7,0(r4) ; and RHS | |
52 | lhz r9,4(r6) ; next 2 of LHS | |
53 | sub. r3,r8,r7 ; compare first 4 | |
54 | bnelr ; first 4 differed (r3!=0) | |
55 | lhz r10,4(r4) ; next 2 of RHS | |
56 | sub r3,r9,r10 ; compare last 2 | |
57 | blr ; done, result in r3 | |
58 | ||
59 | ; handle long strings | |
60 | Llong: | |
61 | srwi r0,r5,2 ; r0 = word len | |
62 | mtctr r0 ; set up for loop | |
63 | Llongloop: | |
64 | lwz r8,0(r6) ; next 4 bytes from LHS | |
65 | addi r6,r6,4 | |
66 | lwz r7,0(r4) ; next 4 from RHS | |
67 | addi r4,r4,4 | |
68 | sub. r3,r8,r7 ; compare next 4 bytes | |
69 | bdnzt+ eq,Llongloop ; loop if ctr!=0 and cr0_eq | |
70 | bnelr ; done if not equal (r3!=0) | |
71 | ||
72 | andi. r5,r5,3 ; more to go? | |
73 | ||
74 | ; compare short strings (0-5 bytes long) | |
75 | ; r5 = length remaining | |
76 | ; cr0= set on length | |
77 | ; r3 = zero if length is zero | |
78 | Lshort: | |
79 | beqlr ; done (r3=0) | |
80 | mtctr r5 | |
81 | Lshortloop: | |
82 | lbz r8,0(r6) ; get next byte from LHS | |
83 | addi r6,r6,1 | |
84 | lbz r7,0(r4) ; and next byte from RHS | |
85 | addi r4,r4,1 | |
86 | sub. r3,r8,r7 ; compare | |
87 | bdnzt+ eq,Lshortloop ; loop if ctr!=0 and cr0_eq | |
88 | blr ; done, r3 set correctly by the subtract | |
89 |