xref: /freebsd/lib/libc/arm/string/strncmp.S (revision 96cdb0ab9d6d89d47c14f239933391a1f7d465c7)
12357939bSOlivier Houchard/*      $NetBSD: strncmp.S,v 1.2 2003/04/05 23:08:52 bjh21 Exp $ */
22357939bSOlivier Houchard
32357939bSOlivier Houchard/*
42357939bSOlivier Houchard * Copyright (c) 2002 ARM Ltd
52357939bSOlivier Houchard * All rights reserved.
62357939bSOlivier Houchard *
72357939bSOlivier Houchard * Redistribution and use in source and binary forms, with or without
82357939bSOlivier Houchard * modification, are permitted provided that the following conditions
92357939bSOlivier Houchard * are met:
102357939bSOlivier Houchard * 1. Redistributions of source code must retain the above copyright
112357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer.
122357939bSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright
132357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer in the
142357939bSOlivier Houchard *    documentation and/or other materials provided with the distribution.
152357939bSOlivier Houchard * 3. The name of the company may not be used to endorse or promote
162357939bSOlivier Houchard *    products derived from this software without specific prior written
172357939bSOlivier Houchard *    permission.
182357939bSOlivier Houchard *
192357939bSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
202357939bSOlivier Houchard * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
212357939bSOlivier Houchard * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
222357939bSOlivier Houchard * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
232357939bSOlivier Houchard * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
242357939bSOlivier Houchard * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
252357939bSOlivier Houchard * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
262357939bSOlivier Houchard * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
272357939bSOlivier Houchard * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
282357939bSOlivier Houchard * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292357939bSOlivier Houchard */
302357939bSOlivier Houchard
312357939bSOlivier Houchard#include <machine/asm.h>
322357939bSOlivier Houchard
332357939bSOlivier Houchard__FBSDID("$FreeBSD$");
342357939bSOlivier Houchard
352357939bSOlivier HouchardENTRY(strncmp)
36aa79fe24SStanislav Sedov/* if (len == 0) return 0 */
37aa79fe24SStanislav Sedov	cmp	r2, #0
386c5bc49cSAndrew Turner	itt	eq
39aa79fe24SStanislav Sedov	moveq	r0, #0
40aa79fe24SStanislav Sedov	moveq	pc, lr
412357939bSOlivier Houchard
422357939bSOlivier Houchard/* ip == last src address to compare */
43aa79fe24SStanislav Sedov	adds	ip, r0, r2
44aa79fe24SStanislav Sedov/* Use last possible address on overflow. */
456c5bc49cSAndrew Turner	it	cs
46aa79fe24SStanislav Sedov	movcs	ip, #0
47c61860f8SStanislav Sedov	sub	ip, ip, #1
482357939bSOlivier Houchard1:
492357939bSOlivier Houchard	ldrb	r2, [r0], #1
502357939bSOlivier Houchard	ldrb	r3, [r1], #1
512357939bSOlivier Houchard	cmp	ip, r0
526c5bc49cSAndrew Turner	itt	cs
532357939bSOlivier Houchard	cmpcs	r2, #1
542357939bSOlivier Houchard	cmpcs	r2, r3
552357939bSOlivier Houchard	beq	1b
562357939bSOlivier Houchard	sub	r0, r2, r3
5731489a9aSOlivier Houchard	RET
58f2e71517SIan LeporeEND(strncmp)
59*96cdb0abSKonstantin Belousov
60*96cdb0abSKonstantin Belousov	.section .note.GNU-stack,"",%progbits
61