11.5Schs/* $NetBSD: memcmp.S,v 1.5 2013/09/07 19:06:29 chs Exp $ */ 21.1Schristos 31.1Schristos/*- 41.1Schristos * Copyright (c) 1990 The Regents of the University of California. 51.1Schristos * All rights reserved. 61.1Schristos * 71.1Schristos * This code is derived from software contributed to Berkeley by 81.1Schristos * the Systems Programming Group of the University of Utah Computer 91.1Schristos * Science Department. 101.1Schristos * 111.1Schristos * Redistribution and use in source and binary forms, with or without 121.1Schristos * modification, are permitted provided that the following conditions 131.1Schristos * are met: 141.1Schristos * 1. Redistributions of source code must retain the above copyright 151.1Schristos * notice, this list of conditions and the following disclaimer. 161.1Schristos * 2. Redistributions in binary form must reproduce the above copyright 171.1Schristos * notice, this list of conditions and the following disclaimer in the 181.1Schristos * documentation and/or other materials provided with the distribution. 191.1Schristos * 3. Neither the name of the University nor the names of its contributors 201.1Schristos * may be used to endorse or promote products derived from this software 211.1Schristos * without specific prior written permission. 221.1Schristos * 231.1Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241.1Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251.1Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261.1Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271.1Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281.1Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291.1Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.1Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.1Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.1Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.1Schristos * SUCH DAMAGE. 341.1Schristos */ 351.1Schristos 361.1Schristos#include <machine/asm.h> 371.1Schristos 381.1Schristos#if defined(LIBC_SCCS) && !defined(lint) 391.1Schristos#if 0 401.1Schristos RCSID("from: @(#)bcmp.s 5.1 (Berkeley) 5/12/90") 411.1Schristos#else 421.5Schs RCSID("$NetBSD: memcmp.S,v 1.5 2013/09/07 19:06:29 chs Exp $") 431.1Schristos#endif 441.1Schristos#endif /* LIBC_SCCS and not lint */ 451.1Schristos 461.1Schristos/* memcmp(s1, s2, n) */ 471.1Schristos 481.4Smatt#ifdef __mcoldfire__ 491.4Smatt#define CMPMB(a,b) movb b,%d2; cmpb a,%d2 501.4Smatt#define CMPMW(a,b) movw b,%d2; cmpw a,%d2 511.4Smatt#define CMPML(a,b) movl b,%d2; cmpl a,%d2 521.4Smatt#else 531.4Smatt#define CMPMB(a,b) cmpmb a,b 541.4Smatt#define CMPMW(a,b) cmpmw a,b 551.4Smatt#define CMPML(a,b) cmpml a,b 561.4Smatt#endif 571.4Smatt 581.1Schristos/* 591.1Schristos * This is probably not the best we can do, but it is still 2-10 times 601.1Schristos * faster than the C version in the portable gen directory. 611.1Schristos * 621.1Schristos * Things that might help: 631.1Schristos * - longword align when possible (only on the 68020) 641.1Schristos * - use nested DBcc instructions or use one and limit size to 64K 651.1Schristos */ 661.1SchristosENTRY(memcmp) 671.2Smatt movl 4(%sp),%a0 | string 1 681.2Smatt movl 8(%sp),%a1 | string 2 691.2Smatt movl 12(%sp),%d0 | length 701.4Smatt#ifdef __mcoldfire__ 711.4Smatt movl %d2,-(%sp) | save temp 721.4Smatt#endif 731.5Schs jeq .Lbcdone | if zero, nothing to do 741.1Schristos movl %a0,%d1 751.1Schristos btst #0,%d1 | string 1 address odd? 761.5Schs jeq .Lbceven | no, skip alignment 771.4Smatt CMPMB((%a0)+,(%a1)+) | yes, compare a byte 781.5Schs jne .Lbcnoteq | not equal, return non-zero 791.1Schristos subql #1,%d0 | adjust count 801.5Schs jeq .Lbcdone | count 0, reutrn zero 811.5Schs.Lbceven: 821.1Schristos movl %a1,%d1 831.1Schristos btst #0,%d1 | string 2 address odd? 841.5Schs jne .Lbcbloop | yes, no hope for alignment, compare bytes 851.1Schristos movl %d0,%d1 | no, both even 861.1Schristos lsrl #2,%d1 | convert count to longword count 871.5Schs jeq .Lbcbloop | count 0, skip longword loop 881.5Schs.Lbclloop: 891.4Smatt CMPML((%a0)+,(%a1)+) | compare a longword 901.5Schs jne .Lbcnoteql | not equal, return non-zero 911.1Schristos subql #1,%d1 | adjust count 921.5Schs jne .Lbclloop | still more, keep comparing 931.1Schristos andl #3,%d0 | what remains 941.5Schs jeq .Lbcdone | nothing, all done 951.5Schs.Lbcbloop: 961.4Smatt CMPMB((%a0)+,(%a1)+) | compare a byte 971.5Schs jne .Lbcnoteq | not equal, return non-zero 981.1Schristos subql #1,%d0 | adjust count 991.5Schs jne .Lbcbloop | still more, keep going 1001.1Schristos rts 1011.5Schs.Lbcnoteql: 1021.1Schristos subql #4,%a0 1031.1Schristos subql #4,%a1 1041.1Schristos movl #4,%d0 1051.5Schs jra .Lbcbloop 1061.5Schs.Lbcnoteq: 1071.1Schristos clrl %d0 1081.1Schristos clrl %d1 1091.2Smatt movb -(%a0),%d0 1101.2Smatt movb -(%a1),%d1 1111.1Schristos subl %d1,%d0 1121.5Schs.Lbcdone: 1131.4Smatt#ifdef __mcoldfire__ 1141.4Smatt movl (%sp)+,%sp | restore temp 1151.4Smatt#endif 1161.1Schristos rts 1171.3SmattEND(memcmp) 118