xref: /openbsd-src/lib/libc/arch/arm/string/strncmp.S (revision 3884871817cb6c13555e7e8b09d51aa7e2b64045)
1*38848718Sguenther/*	$OpenBSD: strncmp.S,v 1.6 2016/08/06 19:16:09 guenther Exp $	*/
2d987040fSdrahn/*      $NetBSD: strncmp.S,v 1.2 2003/04/05 23:08:52 bjh21 Exp $ */
3d987040fSdrahn
4d987040fSdrahn/*
5d987040fSdrahn * Copyright (c) 2002 ARM Ltd
6d987040fSdrahn * All rights reserved.
7d987040fSdrahn *
8d987040fSdrahn * Redistribution and use in source and binary forms, with or without
9d987040fSdrahn * modification, are permitted provided that the following conditions
10d987040fSdrahn * are met:
11d987040fSdrahn * 1. Redistributions of source code must retain the above copyright
12d987040fSdrahn *    notice, this list of conditions and the following disclaimer.
13d987040fSdrahn * 2. Redistributions in binary form must reproduce the above copyright
14d987040fSdrahn *    notice, this list of conditions and the following disclaimer in the
15d987040fSdrahn *    documentation and/or other materials provided with the distribution.
16d987040fSdrahn * 3. The name of the company may not be used to endorse or promote
17d987040fSdrahn *    products derived from this software without specific prior written
18d987040fSdrahn *    permission.
19d987040fSdrahn *
20d987040fSdrahn * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
21d987040fSdrahn * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22d987040fSdrahn * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23d987040fSdrahn * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24d987040fSdrahn * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25d987040fSdrahn * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26d987040fSdrahn * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27d987040fSdrahn * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28d987040fSdrahn * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29d987040fSdrahn * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30d987040fSdrahn */
31d987040fSdrahn
32*38848718Sguenther#include "DEFS.h"
33d987040fSdrahn
34d987040fSdrahnENTRY(strncmp)
35951d8da3Sdrahn/* if (len == 0) return 0 */
36951d8da3Sdrahn	cmp	r2, #0
37951d8da3Sdrahn	moveq	r0, #0
38951d8da3Sdrahn	moveq	pc, lr
39951d8da3Sdrahn
40951d8da3Sdrahn/* subtract one to have the index of the last character to check */
41951d8da3Sdrahn	sub	r2, r2, #1
42d987040fSdrahn
43d987040fSdrahn/* ip == last src address to compare */
44d987040fSdrahn	add	ip, r0, r2
45d987040fSdrahn1:
46d987040fSdrahn	ldrb	r2, [r0], #1
47d987040fSdrahn	ldrb	r3, [r1], #1
48d987040fSdrahn	cmp	ip, r0
49d987040fSdrahn	cmpcs	r2, #1
50d987040fSdrahn	cmpcs	r2, r3
51d987040fSdrahn	beq	1b
52d987040fSdrahn	sub	r0, r2, r3
53d987040fSdrahn	mov	pc, lr
549b9d2a55SguentherEND_STRONG(strncmp)
55