xref: /minix3/common/lib/libc/arch/m68k/string/strncmp.S (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc/*	$NetBSD: strncmp.S,v 1.7 2013/09/07 19:06:29 chs Exp $	*/
2b6cbf720SGianluca Guida
3b6cbf720SGianluca Guida/*-
4b6cbf720SGianluca Guida * Copyright (c) 1997 The NetBSD Foundation, Inc.
5b6cbf720SGianluca Guida * All rights reserved.
6b6cbf720SGianluca Guida *
7b6cbf720SGianluca Guida * This code is derived from software contributed to The NetBSD Foundation
8b6cbf720SGianluca Guida * by Hiroshi Horimoto <horimoto@cs-aoi.cs.sist.ac.jp> and
9b6cbf720SGianluca Guida * by J.T. Conklin <jtc@NetBSD.org>.
10b6cbf720SGianluca Guida *
11b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without
12b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions
13b6cbf720SGianluca Guida * are met:
14b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright
15b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer.
16b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright
17b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer in the
18b6cbf720SGianluca Guida *    documentation and/or other materials provided with the distribution.
19b6cbf720SGianluca Guida *
20b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21b6cbf720SGianluca Guida * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22b6cbf720SGianluca Guida * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23b6cbf720SGianluca Guida * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24b6cbf720SGianluca Guida * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25b6cbf720SGianluca Guida * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26b6cbf720SGianluca Guida * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27b6cbf720SGianluca Guida * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28b6cbf720SGianluca Guida * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29b6cbf720SGianluca Guida * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30b6cbf720SGianluca Guida * POSSIBILITY OF SUCH DAMAGE.
31b6cbf720SGianluca Guida */
32b6cbf720SGianluca Guida
33b6cbf720SGianluca Guida#include <machine/asm.h>
34b6cbf720SGianluca Guida
35b6cbf720SGianluca Guida#if defined(LIBC_SCCS) && !defined(lint)
36*84d9c625SLionel Sambuc	RCSID("$NetBSD: strncmp.S,v 1.7 2013/09/07 19:06:29 chs Exp $")
37b6cbf720SGianluca Guida#endif /* LIBC_SCCS and not lint */
38b6cbf720SGianluca Guida
39*84d9c625SLionel Sambuc
40*84d9c625SLionel Sambuc#ifdef __mcoldfire__
41*84d9c625SLionel Sambuc#define GETC(a,b)	mvsb	a,b
42*84d9c625SLionel Sambuc#define	SUBC(a,b)	mvsb	a,%d2; subl %d2,b
43*84d9c625SLionel Sambuc#else
44*84d9c625SLionel Sambuc#define GETC(a,b)	movb	a,b
45*84d9c625SLionel Sambuc#define	SUBC(a,b)	subb	a,b
46*84d9c625SLionel Sambuc#endif
47*84d9c625SLionel Sambuc
48b6cbf720SGianluca GuidaENTRY(strncmp)
49*84d9c625SLionel Sambuc	movl	12(%sp),%d0
50*84d9c625SLionel Sambuc	jeq	.L4
51*84d9c625SLionel Sambuc	movl	4(%sp),%a0
52*84d9c625SLionel Sambuc	movl	8(%sp),%a1
53*84d9c625SLionel Sambuc#ifdef __coldfire__
54*84d9c625SLionel Sambuc	movl	%d2,-(%sp)	| save temp
55*84d9c625SLionel Sambuc#endif
56*84d9c625SLionel Sambuc.L1:				/* unroll by 4 for m680[23]0's */
57*84d9c625SLionel Sambuc	GETC((%a0)+,%d1)
58*84d9c625SLionel Sambuc	jeq	.L2
59*84d9c625SLionel Sambuc	SUBC((%a1)+,%d1)
60*84d9c625SLionel Sambuc	jne	.L3
61b6cbf720SGianluca Guida	subql	#1,%d0
62*84d9c625SLionel Sambuc	jeq	.L4
63b6cbf720SGianluca Guida
64*84d9c625SLionel Sambuc	GETC((%a0)+,%d1)
65*84d9c625SLionel Sambuc	jeq	.L2
66*84d9c625SLionel Sambuc	SUBC((%a1)+,%d1)
67*84d9c625SLionel Sambuc	jne	.L3
68b6cbf720SGianluca Guida	subql	#1,%d0
69*84d9c625SLionel Sambuc	jeq	.L4
70b6cbf720SGianluca Guida
71*84d9c625SLionel Sambuc	GETC((%a0)+,%d1)
72*84d9c625SLionel Sambuc	jeq	.L2
73*84d9c625SLionel Sambuc	SUBC((%a1)+,%d1)
74*84d9c625SLionel Sambuc	jne	.L3
75b6cbf720SGianluca Guida	subql	#1,%d0
76*84d9c625SLionel Sambuc	jeq	.L4
77b6cbf720SGianluca Guida
78*84d9c625SLionel Sambuc	GETC((%a0)+,%d1)
79*84d9c625SLionel Sambuc	jeq	.L2
80*84d9c625SLionel Sambuc	SUBC((%a1)+,%d1)
81*84d9c625SLionel Sambuc	jne	.L3
82b6cbf720SGianluca Guida	subql	#1,%d0
83*84d9c625SLionel Sambuc	jne	.L1
84*84d9c625SLionel Sambuc#ifdef __mcoldfire__
85*84d9c625SLionel Sambuc	movl	(%sp)+,%d2		| restore temp
86*84d9c625SLionel Sambuc#endif
87*84d9c625SLionel Sambuc.L4:	rts
88b6cbf720SGianluca Guida
89*84d9c625SLionel Sambuc.L2:	SUBC((%a1),%d1)
90*84d9c625SLionel Sambuc.L3:
91*84d9c625SLionel Sambuc#ifdef __mcoldfire__
92*84d9c625SLionel Sambuc	movl	(%sp)+,%d2		| restore temp
93*84d9c625SLionel Sambuc	movl	%d1,%d0
94*84d9c625SLionel Sambuc#else
95*84d9c625SLionel Sambuc	scs	%d0
96b6cbf720SGianluca Guida	EXTBL(%d0)
97*84d9c625SLionel Sambuc	moveb	%d1,%d0
98*84d9c625SLionel Sambuc#endif
99b6cbf720SGianluca Guida	rts
100*84d9c625SLionel SambucEND(strncmp)
101