141808Sbostic/*- 2*61123Sbostic * Copyright (c) 1990, 1993 3*61123Sbostic * The Regents of the University of California. All rights reserved. 441808Sbostic * 541808Sbostic * This code is derived from software contributed to Berkeley by 641808Sbostic * the Systems Programming Group of the University of Utah Computer 741808Sbostic * Science Department. 841808Sbostic * 941808Sbostic * %sccs.include.redist.c% 1041808Sbostic */ 1141808Sbostic 1241808Sbostic#if defined(LIBC_SCCS) && !defined(lint) 13*61123Sbostic .asciz "@(#)bcmp.s 8.1 (Berkeley) 06/04/93" 1441808Sbostic#endif /* LIBC_SCCS and not lint */ 1541808Sbostic 1641808Sbostic/* bcmp(s1, s2, n) */ 1741808Sbostic 1841808Sbostic#include "DEFS.h" 1941808Sbostic 2041808Sbostic/* 2141808Sbostic * This is probably not the best we can do, but it is still 2-10 times 2241808Sbostic * faster than the C version in the portable gen directory. 2341808Sbostic * 2441808Sbostic * Things that might help: 2541808Sbostic * - longword align when possible (only on the 68020) 2641808Sbostic * - use nested DBcc instructions or use one and limit size to 64K 2741808Sbostic */ 2841808SbosticENTRY(bcmp) 2941808Sbostic movl sp@(4),a0 /* string 1 */ 3041808Sbostic movl sp@(8),a1 /* string 2 */ 3141808Sbostic movl sp@(12),d0 /* length */ 3241808Sbostic jeq bcdone /* if zero, nothing to do */ 3341808Sbostic movl a0,d1 3441808Sbostic btst #0,d1 /* string 1 address odd? */ 3541808Sbostic jeq bceven /* no, skip alignment */ 3641808Sbostic cmpmb a0@+,a1@+ /* yes, compare a byte */ 3741808Sbostic jne bcnoteq /* not equal, return non-zero */ 3841808Sbostic subql #1,d0 /* adjust count */ 3941808Sbostic jeq bcdone /* count 0, reutrn zero */ 4041808Sbosticbceven: 4141808Sbostic movl a1,d1 4241808Sbostic btst #0,d1 /* string 2 address odd? */ 4341808Sbostic jne bcbloop /* yes, no hope for alignment, compare bytes */ 4441808Sbostic movl d0,d1 /* no, both even */ 4541808Sbostic lsrl #2,d1 /* convert count to longword count */ 4641808Sbostic jeq bcbloop /* count 0, skip longword loop */ 4741808Sbosticbclloop: 4841808Sbostic cmpml a0@+,a1@+ /* compare a longword */ 4941808Sbostic jne bcnoteq /* not equal, return non-zero */ 5041808Sbostic subql #1,d1 /* adjust count */ 5141808Sbostic jne bclloop /* still more, keep comparing */ 5241808Sbostic andl #3,d0 /* what remains */ 5341808Sbostic jeq bcdone /* nothing, all done */ 5441808Sbosticbcbloop: 5541808Sbostic cmpmb a0@+,a1@+ /* compare a byte */ 5641808Sbostic jne bcnoteq /* not equal, return non-zero */ 5741808Sbostic subql #1,d0 /* adjust count */ 5841808Sbostic jne bcbloop /* still more, keep going */ 5941808Sbostic rts 6041808Sbosticbcnoteq: 6141808Sbostic moveq #1,d0 6241808Sbosticbcdone: 6341808Sbostic rts 64