]> git.saurik.com Git - apple/xnu.git/blame - libkern/ppc/bcmp.s
xnu-201.tar.gz
[apple/xnu.git] / libkern / ppc / bcmp.s
CommitLineData
0b4e3aa0
A
1/*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22;
23#include <ppc/asm.h>
24#include <ppc/proc_reg.h>
25;
26; int bcmp(const void *LHS, const void *RHS, size_t len);
27;
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
30; bytes.
31; r3 - LHS
32; r4 - RHS
33; r5 - len
34
35 .align 5
36 .globl EXT(bcmp)
37LEXT(bcmp)
38
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
44
45 ; most common operand length is 6 chars (enet addrs)
46
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
55
56 ; handle long strings
57Llong:
58 srwi r0,r5,2 ; r0 = word len
59 mtctr r0 ; set up for loop
60Llongloop:
61 lwz r8,0(r6) ; next 4 bytes from LHS
62 addi r6,r6,4
63 lwz r7,0(r4) ; next 4 from RHS
64 addi r4,r4,4
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)
68
69 andi. r5,r5,3 ; more to go?
70
71 ; compare short strings (0-5 bytes long)
72 ; r5 = length remaining
73 ; cr0= set on length
74 ; r3 = zero if length is zero
75Lshort:
76 beqlr ; done (r3=0)
77 mtctr r5
78Lshortloop:
79 lbz r8,0(r6) ; get next byte from LHS
80 addi r6,r6,1
81 lbz r7,0(r4) ; and next byte from RHS
82 addi r4,r4,1
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
86