xref: /minix3/common/lib/libc/arch/m68k/string/memcmp.S (revision b6cbf7203b080219de306404f8022a65b7884f33)
1*b6cbf720SGianluca Guida/*	$NetBSD: memcmp.S,v 1.1 2005/12/20 19:28:49 christos Exp $	*/
2*b6cbf720SGianluca Guida
3*b6cbf720SGianluca Guida/*-
4*b6cbf720SGianluca Guida * Copyright (c) 1990 The Regents of the University of California.
5*b6cbf720SGianluca Guida * All rights reserved.
6*b6cbf720SGianluca Guida *
7*b6cbf720SGianluca Guida * This code is derived from software contributed to Berkeley by
8*b6cbf720SGianluca Guida * the Systems Programming Group of the University of Utah Computer
9*b6cbf720SGianluca Guida * Science Department.
10*b6cbf720SGianluca Guida *
11*b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without
12*b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions
13*b6cbf720SGianluca Guida * are met:
14*b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright
15*b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer.
16*b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright
17*b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer in the
18*b6cbf720SGianluca Guida *    documentation and/or other materials provided with the distribution.
19*b6cbf720SGianluca Guida * 3. Neither the name of the University nor the names of its contributors
20*b6cbf720SGianluca Guida *    may be used to endorse or promote products derived from this software
21*b6cbf720SGianluca Guida *    without specific prior written permission.
22*b6cbf720SGianluca Guida *
23*b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24*b6cbf720SGianluca Guida * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*b6cbf720SGianluca Guida * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26*b6cbf720SGianluca Guida * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27*b6cbf720SGianluca Guida * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28*b6cbf720SGianluca Guida * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29*b6cbf720SGianluca Guida * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30*b6cbf720SGianluca Guida * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31*b6cbf720SGianluca Guida * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32*b6cbf720SGianluca Guida * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33*b6cbf720SGianluca Guida * SUCH DAMAGE.
34*b6cbf720SGianluca Guida */
35*b6cbf720SGianluca Guida
36*b6cbf720SGianluca Guida#include <machine/asm.h>
37*b6cbf720SGianluca Guida
38*b6cbf720SGianluca Guida#if defined(LIBC_SCCS) && !defined(lint)
39*b6cbf720SGianluca Guida#if 0
40*b6cbf720SGianluca Guida	RCSID("from: @(#)bcmp.s	5.1 (Berkeley) 5/12/90")
41*b6cbf720SGianluca Guida#else
42*b6cbf720SGianluca Guida	RCSID("$NetBSD: memcmp.S,v 1.1 2005/12/20 19:28:49 christos Exp $")
43*b6cbf720SGianluca Guida#endif
44*b6cbf720SGianluca Guida#endif /* LIBC_SCCS and not lint */
45*b6cbf720SGianluca Guida
46*b6cbf720SGianluca Guida/* memcmp(s1, s2, n) */
47*b6cbf720SGianluca Guida
48*b6cbf720SGianluca Guida/*
49*b6cbf720SGianluca Guida * This is probably not the best we can do, but it is still 2-10 times
50*b6cbf720SGianluca Guida * faster than the C version in the portable gen directory.
51*b6cbf720SGianluca Guida *
52*b6cbf720SGianluca Guida * Things that might help:
53*b6cbf720SGianluca Guida *	- longword align when possible (only on the 68020)
54*b6cbf720SGianluca Guida *	- use nested DBcc instructions or use one and limit size to 64K
55*b6cbf720SGianluca Guida */
56*b6cbf720SGianluca GuidaENTRY(memcmp)
57*b6cbf720SGianluca Guida	movl	%sp@(4),%a0		| string 1
58*b6cbf720SGianluca Guida	movl	%sp@(8),%a1		| string 2
59*b6cbf720SGianluca Guida	movl	%sp@(12),%d0		| length
60*b6cbf720SGianluca Guida	jeq	bcdone			| if zero, nothing to do
61*b6cbf720SGianluca Guida	movl	%a0,%d1
62*b6cbf720SGianluca Guida	btst	#0,%d1			| string 1 address odd?
63*b6cbf720SGianluca Guida	jeq	bceven			| no, skip alignment
64*b6cbf720SGianluca Guida	cmpmb	%a0@+,%a1@+		| yes, compare a byte
65*b6cbf720SGianluca Guida	jne	bcnoteq			| not equal, return non-zero
66*b6cbf720SGianluca Guida	subql	#1,%d0			| adjust count
67*b6cbf720SGianluca Guida	jeq	bcdone			| count 0, reutrn zero
68*b6cbf720SGianluca Guidabceven:
69*b6cbf720SGianluca Guida	movl	%a1,%d1
70*b6cbf720SGianluca Guida	btst	#0,%d1			| string 2 address odd?
71*b6cbf720SGianluca Guida	jne	bcbloop			| yes, no hope for alignment, compare bytes
72*b6cbf720SGianluca Guida	movl	%d0,%d1			| no, both even
73*b6cbf720SGianluca Guida	lsrl	#2,%d1			| convert count to longword count
74*b6cbf720SGianluca Guida	jeq	bcbloop			| count 0, skip longword loop
75*b6cbf720SGianluca Guidabclloop:
76*b6cbf720SGianluca Guida	cmpml	%a0@+,%a1@+		| compare a longword
77*b6cbf720SGianluca Guida	jne	bcnoteql		| not equal, return non-zero
78*b6cbf720SGianluca Guida	subql	#1,%d1			| adjust count
79*b6cbf720SGianluca Guida	jne	bclloop			| still more, keep comparing
80*b6cbf720SGianluca Guida	andl	#3,%d0			| what remains
81*b6cbf720SGianluca Guida	jeq	bcdone			| nothing, all done
82*b6cbf720SGianluca Guidabcbloop:
83*b6cbf720SGianluca Guida	cmpmb	%a0@+,%a1@+		| compare a byte
84*b6cbf720SGianluca Guida	jne	bcnoteq			| not equal, return non-zero
85*b6cbf720SGianluca Guida	subql	#1,%d0			| adjust count
86*b6cbf720SGianluca Guida	jne	bcbloop			| still more, keep going
87*b6cbf720SGianluca Guida	rts
88*b6cbf720SGianluca Guidabcnoteql:
89*b6cbf720SGianluca Guida	subql	#4,%a0
90*b6cbf720SGianluca Guida	subql	#4,%a1
91*b6cbf720SGianluca Guida	movl	#4,%d0
92*b6cbf720SGianluca Guida	jra	bcbloop
93*b6cbf720SGianluca Guidabcnoteq:
94*b6cbf720SGianluca Guida	clrl	%d0
95*b6cbf720SGianluca Guida	clrl	%d1
96*b6cbf720SGianluca Guida	movb	%a0@-,%d0
97*b6cbf720SGianluca Guida	movb	%a1@-,%d1
98*b6cbf720SGianluca Guida	subl	%d1,%d0
99*b6cbf720SGianluca Guidabcdone:
100*b6cbf720SGianluca Guida	rts
101