1 /* string-fzi.h -- zero byte detection; indices. Alpha version.
2 Copyright (C) 2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <http://www.gnu.org/licenses/>. */
23 #include <string-optype.h>
24 #include <string-fza.h>
26 /* Note that since CMPBGE creates a bit mask rather than a byte mask,
27 we cannot simply provide a target-specific string-fza.h. */
29 /* A subroutine for the index_zero functions. Given a bitmask C,
30 return the index of the first bit set in memory order. */
31 static __always_inline
unsigned int
32 index_first (find_t c
)
35 return __builtin_ctzl (c
);
38 return (c
& 0xf0 ? 4 : 0) + (c
& 0xcc ? 2 : 0) + (c
& 0xaa ? 1 : 0);
42 /* Similarly, but return the (memory order) index of the last bit
43 that is non-zero. Note that only the least 8 bits may be nonzero. */
45 static __always_inline
unsigned int
49 return __builtin_clzl (x
) ^ 63;
62 #endif /* _STRING_FZI_H */