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 * %sccs.include.redist.c% 9 */ 10 11#include <machine/machAsmDefs.h> 12 13#if defined(LIBC_SCCS) && !defined(lint) 14 ASMSTR("@(#)bcmp.s 8.1 (Berkeley) 06/04/93") 15#endif /* LIBC_SCCS and not lint */ 16 17/* bcmp(s1, s2, n) */ 18 19#ifdef MIPSEL 20# define LWHI lwr 21# define LWLO lwl 22# define SWHI swr 23# define SWLO swl 24#endif 25#ifdef MIPSEB 26# define LWHI lwl 27# define LWLO lwr 28# define SWHI swl 29# define SWLO swr 30#endif 31 32LEAF(bcmp) 33 .set noreorder 34 blt a2, 16, small # is it worth any trouble? 35 xor v0, a0, a1 # compare low two bits of addresses 36 and v0, v0, 3 37 subu a3, zero, a1 # compute # bytes to word align address 38 bne v0, zero, unaligned # not possible to align addresses 39 and a3, a3, 3 40 41 beq a3, zero, 1f 42 subu a2, a2, a3 # subtract from remaining count 43 move v0, v1 # init v0,v1 so unmodified bytes match 44 LWHI v0, 0(a0) # read 1, 2, or 3 bytes 45 LWHI v1, 0(a1) 46 addu a1, a1, a3 47 bne v0, v1, nomatch 48 addu a0, a0, a3 491: 50 and a3, a2, ~3 # compute number of whole words left 51 subu a2, a2, a3 # which has to be >= (16-3) & ~3 52 addu a3, a3, a0 # compute ending address 532: 54 lw v0, 0(a0) # compare words 55 lw v1, 0(a1) 56 addu a0, a0, 4 57 bne v0, v1, nomatch 58 addu a1, a1, 4 59 bne a0, a3, 2b 60 nop 61 b small # finish remainder 62 nop 63unaligned: 64 beq a3, zero, 2f 65 subu a2, a2, a3 # subtract from remaining count 66 addu a3, a3, a0 # compute ending address 671: 68 lbu v0, 0(a0) # compare bytes until a1 word aligned 69 lbu v1, 0(a1) 70 addu a0, a0, 1 71 bne v0, v1, nomatch 72 addu a1, a1, 1 73 bne a0, a3, 1b 74 nop 752: 76 and a3, a2, ~3 # compute number of whole words left 77 subu a2, a2, a3 # which has to be >= (16-3) & ~3 78 addu a3, a3, a0 # compute ending address 793: 80 LWHI v0, 0(a0) # compare words a0 unaligned, a1 aligned 81 LWLO v0, 3(a0) 82 lw v1, 0(a1) 83 addu a0, a0, 4 84 bne v0, v1, nomatch 85 addu a1, a1, 4 86 bne a0, a3, 3b 87 nop 88small: 89 ble a2, zero, match 90 addu a3, a2, a0 # compute ending address 911: 92 lbu v0, 0(a0) 93 lbu v1, 0(a1) 94 addu a0, a0, 1 95 bne v0, v1, nomatch 96 addu a1, a1, 1 97 bne a0, a3, 1b 98 nop 99match: 100 j ra 101 move v0, zero 102nomatch: 103 j ra 104 li v0, 1 105 .set reorder 106END(bcmp) 107