xref: /netbsd-src/common/lib/libc/arch/m68k/string/strncmp.S (revision 18ec38ea7c8331c5bc28d877de4a5b1391957c39)
1*18ec38eaSchs/*	$NetBSD: strncmp.S,v 1.7 2013/09/07 19:06:29 chs Exp $	*/
237c9f0a6Schristos
337c9f0a6Schristos/*-
437c9f0a6Schristos * Copyright (c) 1997 The NetBSD Foundation, Inc.
537c9f0a6Schristos * All rights reserved.
637c9f0a6Schristos *
737c9f0a6Schristos * This code is derived from software contributed to The NetBSD Foundation
837c9f0a6Schristos * by Hiroshi Horimoto <horimoto@cs-aoi.cs.sist.ac.jp> and
937c9f0a6Schristos * by J.T. Conklin <jtc@NetBSD.org>.
1037c9f0a6Schristos *
1137c9f0a6Schristos * Redistribution and use in source and binary forms, with or without
1237c9f0a6Schristos * modification, are permitted provided that the following conditions
1337c9f0a6Schristos * are met:
1437c9f0a6Schristos * 1. Redistributions of source code must retain the above copyright
1537c9f0a6Schristos *    notice, this list of conditions and the following disclaimer.
1637c9f0a6Schristos * 2. Redistributions in binary form must reproduce the above copyright
1737c9f0a6Schristos *    notice, this list of conditions and the following disclaimer in the
1837c9f0a6Schristos *    documentation and/or other materials provided with the distribution.
1937c9f0a6Schristos *
2037c9f0a6Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2137c9f0a6Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2237c9f0a6Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2337c9f0a6Schristos * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2437c9f0a6Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2537c9f0a6Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2637c9f0a6Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2737c9f0a6Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2837c9f0a6Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2937c9f0a6Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3037c9f0a6Schristos * POSSIBILITY OF SUCH DAMAGE.
3137c9f0a6Schristos */
3237c9f0a6Schristos
3337c9f0a6Schristos#include <machine/asm.h>
3437c9f0a6Schristos
3537c9f0a6Schristos#if defined(LIBC_SCCS) && !defined(lint)
36*18ec38eaSchs	RCSID("$NetBSD: strncmp.S,v 1.7 2013/09/07 19:06:29 chs Exp $")
3737c9f0a6Schristos#endif /* LIBC_SCCS and not lint */
3837c9f0a6Schristos
391d398a17Smatt
401d398a17Smatt#ifdef __mcoldfire__
411d398a17Smatt#define GETC(a,b)	mvsb	a,b
421d398a17Smatt#define	SUBC(a,b)	mvsb	a,%d2; subl %d2,b
431d398a17Smatt#else
441d398a17Smatt#define GETC(a,b)	movb	a,b
451d398a17Smatt#define	SUBC(a,b)	subb	a,b
461d398a17Smatt#endif
471d398a17Smatt
4837c9f0a6SchristosENTRY(strncmp)
4907a0a325Smatt	movl	12(%sp),%d0
50*18ec38eaSchs	jeq	.L4
5107a0a325Smatt	movl	4(%sp),%a0
5207a0a325Smatt	movl	8(%sp),%a1
53cb2ad9b1Smatt#ifdef __coldfire__
541d398a17Smatt	movl	%d2,-(%sp)	| save temp
55cb2ad9b1Smatt#endif
56*18ec38eaSchs.L1:				/* unroll by 4 for m680[23]0's */
571d398a17Smatt	GETC((%a0)+,%d1)
58*18ec38eaSchs	jeq	.L2
591d398a17Smatt	SUBC((%a1)+,%d1)
60*18ec38eaSchs	jne	.L3
6137c9f0a6Schristos	subql	#1,%d0
62*18ec38eaSchs	jeq	.L4
6337c9f0a6Schristos
641d398a17Smatt	GETC((%a0)+,%d1)
65*18ec38eaSchs	jeq	.L2
661d398a17Smatt	SUBC((%a1)+,%d1)
67*18ec38eaSchs	jne	.L3
6837c9f0a6Schristos	subql	#1,%d0
69*18ec38eaSchs	jeq	.L4
7037c9f0a6Schristos
711d398a17Smatt	GETC((%a0)+,%d1)
72*18ec38eaSchs	jeq	.L2
731d398a17Smatt	SUBC((%a1)+,%d1)
74*18ec38eaSchs	jne	.L3
7537c9f0a6Schristos	subql	#1,%d0
76*18ec38eaSchs	jeq	.L4
7737c9f0a6Schristos
781d398a17Smatt	GETC((%a0)+,%d1)
79*18ec38eaSchs	jeq	.L2
801d398a17Smatt	SUBC((%a1)+,%d1)
81*18ec38eaSchs	jne	.L3
8237c9f0a6Schristos	subql	#1,%d0
83*18ec38eaSchs	jne	.L1
841d398a17Smatt#ifdef __mcoldfire__
851d398a17Smatt	movl	(%sp)+,%d2		| restore temp
861d398a17Smatt#endif
87*18ec38eaSchs.L4:	rts
8837c9f0a6Schristos
89*18ec38eaSchs.L2:	SUBC((%a1),%d1)
90*18ec38eaSchs.L3:
911d398a17Smatt#ifdef __mcoldfire__
921d398a17Smatt	movl	(%sp)+,%d2		| restore temp
931d398a17Smatt	movl	%d1,%d0
94cb2ad9b1Smatt#else
95cb2ad9b1Smatt	scs	%d0
96cb2ad9b1Smatt	EXTBL(%d0)
97cb2ad9b1Smatt	moveb	%d1,%d0
98cb2ad9b1Smatt#endif
9937c9f0a6Schristos	rts
10065726debSmattEND(strncmp)
101