1 /* strrchr: find the last instance of a character in a string.
3 Copyright (C) 2014-2020 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library. If not, see
19 <https://www.gnu.org/licenses/>. */
30 /* Arguments and results. */
55 For each 16-byte chunk we calculate a 64-bit syndrome value, with
56 four bits per byte (LSB is always in bits 0 and 1, for both big
57 and little-endian systems). For each tuple, bits 0-1 are set if
58 the relevant byte matched the requested character; bits 2-3 are set
59 if the relevant byte matched the NUL end of string. */
64 dup vrepchr.16b, chrin
70 ld1 {vdata.16b}, [src], 16
71 cmeq vhas_nul.16b, vdata.16b, 0
72 cmeq vhas_chr.16b, vdata.16b, vrepchr.16b
74 dup vrepmask2.8h, wtmp
75 bit vhas_nul.16b, vhas_chr.16b, vrepmask.16b
76 and vhas_nul.16b, vhas_nul.16b, vrepmask2.16b
77 addp vend.16b, vhas_nul.16b, vhas_nul.16b
82 ands nul_match, synd, 0xcccccccccccccccc
88 ld1 {vdata.16b}, [src], 16
89 cmeq vhas_chr.16b, vdata.16b, vrepchr.16b
90 cmhs vhas_nul.16b, vhas_chr.16b, vdata.16b
91 umaxp vend.16b, vhas_nul.16b, vhas_nul.16b
95 cmeq vhas_nul.16b, vdata.16b, 0
96 bit vhas_nul.16b, vhas_chr.16b, vrepmask.16b
97 bic vhas_nul.8h, 0x0f, lsl 8
98 addp vend.16b, vhas_nul.16b, vhas_nul.16b
100 ands nul_match, synd, 0xcccccccccccccccc
104 sub nul_match, nul_match, 1
105 and chr_match, synd, 0x3333333333333333
106 ands chr_match, chr_match, nul_match
109 sub result, result, tmp, lsr 2
110 csel result, result, xzr, ne
116 csel src_match, src, src_match, ne
117 csel chr_match, synd, chr_match, ne
118 ld1 {vdata.16b}, [src], 16
119 cmeq vhas_nul.16b, vdata.16b, 0
120 cmeq vhas_chr.16b, vdata.16b, vrepchr.16b
121 bit vhas_nul.16b, vhas_chr.16b, vrepmask.16b
122 umaxp vend.16b, vhas_nul.16b, vhas_nul.16b
124 tst synd, 0xcccccccccccccccc
127 bic vhas_nul.8h, 0x0f, lsl 8
128 addp vend.16b, vhas_nul.16b, vhas_nul.16b
130 and nul_match, synd, 0xcccccccccccccccc
131 sub nul_match, nul_match, 1
132 and tmp, synd, 0x3333333333333333
133 ands tmp, tmp, nul_match
134 csel chr_match, tmp, chr_match, ne
135 csel src_match, src, src_match, ne
136 sub src_match, src_match, 1
138 sub result, src_match, tmp, lsr 2
142 weak_alias (strrchr, rindex)
143 libc_hidden_builtin_def (strrchr)