xref: /original-bsd/lib/libc/mips/string/bcmp.s (revision 3b6250d9)
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * 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 "DEFS.h"
12
13#if defined(LIBC_SCCS) && !defined(lint)
14	ASMSTR("@(#)bcmp.s	5.2 (Berkeley) 02/29/92")
15#endif /* LIBC_SCCS and not lint */
16
17/* bcmp(s1, s2, n) */
18
19LEAF(bcmp)
20	.set	noreorder
21	blt	a2, 16, small		# is it worth any trouble?
22	xor	v0, a0, a1		# compare low two bits of addresses
23	and	v0, v0, 3
24	subu	a3, zero, a1		# compute # bytes to word align address
25	bne	v0, zero, unaligned	# not possible to align addresses
26	and	a3, a3, 3
27
28	beq	a3, zero, 1f
29	subu	a2, a2, a3		# subtract from remaining count
30	move	v0, v1			# init v0,v1 so unmodified bytes match
31	lwr	v0, 0(a0)		# read 1, 2, or 3 bytes
32	lwr	v1, 0(a1)
33	addu	a1, a1, a3
34	bne	v0, v1, nomatch
35	addu	a0, a0, a3
361:
37	and	a3, a2, ~3		# compute number of whole words left
38	subu	a2, a2, a3		#   which has to be >= (16-3) & ~3
39	addu	a3, a3, a0		# compute ending address
402:
41	lw	v0, 0(a0)		# compare words
42	lw	v1, 0(a1)
43	addu	a0, a0, 4
44	bne	v0, v1, nomatch
45	addu	a1, a1, 4
46	bne	a0, a3, 2b
47	nop
48	b	small			# finish remainder
49	nop
50unaligned:
51	beq	a3, zero, 2f
52	subu	a2, a2, a3		# subtract from remaining count
53	addu	a3, a3, a0		# compute ending address
541:
55	lbu	v0, 0(a0)		# compare bytes until a1 word aligned
56	lbu	v1, 0(a1)
57	addu	a0, a0, 1
58	bne	v0, v1, nomatch
59	addu	a1, a1, 1
60	bne	a0, a3, 1b
61	nop
622:
63	and	a3, a2, ~3		# compute number of whole words left
64	subu	a2, a2, a3		#   which has to be >= (16-3) & ~3
65	addu	a3, a3, a0		# compute ending address
663:
67	lwr	v0, 0(a0)		# compare words a0 unaligned, a1 aligned
68	lwl	v0, 3(a0)
69	lw	v1, 0(a1)
70	addu	a0, a0, 4
71	bne	v0, v1, nomatch
72	addu	a1, a1, 4
73	bne	a0, a3, 3b
74	nop
75small:
76	ble	a2, zero, match
77	addu	a3, a2, a0		# compute ending address
781:
79	lbu	v0, 0(a0)
80	lbu	v1, 0(a1)
81	addu	a0, a0, 1
82	bne	v0, v1, nomatch
83	addu	a1, a1, 1
84	bne	a0, a3, 1b
85	nop
86match:
87	j	ra
88	move	v0, zero
89nomatch:
90	j	ra
91	li	v0, 1
92	.set	reorder
93END(bcmp)
94