xref: /original-bsd/lib/libc/hp300/string/bcmp.s (revision c3e32dec)
1/*-
2 * Copyright (c) 1990, 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 * the Systems Programming Group of the University of Utah Computer
7 * Science Department.
8 *
9 * %sccs.include.redist.c%
10 */
11
12#if defined(LIBC_SCCS) && !defined(lint)
13	.asciz "@(#)bcmp.s	8.1 (Berkeley) 06/04/93"
14#endif /* LIBC_SCCS and not lint */
15
16/* bcmp(s1, s2, n) */
17
18#include "DEFS.h"
19
20/*
21 * This is probably not the best we can do, but it is still 2-10 times
22 * faster than the C version in the portable gen directory.
23 *
24 * Things that might help:
25 *	- longword align when possible (only on the 68020)
26 *	- use nested DBcc instructions or use one and limit size to 64K
27 */
28ENTRY(bcmp)
29	movl	sp@(4),a0	/* string 1 */
30	movl	sp@(8),a1	/* string 2 */
31	movl	sp@(12),d0	/* length */
32	jeq	bcdone		/* if zero, nothing to do */
33	movl	a0,d1
34	btst	#0,d1		/* string 1 address odd? */
35	jeq	bceven		/* no, skip alignment */
36	cmpmb	a0@+,a1@+	/* yes, compare a byte */
37	jne	bcnoteq		/* not equal, return non-zero */
38	subql	#1,d0		/* adjust count */
39	jeq	bcdone		/* count 0, reutrn zero */
40bceven:
41	movl	a1,d1
42	btst	#0,d1		/* string 2 address odd? */
43	jne	bcbloop		/* yes, no hope for alignment, compare bytes */
44	movl	d0,d1		/* no, both even */
45	lsrl	#2,d1		/* convert count to longword count */
46	jeq	bcbloop		/* count 0, skip longword loop */
47bclloop:
48	cmpml	a0@+,a1@+	/* compare a longword */
49	jne	bcnoteq		/* not equal, return non-zero */
50	subql	#1,d1		/* adjust count */
51	jne	bclloop		/* still more, keep comparing */
52	andl	#3,d0		/* what remains */
53	jeq	bcdone		/* nothing, all done */
54bcbloop:
55	cmpmb	a0@+,a1@+	/* compare a byte */
56	jne	bcnoteq		/* not equal, return non-zero */
57	subql	#1,d0		/* adjust count */
58	jne	bcbloop		/* still more, keep going */
59	rts
60bcnoteq:
61	moveq	#1,d0
62bcdone:
63	rts
64