MIPSr6/math: Use builtin fma and fmaf
[glibc.git] / string / strchrnul.c
blobf64d52ea6750106249f200fa49086d85f99dea7f
1 /* Copyright (C) 1991-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <libc-pointer-arith.h>
19 #include <string-fzb.h>
20 #include <string-fzc.h>
21 #include <string-fzi.h>
22 #include <string-shift.h>
23 #include <string.h>
25 #undef __strchrnul
26 #undef strchrnul
28 #ifdef STRCHRNUL
29 # define __strchrnul STRCHRNUL
30 #endif
32 /* Find the first occurrence of C in S or the final NUL byte. */
33 char *
34 __strchrnul (const char *str, int c_in)
36 /* Align pointer to sizeof op_t. */
37 uintptr_t s_int = (uintptr_t) str;
38 const op_t *word_ptr = (const op_t *) PTR_ALIGN_DOWN (str, sizeof (op_t));
40 op_t repeated_c = repeat_bytes (c_in);
42 op_t word = *word_ptr;
43 find_t mask = shift_find (find_zero_eq_all (word, repeated_c), s_int);
44 if (mask != 0)
45 return (char *) str + index_first (mask);
48 word = *++word_ptr;
49 while (! has_zero_eq (word, repeated_c));
51 return (char *) word_ptr + index_first_zero_eq (word, repeated_c);
53 #ifndef STRCHRNUL
54 libc_hidden_def (__strchrnul)
55 weak_alias (__strchrnul, strchrnul)
56 #endif