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