initial commit
[glibc.git] / sysdeps / s390 / memchr-z900.S
1 /* Search a character in a block of memory. 31/64 bit S/390 version.
2 Copyright (C) 2001-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 /* INPUT PARAMETERS
20 %r2 = address to memory area
21 %r3 = character to find
22 %r4 = number of bytes to search. */
23
24 #include <ifunc-memchr.h>
25 #include "sysdep.h"
26 #include "asm-syntax.h"
27
28 #if HAVE_MEMCHR_Z900_G5
29 # if defined __s390x__
30 # define SLGR slgr
31 # define LGHI lghi
32 # define NGR ngr
33 # define LGR lgr
34 # else
35 # define SLGR slr
36 # define LGHI lhi
37 # define NGR nr
38 # define LGR lr
39 # endif /* ! defined __s390x__ */
40
41 .text
42 ENTRY(MEMCHR_Z900_G5)
43 LGHI %r0,0xff
44 NGR %r0,%r3
45 LGR %r1,%r2
46 # if ! defined __s390x__
47 tmlh %r4,32768
48 jo 3f /* Jump away if n >= 0x80000000 */
49 # endif
50 la %r2,0(%r4,%r1)
51 0: srst %r2,%r1
52 jo 0b
53 brc 13,1f
54 SLGR %r2,%r2
55 1: br %r14
56 # if ! defined __s390x__
57 /* On s390 (31bit), the pointer to the first byte after s (stored in
58 r2) always wraps around with n >= 0x80000000 and can lead to stop
59 searching before end of s. Thus just use r2=0 in this case.
60 If r2 < r1, the srst instruction stops searching with cc=2 "not
61 found" when wrapping around from top address to zero. */
62 3: SLGR %r2,%r2
63 j 0b
64 # endif
65 END(MEMCHR_Z900_G5)
66
67 # if ! HAVE_MEMCHR_IFUNC
68 strong_alias (MEMCHR_Z900_G5, __memchr)
69 weak_alias (__memchr, memchr)
70 # endif
71
72 # if defined SHARED && IS_IN (libc)
73 strong_alias (MEMCHR_Z900_G5, __GI_memchr)
74 # endif
75 #endif