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