1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ralph Campbell. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#include <machine/machAsmDefs.h> 38 39#if defined(LIBC_SCCS) && !defined(lint) 40 ASMSTR("from: @(#)bcmp.s 8.1 (Berkeley) 6/4/93") 41 ASMSTR("$Id: bcmp.S,v 1.3 1994/12/15 17:24:57 mycroft Exp $") 42#endif /* LIBC_SCCS and not lint */ 43 44/* bcmp(s1, s2, n) */ 45 46#ifdef MIPSEL 47# define LWHI lwr 48# define LWLO lwl 49# define SWHI swr 50# define SWLO swl 51#endif 52#ifdef MIPSEB 53# define LWHI lwl 54# define LWLO lwr 55# define SWHI swl 56# define SWLO swr 57#endif 58 59LEAF(bcmp) 60 .set noreorder 61 blt a2, 16, small # is it worth any trouble? 62 xor v0, a0, a1 # compare low two bits of addresses 63 and v0, v0, 3 64 subu a3, zero, a1 # compute # bytes to word align address 65 bne v0, zero, unaligned # not possible to align addresses 66 and a3, a3, 3 67 68 beq a3, zero, 1f 69 subu a2, a2, a3 # subtract from remaining count 70 move v0, v1 # init v0,v1 so unmodified bytes match 71 LWHI v0, 0(a0) # read 1, 2, or 3 bytes 72 LWHI v1, 0(a1) 73 addu a1, a1, a3 74 bne v0, v1, nomatch 75 addu a0, a0, a3 761: 77 and a3, a2, ~3 # compute number of whole words left 78 subu a2, a2, a3 # which has to be >= (16-3) & ~3 79 addu a3, a3, a0 # compute ending address 802: 81 lw v0, 0(a0) # compare words 82 lw v1, 0(a1) 83 addu a0, a0, 4 84 bne v0, v1, nomatch 85 addu a1, a1, 4 86 bne a0, a3, 2b 87 nop 88 b small # finish remainder 89 nop 90unaligned: 91 beq a3, zero, 2f 92 subu a2, a2, a3 # subtract from remaining count 93 addu a3, a3, a0 # compute ending address 941: 95 lbu v0, 0(a0) # compare bytes until a1 word aligned 96 lbu v1, 0(a1) 97 addu a0, a0, 1 98 bne v0, v1, nomatch 99 addu a1, a1, 1 100 bne a0, a3, 1b 101 nop 1022: 103 and a3, a2, ~3 # compute number of whole words left 104 subu a2, a2, a3 # which has to be >= (16-3) & ~3 105 addu a3, a3, a0 # compute ending address 1063: 107 LWHI v0, 0(a0) # compare words a0 unaligned, a1 aligned 108 LWLO v0, 3(a0) 109 lw v1, 0(a1) 110 addu a0, a0, 4 111 bne v0, v1, nomatch 112 addu a1, a1, 4 113 bne a0, a3, 3b 114 nop 115small: 116 ble a2, zero, match 117 addu a3, a2, a0 # compute ending address 1181: 119 lbu v0, 0(a0) 120 lbu v1, 0(a1) 121 addu a0, a0, 1 122 bne v0, v1, nomatch 123 addu a1, a1, 1 124 bne a0, a3, 1b 125 nop 126match: 127 j ra 128 move v0, zero 129nomatch: 130 j ra 131 li v0, 1 132 .set reorder 133END(bcmp) 134