]>
Commit | Line | Data |
---|---|---|
568035b7 | 1 | /* Copyright (C) 2011-2013 Free Software Foundation, Inc. |
63d143a2 CM |
2 | This file is part of the GNU C Library. |
3 | Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. | |
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 | |
ab84e3ff PE |
16 | License along with the GNU C Library. If not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
63d143a2 CM |
18 | |
19 | /* Provide a mask based on the pointer alignment that | |
20 | sets up non-zero bytes before the beginning of the string. | |
21 | The MASK expression works because shift counts are taken mod 64. | |
22 | Also, specify how to count "first" and "last" bits | |
23 | when the bits have been read as a word. */ | |
24 | ||
e054f494 RA |
25 | #include <stdint.h> |
26 | ||
63d143a2 CM |
27 | #ifndef __BIG_ENDIAN__ |
28 | #define MASK(x) (__insn_shl(1ULL, (x << 3)) - 1) | |
29 | #define NULMASK(x) ((2ULL << x) - 1) | |
30 | #define CFZ(x) __insn_ctz(x) | |
31 | #define REVCZ(x) __insn_clz(x) | |
32 | #else | |
33 | #define MASK(x) (__insn_shl(-2LL, ((-x << 3) - 1))) | |
34 | #define NULMASK(x) (-2LL << (63 - x)) | |
35 | #define CFZ(x) __insn_clz(x) | |
36 | #define REVCZ(x) __insn_ctz(x) | |
37 | #endif | |
64d76ca0 CM |
38 | |
39 | /* Create eight copies of the byte in a uint64_t. */ | |
40 | static inline uint64_t copy_byte(uint8_t byte) | |
41 | { | |
42 | uint64_t word = byte; | |
43 | word = __insn_bfins(word, word, 8, 15); | |
44 | word = __insn_bfins(word, word, 16, 31); | |
45 | word = __insn_bfins(word, word, 32, 63); | |
46 | return word; | |
47 | } |