xref: /minix3/common/lib/libc/arch/arm/string/strncmp.S (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc/*      $NetBSD: strncmp.S,v 1.2 2013/08/19 00:57:25 matt Exp $ */
2b6cbf720SGianluca Guida
3b6cbf720SGianluca Guida/*
4b6cbf720SGianluca Guida * Copyright (c) 2002 ARM Ltd
5b6cbf720SGianluca Guida * All rights reserved.
6b6cbf720SGianluca Guida *
7b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without
8b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions
9b6cbf720SGianluca Guida * are met:
10b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright
11b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer.
12b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright
13b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer in the
14b6cbf720SGianluca Guida *    documentation and/or other materials provided with the distribution.
15b6cbf720SGianluca Guida * 3. The name of the company may not be used to endorse or promote
16b6cbf720SGianluca Guida *    products derived from this software without specific prior written
17b6cbf720SGianluca Guida *    permission.
18b6cbf720SGianluca Guida *
19b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
20b6cbf720SGianluca Guida * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21b6cbf720SGianluca Guida * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22b6cbf720SGianluca Guida * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23b6cbf720SGianluca Guida * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24b6cbf720SGianluca Guida * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25b6cbf720SGianluca Guida * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26b6cbf720SGianluca Guida * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27b6cbf720SGianluca Guida * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28b6cbf720SGianluca Guida * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29b6cbf720SGianluca Guida */
30b6cbf720SGianluca Guida
31b6cbf720SGianluca Guida#include <machine/asm.h>
32b6cbf720SGianluca Guida
33*84d9c625SLionel SambucRCSID("$NetBSD: strncmp.S,v 1.2 2013/08/19 00:57:25 matt Exp $")
34b6cbf720SGianluca Guida
35b6cbf720SGianluca GuidaENTRY(strncmp)
36b6cbf720SGianluca Guida/* if ((len - 1) < 0) return 0 */
37b6cbf720SGianluca Guida	subs	r2, r2, #1
38*84d9c625SLionel Sambuc#ifdef __thumb__
39*84d9c625SLionel Sambuc	bmi	5f
40*84d9c625SLionel Sambuc#else
41b6cbf720SGianluca Guida	movmi	r0, #0
42b6cbf720SGianluca Guida	RETc(mi)
43*84d9c625SLionel Sambuc#endif
44b6cbf720SGianluca Guida
45b6cbf720SGianluca Guida/* ip == last src address to compare */
46*84d9c625SLionel Sambuc#ifdef __thumb__
47*84d9c625SLionel Sambuc	adds	r3, r0, r2
48*84d9c625SLionel Sambuc	mov	ip, r3
49*84d9c625SLionel Sambuc	subs	r1, r1, r0
50*84d9c625SLionel Sambuc#else
51b6cbf720SGianluca Guida	add	ip, r0, r2
52*84d9c625SLionel Sambuc#endif
53b6cbf720SGianluca Guida1:
54*84d9c625SLionel Sambuc#ifdef __thumb__
55*84d9c625SLionel Sambuc	ldrb	r2, [r0]
56*84d9c625SLionel Sambuc	ldrb	r3, [r1, r0]
57*84d9c625SLionel Sambuc	adds	r0, r0, #1
58*84d9c625SLionel Sambuc	cmp	ip, r0		/* exhausted length? */
59*84d9c625SLionel Sambuc	bcc	4f		/*   yes, we're done */
60*84d9c625SLionel Sambuc	cmp	r2, #1		/* NUL? */
61*84d9c625SLionel Sambuc	bcc	4f		/*   yes, we're done */
62*84d9c625SLionel Sambuc	cmp	r2, r3		/* different? */
63*84d9c625SLionel Sambuc#else
64b6cbf720SGianluca Guida	ldrb	r2, [r0], #1
65b6cbf720SGianluca Guida	ldrb	r3, [r1], #1
66b6cbf720SGianluca Guida	cmp	ip, r0
67b6cbf720SGianluca Guida	cmpcs	r2, #1
68b6cbf720SGianluca Guida	cmpcs	r2, r3
69*84d9c625SLionel Sambuc#endif
70b6cbf720SGianluca Guida	beq	1b
71*84d9c625SLionel Sambuc4:	subs	r0, r2, r3
72b6cbf720SGianluca Guida	RET
73*84d9c625SLionel Sambuc#ifdef __thumb__
74*84d9c625SLionel Sambuc5:	movs	r0, #0
75*84d9c625SLionel Sambuc	RET
76*84d9c625SLionel Sambuc#endif
77*84d9c625SLionel SambucEND(strncmp)
78