bcmp.S revision 1.1
1/* $NetBSD: bcmp.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */ 2 3/*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by J.T. Conklin. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39/*- 40 * Copyright (c) 1990 The Regents of the University of California. 41 * All rights reserved. 42 * 43 * This code is derived from software contributed to Berkeley by 44 * the Systems Programming Group of the University of Utah Computer 45 * Science Department. 46 * 47 * Redistribution and use in source and binary forms, with or without 48 * modification, are permitted provided that the following conditions 49 * are met: 50 * 1. Redistributions of source code must retain the above copyright 51 * notice, this list of conditions and the following disclaimer. 52 * 2. Redistributions in binary form must reproduce the above copyright 53 * notice, this list of conditions and the following disclaimer in the 54 * documentation and/or other materials provided with the distribution. 55 * 3. Neither the name of the University nor the names of its contributors 56 * may be used to endorse or promote products derived from this software 57 * without specific prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 */ 71 72#include <machine/asm.h> 73 74#if defined(LIBC_SCCS) && !defined(lint) 75#if 0 76 RCSID("from: @(#)bcmp.s 5.1 (Berkeley) 5/12/90") 77#else 78 RCSID("$NetBSD: bcmp.S,v 1.1 2005/12/20 19:28:49 christos Exp $") 79#endif 80#endif /* LIBC_SCCS and not lint */ 81 82ENTRY(bcmp) 83 movl %sp@(4),%a0 | string 1 84 movl %sp@(8),%a1 | string 2 85 movl %sp@(12),%d1 | length 86 87 /* 88 * It isn't worth the overhead of aligning to {long}word boundries 89 * if the string is too short. 90 */ 91 cmpl #8,%d1 92 jlt Lbcbyte 93 94#ifdef __mc68010__ 95 /* 96 * The 68010 cannot access a word or long on an odd boundary, 97 * period. If the source and the destination addresses aren't 98 * of the same evenness, we're forced to do a bytewise compare. 99 */ 100 movl %a0,%d0 101 addl %a1,%d0 102 btst #0,%d0 103 jne Lbcbyte 104#endif /* __mc68010__ */ 105 106 /* word align */ 107 movl %a0,%d0 108 btst #0,%d0 109 jeq Lbcalgndw 110 cmpmb %a0@+,%a1@+ 111 jne Lbcnoteq 112 subql #1,%d1 113Lbcalgndw: 114 /* long word align */ 115 btst #1,%d0 116 jeq Lbcalgndl 117 cmpmw %a0@+,%a1@+ 118 jne Lbcnoteq 119 subql #2,%d1 120Lbcalgndl: 121 /* compare by 8 longwords */ 122 movl %d1,%d0 123 lsrl #5,%d0 | cnt = len / 32 124 jeq Lbclong | if (cnt) 125 andl #31,%d1 | len %= 32 126 subql #1,%d0 | set up for dbf 127Lbc32loop: 128 cmpml %a0@+,%a1@+ | compare 8 longwords 129 jne Lbcnoteq | not equal, return non-zero 130 cmpml %a0@+,%a1@+ 131 jne Lbcnoteq 132 cmpml %a0@+,%a1@+ 133 jne Lbcnoteq 134 cmpml %a0@+,%a1@+ 135 jne Lbcnoteq 136 cmpml %a0@+,%a1@+ 137 jne Lbcnoteq 138 cmpml %a0@+,%a1@+ 139 jne Lbcnoteq 140 cmpml %a0@+,%a1@+ 141 jne Lbcnoteq 142 cmpml %a0@+,%a1@+ 143 jne Lbcnoteq 144 dbf %d0,Lbc32loop | till done 145 clrw %d0 146 subql #1,%d0 147 jcc Lbc32loop 148 149Lbclong: 150 /* compare by longwords */ 151 movl %d1,%d0 152 lsrl #2,%d0 | cnt = len / 4 153 jeq Lbcbyte | if (cnt) 154 subql #1,%d0 | set up for dbf 155Lbclloop: 156 cmpml %a0@+,%a1@+ | compare a longword 157 jne Lbcnoteq | not equal, return non-zero 158 dbf %d0,Lbclloop | till done 159 andl #3,%d1 | len %= 4 160 jeq Lbcdone 161 162 subql #1,%d1 | set up for dbf 163Lbcbloop: 164 cmpmb %a0@+,%a1@+ | compare a byte 165 jne Lbcnoteq | not equal, return non-zero 166Lbcbyte: 167 dbf %d1,Lbcbloop 168Lbcdone: 169 movql #0,%d0 170 rts 171 172Lbcnoteq: 173 movql #1,%d0 174 rts 175