blob: 26d419f7c6d1acd15cc5078136764f8f05346fca [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* memchr.S
2 * Copyright (C) 2003-2007 Analog Devices Inc., All Rights Reserved.
3 *
4 * This file is subject to the terms and conditions of the GNU Library General
5 * Public License. See the file "COPYING.LIB" in the main directory of this
6 * archive for more details.
7 *
8 * Non-LGPL License also available as part of VisualDSP++
9 * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html
10 */
11
12#include <sysdep.h>
13
14/* void *memchr(const void *s, int c, size_t n);
15 * R0 = address (s)
16 * R1 = sought byte (c)
17 * R2 = count (n)
18 *
19 * Returns pointer to located character.
20 */
21
22.text
23
24.align 2
25
26.weak _memchr
27ENTRY(_memchr)
28 P0 = R0; /* P0 = address */
29 P2 = R2; /* P2 = count */
30 R1 = R1.B(Z);
31 CC = R2 == 0;
32 IF CC JUMP .Lfailed;
33
34.Lbytes:
35 LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2;
36
37.Lbyte_loop_s:
38 R3 = B[P0++](Z);
39 CC = R3 == R1;
40 IF CC JUMP .Lfound;
41.Lbyte_loop_e:
42 NOP;
43
44.Lfailed:
45 R0=0;
46 RTS;
47
48.Lfound:
49 R0 = P0;
50 R0 += -1;
51 RTS;
52
53.size _memchr,.-_memchr
54
55libc_hidden_def (memchr)