1*52713Sbostic/*- 2*52713Sbostic * Copyright (c) 1991 The Regents of the University of California. 3*52713Sbostic * All rights reserved. 4*52713Sbostic * 5*52713Sbostic * This code is derived from software contributed to Berkeley by 6*52713Sbostic * Ralph Campbell. 7*52713Sbostic * 8*52713Sbostic * %sccs.include.redist.c% 9*52713Sbostic */ 10*52713Sbostic 11*52713Sbostic#if defined(LIBC_SCCS) && !defined(lint) 12*52713Sbostic ASMSTR("@(#)bcmp.s 5.1 (Berkeley) 02/29/92") 13*52713Sbostic#endif /* LIBC_SCCS and not lint */ 14*52713Sbostic 15*52713Sbostic#include "DEFS.h" 16*52713Sbostic 17*52713Sbostic/* bcmp(s1, s2, n) */ 18*52713Sbostic 19*52713SbosticLEAF(bcmp) 20*52713Sbostic .set noreorder 21*52713Sbostic blt a2, 16, small # is it worth any trouble? 22*52713Sbostic xor v0, a0, a1 # compare low two bits of addresses 23*52713Sbostic and v0, v0, 3 24*52713Sbostic subu a3, zero, a1 # compute # bytes to word align address 25*52713Sbostic bne v0, zero, unaligned # not possible to align addresses 26*52713Sbostic and a3, a3, 3 27*52713Sbostic 28*52713Sbostic beq a3, zero, 1f 29*52713Sbostic subu a2, a2, a3 # subtract from remaining count 30*52713Sbostic move v0, v1 # init v0,v1 so unmodified bytes match 31*52713Sbostic lwr v0, 0(a0) # read 1, 2, or 3 bytes 32*52713Sbostic lwr v1, 0(a1) 33*52713Sbostic addu a1, a1, a3 34*52713Sbostic bne v0, v1, nomatch 35*52713Sbostic addu a0, a0, a3 36*52713Sbostic1: 37*52713Sbostic and a3, a2, ~3 # compute number of whole words left 38*52713Sbostic subu a2, a2, a3 # which has to be >= (16-3) & ~3 39*52713Sbostic addu a3, a3, a0 # compute ending address 40*52713Sbostic2: 41*52713Sbostic lw v0, 0(a0) # compare words 42*52713Sbostic lw v1, 0(a1) 43*52713Sbostic addu a0, a0, 4 44*52713Sbostic bne v0, v1, nomatch 45*52713Sbostic addu a1, a1, 4 46*52713Sbostic bne a0, a3, 2b 47*52713Sbostic nop 48*52713Sbostic b small # finish remainder 49*52713Sbostic nop 50*52713Sbosticunaligned: 51*52713Sbostic beq a3, zero, 2f 52*52713Sbostic subu a2, a2, a3 # subtract from remaining count 53*52713Sbostic addu a3, a3, a0 # compute ending address 54*52713Sbostic1: 55*52713Sbostic lbu v0, 0(a0) # compare bytes until a1 word aligned 56*52713Sbostic lbu v1, 0(a1) 57*52713Sbostic addu a0, a0, 1 58*52713Sbostic bne v0, v1, nomatch 59*52713Sbostic addu a1, a1, 1 60*52713Sbostic bne a0, a3, 1b 61*52713Sbostic nop 62*52713Sbostic2: 63*52713Sbostic and a3, a2, ~3 # compute number of whole words left 64*52713Sbostic subu a2, a2, a3 # which has to be >= (16-3) & ~3 65*52713Sbostic addu a3, a3, a0 # compute ending address 66*52713Sbostic3: 67*52713Sbostic lwr v0, 0(a0) # compare words a0 unaligned, a1 aligned 68*52713Sbostic lwl v0, 3(a0) 69*52713Sbostic lw v1, 0(a1) 70*52713Sbostic addu a0, a0, 4 71*52713Sbostic bne v0, v1, nomatch 72*52713Sbostic addu a1, a1, 4 73*52713Sbostic bne a0, a3, 3b 74*52713Sbostic nop 75*52713Sbosticsmall: 76*52713Sbostic ble a2, zero, match 77*52713Sbostic addu a3, a2, a0 # compute ending address 78*52713Sbostic1: 79*52713Sbostic lbu v0, 0(a0) 80*52713Sbostic lbu v1, 0(a1) 81*52713Sbostic addu a0, a0, 1 82*52713Sbostic bne v0, v1, nomatch 83*52713Sbostic addu a1, a1, 1 84*52713Sbostic bne a0, a3, 1b 85*52713Sbostic nop 86*52713Sbosticmatch: 87*52713Sbostic j ra 88*52713Sbostic move v0, zero 89*52713Sbosticnomatch: 90*52713Sbostic j ra 91*52713Sbostic li v0, 1 92*52713Sbostic .set reorder 93*52713SbosticEND(bcmp) 94