152713Sbostic/*- 2*61146Sbostic * Copyright (c) 1991, 1993 3*61146Sbostic * The Regents of the University of California. 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 1155708Sralph#include <machine/machAsmDefs.h> 1252737Sbostic 1352713Sbostic#if defined(LIBC_SCCS) && !defined(lint) 14*61146Sbostic ASMSTR("@(#)bcmp.s 8.1 (Berkeley) 06/04/93") 1552713Sbostic#endif /* LIBC_SCCS and not lint */ 1652713Sbostic 1752713Sbostic/* bcmp(s1, s2, n) */ 1852713Sbostic 1958124Sralph#ifdef MIPSEL 2054155Sralph# define LWHI lwr 2154155Sralph# define LWLO lwl 2254155Sralph# define SWHI swr 2354155Sralph# define SWLO swl 2454155Sralph#endif 2558124Sralph#ifdef MIPSEB 2654155Sralph# define LWHI lwl 2754155Sralph# define LWLO lwr 2854155Sralph# define SWHI swl 2954155Sralph# define SWLO swr 3054155Sralph#endif 3154155Sralph 3252713SbosticLEAF(bcmp) 3352713Sbostic .set noreorder 3452713Sbostic blt a2, 16, small # is it worth any trouble? 3552713Sbostic xor v0, a0, a1 # compare low two bits of addresses 3652713Sbostic and v0, v0, 3 3752713Sbostic subu a3, zero, a1 # compute # bytes to word align address 3852713Sbostic bne v0, zero, unaligned # not possible to align addresses 3952713Sbostic and a3, a3, 3 4052713Sbostic 4152713Sbostic beq a3, zero, 1f 4252713Sbostic subu a2, a2, a3 # subtract from remaining count 4352713Sbostic move v0, v1 # init v0,v1 so unmodified bytes match 4454155Sralph LWHI v0, 0(a0) # read 1, 2, or 3 bytes 4554155Sralph LWHI v1, 0(a1) 4652713Sbostic addu a1, a1, a3 4752713Sbostic bne v0, v1, nomatch 4852713Sbostic addu a0, a0, a3 4952713Sbostic1: 5052713Sbostic and a3, a2, ~3 # compute number of whole words left 5152713Sbostic subu a2, a2, a3 # which has to be >= (16-3) & ~3 5252713Sbostic addu a3, a3, a0 # compute ending address 5352713Sbostic2: 5452713Sbostic lw v0, 0(a0) # compare words 5552713Sbostic lw v1, 0(a1) 5652713Sbostic addu a0, a0, 4 5752713Sbostic bne v0, v1, nomatch 5852713Sbostic addu a1, a1, 4 5952713Sbostic bne a0, a3, 2b 6052713Sbostic nop 6152713Sbostic b small # finish remainder 6252713Sbostic nop 6352713Sbosticunaligned: 6452713Sbostic beq a3, zero, 2f 6552713Sbostic subu a2, a2, a3 # subtract from remaining count 6652713Sbostic addu a3, a3, a0 # compute ending address 6752713Sbostic1: 6852713Sbostic lbu v0, 0(a0) # compare bytes until a1 word aligned 6952713Sbostic lbu v1, 0(a1) 7052713Sbostic addu a0, a0, 1 7152713Sbostic bne v0, v1, nomatch 7252713Sbostic addu a1, a1, 1 7352713Sbostic bne a0, a3, 1b 7452713Sbostic nop 7552713Sbostic2: 7652713Sbostic and a3, a2, ~3 # compute number of whole words left 7752713Sbostic subu a2, a2, a3 # which has to be >= (16-3) & ~3 7852713Sbostic addu a3, a3, a0 # compute ending address 7952713Sbostic3: 8054155Sralph LWHI v0, 0(a0) # compare words a0 unaligned, a1 aligned 8154155Sralph LWLO v0, 3(a0) 8252713Sbostic lw v1, 0(a1) 8352713Sbostic addu a0, a0, 4 8452713Sbostic bne v0, v1, nomatch 8552713Sbostic addu a1, a1, 4 8652713Sbostic bne a0, a3, 3b 8752713Sbostic nop 8852713Sbosticsmall: 8952713Sbostic ble a2, zero, match 9052713Sbostic addu a3, a2, a0 # compute ending address 9152713Sbostic1: 9252713Sbostic lbu v0, 0(a0) 9352713Sbostic lbu v1, 0(a1) 9452713Sbostic addu a0, a0, 1 9552713Sbostic bne v0, v1, nomatch 9652713Sbostic addu a1, a1, 1 9752713Sbostic bne a0, a3, 1b 9852713Sbostic nop 9952713Sbosticmatch: 10052713Sbostic j ra 10152713Sbostic move v0, zero 10252713Sbosticnomatch: 10352713Sbostic j ra 10452713Sbostic li v0, 1 10552713Sbostic .set reorder 10652713SbosticEND(bcmp) 107