Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / tile / tilegx / string-endian.h
blob0c4d51766d70107c662fa8d433820f6cf4f902c7
1 /* Copyright (C) 2011-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
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/>. */
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. */
25 #include <stdint.h>
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
39 /* Create eight copies of the byte in a uint64_t. */
40 static inline uint64_t copy_byte(uint8_t byte)
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;