152713Sbostic/*- 252713Sbostic * Copyright (c) 1991 The Regents of the University of California. 352713Sbostic * All rights reserved. 452713Sbostic * 552713Sbostic * This code is derived from software contributed to Berkeley by 652713Sbostic * Ralph Campbell. 752713Sbostic * 852713Sbostic * %sccs.include.redist.c% 952713Sbostic */ 1052713Sbostic 11*52737Sbostic#include "DEFS.h" 12*52737Sbostic 1352713Sbostic#if defined(LIBC_SCCS) && !defined(lint) 14*52737Sbostic ASMSTR("@(#)bcmp.s 5.2 (Berkeley) 02/29/92") 1552713Sbostic#endif /* LIBC_SCCS and not lint */ 1652713Sbostic 1752713Sbostic/* bcmp(s1, s2, n) */ 1852713Sbostic 1952713SbosticLEAF(bcmp) 2052713Sbostic .set noreorder 2152713Sbostic blt a2, 16, small # is it worth any trouble? 2252713Sbostic xor v0, a0, a1 # compare low two bits of addresses 2352713Sbostic and v0, v0, 3 2452713Sbostic subu a3, zero, a1 # compute # bytes to word align address 2552713Sbostic bne v0, zero, unaligned # not possible to align addresses 2652713Sbostic and a3, a3, 3 2752713Sbostic 2852713Sbostic beq a3, zero, 1f 2952713Sbostic subu a2, a2, a3 # subtract from remaining count 3052713Sbostic move v0, v1 # init v0,v1 so unmodified bytes match 3152713Sbostic lwr v0, 0(a0) # read 1, 2, or 3 bytes 3252713Sbostic lwr v1, 0(a1) 3352713Sbostic addu a1, a1, a3 3452713Sbostic bne v0, v1, nomatch 3552713Sbostic addu a0, a0, a3 3652713Sbostic1: 3752713Sbostic and a3, a2, ~3 # compute number of whole words left 3852713Sbostic subu a2, a2, a3 # which has to be >= (16-3) & ~3 3952713Sbostic addu a3, a3, a0 # compute ending address 4052713Sbostic2: 4152713Sbostic lw v0, 0(a0) # compare words 4252713Sbostic lw v1, 0(a1) 4352713Sbostic addu a0, a0, 4 4452713Sbostic bne v0, v1, nomatch 4552713Sbostic addu a1, a1, 4 4652713Sbostic bne a0, a3, 2b 4752713Sbostic nop 4852713Sbostic b small # finish remainder 4952713Sbostic nop 5052713Sbosticunaligned: 5152713Sbostic beq a3, zero, 2f 5252713Sbostic subu a2, a2, a3 # subtract from remaining count 5352713Sbostic addu a3, a3, a0 # compute ending address 5452713Sbostic1: 5552713Sbostic lbu v0, 0(a0) # compare bytes until a1 word aligned 5652713Sbostic lbu v1, 0(a1) 5752713Sbostic addu a0, a0, 1 5852713Sbostic bne v0, v1, nomatch 5952713Sbostic addu a1, a1, 1 6052713Sbostic bne a0, a3, 1b 6152713Sbostic nop 6252713Sbostic2: 6352713Sbostic and a3, a2, ~3 # compute number of whole words left 6452713Sbostic subu a2, a2, a3 # which has to be >= (16-3) & ~3 6552713Sbostic addu a3, a3, a0 # compute ending address 6652713Sbostic3: 6752713Sbostic lwr v0, 0(a0) # compare words a0 unaligned, a1 aligned 6852713Sbostic lwl v0, 3(a0) 6952713Sbostic lw v1, 0(a1) 7052713Sbostic addu a0, a0, 4 7152713Sbostic bne v0, v1, nomatch 7252713Sbostic addu a1, a1, 4 7352713Sbostic bne a0, a3, 3b 7452713Sbostic nop 7552713Sbosticsmall: 7652713Sbostic ble a2, zero, match 7752713Sbostic addu a3, a2, a0 # compute ending address 7852713Sbostic1: 7952713Sbostic lbu v0, 0(a0) 8052713Sbostic lbu v1, 0(a1) 8152713Sbostic addu a0, a0, 1 8252713Sbostic bne v0, v1, nomatch 8352713Sbostic addu a1, a1, 1 8452713Sbostic bne a0, a3, 1b 8552713Sbostic nop 8652713Sbosticmatch: 8752713Sbostic j ra 8852713Sbostic move v0, zero 8952713Sbosticnomatch: 9052713Sbostic j ra 9152713Sbostic li v0, 1 9252713Sbostic .set reorder 9352713SbosticEND(bcmp) 94